|
|
1.1 ! root 1: /* @(#)getpwinfo.c 1.2 ! 2: */ ! 3: #include "uucp.h" ! 4: VERSION(@(#)getpwinfo.c 1.2); ! 5: ! 6: #include <pwd.h> ! 7: extern struct passwd *getpwuid(), *getpwnam(); ! 8: extern char *getlogin(); ! 9: ! 10: /* ! 11: * get passwd file info for logname or uid ! 12: * uid -> uid # ! 13: * name -> address of buffer to return ascii user name ! 14: * This will be set to pw->pw_name. ! 15: * ! 16: * return: ! 17: * 0 -> success ! 18: * FAIL -> failure (logname and uid not found) ! 19: */ ! 20: guinfo(uid, name) ! 21: int uid; ! 22: char *name; ! 23: { ! 24: register struct passwd *pwd; ! 25: char *login_name; ! 26: ! 27: /* look for this user as logged in utmp */ ! 28: if ((login_name = getlogin()) != NULL) { ! 29: strcpy(name, login_name); ! 30: return(0); ! 31: } ! 32: ! 33: /* no dice on utmp -- get first from passwd file */ ! 34: if ((pwd = getpwuid(uid)) == NULL) { ! 35: if ((pwd = getpwuid(UUCPUID)) == NULL) ! 36: /* can not find uid in passwd file */ ! 37: return(FAIL); ! 38: } ! 39: ! 40: uid_found: ! 41: (void) strcpy(name, pwd->pw_name); ! 42: return(0); ! 43: } ! 44: ! 45: /* ! 46: * get passwd file info for name ! 47: * name -> ascii user name ! 48: * uid -> address of integer to return uid # in ! 49: * path -> address of buffer to return working directory in ! 50: * returns: ! 51: * 0 -> success ! 52: * FAIL -> failure ! 53: */ ! 54: gninfo(name, uid, path) ! 55: char *path, *name; ! 56: int *uid; ! 57: { ! 58: register struct passwd *pwd; ! 59: ! 60: if ((pwd = getpwnam(name)) == NULL) { ! 61: /* can not find name in passwd file */ ! 62: *path = '\0'; ! 63: return(FAIL); ! 64: } ! 65: ! 66: (void) strcpy(path, pwd->pw_dir); ! 67: *uid = pwd->pw_uid; ! 68: return(0); ! 69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.