xref: /original-bsd/usr.bin/mail/getname.c (revision ad93c43e)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifdef notdef
14 static char sccsid[] = "@(#)getname.c	5.4 (Berkeley) 02/18/88";
15 #endif /* notdef */
16 
17 #include <pwd.h>
18 
19 /*
20  * Getname / getuserid for those with
21  * hashed passwd data base).
22  *
23  */
24 
25 #include "rcv.h"
26 
27 /*
28  * Search the passwd file for a uid.  Return name through ref parameter
29  * if found, indicating success with 0 return.  Return -1 on error.
30  */
31 
32 getname(uid, namebuf)
33 	char namebuf[];
34 {
35 	struct passwd *pw;
36 
37 	if ((pw = getpwuid(uid)) == NULL)
38 		return -1;
39 	strcpy(namebuf, pw->pw_name);
40 	return 0;
41 }
42 
43 /*
44  * Convert the passed name to a user id and return it.  Return -1
45  * on error.
46  */
47 
48 getuserid(name)
49 	char name[];
50 {
51 	struct passwd *pw;
52 
53 	if ((pw = getpwnam(name)) == NULL)
54 		return -1;
55 	return pw->pw_uid;
56 }
57