xref: /titanic_41/usr/src/lib/libc/port/gen/getpwnam.c (revision a90d965d832a5578dbfc2eadd1617e8cccf25264)
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 (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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*	Copyright (c) 1988 AT&T	*/
29 /*	All Rights Reserved  	*/
30 
31 
32 #pragma weak getpwnam = _getpwnam
33 #pragma weak getpwuid = _getpwuid
34 #pragma weak getpwent = _getpwent
35 #pragma weak fgetpwent = _fgetpwent
36 
37 #include "synonyms.h"
38 #include <sys/types.h>
39 #include <pwd.h>
40 #include <nss_dbdefs.h>
41 #include <stdio.h>
42 #include "tsd.h"
43 
44 #ifdef	NSS_INCLUDE_UNSAFE
45 
46 /*
47  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
48  */
49 
50 static void
51 free_pwbuf(void *arg)
52 {
53 	nss_XbyY_buf_t **buffer = arg;
54 
55 	NSS_XbyY_FREE(buffer);
56 }
57 
58 static nss_XbyY_buf_t *
59 get_pwbuf()
60 {
61 	nss_XbyY_buf_t **buffer =
62 	    tsdalloc(_T_PWBUF, sizeof (nss_XbyY_buf_t *), free_pwbuf);
63 	nss_XbyY_buf_t *b;
64 
65 	if (buffer == NULL)
66 		return (NULL);
67 	b = NSS_XbyY_ALLOC(buffer, sizeof (struct passwd), NSS_BUFLEN_PASSWD);
68 	return (b);
69 }
70 
71 struct passwd *
72 getpwuid(uid_t uid)
73 {
74 	nss_XbyY_buf_t *b = get_pwbuf();
75 
76 	return (b == NULL ? NULL :
77 	    getpwuid_r(uid, b->result, b->buffer, b->buflen));
78 }
79 
80 struct passwd *
81 getpwnam(const char *nam)
82 {
83 	nss_XbyY_buf_t *b = get_pwbuf();
84 
85 	return (b == NULL ? NULL :
86 	    getpwnam_r(nam, b->result, b->buffer, b->buflen));
87 }
88 
89 struct passwd *
90 getpwent(void)
91 {
92 	nss_XbyY_buf_t *b = get_pwbuf();
93 
94 	return (b == NULL ? NULL :
95 	    getpwent_r(b->result, b->buffer, b->buflen));
96 }
97 
98 struct passwd *
99 fgetpwent(FILE *f)
100 {
101 	nss_XbyY_buf_t *b = get_pwbuf();
102 
103 	return (b == NULL ? NULL :
104 	    fgetpwent_r(f, b->result, b->buffer, b->buflen));
105 }
106 
107 #endif	/* NSS_INCLUDE_UNSAFE */
108