1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) |
35static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95"; |
36#endif /* LIBC_SCCS and not lint */ 37 38#include <stdio.h> 39#include <sys/param.h> 40#include <fcntl.h> 41#include <db.h> 42#include <syslog.h> 43#include <pwd.h> --- 4 unchanged lines hidden (view full) --- 48#include <string.h> 49#include <limits.h> 50#include <grp.h> 51 52extern void setnetgrent __P(( char * )); 53extern int getnetgrent __P(( char **, char **, char ** )); 54extern int innetgr __P(( const char *, const char *, const char *, const char * )); 55 |
56/* 57 * The lookup techniques and data extraction code here must be kept 58 * in sync with that in `pwd_mkdb'. 59 */ 60 |
61static struct passwd _pw_passwd; /* password structure */ 62static DB *_pw_db; /* password database */ 63static int _pw_keynum; /* key counter */ 64static int _pw_stayopen; /* keep fd's open */ 65#ifdef YP 66#include <rpc/rpc.h> 67#include <rpcsvc/yp_prot.h> 68#include <rpcsvc/ypclnt.h> --- 93 unchanged lines hidden (view full) --- 162 if (rval && (_pw_passwd.pw_name[0] == '+'|| 163 _pw_passwd.pw_name[0] == '-')) rval = 0; 164 165 endpwent(); 166 return(rval ? &_pw_passwd : (struct passwd *)NULL); 167} 168 169struct passwd * |
170getpwuid(uid) |
171 uid_t uid; |
172{ 173 DBT key; 174 int keyuid, rval; 175 char bf[sizeof(keyuid) + 1]; 176 177 if (!_pw_db && !__initdb()) 178 return((struct passwd *)NULL); 179 --- 111 unchanged lines hidden (view full) --- 291 DBT data; 292 293 if ((_pw_db->get)(_pw_db, key, &data, 0)) 294 return(0); 295 p = (char *)data.data; 296 if (data.size > max && !(line = realloc(line, max += 1024))) 297 return(0); 298 |
299 /* THIS CODE MUST MATCH THAT IN pwd_mkdb. */ |
300 t = line; 301#define EXPAND(e) e = t; while ( (*t++ = *p++) ); |
302#define SCALAR(v) memmove(&(v), p, sizeof v); p += sizeof v |
303 EXPAND(_pw_passwd.pw_name); 304 EXPAND(_pw_passwd.pw_passwd); |
305 SCALAR(_pw_passwd.pw_uid); 306 SCALAR(_pw_passwd.pw_gid); 307 SCALAR(_pw_passwd.pw_change); |
308 EXPAND(_pw_passwd.pw_class); 309 EXPAND(_pw_passwd.pw_gecos); 310 EXPAND(_pw_passwd.pw_dir); 311 EXPAND(_pw_passwd.pw_shell); |
312 SCALAR(_pw_passwd.pw_expire); |
313 bcopy(p, (char *)&_pw_passwd.pw_fields, sizeof _pw_passwd.pw_fields); 314 p += sizeof _pw_passwd.pw_fields; 315 return(1); 316} 317 318#ifdef YP 319 320/* --- 510 unchanged lines hidden --- |