xref: /original-bsd/usr.bin/uucp/libuu/getpwinfo.c (revision 2852c678)
1 #ifndef lint
2 static char sccsid[] = "@(#)getpwinfo.c	5.4 (Berkeley) 03/02/91";
3 #endif
4 
5 #include "uucp.h"
6 #include <pwd.h>
7 
8 /*LINTLIBRARY*/
9 
10 /*
11  *	get passwd file info for uid
12  *
13  *	return codes:  SUCCESS  |  FAIL
14  *
15  */
16 
17 guinfo(uid, name, path)
18 int uid;
19 register char *path, *name;
20 {
21 	register struct passwd *pwd;
22 	char *getlogin(), *getenv(), *l;
23 
24 	if ((l = getlogin()) == NULL) {
25 		l = getenv("USER");
26 	}
27 	if (l != NULL) {
28 		pwd = getpwnam(l);
29 		if (pwd != NULL && pwd->pw_uid == uid)
30 			goto setup;
31 	}
32 	if ((pwd = getpwuid(uid)) == NULL) {
33 		/* can not find uid in passwd file */
34 		*name = '\0';
35 		*path = '\0';
36 		return FAIL;
37 	}
38 
39     setup:
40 	strcpy(path, pwd->pw_dir);
41 	strcpy(name, pwd->pw_name);
42 	return SUCCESS;
43 }
44 
45 
46 /*
47  *	get passwd file info for name
48  *
49  *	return codes:  SUCCESS  |  FAIL
50  */
51 
52 gninfo(name, uid, path)
53 char *path, *name;
54 int *uid;
55 {
56 	register struct passwd *pwd;
57 	struct passwd *getpwnam();
58 
59 	if ((pwd = getpwnam(name)) == NULL) {
60 		/* can not find name in passwd file */
61 		*path = '\0';
62 		return FAIL;
63 	}
64 
65 	strcpy(path, pwd->pw_dir);
66 	*uid = pwd->pw_uid;
67 	return SUCCESS;
68 }
69