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