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