xref: /titanic_52/usr/src/cmd/getent/dogetpw.c (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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 #ident	"%Z%%M%	%I%	%E% SMI"
23 
24 /*
25  * Copyright (c) 1994, by Sun Microsystems, Inc.
26  */
27 
28 #include <stdio.h>
29 #include <pwd.h>
30 #include <stdlib.h>
31 #include "getent.h"
32 
33 /*
34  * getpwnam - get entries from password database
35  */
36 int
37 dogetpw(const char **list)
38 {
39 	struct passwd *pwp;
40 	int rc = EXC_SUCCESS;
41 	char *ptr;
42 	uid_t uid;
43 
44 
45 	if (list == NULL || *list == NULL) {
46 		while ((pwp = getpwent()) != NULL)
47 			(void) putpwent(pwp, stdout);
48 	} else {
49 		for (; *list != NULL; list++) {
50 			uid = strtol(*list, &ptr, 10);
51 			if (ptr == *list)
52 				pwp = getpwnam(*list);
53 			else
54 				pwp = getpwuid(uid);
55 			if (pwp == NULL)
56 				rc = EXC_NAME_NOT_FOUND;
57 			else
58 				(void) putpwent(pwp, stdout);
59 		}
60 	}
61 
62 	return (rc);
63 }
64