|
|
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: pwd = getpwnam(login_name);
30: if (pwd != NULL && pwd->pw_uid == uid)
31: goto uid_found;
32: }
33:
34: /* no dice on utmp -- get first from passwd file */
35: if ((pwd = getpwuid(uid)) == NULL) {
36: if ((pwd = getpwuid(UUCPUID)) == NULL)
37: /* can not find uid in passwd file */
38: return(FAIL);
39: }
40:
41: uid_found:
42: (void) strcpy(name, pwd->pw_name);
43: return(0);
44: }
45:
46: /*
47: * get passwd file info for name
48: * name -> ascii user name
49: * uid -> address of integer to return uid # in
50: * path -> address of buffer to return working directory in
51: * returns:
52: * 0 -> success
53: * FAIL -> failure
54: */
55: gninfo(name, uid, path)
56: char *path, *name;
57: int *uid;
58: {
59: register struct passwd *pwd;
60:
61: if ((pwd = getpwnam(name)) == NULL) {
62: /* can not find name in passwd file */
63: *path = '\0';
64: return(FAIL);
65: }
66:
67: (void) strcpy(path, pwd->pw_dir);
68: *uid = pwd->pw_uid;
69: return(0);
70: }
71:
72:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.