xref: /onnv-gate/usr/src/lib/libc/port/gen/getpwnam.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52830Sdjl  * Common Development and Distribution License (the "License").
62830Sdjl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*6812Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	All Rights Reserved  	*/
290Sstevel@tonic-gate 
30*6812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
32*6812Sraf #pragma weak _getpwnam = getpwnam
33*6812Sraf #pragma weak _getpwuid = getpwuid
340Sstevel@tonic-gate 
35*6812Sraf #include "lint.h"
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <pwd.h>
380Sstevel@tonic-gate #include <nss_dbdefs.h>
390Sstevel@tonic-gate #include <stdio.h>
400Sstevel@tonic-gate #include "tsd.h"
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	NSS_INCLUDE_UNSAFE
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate static void
free_pwbuf(void * arg)490Sstevel@tonic-gate free_pwbuf(void *arg)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate 	nss_XbyY_buf_t **buffer = arg;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate 	NSS_XbyY_FREE(buffer);
540Sstevel@tonic-gate }
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static nss_XbyY_buf_t *
get_pwbuf()570Sstevel@tonic-gate get_pwbuf()
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	nss_XbyY_buf_t **buffer =
600Sstevel@tonic-gate 	    tsdalloc(_T_PWBUF, sizeof (nss_XbyY_buf_t *), free_pwbuf);
610Sstevel@tonic-gate 	nss_XbyY_buf_t *b;
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	if (buffer == NULL)
640Sstevel@tonic-gate 		return (NULL);
650Sstevel@tonic-gate 	b = NSS_XbyY_ALLOC(buffer, sizeof (struct passwd), NSS_BUFLEN_PASSWD);
660Sstevel@tonic-gate 	return (b);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate struct passwd *
getpwuid(uid_t uid)700Sstevel@tonic-gate getpwuid(uid_t uid)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	nss_XbyY_buf_t *b = get_pwbuf();
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	return (b == NULL ? NULL :
750Sstevel@tonic-gate 	    getpwuid_r(uid, b->result, b->buffer, b->buflen));
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate struct passwd *
getpwnam(const char * nam)790Sstevel@tonic-gate getpwnam(const char *nam)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate 	nss_XbyY_buf_t *b = get_pwbuf();
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	return (b == NULL ? NULL :
840Sstevel@tonic-gate 	    getpwnam_r(nam, b->result, b->buffer, b->buflen));
850Sstevel@tonic-gate }
860Sstevel@tonic-gate 
870Sstevel@tonic-gate struct passwd *
getpwent(void)880Sstevel@tonic-gate getpwent(void)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	nss_XbyY_buf_t *b = get_pwbuf();
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	return (b == NULL ? NULL :
930Sstevel@tonic-gate 	    getpwent_r(b->result, b->buffer, b->buflen));
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
960Sstevel@tonic-gate struct passwd *
fgetpwent(FILE * f)970Sstevel@tonic-gate fgetpwent(FILE *f)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate 	nss_XbyY_buf_t *b = get_pwbuf();
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	return (b == NULL ? NULL :
1020Sstevel@tonic-gate 	    fgetpwent_r(f, b->result, b->buffer, b->buflen));
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate #endif	/* NSS_INCLUDE_UNSAFE */
106