getpwent.c (23608) | getpwent.c (23668) |
---|---|
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) | 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.1 (Berkeley) 6/4/93"; | 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 | 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 |
|
56static struct passwd _pw_passwd; /* password structure */ 57static DB *_pw_db; /* password database */ 58static int _pw_keynum; /* key counter */ 59static int _pw_stayopen; /* keep fd's open */ 60#ifdef YP 61#include <rpc/rpc.h> 62#include <rpcsvc/yp_prot.h> 63#include <rpcsvc/ypclnt.h> --- 93 unchanged lines hidden (view full) --- 157 if (rval && (_pw_passwd.pw_name[0] == '+'|| 158 _pw_passwd.pw_name[0] == '-')) rval = 0; 159 160 endpwent(); 161 return(rval ? &_pw_passwd : (struct passwd *)NULL); 162} 163 164struct passwd * | 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 * |
165#ifdef __STDC__ 166getpwuid(uid_t uid) 167#else | |
168getpwuid(uid) | 170getpwuid(uid) |
169 int uid; 170#endif | 171 uid_t uid; |
171{ 172 DBT key; 173 int keyuid, rval; 174 char bf[sizeof(keyuid) + 1]; 175 176 if (!_pw_db && !__initdb()) 177 return((struct passwd *)NULL); 178 --- 111 unchanged lines hidden (view full) --- 290 DBT data; 291 292 if ((_pw_db->get)(_pw_db, key, &data, 0)) 293 return(0); 294 p = (char *)data.data; 295 if (data.size > max && !(line = realloc(line, max += 1024))) 296 return(0); 297 | 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. */ |
|
298 t = line; 299#define EXPAND(e) e = t; while ( (*t++ = *p++) ); | 300 t = line; 301#define EXPAND(e) e = t; while ( (*t++ = *p++) ); |
302#define SCALAR(v) memmove(&(v), p, sizeof v); p += sizeof v |
|
300 EXPAND(_pw_passwd.pw_name); 301 EXPAND(_pw_passwd.pw_passwd); | 303 EXPAND(_pw_passwd.pw_name); 304 EXPAND(_pw_passwd.pw_passwd); |
302 bcopy(p, (char *)&_pw_passwd.pw_uid, sizeof(int)); 303 p += sizeof(int); 304 bcopy(p, (char *)&_pw_passwd.pw_gid, sizeof(int)); 305 p += sizeof(int); 306 bcopy(p, (char *)&_pw_passwd.pw_change, sizeof(time_t)); 307 p += sizeof(time_t); | 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); | 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 bcopy(p, (char *)&_pw_passwd.pw_expire, sizeof(time_t)); 313 p += sizeof(time_t); | 312 SCALAR(_pw_passwd.pw_expire); |
314 bcopy(p, (char *)&_pw_passwd.pw_fields, sizeof _pw_passwd.pw_fields); 315 p += sizeof _pw_passwd.pw_fields; 316 return(1); 317} 318 319#ifdef YP 320 321/* --- 510 unchanged lines hidden --- | 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 --- |