bug fixes and changes from Rick Adams
[unix-history] / usr / src / usr.bin / uucp / libuu / getpwinfo.c
CommitLineData
48eef284 1#ifndef lint
46b15d8a 2static char sccsid[] = "@(#)getpwinfo.c 5.2 (Berkeley) %G%";
48eef284
SL
3#endif
4
5#include "uucp.h"
6#include <pwd.h>
7
8/*******
9 * guinfo(uid, name, path) get passwd file info for uid
10 * int uid;
11 * char *path, *name;
12 *
13 * return codes: 0 | FAIL
14 *
15 * modified 3/16/81 to use the "real" login name -- mcnc!dennis
16 * (Dennis Rockwell)
17 */
18
19guinfo(uid, name, path)
20int uid;
21register char *path, *name;
22{
23 register struct passwd *pwd;
24 struct passwd *getpwuid(), *getpwnam();
25 char *getlogin(), *l;
26
27 if ((l = getlogin()) != NULL) {
28 pwd = getpwnam(l);
46b15d8a 29 if (pwd->pw_uid == uid || *l == 'U')
48eef284
SL
30 goto setup;
31 }
32 if ((pwd = getpwuid(uid)) == NULL) {
33 /* can not find uid in passwd file */
34 *path = '\0';
46b15d8a 35 return FAIL;
48eef284
SL
36 }
37
38 setup:
39 strcpy(path, pwd->pw_dir);
40 strcpy(name, pwd->pw_name);
46b15d8a 41 return SUCCESS;
48eef284
SL
42}
43
44
46b15d8a
RC
45/*
46 * get passwd file info for name
48eef284 47 *
46b15d8a 48 * return codes: SUCCESS | FAIL
48eef284
SL
49 */
50
51gninfo(name, uid, path)
52char *path, *name;
53int *uid;
54{
55 register struct passwd *pwd;
56 struct passwd *getpwnam();
57
58 if ((pwd = getpwnam(name)) == NULL) {
59 /* can not find name in passwd file */
60 *path = '\0';
46b15d8a 61 return FAIL;
48eef284
SL
62 }
63
64 strcpy(path, pwd->pw_dir);
65 *uid = pwd->pw_uid;
46b15d8a 66 return SUCCESS;
48eef284 67}