Commit | Line | Data |
---|---|---|
9552e6b8 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
0c5f72fb KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
acfc7e9b KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
9552e6b8 DF |
16 | */ |
17 | ||
acfc7e9b KB |
18 | #ifndef lint |
19 | static char sccsid[] = "@(#)getname.c 5.5 (Berkeley) %G%"; | |
20 | #endif /* not lint */ | |
9552e6b8 | 21 | |
4e161d3b | 22 | #include <pwd.h> |
b0f79ad7 KS |
23 | |
24 | /* | |
4e161d3b | 25 | * Getname / getuserid for those with |
b0f79ad7 | 26 | * hashed passwd data base). |
b0f79ad7 | 27 | * |
b0f79ad7 KS |
28 | */ |
29 | ||
b0f79ad7 KS |
30 | #include "rcv.h" |
31 | ||
b0f79ad7 KS |
32 | /* |
33 | * Search the passwd file for a uid. Return name through ref parameter | |
34 | * if found, indicating success with 0 return. Return -1 on error. | |
b0f79ad7 KS |
35 | */ |
36 | ||
37 | getname(uid, namebuf) | |
38 | char namebuf[]; | |
39 | { | |
4e161d3b | 40 | struct passwd *pw; |
b0f79ad7 | 41 | |
4e161d3b | 42 | if ((pw = getpwuid(uid)) == NULL) |
828615a1 | 43 | return -1; |
4e161d3b RC |
44 | strcpy(namebuf, pw->pw_name); |
45 | return 0; | |
b0f79ad7 KS |
46 | } |
47 | ||
48 | /* | |
49 | * Convert the passed name to a user id and return it. Return -1 | |
828615a1 | 50 | * on error. |
b0f79ad7 KS |
51 | */ |
52 | ||
53 | getuserid(name) | |
54 | char name[]; | |
55 | { | |
4e161d3b | 56 | struct passwd *pw; |
b0f79ad7 | 57 | |
4e161d3b | 58 | if ((pw = getpwnam(name)) == NULL) |
828615a1 | 59 | return -1; |
4e161d3b | 60 | return pw->pw_uid; |
b0f79ad7 | 61 | } |