18 static char * lastUname = NULL;
19 static size_t lastUnameLen = 0;
20 static size_t lastUnameAlloced;
22 struct passwd * pwent;
28 }
else if (strcmp(thisUname,
"root") == 0) {
35 thisUnameLen = strlen(thisUname);
36 if (lastUname == NULL || thisUnameLen != lastUnameLen ||
37 strcmp(thisUname, lastUname) != 0)
39 if (lastUnameAlloced < thisUnameLen + 1) {
40 lastUnameAlloced = thisUnameLen + 10;
41 lastUname =
xrealloc(lastUname, lastUnameAlloced);
44 strcpy(lastUname, thisUname);
47 pwent = getpwnam(thisUname);
52 pwent = getpwnam(thisUname);
53 if (pwent == NULL)
return -1;
56 lastUid = pwent->pw_uid;
68 static char * lastGname = NULL;
69 static size_t lastGnameLen = 0;
70 static size_t lastGnameAlloced;
75 if (thisGname == NULL) {
78 }
else if (strcmp(thisGname,
"root") == 0) {
85 thisGnameLen = strlen(thisGname);
86 if (lastGname == NULL || thisGnameLen != lastGnameLen ||
87 strcmp(thisGname, lastGname) != 0)
89 if (lastGnameAlloced < thisGnameLen + 1) {
90 lastGnameAlloced = thisGnameLen + 10;
91 lastGname =
xrealloc(lastGname, lastGnameAlloced);
94 strcpy(lastGname, thisGname);
97 grent = getgrnam(thisGname);
102 grent = getgrnam(thisGname);
105 if (strcmp(thisGname,
"uucp") == 0) {
111 if (strcmp(thisGname,
"mail") == 0) {
117 if (strcmp(thisGname,
"adm") == 0) {
126 lastGid = grent->gr_gid;
138 static uid_t lastUid = (uid_t) -1;
139 static char * lastUname = NULL;
140 static size_t lastUnameLen = 0;
142 if (uid == (uid_t) -1) {
143 lastUid = (uid_t) -1;
145 }
else if (uid == (uid_t) 0) {
147 }
else if (uid == lastUid) {
150 struct passwd * pwent = getpwuid(uid);
153 if (pwent == NULL)
return NULL;
156 len = strlen(pwent->pw_name);
157 if (lastUnameLen < len + 1) {
158 lastUnameLen = len + 20;
159 lastUname =
xrealloc(lastUname, lastUnameLen);
162 strcpy(lastUname, pwent->pw_name);
171 static gid_t lastGid = (gid_t) -1;
172 static char * lastGname = NULL;
173 static size_t lastGnameLen = 0;
175 if (gid == (gid_t) -1) {
176 lastGid = (gid_t) -1;
178 }
else if (gid == (gid_t) 0) {
180 }
else if (gid == lastGid) {
183 struct group * grent = getgrgid(gid);
186 if (grent == NULL)
return NULL;
189 len = strlen(grent->gr_name);
190 if (lastGnameLen < len + 1) {
191 lastGnameLen = len + 20;
192 lastGname =
xrealloc(lastGname, lastGnameLen);
195 strcpy(lastGname, grent->gr_name);