xref: /titanic_41/usr/src/lib/libc/port/gen/getgrnam.c (revision 69bb4bb45c98da60d21839c4dc3c01ea1be60585)
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 /*	3.0 SID #	1.2	*/
34 
35 #pragma weak getgrnam	= _getgrnam
36 #pragma weak getgrgid	= _getgrgid
37 #pragma weak getgrent	= _getgrent
38 #pragma weak fgetgrent	= _fgetgrent
39 
40 #include "synonyms.h"
41 #include <sys/types.h>
42 #include <grp.h>
43 #include <nss_dbdefs.h>
44 #include <stdio.h>
45 #include "tsd.h"
46 
47 #ifdef	NSS_INCLUDE_UNSAFE
48 
49 /*
50  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
51  */
52 
53 static void
54 free_grbuf(void *arg)
55 {
56 	nss_XbyY_buf_t **buffer = arg;
57 
58 	NSS_XbyY_FREE(buffer);
59 }
60 
61 static nss_XbyY_buf_t *
62 get_grbuf()
63 {
64 	nss_XbyY_buf_t **buffer =
65 	    tsdalloc(_T_GRBUF, sizeof (nss_XbyY_buf_t *), free_grbuf);
66 	nss_XbyY_buf_t *b;
67 
68 	if (buffer == NULL)
69 		return (NULL);
70 	b = NSS_XbyY_ALLOC(buffer, sizeof (struct group), NSS_BUFLEN_GROUP);
71 	return (b);
72 }
73 
74 struct group *
75 getgrgid(gid_t gid)
76 {
77 	nss_XbyY_buf_t	*b = get_grbuf();
78 
79 	return (b == NULL ? NULL :
80 	    getgrgid_r(gid, b->result, b->buffer, b->buflen));
81 }
82 
83 struct group *
84 getgrnam(const char *nam)
85 {
86 	nss_XbyY_buf_t	*b = get_grbuf();
87 
88 	return (b == NULL ? NULL :
89 	    getgrnam_r(nam, b->result, b->buffer, b->buflen));
90 }
91 
92 struct group *
93 getgrent(void)
94 {
95 	nss_XbyY_buf_t	*b = get_grbuf();
96 
97 	return (b == NULL ? NULL :
98 	    getgrent_r(b->result, b->buffer, b->buflen));
99 }
100 
101 struct group *
102 fgetgrent(FILE *f)
103 {
104 	nss_XbyY_buf_t	*b = get_grbuf();
105 
106 	return (b == NULL ? NULL :
107 	    fgetgrent_r(f, b->result, b->buffer, b->buflen));
108 }
109 
110 #endif	/* NSS_INCLUDE_UNSAFE */
111