Commit | Line | Data |
---|---|---|
2ae9f53f | 1 | #ifndef lint |
4e161d3b | 2 | static char sccsid[] = "@(#)getname.c 2.3 (Berkeley) %G%"; |
2ae9f53f | 3 | #endif |
4e161d3b | 4 | #include <pwd.h> |
b0f79ad7 KS |
5 | |
6 | /* | |
4e161d3b | 7 | * Getname / getuserid for those with |
b0f79ad7 | 8 | * hashed passwd data base). |
b0f79ad7 | 9 | * |
b0f79ad7 KS |
10 | */ |
11 | ||
b0f79ad7 KS |
12 | #include "rcv.h" |
13 | ||
b0f79ad7 KS |
14 | /* |
15 | * Search the passwd file for a uid. Return name through ref parameter | |
16 | * if found, indicating success with 0 return. Return -1 on error. | |
17 | * If -1 is passed as the user id, close the passwd file. | |
18 | */ | |
19 | ||
20 | getname(uid, namebuf) | |
21 | char namebuf[]; | |
22 | { | |
4e161d3b | 23 | struct passwd *pw; |
b0f79ad7 KS |
24 | |
25 | if (uid == -1) { | |
b0f79ad7 KS |
26 | return(0); |
27 | } | |
4e161d3b | 28 | if ((pw = getpwuid(uid)) == NULL) |
b0f79ad7 | 29 | return(-1); |
4e161d3b RC |
30 | strcpy(namebuf, pw->pw_name); |
31 | return 0; | |
b0f79ad7 KS |
32 | } |
33 | ||
34 | /* | |
35 | * Convert the passed name to a user id and return it. Return -1 | |
36 | * on error. Iff the name passed is -1 (yech) close the pwfile. | |
37 | */ | |
38 | ||
39 | getuserid(name) | |
40 | char name[]; | |
41 | { | |
4e161d3b | 42 | struct passwd *pw; |
b0f79ad7 KS |
43 | |
44 | if (name == (char *) -1) { | |
b0f79ad7 KS |
45 | return(0); |
46 | } | |
4e161d3b RC |
47 | if ((pw = getpwnam(name)) == NULL) |
48 | return 0; | |
49 | return pw->pw_uid; | |
b0f79ad7 | 50 | } |