import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / getpwnam.c
blobbaf903913ea671204f03f9aa0943a6fcb65bd77e
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) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma weak _getpwnam = getpwnam
31 #pragma weak _getpwuid = getpwuid
33 #include "lint.h"
34 #include <sys/types.h>
35 #include <pwd.h>
36 #include <nss_dbdefs.h>
37 #include <stdio.h>
38 #include "tsd.h"
40 void _nss_initf_passwd(nss_db_params_t *p);
41 void _nss_XbyY_fgets(FILE *, nss_XbyY_args_t *);
42 int str2passwd(const char *, int, void *, char *, int);
44 static struct passwd _pw_passwd;
45 static char _pw_buf[NSS_BUFLEN_PASSWD];
46 static DEFINE_NSS_DB_ROOT(db_root);
47 static DEFINE_NSS_GETENT(context);
49 struct passwd *
50 getpwuid(uid_t uid)
52 struct passwd *result;
53 int ret;
54 if ((ret = getpwuid_r(uid, &_pw_passwd, _pw_buf, sizeof (_pw_buf),
55 &result)) != 0)
56 errno = ret;
57 return (result);
60 struct passwd *
61 getpwnam(const char *nam)
63 struct passwd *result;
64 int ret;
65 if ((ret = getpwnam_r(nam, &_pw_passwd, _pw_buf, sizeof (_pw_buf),
66 &result)) != 0)
67 errno = ret;
68 return (result);
71 struct passwd *
72 getpwent(void)
74 nss_XbyY_args_t arg;
75 NSS_XbyY_INIT(&arg, &_pw_passwd, _pw_buf, sizeof(_pw_buf), str2passwd);
76 (void) nss_getent(&db_root, _nss_initf_passwd, &context, &arg);
77 return (NSS_XbyY_FINI(&arg));
80 struct passwd *
81 fgetpwent(FILE *f)
83 nss_XbyY_args_t arg;
84 NSS_XbyY_INIT(&arg, &_pw_passwd, _pw_buf, sizeof(_pw_buf), str2passwd);
85 (void) _nss_XbyY_fgets(f, &arg);
86 return (NSS_XbyY_FINI(&arg));