xref: /titanic_41/usr/src/cmd/oamuser/lib/vgroup.c (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.2 */
32 
33 /*LINTLIBRARY*/
34 
35 #include	<sys/types.h>
36 #include	<stdio.h>
37 #include	<stdlib.h>
38 #include	<ctype.h>
39 #include	<users.h>
40 #include	<userdefs.h>
41 
42 extern int valid_gid();
43 
44 /*
45  *	validate a group name or number and return the appropriate
46  *	group structure for it.
47  */
48 int
49 valid_group(char *group, struct group **gptr, int *warning)
50 {
51 	gid_t gid;
52 	char *ptr;
53 
54 	*warning = 0;
55 	if (isdigit(*group)) {
56 		gid = (gid_t) strtol(group, &ptr, (int) 10);
57 		if (! *ptr)
58 		return (valid_gid(gid, gptr));
59 	}
60 	for (ptr = group; *ptr != NULL; ptr++) {
61 		if (!isprint(*ptr) || (*ptr == ':') || (*ptr == '\n'))
62 			return (INVALID);
63 	}
64 
65 	/* length checking and other warnings are done in valid_gname() */
66 	return (valid_gname(group, gptr, warning));
67 }
68