View | Details | Raw Unified | Return to bug 27829
Collapse All | Expand All

(-)cache.c 2001/01/16 23:20:28 1.3 (-5 / +18 lines)
Lines 210-223 Link Here
210
{
210
{
211
       register struct passwd *pw;
211
       register struct passwd *pw;
212
       register UIDC *ptr;
212
       register UIDC *ptr;
213
213
       register int hash;
214
       if ((uidtb == NULL) && (uidtb_start() < 0))
214
       if ((uidtb == NULL) && (uidtb_start() < 0))
215
               return("");
215
               return("");
216
216
217
       /*
217
       /*
218
        * see if we have this uid cached
218
        * see if we have this uid cached
219
        */
219
        */
220
       ptr = uidtb[uid % UID_SZ];
220
       hash = uid % UID_SZ;
221
       ptr = uidtb[hash];
221
       if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
222
       if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
222
               /*
223
               /*
223
                * have an entry for this uid
224
                * have an entry for this uid
Lines 252-257 Link Here
252
               (void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
253
               (void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
253
                              (unsigned long)uid);
254
                              (unsigned long)uid);
254
#              endif
255
#              endif
256
               uidtb[hash] = ptr;
255
               if (frc == 0)
257
               if (frc == 0)
256
                       return("");
258
                       return("");
257
       } else {
259
       } else {
Lines 264-269 Link Here
264
               (void)strncpy(ptr->name, pw->pw_name, UNMLEN-1);
266
               (void)strncpy(ptr->name, pw->pw_name, UNMLEN-1);
265
               ptr->name[UNMLEN-1] = '\0';
267
               ptr->name[UNMLEN-1] = '\0';
266
               ptr->valid = VALID;
268
               ptr->valid = VALID;
269
               uidtb[hash] = ptr;
267
       }
270
       }
268
       return(ptr->name);
271
       return(ptr->name);
269
}
272
}
Lines 288-293 Link Here
288
{
291
{
289
       register struct group *gr;
292
       register struct group *gr;
290
       register GIDC *ptr;
293
       register GIDC *ptr;
294
       register int hash;
291
295
292
       if ((gidtb == NULL) && (gidtb_start() < 0))
296
       if ((gidtb == NULL) && (gidtb_start() < 0))
293
               return("");
297
               return("");
Lines 295-301 Link Here
295
       /*
299
       /*
296
        * see if we have this gid cached
300
        * see if we have this gid cached
297
        */
301
        */
298
       ptr = gidtb[gid % GID_SZ];
302
       hash = gid % GID_SZ;
303
       ptr = gidtb[hash];
299
       if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
304
       if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
300
               /*
305
               /*
301
                * have an entry for this gid
306
                * have an entry for this gid
Lines 330-335 Link Here
330
               (void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
335
               (void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
331
                              (unsigned long)gid);
336
                              (unsigned long)gid);
332
#              endif
337
#              endif
338
               gidtb[hash] = ptr;
333
               if (frc == 0)
339
               if (frc == 0)
334
                       return("");
340
                       return("");
335
       } else {
341
       } else {
Lines 342-347 Link Here
342
               (void)strncpy(ptr->name, gr->gr_name, GNMLEN-1);
348
               (void)strncpy(ptr->name, gr->gr_name, GNMLEN-1);
343
               ptr->name[GNMLEN-1] = '\0';
349
               ptr->name[GNMLEN-1] = '\0';
344
               ptr->valid = VALID;
350
               ptr->valid = VALID;
351
               gidtb[hash] = ptr;
345
       }
352
       }
346
       return(ptr->name);
353
       return(ptr->name);
347
}
354
}
Lines 366-371 Link Here
366
       register struct passwd *pw;
373
       register struct passwd *pw;
367
       register UIDC *ptr;
374
       register UIDC *ptr;
368
       register int namelen;
375
       register int namelen;
376
       register int hash;
369
377
370
       /*
378
       /*
371
        * return -1 for mangled names
379
        * return -1 for mangled names
Lines 379-385 Link Here
379
        * look up in hash table, if found and valid return the uid,
387
        * look up in hash table, if found and valid return the uid,
380
        * if found and invalid, return a -1
388
        * if found and invalid, return a -1
381
        */
389
        */
382
       ptr = usrtb[st_hash(name, namelen, UNM_SZ)];
390
       hash = st_hash(name, namelen, UNM_SZ);
391
       ptr = usrtb[hash];
383
       if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
392
       if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
384
               if (ptr->valid == INVALID)
393
               if (ptr->valid == INVALID)
385
                       return(-1);
394
                       return(-1);
Lines 405-410 Link Here
405
               *uid = pw->pw_uid;
414
               *uid = pw->pw_uid;
406
               return(0);
415
               return(0);
407
       }
416
       }
417
       usrtb[hash] = ptr;
408
       (void)strncpy(ptr->name, name, UNMLEN-1);
418
       (void)strncpy(ptr->name, name, UNMLEN-1);
409
       ptr->name[UNMLEN-1] = '\0';
419
       ptr->name[UNMLEN-1] = '\0';
410
       if ((pw = getpwnam(name)) == NULL) {
420
       if ((pw = getpwnam(name)) == NULL) {
Lines 436-441 Link Here
436
       register struct group *gr;
446
       register struct group *gr;
437
       register GIDC *ptr;
447
       register GIDC *ptr;
438
       register int namelen;
448
       register int namelen;
449
       register int hash;
439
450
440
       /*
451
       /*
441
        * return -1 for mangled names
452
        * return -1 for mangled names
Lines 449-455 Link Here
449
        * look up in hash table, if found and valid return the uid,
460
        * look up in hash table, if found and valid return the uid,
450
        * if found and invalid, return a -1
461
        * if found and invalid, return a -1
451
        */
462
        */
452
       ptr = grptb[st_hash(name, namelen, GID_SZ)];
463
       hash = st_hash(name, namelen, GID_SZ);
464
       ptr = grptb[hash];
453
       if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
465
       if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
454
               if (ptr->valid == INVALID)
466
               if (ptr->valid == INVALID)
455
                       return(-1);
467
                       return(-1);
Lines 475-480 Link Here
475
               return(0);
487
               return(0);
476
       }
488
       }
477
489
490
       grptb[hash] = ptr;
478
       (void)strncpy(ptr->name, name, GNMLEN-1);
491
       (void)strncpy(ptr->name, name, GNMLEN-1);
479
       ptr->name[GNMLEN-1] = '\0';
492
       ptr->name[GNMLEN-1] = '\0';
480
       if ((gr = getgrnam(name)) == NULL) {
493
       if ((gr = getgrnam(name)) == NULL) {

Return to bug 27829