1 /*- 2 * Copyright (c) 1985, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)getpwinfo.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include "uucp.h" 13 #include <pwd.h> 14 15 /*LINTLIBRARY*/ 16 17 /* 18 * get passwd file info for uid 19 * 20 * return codes: SUCCESS | FAIL 21 * 22 */ 23 24 guinfo(uid, name, path) 25 int uid; 26 register char *path, *name; 27 { 28 register struct passwd *pwd; 29 char *getlogin(), *getenv(), *l; 30 31 if ((l = getlogin()) == NULL) { 32 l = getenv("USER"); 33 } 34 if (l != NULL) { 35 pwd = getpwnam(l); 36 if (pwd != NULL && pwd->pw_uid == uid) 37 goto setup; 38 } 39 if ((pwd = getpwuid(uid)) == NULL) { 40 /* can not find uid in passwd file */ 41 *name = '\0'; 42 *path = '\0'; 43 return FAIL; 44 } 45 46 setup: 47 strcpy(path, pwd->pw_dir); 48 strcpy(name, pwd->pw_name); 49 return SUCCESS; 50 } 51 52 53 /* 54 * get passwd file info for name 55 * 56 * return codes: SUCCESS | FAIL 57 */ 58 59 gninfo(name, uid, path) 60 char *path, *name; 61 int *uid; 62 { 63 register struct passwd *pwd; 64 struct passwd *getpwnam(); 65 66 if ((pwd = getpwnam(name)) == NULL) { 67 /* can not find name in passwd file */ 68 *path = '\0'; 69 return FAIL; 70 } 71 72 strcpy(path, pwd->pw_dir); 73 *uid = pwd->pw_uid; 74 return SUCCESS; 75 } 76