dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / oamuser / lib / vgroup.c
blob2e33f9ad640f16959cf7f60436ba7aaf54adb3e4
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
33 /*LINTLIBRARY*/
35 #include <sys/types.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <errno.h>
40 #include <limits.h>
41 #include <sys/param.h>
42 #include <users.h>
43 #include <userdefs.h>
45 extern int valid_gid(gid_t, struct group **);
47 static int isalldigit(char *);
50 * validate a group name or number and return the appropriate
51 * group structure for it.
53 int
54 valid_group(char *group, struct group **gptr, int *warning)
56 int r, warn;
57 long l;
58 char *ptr;
59 struct group *grp;
61 *warning = 0;
63 if (!isalldigit(group))
64 return (valid_gname(group, gptr, warning));
67 * There are only digits in group name.
68 * strtol() doesn't return negative number here.
70 errno = 0;
71 l = strtol(group, &ptr, 10);
72 if ((l == LONG_MAX && errno == ERANGE) || l > MAXUID) {
73 r = TOOBIG;
74 } else {
75 if ((r = valid_gid((gid_t)l, &grp)) == NOTUNIQUE) {
76 /* It is a valid existing gid */
77 if (gptr != NULL)
78 *gptr = grp;
79 return (NOTUNIQUE);
83 * It's all digit, but not a valid gid nor an existing gid.
84 * There might be an existing group name of all digits.
86 if (valid_gname(group, &grp, &warn) == NOTUNIQUE) {
87 /* It does exist */
88 *warning = warn;
89 if (gptr != NULL)
90 *gptr = grp;
91 return (NOTUNIQUE);
94 * It isn't either existing gid or group name. We return the
95 * error code from valid_gid() assuming that given string
96 * represents an integer GID.
98 return (r);
101 static int
102 isalldigit(char *str)
104 while (*str != '\0') {
105 if (!isdigit((unsigned char)*str))
106 return (0);
107 str++;
109 return (1);