Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:15

0001 /**
0002  *  @file
0003  *
0004  *  @brief User Database Access Routines
0005  *  @ingroup libcsupport
0006  */
0007 
0008 /*
0009  *  Copyright (c) 1999-2009 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
0010  *  Copyright (c) 1999-2013 Joel Sherrill <joel.sherrill@OARcorp.com>
0011  *  Copyright (c) 2000-2001 Fernando Ruiz Casas <fruizcasas@gmail.com>
0012  *  Copyright (c) 2002 Eric Norum <eric@norum.ca>
0013  *  Copyright (c) 2003 Till Straumann <strauman@slac.stanford.edu>
0014  *  Copyright (c) 2012 Alex Ivanov <alexivanov97@gmail.com>
0015  *
0016  *  The license and distribution terms for this file may be
0017  *  found in the file LICENSE in this distribution or at
0018  *  http://www.rtems.org/license/LICENSE.
0019  */
0020 
0021 #ifdef HAVE_CONFIG_H
0022 #include "config.h"
0023 #endif
0024 
0025 #include "pwdgrp.h"
0026 
0027 /*
0028  * Static, thread-unsafe, buffers
0029  */
0030 static FILE *passwd_fp;
0031 static char pwbuf[200];
0032 static struct passwd pwent;
0033 
0034 struct passwd *getpwnam(
0035   const char *name
0036 )
0037 {
0038   struct passwd *p;
0039 
0040   if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p))
0041     return NULL;
0042   return p;
0043 }
0044 
0045 struct passwd *getpwuid(
0046   uid_t uid
0047 )
0048 {
0049   struct passwd *p;
0050 
0051   if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p))
0052     return NULL;
0053   return p;
0054 }
0055 
0056 struct passwd *getpwent(void)
0057 {
0058   if (passwd_fp == NULL)
0059     return NULL;
0060   if (!_libcsupport_scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf))
0061     return NULL;
0062   return &pwent;
0063 }
0064 
0065 void setpwent(void)
0066 {
0067   _libcsupport_pwdgrp_init();
0068 
0069   if (passwd_fp != NULL)
0070     fclose(passwd_fp);
0071   passwd_fp = fopen("/etc/passwd", "r");
0072 }
0073 
0074 void endpwent(void)
0075 {
0076   if (passwd_fp != NULL)
0077     fclose(passwd_fp);
0078 }