18 static char * lastUname = NULL;
19 static size_t lastUnameLen = 0;
20 static size_t lastUnameAlloced;
22 struct passwd _pw, *pwent = NULL;
24 size_t _nb =
sizeof(_b);
36 if (thisUname == NULL) {
39 #if !defined(RPM_VENDOR_OPENPKG)
40 }
else if (strcmp(thisUname,
"root") == 0) {
46 thisUnameLen = strlen(thisUname);
47 if (lastUname == NULL || thisUnameLen != lastUnameLen ||
48 strcmp(thisUname, lastUname) != 0)
50 if (lastUnameAlloced < thisUnameLen + 1) {
51 lastUnameAlloced = thisUnameLen + 10;
52 lastUname = (
char *)
DRD_xrealloc(lastUname, lastUnameAlloced);
54 strcpy(lastUname, thisUname);
56 if (getpwnam_r(thisUname, &_pw, _b, _nb, &pwent) || pwent == NULL) {
60 if (getpwnam_r(thisUname, &_pw, _b, _nb, &pwent) || pwent == NULL)
63 lastUid = pwent->pw_uid;
73 static char * lastGname = NULL;
74 static size_t lastGnameLen = 0;
75 static size_t lastGnameAlloced;
77 struct group _gr, *grent = NULL;
79 size_t _nb =
sizeof(_b);
88 if (thisGname == NULL) {
91 #if !defined(RPM_VENDOR_OPENPKG)
92 }
else if (strcmp(thisGname,
"root") == 0) {
98 thisGnameLen = strlen(thisGname);
99 if (lastGname == NULL || thisGnameLen != lastGnameLen ||
100 strcmp(thisGname, lastGname) != 0)
102 if (lastGnameAlloced < thisGnameLen + 1) {
103 lastGnameAlloced = thisGnameLen + 10;
104 lastGname = (
char *)
DRD_xrealloc(lastGname, lastGnameAlloced);
106 strcpy(lastGname, thisGname);
108 if (getgrnam_r(thisGname, &_gr, _b, _nb, &grent) || grent == NULL) {
112 if (getgrnam_r(thisGname, &_gr, _b, _nb, &grent) || grent == NULL) {
113 #if !defined(RPM_VENDOR_OPENPKG)
115 if (strcmp(thisGname,
"lock") == 0) {
119 if (strcmp(thisGname,
"mail") == 0) {
127 lastGid = grent->gr_gid;
137 static uid_t lastUid = (uid_t) -1;
138 static char * lastUname = NULL;
139 static size_t lastUnameLen = 0;
141 if (uid == (uid_t) -1) {
142 lastUid = (uid_t) -1;
144 #if !defined(RPM_VENDOR_OPENPKG)
145 }
else if (uid == (uid_t) 0) {
146 return (
char *)
"root";
148 }
else if (uid == lastUid) {
151 struct passwd _pw, *pwent = NULL;
153 size_t _nb =
sizeof(_b);
156 if (getpwuid_r(uid, &_pw, _b, _nb, &pwent) || pwent == NULL)
160 len = strlen(pwent->pw_name);
161 if (lastUnameLen < len + 1) {
162 lastUnameLen = len + 20;
163 lastUname = (
char *)
DRD_xrealloc(lastUname, lastUnameLen);
165 strcpy(lastUname, pwent->pw_name);
173 static gid_t lastGid = (gid_t) -1;
174 static char * lastGname = NULL;
175 static size_t lastGnameLen = 0;
177 if (gid == (gid_t) -1) {
178 lastGid = (gid_t) -1;
180 #if !defined(RPM_VENDOR_OPENPKG)
181 }
else if (gid == (gid_t) 0) {
182 return (
char *)
"root";
184 }
else if (gid == lastGid) {
187 struct group _gr, *grent = NULL;
189 size_t _nb =
sizeof(_b);
192 if (getgrgid_r(gid, &_gr, _b, _nb, &grent) || grent == NULL)
196 len = strlen(grent->gr_name);
197 if (lastGnameLen < len + 1) {
198 lastGnameLen = len + 20;
199 lastGname = (
char *)
DRD_xrealloc(lastGname, lastGnameLen);
201 strcpy(lastGname, grent->gr_name);
const char const char size_t len
char * gidToGname(gid_t gid)
#define DRD_xrealloc(_ptr, _size)
int gnameToGid(const char *thisGname, gid_t *gid)
char * uidToUname(uid_t uid)
int unameToUid(const char *thisUname, uid_t *uid)