1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * AT&T Bell Laboratories
30 #if defined(__STDPP__directive) && defined(__STDPP__hide)
31 __STDPP__directive pragma pp
:hide getpwnam getpwuid
33 #define getpwnam ______getpwnam
34 #define getpwuid ______getpwuid
41 #if defined(__STDPP__directive) && defined(__STDPP__hide)
42 __STDPP__directive pragma pp
:nohide getpwnam getpwuid
48 extern struct passwd
* getpwnam(const char*);
49 extern struct passwd
* getpwuid(uid_t
);
59 * return uid number given uid name
60 * -1 on first error for a given name
61 * -2 on subsequent errors for a given name
65 struid(const char* name
)
68 register struct passwd
* pw
;
77 disc
.key
= offsetof(Id_t
, name
);
78 dict
= dtopen(&disc
, Dthash
);
80 else if (ip
= (Id_t
*)dtmatch(dict
, name
))
82 if (pw
= getpwnam(name
))
86 id
= strtol(name
, &e
, 0);
93 else if (streq(name
, "root") && (pw
= getpwnam("Administrator")))
98 if (*e
|| !getpwuid(id
))
102 if (dict
&& (ip
= newof(0, Id_t
, 1, strlen(name
))))
104 strcpy(ip
->name
, name
);
105 ip
->id
= id
>= 0 ? id
: -2;