xref: /titanic_50/usr/src/lib/libc/port/gen/getspent.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 getspent	= _getspent
34 #pragma weak getspnam	= _getspnam
35 #pragma weak fgetspent	= _fgetspent
36 	/* putspent() has been moved to putspent.c */
37 
38 #include "synonyms.h"
39 #include <sys/types.h>
40 #include <shadow.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_spbuf(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_spbuf()
61 {
62 	nss_XbyY_buf_t **buffer =
63 	    tsdalloc(_T_SPBUF, sizeof (nss_XbyY_buf_t *), free_spbuf);
64 	nss_XbyY_buf_t *b;
65 
66 	if (buffer == NULL)
67 		return (NULL);
68 	b = NSS_XbyY_ALLOC(buffer, sizeof (struct spwd), NSS_BUFLEN_SHADOW);
69 	return (b);
70 }
71 
72 struct spwd *
73 getspnam(const char *nam)
74 {
75 	nss_XbyY_buf_t	*b = get_spbuf();
76 
77 	return (b == NULL ? NULL :
78 	    getspnam_r(nam, b->result, b->buffer, b->buflen));
79 }
80 
81 struct spwd *
82 getspent(void)
83 {
84 	nss_XbyY_buf_t	*b = get_spbuf();
85 
86 	return (b == NULL ? NULL :
87 	    getspent_r(b->result, b->buffer, b->buflen));
88 }
89 
90 struct spwd *
91 fgetspent(FILE *f)
92 {
93 	nss_XbyY_buf_t	*b = get_spbuf();
94 
95 	return (b == NULL ? NULL :
96 	    fgetspent_r(f, b->result, b->buffer, b->buflen));
97 }
98 
99 #endif	/* NSS_INCLUDE_UNSAFE */
100