sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libast / common / string / struid.c
blob6b614e878dbffd9bd8416c93050663ec2f4c832e
1 /***********************************************************************
2 * *
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 *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * Glenn Fowler
25 * AT&T Bell Laboratories
27 * uid name -> number
30 #if defined(__STDPP__directive) && defined(__STDPP__hide)
31 __STDPP__directive pragma pp:hide getpwnam getpwuid
32 #else
33 #define getpwnam ______getpwnam
34 #define getpwuid ______getpwuid
35 #endif
37 #include <ast.h>
38 #include <cdt.h>
39 #include <pwd.h>
41 #if defined(__STDPP__directive) && defined(__STDPP__hide)
42 __STDPP__directive pragma pp:nohide getpwnam getpwuid
43 #else
44 #undef getpwnam
45 #undef getpwuid
46 #endif
48 extern struct passwd* getpwnam(const char*);
49 extern struct passwd* getpwuid(uid_t);
51 typedef struct Id_s
53 Dtlink_t link;
54 int id;
55 char name[1];
56 } Id_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
64 int
65 struid(const char* name)
67 register Id_t* ip;
68 register struct passwd* pw;
69 int id;
70 char* e;
72 static Dt_t* dict;
73 static Dtdisc_t disc;
75 if (!dict)
77 disc.key = offsetof(Id_t, name);
78 dict = dtopen(&disc, Dthash);
80 else if (ip = (Id_t*)dtmatch(dict, name))
81 return ip->id;
82 if (pw = getpwnam(name))
83 id = pw->pw_uid;
84 else
86 id = strtol(name, &e, 0);
87 #if _WINIX
88 if (!*e)
90 if (!getpwuid(id))
91 id = -1;
93 else if (streq(name, "root") && (pw = getpwnam("Administrator")))
94 id = pw->pw_uid;
95 else
96 id = -1;
97 #else
98 if (*e || !getpwuid(id))
99 id = -1;
100 #endif
102 if (dict && (ip = newof(0, Id_t, 1, strlen(name))))
104 strcpy(ip->name, name);
105 ip->id = id >= 0 ? id : -2;
106 dtinsert(dict, ip);
108 return id;