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]
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 ident "%Z%%M% %I% %E% SMI"
32 #pragma weak _getgrnam = getgrnam
33 #pragma weak _getgrgid = getgrgid
36 #include <sys/types.h>
38 #include <nss_dbdefs.h>
42 extern size_t _nss_get_bufsizes(int arg
);
45 * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
51 nss_XbyY_buf_t
**buffer
= arg
;
53 NSS_XbyY_FREE(buffer
);
56 static nss_XbyY_buf_t
*
57 get_grbuf(int max_buf
)
59 nss_XbyY_buf_t
**buffer
=
60 tsdalloc(_T_GRBUF
, sizeof (nss_XbyY_buf_t
*), free_grbuf
);
67 blen
= _nss_get_bufsizes(0); /* default size */
69 blen
= sysconf(_SC_GETGR_R_SIZE_MAX
); /* max size */
71 if ((*buffer
)->buflen
>= blen
) /* existing size fits */
73 NSS_XbyY_FREE(buffer
); /* existing is too small */
75 b
= NSS_XbyY_ALLOC(buffer
, sizeof (struct group
), blen
);
82 nss_XbyY_buf_t
*b
= get_grbuf(0);
88 ret
= getgrgid_r(gid
, b
->result
, b
->buffer
, b
->buflen
);
89 if (ret
== NULL
&& errno
== ERANGE
) {
93 ret
= getgrgid_r(gid
, b
->result
, b
->buffer
, b
->buflen
);
99 getgrnam(const char *nam
)
101 nss_XbyY_buf_t
*b
= get_grbuf(0);
107 ret
= getgrnam_r(nam
, b
->result
, b
->buffer
, b
->buflen
);
108 if (ret
== NULL
&& errno
== ERANGE
&& nam
!= NULL
) {
112 ret
= getgrnam_r(nam
, b
->result
, b
->buffer
, b
->buflen
);
120 nss_XbyY_buf_t
*b
= get_grbuf(1);
122 return (b
== NULL
? NULL
:
123 getgrent_r(b
->result
, b
->buffer
, b
->buflen
));
129 nss_XbyY_buf_t
*b
= get_grbuf(1);
131 return (b
== NULL
? NULL
:
132 fgetgrent_r(f
, b
->result
, b
->buffer
, b
->buflen
));