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