2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29
30 #pragma ident "%Z%%M% %I% %E% SMI"
31
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <pwd.h>
40 #include <errno.h>
41 #include <locale.h>
42 #include <limits.h>
43
44 #define BADLINE "Too many/few fields"
45 #define TOOLONG "Line too long"
46 #define NONAME "No group name"
47 #define BADNAME "Bad character(s) in group name"
48 #define BADGID "Invalid GID"
49 #define NULLNAME "Null login name"
50 #define NOTFOUND "Logname not found in password file"
51 #define DUPNAME "Duplicate logname entry"
52 #define DUPNAME2 "Duplicate logname entry (gid first occurs in passwd entry)"
53 #define NOMEM "Out of memory"
54 #define NGROUPS "Maximum groups exceeded for logname "
55 #define BLANKLINE "Blank line detected. Please remove line"
56 #define LONGNAME "Group name too long"
57
58 int eflag, badchar, baddigit, badlognam, colons, len;
59 static int longnam = 0;
60 int code;
61
62 #define MYBUFSIZE (LINE_MAX) /* max line length including newline and null */
63 #define NUM_COLONS 3
64
65 char *buf;
66 char *nptr;
67 char *cptr;
68 FILE *fptr;
69 gid_t gid;
70 void error(char *msg);
71
72 struct group {
73 struct group *nxt;
74 int cnt;
75 gid_t grp;
76 };
77
230 for (i = 0; buf[i] != NULL; i++) {
231 if (buf[i] == ':') {
232 delim[colons] = i;
233 if (++colons > NUM_COLONS)
234 break;
235 }
236 }
237 if (colons != NUM_COLONS) {
238 error(BADLINE);
239 free(tmpbuf);
240 continue;
241 }
242
243 /* check to see that group name is at least 1 character */
244 /* and that all characters are lowrcase or digits. */
245
246 if (buf[0] == ':')
247 error(NONAME);
248 else {
249 for (i = 0; buf[i] != ':'; i++) {
250 if (i >= LOGNAME_MAX)
251 longnam++;
252 if (!(islower(buf[i]) || isdigit(buf[i])))
253 badchar++;
254 }
255 if (longnam > 0)
256 error(LONGNAME);
257 if (badchar > 0)
258 error(BADNAME);
259 }
260
261 /* check that GID is numeric and <= 31 bits */
262
263 len = (delim[2] - delim[1]) - 1;
264
265 if (len > 10 || len < 1)
266 error(BADGID);
267 else {
268 for (i = (delim[1]+1); i < delim[2]; i++) {
269 if (! (isdigit(buf[i])))
270 baddigit++;
|
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2013 Gary Mills
23 *
24 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <pwd.h>
40 #include <errno.h>
41 #include <locale.h>
42 #include <limits.h>
43
44 #define BADLINE "Too many/few fields"
45 #define TOOLONG "Line too long"
46 #define NONAME "No group name"
47 #define BADNAME "Bad character(s) in group name"
48 #define BADGID "Invalid GID"
49 #define NULLNAME "Null login name"
50 #define NOTFOUND "Logname not found in password file"
51 #define DUPNAME "Duplicate logname entry"
52 #define DUPNAME2 "Duplicate logname entry (gid first occurs in passwd entry)"
53 #define NOMEM "Out of memory"
54 #define NGROUPS "Maximum groups exceeded for logname "
55 #define BLANKLINE "Blank line detected. Please remove line"
56 #define LONGNAME "Group name too long"
57
58 #ifdef LOGNAME_MAX_ILLUMOS
59 #define _LOGNAME_MAX LOGNAME_MAX_ILLUMOS
60 #else /* LOGNAME_MAX_ILLUMOS */
61 #define _LOGNAME_MAX LOGNAME_MAX
62 #endif /* LOGNAME_MAX_ILLUMOS */
63
64 int eflag, badchar, baddigit, badlognam, colons, len;
65 static int longnam = 0;
66 int code;
67
68 #define MYBUFSIZE (LINE_MAX) /* max line length including newline and null */
69 #define NUM_COLONS 3
70
71 char *buf;
72 char *nptr;
73 char *cptr;
74 FILE *fptr;
75 gid_t gid;
76 void error(char *msg);
77
78 struct group {
79 struct group *nxt;
80 int cnt;
81 gid_t grp;
82 };
83
236 for (i = 0; buf[i] != NULL; i++) {
237 if (buf[i] == ':') {
238 delim[colons] = i;
239 if (++colons > NUM_COLONS)
240 break;
241 }
242 }
243 if (colons != NUM_COLONS) {
244 error(BADLINE);
245 free(tmpbuf);
246 continue;
247 }
248
249 /* check to see that group name is at least 1 character */
250 /* and that all characters are lowrcase or digits. */
251
252 if (buf[0] == ':')
253 error(NONAME);
254 else {
255 for (i = 0; buf[i] != ':'; i++) {
256 if (i >= _LOGNAME_MAX)
257 longnam++;
258 if (!(islower(buf[i]) || isdigit(buf[i])))
259 badchar++;
260 }
261 if (longnam > 0)
262 error(LONGNAME);
263 if (badchar > 0)
264 error(BADNAME);
265 }
266
267 /* check that GID is numeric and <= 31 bits */
268
269 len = (delim[2] - delim[1]) - 1;
270
271 if (len > 10 || len < 1)
272 error(BADGID);
273 else {
274 for (i = (delim[1]+1); i < delim[2]; i++) {
275 if (! (isdigit(buf[i])))
276 baddigit++;
|