homedir.c (131706) | homedir.c (174313) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1997-2004 Erez Zadok | 2 * Copyright (c) 1997-2006 Erez Zadok |
3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * | 3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * |
39 * %W% (Berkeley) %G% | |
40 * | 39 * |
41 * $Id: homedir.c,v 1.5.2.11 2004/01/06 03:15:23 ezk Exp $ 42 * $FreeBSD: head/contrib/amd/hlfsd/homedir.c 131706 2004-07-06 13:16:49Z mbr $ | 40 * File: am-utils/hlfsd/homedir.c |
43 * 44 * HLFSD was written at Columbia University Computer Science Department, by 45 * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> 46 * It is being distributed under the same terms and conditions as amd does. 47 */ 48 49#ifdef HAVE_CONFIG_H 50# include <config.h> --- 11 unchanged lines hidden (view full) --- 62static int hlfsd_diskspace(char *); 63static int hlfsd_stat(char *, struct stat *); 64static int passwd_line = 0; 65static int plt_reset(void); 66static struct passwd passwd_ent; 67static uid2home_t *lastchild; 68static uid2home_t *pwtab; 69static void delay(uid2home_t *, int); | 41 * 42 * HLFSD was written at Columbia University Computer Science Department, by 43 * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> 44 * It is being distributed under the same terms and conditions as amd does. 45 */ 46 47#ifdef HAVE_CONFIG_H 48# include <config.h> --- 11 unchanged lines hidden (view full) --- 60static int hlfsd_diskspace(char *); 61static int hlfsd_stat(char *, struct stat *); 62static int passwd_line = 0; 63static int plt_reset(void); 64static struct passwd passwd_ent; 65static uid2home_t *lastchild; 66static uid2home_t *pwtab; 67static void delay(uid2home_t *, int); |
70static void table_add(int, const char *, const char *); | 68static void table_add(u_int, const char *, const char *); |
71static char mboxfile[MAXPATHLEN]; 72static char *root_home; /* root's home directory */ 73 74/* GLOBAL FUNCTIONS */ 75char *homeof(char *username); 76int uidof(char *username); 77 78/* GLOBALS VARIABLES */ --- 7 unchanged lines hidden (view full) --- 86{ 87 static char linkval[MAXPATHLEN + 1]; 88 static struct timeval tp; 89 uid2home_t *found; 90 char *homename; 91 struct stat homestat; 92 int old_groupid, old_userid; 93 | 69static char mboxfile[MAXPATHLEN]; 70static char *root_home; /* root's home directory */ 71 72/* GLOBAL FUNCTIONS */ 73char *homeof(char *username); 74int uidof(char *username); 75 76/* GLOBALS VARIABLES */ --- 7 unchanged lines hidden (view full) --- 84{ 85 static char linkval[MAXPATHLEN + 1]; 86 static struct timeval tp; 87 uid2home_t *found; 88 char *homename; 89 struct stat homestat; 90 int old_groupid, old_userid; 91 |
94 clock_valid = 0; /* invalidate logging clock */ 95 | |
96 if ((found = plt_search(userid)) == (uid2home_t *) NULL) { 97 return alt_spooldir; /* use alt spool for unknown uid */ 98 } 99 homename = found->home; 100 101 if (homename[0] != '/' || homename[1] == '\0') { 102 found->last_status = 1; 103 return alt_spooldir; /* use alt spool for / or rel. home */ 104 } 105 if ((int) userid == 0) /* force all uid 0 to use root's home */ | 92 if ((found = plt_search(userid)) == (uid2home_t *) NULL) { 93 return alt_spooldir; /* use alt spool for unknown uid */ 94 } 95 homename = found->home; 96 97 if (homename[0] != '/' || homename[1] == '\0') { 98 found->last_status = 1; 99 return alt_spooldir; /* use alt spool for / or rel. home */ 100 } 101 if ((int) userid == 0) /* force all uid 0 to use root's home */ |
106 sprintf(linkval, "%s/%s", root_home, home_subdir); | 102 xsnprintf(linkval, sizeof(linkval), "%s/%s", root_home, home_subdir); |
107 else | 103 else |
108 sprintf(linkval, "%s/%s", homename, home_subdir); | 104 xsnprintf(linkval, sizeof(linkval), "%s/%s", homename, home_subdir); |
109 110 if (noverify) { 111 found->last_status = 0; 112 return linkval; 113 } 114 115 /* 116 * To optimize hlfsd, we don't actually check the validity of the --- 14 unchanged lines hidden (view full) --- 131 } else { 132 return alt_spooldir; 133 } 134 } else { 135 found->last_access_time = tp.tv_sec; 136 } 137 } 138 | 105 106 if (noverify) { 107 found->last_status = 0; 108 return linkval; 109 } 110 111 /* 112 * To optimize hlfsd, we don't actually check the validity of the --- 14 unchanged lines hidden (view full) --- 127 } else { 128 return alt_spooldir; 129 } 130 } else { 131 found->last_access_time = tp.tv_sec; 132 } 133 } 134 |
139#ifdef DEBUG | |
140 /* | 135 /* |
141 * only run this forking code if asked for -D fork 142 * or if did not ask for -D nofork | 136 * only run this forking code if did not ask for -D fork |
143 */ | 137 */ |
144 amuDebug(D_FORK) { 145#endif /* DEBUG */ | 138 if (!amuDebug(D_FORK)) { |
146 /* fork child to process request if none in progress */ | 139 /* fork child to process request if none in progress */ |
147 if (found->child && kill(found->child, 0) < 0) | 140 if (found->child && kill(found->child, 0)) |
148 found->child = 0; 149 150 if (found->child) 151 delay(found, 5); /* wait a bit if in progress */ | 141 found->child = 0; 142 143 if (found->child) 144 delay(found, 5); /* wait a bit if in progress */ |
152 153#if defined(DEBUG) && defined(HAVE_WAITPID) 154 if (found->child) { 155 /* perhaps it's a child we lost count of? let's wait on it */ 156 int status, child; 157 if ((child = waitpid((pid_t) found->child, &status, WNOHANG)) > 0) { 158 plog(XLOG_ERROR, "found lost child %d", child); 159 found->child = 0; 160 if (WIFEXITED(status)) 161 found->last_status = WEXITSTATUS(status); 162 else if (WIFSIGNALED(status)) 163 found->last_status = -WTERMSIG(status); 164 else { 165 plog(XLOG_ERROR, "unknown child exit status (%d) ???", status); 166 found->last_status = 255; 167 } 168 } 169 } 170#endif /* DEBUG && HAVE_WAITPID */ 171 172 if (found->child) { 173 found->last_status = 1; /* better safe than sorry - maybe */ | 145 if (found->child) { /* better safe than sorry - maybe */ 146 found->last_status = 1; |
174 return alt_spooldir; 175 } 176 if ((found->child = fork()) < 0) { 177 found->last_status = 1; 178 return alt_spooldir; 179 } 180 if (found->child) { /* PARENT */ | 147 return alt_spooldir; 148 } 149 if ((found->child = fork()) < 0) { 150 found->last_status = 1; 151 return alt_spooldir; 152 } 153 if (found->child) { /* PARENT */ |
181#ifdef DEBUG | |
182 if (lastchild) | 154 if (lastchild) |
183 plog(XLOG_INFO, "cache spill uid = %ld, pid = %ld, home = %s", | 155 dlog("cache spill uid = %ld, pid = %ld, home = %s", |
184 (long) lastchild->uid, (long) lastchild->child, 185 lastchild->home); | 156 (long) lastchild->uid, (long) lastchild->child, 157 lastchild->home); |
186#endif /* DEBUG */ | |
187 lastchild = found; 188 return (char *) NULL; /* return NULL to parent, so it can continue */ 189 } | 158 lastchild = found; 159 return (char *) NULL; /* return NULL to parent, so it can continue */ 160 } |
190#ifdef DEBUG 191 } /* end of Debug(D_FORK) */ 192#endif /* DEBUG */ | 161 } |
193 194 /* | 162 163 /* |
195 * CHILD: (or parent if -D nofork) | 164 * CHILD: (or parent if -D fork) |
196 * 197 * Check and create dir if needed. 198 * Check disk space and/or quotas too. 199 * 200 * We don't need to set the _last_status field of found after the fork 201 * in the child, b/c that information would be later determined in 202 * nfsproc_readlink_2() and the correct exit status would be returned 203 * to the parent upon SIGCHLD in interlock(). --- 49 unchanged lines hidden (view full) --- 253 254 255static int 256hlfsd_diskspace(char *path) 257{ 258 char buf[MAXPATHLEN]; 259 int fd, len; 260 | 165 * 166 * Check and create dir if needed. 167 * Check disk space and/or quotas too. 168 * 169 * We don't need to set the _last_status field of found after the fork 170 * in the child, b/c that information would be later determined in 171 * nfsproc_readlink_2() and the correct exit status would be returned 172 * to the parent upon SIGCHLD in interlock(). --- 49 unchanged lines hidden (view full) --- 222 223 224static int 225hlfsd_diskspace(char *path) 226{ 227 char buf[MAXPATHLEN]; 228 int fd, len; 229 |
261 clock_valid = 0; /* invalidate logging clock */ 262 263 sprintf(buf, "%s/._hlfstmp_%lu", path, (long) getpid()); | 230 xsnprintf(buf, sizeof(buf), "%s/._hlfstmp_%lu", path, (long) getpid()); |
264 if ((fd = open(buf, O_RDWR | O_CREAT, 0600)) < 0) { 265 plog(XLOG_ERROR, "cannot open %s: %m", buf); 266 return -1; 267 } 268 len = strlen(buf); 269 if (write(fd, buf, len) < len) { 270 plog(XLOG_ERROR, "cannot write \"%s\" (%d bytes) to %s : %m", buf, len, buf); 271 close(fd); --- 21 unchanged lines hidden (view full) --- 293} 294 295 296static void 297delay(uid2home_t *found, int secs) 298{ 299 struct timeval tv; 300 | 231 if ((fd = open(buf, O_RDWR | O_CREAT, 0600)) < 0) { 232 plog(XLOG_ERROR, "cannot open %s: %m", buf); 233 return -1; 234 } 235 len = strlen(buf); 236 if (write(fd, buf, len) < len) { 237 plog(XLOG_ERROR, "cannot write \"%s\" (%d bytes) to %s : %m", buf, len, buf); 238 close(fd); --- 21 unchanged lines hidden (view full) --- 260} 261 262 263static void 264delay(uid2home_t *found, int secs) 265{ 266 struct timeval tv; 267 |
301#ifdef DEBUG 302 if (found) 303 dlog("delaying on child %ld for %d seconds", (long) found->child, secs); 304#endif /* DEBUG */ | 268 dlog("delaying on child %ld for %d seconds", (long) found->child, secs); |
305 306 tv.tv_usec = 0; 307 308 do { 309 tv.tv_sec = secs; 310 if (select(0, 0, 0, 0, &tv) == 0) 311 break; 312 } while (--secs && found->child); --- 6 unchanged lines hidden (view full) --- 319 * update the last_status field of the requesting user. 320 */ 321RETSIGTYPE 322interlock(int signum) 323{ 324 int child; 325 uid2home_t *lostchild; 326 int status; | 269 270 tv.tv_usec = 0; 271 272 do { 273 tv.tv_sec = secs; 274 if (select(0, 0, 0, 0, &tv) == 0) 275 break; 276 } while (--secs && found->child); --- 6 unchanged lines hidden (view full) --- 283 * update the last_status field of the requesting user. 284 */ 285RETSIGTYPE 286interlock(int signum) 287{ 288 int child; 289 uid2home_t *lostchild; 290 int status; |
327 int max_errors = 10; /* avoid infinite loops */ | |
328 329#ifdef HAVE_WAITPID | 291 292#ifdef HAVE_WAITPID |
330 while ((child = waitpid((pid_t) -1, &status, WNOHANG)) != 0) { | 293 while ((child = waitpid((pid_t) -1, &status, WNOHANG)) > 0) { |
331#else /* not HAVE_WAITPID */ | 294#else /* not HAVE_WAITPID */ |
332 while ((child = wait3(&status, WNOHANG, (struct rusage *) 0)) != 0) { | 295 while ((child = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0) { |
333#endif /* not HAVE_WAITPID */ 334 | 296#endif /* not HAVE_WAITPID */ 297 |
335 if (child < 0) { 336 plog(XLOG_WARNING, "waitpid/wait3: %m"); 337 if (--max_errors > 0) 338 continue; 339 else 340 break; 341 } 342 | |
343 /* high chances this was the last child forked */ 344 if (lastchild && lastchild->child == child) { 345 lastchild->child = 0; 346 347 if (WIFEXITED(status)) 348 lastchild->last_status = WEXITSTATUS(status); | 298 /* high chances this was the last child forked */ 299 if (lastchild && lastchild->child == child) { 300 lastchild->child = 0; 301 302 if (WIFEXITED(status)) 303 lastchild->last_status = WEXITSTATUS(status); |
349 else if (WIFSIGNALED(status)) 350 lastchild->last_status = -WTERMSIG(status); 351 else { 352 plog(XLOG_ERROR, "unknown child exit status (%d) ???", status); 353 lastchild->last_status = 255; 354 } | |
355 lastchild = (uid2home_t *) NULL; 356 } else { 357 /* and if not, we have to search for it... */ | 304 lastchild = (uid2home_t *) NULL; 305 } else { 306 /* and if not, we have to search for it... */ |
358 int found = 0; | |
359 for (lostchild = pwtab; lostchild < &pwtab[cur_pwtab_num]; lostchild++) { 360 if (lostchild->child == child) { | 307 for (lostchild = pwtab; lostchild < &pwtab[cur_pwtab_num]; lostchild++) { 308 if (lostchild->child == child) { |
361 lostchild->child = 0; | |
362 if (WIFEXITED(status)) 363 lostchild->last_status = WEXITSTATUS(status); | 309 if (WIFEXITED(status)) 310 lostchild->last_status = WEXITSTATUS(status); |
364 else if (WIFSIGNALED(status)) 365 lostchild->last_status = -WTERMSIG(status); 366 else { 367 plog(XLOG_ERROR, "unknown child exit status (%d) ???", status); 368 lostchild->last_status = 255; 369 } 370 found = 1; | 311 lostchild->child = 0; |
371 break; 372 } 373 } | 312 break; 313 } 314 } |
374 if (!found) 375 plog(XLOG_ERROR, "no record of child %d found???", child); | |
376 } 377 } 378} 379 380 381/* 382 * PASSWORD AND USERNAME LOOKUP TABLES FUNCTIONS 383 */ --- 67 unchanged lines hidden (view full) --- 451 char *home; 452 453 if (uid < 0) 454 return (char *) NULL; /* not found */ 455 456 if ((home = homeof(username)) == (char *) NULL) 457 return (char *) NULL; 458 if (STREQ(home, "/")) | 315 } 316 } 317} 318 319 320/* 321 * PASSWORD AND USERNAME LOOKUP TABLES FUNCTIONS 322 */ --- 67 unchanged lines hidden (view full) --- 390 char *home; 391 392 if (uid < 0) 393 return (char *) NULL; /* not found */ 394 395 if ((home = homeof(username)) == (char *) NULL) 396 return (char *) NULL; 397 if (STREQ(home, "/")) |
459 sprintf(mboxfile, "/%s/%s", home_subdir, username); | 398 xsnprintf(mboxfile, sizeof(mboxfile), 399 "/%s/%s", home_subdir, username); |
460 else | 400 else |
461 sprintf(mboxfile, "%s/%s/%s", home, home_subdir, username); | 401 xsnprintf(mboxfile, sizeof(mboxfile), 402 "%s/%s/%s", home, home_subdir, username); |
462 return mboxfile; 463} 464 465 466static int 467plt_compare_fxn(const voidp x, const voidp y) | 403 return mboxfile; 404} 405 406 407static int 408plt_compare_fxn(const voidp x, const voidp y) |
409 |
|
468{ 469 uid2home_t *i = (uid2home_t *) x; 470 uid2home_t *j = (uid2home_t *) y; 471 472 return i->uid - j->uid; 473} 474 475 --- 58 unchanged lines hidden (view full) --- 534{ 535 char buf[256], *cp; 536 537 /* check if to perform standard unix function */ 538 if (!passwdfile) { 539 return getpwent(); 540 } 541 | 410{ 411 uid2home_t *i = (uid2home_t *) x; 412 uid2home_t *j = (uid2home_t *) y; 413 414 return i->uid - j->uid; 415} 416 417 --- 58 unchanged lines hidden (view full) --- 476{ 477 char buf[256], *cp; 478 479 /* check if to perform standard unix function */ 480 if (!passwdfile) { 481 return getpwent(); 482 } 483 |
542 clock_valid = 0; /* invalidate logging clock */ 543 | |
544 /* return here to read another entry */ 545readent: 546 547 /* return NULL if reached end of file */ 548 if (feof(passwd_fp)) 549 return NULL; 550 551 pw_name[0] = pw_dir[0] = '\0'; --- 6 unchanged lines hidden (view full) --- 558 goto readent; 559 560 /* read user name */ 561 cp = strtok(buf, ":"); 562 if (!cp || cp[0] == '\0') { 563 plog(XLOG_ERROR, "no user name on line %d of %s", passwd_line, passwdfile); 564 goto readent; 565 } | 484 /* return here to read another entry */ 485readent: 486 487 /* return NULL if reached end of file */ 488 if (feof(passwd_fp)) 489 return NULL; 490 491 pw_name[0] = pw_dir[0] = '\0'; --- 6 unchanged lines hidden (view full) --- 498 goto readent; 499 500 /* read user name */ 501 cp = strtok(buf, ":"); 502 if (!cp || cp[0] == '\0') { 503 plog(XLOG_ERROR, "no user name on line %d of %s", passwd_line, passwdfile); 504 goto readent; 505 } |
566 strcpy(pw_name, cp); /* will show up in passwd_ent.pw_name */ | 506 /* pw_name will show up in passwd_ent.pw_name */ 507 xstrlcpy(pw_name, cp, sizeof(pw_name)); |
567 568 /* skip passwd */ 569 strtok(NULL, ":"); 570 571 /* read uid */ 572 cp = strtok(NULL, ":"); 573 if (!cp || cp[0] == '\0') { 574 plog(XLOG_ERROR, "no uid on line %d of %s", passwd_line, passwdfile); --- 6 unchanged lines hidden (view full) --- 581 strtok(NULL, ":"); 582 583 /* read home dir */ 584 cp = strtok(NULL, ":"); 585 if (!cp || cp[0] == '\0') { 586 plog(XLOG_ERROR, "no home dir on line %d of %s", passwd_line, passwdfile); 587 goto readent; 588 } | 508 509 /* skip passwd */ 510 strtok(NULL, ":"); 511 512 /* read uid */ 513 cp = strtok(NULL, ":"); 514 if (!cp || cp[0] == '\0') { 515 plog(XLOG_ERROR, "no uid on line %d of %s", passwd_line, passwdfile); --- 6 unchanged lines hidden (view full) --- 522 strtok(NULL, ":"); 523 524 /* read home dir */ 525 cp = strtok(NULL, ":"); 526 if (!cp || cp[0] == '\0') { 527 plog(XLOG_ERROR, "no home dir on line %d of %s", passwd_line, passwdfile); 528 goto readent; 529 } |
589 strcpy(pw_dir, cp); /* will show up in passwd_ent.pw_dir */ | 530 /* pw_dir will show up in passwd_ent.pw_dir */ 531 xstrlcpy(pw_dir, cp, sizeof(pw_dir)); |
590 591 /* the rest of the fields are unimportant and not being considered */ 592 593 plog(XLOG_USER, "hlfsd_getpwent: name=%s, uid=%ld, dir=%s", 594 passwd_ent.pw_name, (long) passwd_ent.pw_uid, passwd_ent.pw_dir); 595 596 return &passwd_ent; 597} --- 46 unchanged lines hidden (view full) --- 644 * This is essentially so that we don't reset known good lookup tables when a 645 * YP server goes down. 646 */ 647static int 648plt_reset(void) 649{ 650 int i; 651 | 532 533 /* the rest of the fields are unimportant and not being considered */ 534 535 plog(XLOG_USER, "hlfsd_getpwent: name=%s, uid=%ld, dir=%s", 536 passwd_ent.pw_name, (long) passwd_ent.pw_uid, passwd_ent.pw_dir); 537 538 return &passwd_ent; 539} --- 46 unchanged lines hidden (view full) --- 586 * This is essentially so that we don't reset known good lookup tables when a 587 * YP server goes down. 588 */ 589static int 590plt_reset(void) 591{ 592 int i; 593 |
652 clock_valid = 0; /* invalidate logging clock */ 653 | |
654 hlfsd_setpwent(); 655 if (hlfsd_getpwent() == (struct passwd *) NULL) { 656 hlfsd_endpwent(); 657 return -1; /* did not reset table */ 658 } 659 hlfsd_endpwent(); 660 661 lastchild = (uid2home_t *) NULL; --- 24 unchanged lines hidden (view full) --- 686 687 688/* 689 * u: uid number 690 * h: home directory 691 * n: user ID name 692 */ 693static void | 594 hlfsd_setpwent(); 595 if (hlfsd_getpwent() == (struct passwd *) NULL) { 596 hlfsd_endpwent(); 597 return -1; /* did not reset table */ 598 } 599 hlfsd_endpwent(); 600 601 lastchild = (uid2home_t *) NULL; --- 24 unchanged lines hidden (view full) --- 626 627 628/* 629 * u: uid number 630 * h: home directory 631 * n: user ID name 632 */ 633static void |
694table_add(int u, const char *h, const char *n) | 634table_add(u_int u, const char *h, const char *n) |
695{ 696 int i; 697 | 635{ 636 int i; 637 |
698 clock_valid = 0; /* invalidate logging clock */ 699 | |
700 if (max_pwtab_num <= 0) { /* was never initialized */ 701 max_pwtab_num = 1; 702 pwtab = (uid2home_t *) xmalloc(max_pwtab_num * 703 sizeof(uid2home_t)); 704 memset((char *) &pwtab[0], 0, max_pwtab_num * sizeof(uid2home_t)); 705 untab = (username2uid_t *) xmalloc(max_pwtab_num * 706 sizeof(username2uid_t)); 707 memset((char *) &untab[0], 0, max_pwtab_num * sizeof(username2uid_t)); --- 14 unchanged lines hidden (view full) --- 722 memset((char *) &pwtab[i], 0, sizeof(uid2home_t)); 723 memset((char *) &untab[i], 0, sizeof(username2uid_t)); 724 } 725 } 726 727 /* do NOT add duplicate entries (this is an O(N^2) algorithm... */ 728 for (i=0; i<cur_pwtab_num; ++i) 729 if (u == pwtab[i].uid && u != 0 ) { | 638 if (max_pwtab_num <= 0) { /* was never initialized */ 639 max_pwtab_num = 1; 640 pwtab = (uid2home_t *) xmalloc(max_pwtab_num * 641 sizeof(uid2home_t)); 642 memset((char *) &pwtab[0], 0, max_pwtab_num * sizeof(uid2home_t)); 643 untab = (username2uid_t *) xmalloc(max_pwtab_num * 644 sizeof(username2uid_t)); 645 memset((char *) &untab[0], 0, max_pwtab_num * sizeof(username2uid_t)); --- 14 unchanged lines hidden (view full) --- 660 memset((char *) &pwtab[i], 0, sizeof(uid2home_t)); 661 memset((char *) &untab[i], 0, sizeof(username2uid_t)); 662 } 663 } 664 665 /* do NOT add duplicate entries (this is an O(N^2) algorithm... */ 666 for (i=0; i<cur_pwtab_num; ++i) 667 if (u == pwtab[i].uid && u != 0 ) { |
730#ifdef DEBUG | |
731 dlog("ignoring duplicate home %s for uid %d (already %s)", 732 h, u, pwtab[i].home); | 668 dlog("ignoring duplicate home %s for uid %d (already %s)", 669 h, u, pwtab[i].home); |
733#endif /* DEBUG */ | |
734 return; 735 } 736 737 /* add new password entry */ 738 pwtab[cur_pwtab_num].home = strdup(h); 739 pwtab[cur_pwtab_num].child = 0; 740 pwtab[cur_pwtab_num].last_access_time = 0; 741 pwtab[cur_pwtab_num].last_status = 0; /* assume best: used homedir */ --- 11 unchanged lines hidden (view full) --- 753 ++cur_pwtab_num; 754} 755 756 757/* 758 * return entry in lookup table 759 */ 760uid2home_t * | 670 return; 671 } 672 673 /* add new password entry */ 674 pwtab[cur_pwtab_num].home = strdup(h); 675 pwtab[cur_pwtab_num].child = 0; 676 pwtab[cur_pwtab_num].last_access_time = 0; 677 pwtab[cur_pwtab_num].last_status = 0; /* assume best: used homedir */ --- 11 unchanged lines hidden (view full) --- 689 ++cur_pwtab_num; 690} 691 692 693/* 694 * return entry in lookup table 695 */ 696uid2home_t * |
761plt_search(int u) | 697plt_search(u_int u) |
762{ 763 int max, min, mid; 764 765 /* 766 * empty table should not happen, 767 * but I have a bug with signals to trace... 768 */ 769 if (pwtab == (uid2home_t *) NULL) --- 102 unchanged lines hidden --- | 698{ 699 int max, min, mid; 700 701 /* 702 * empty table should not happen, 703 * but I have a bug with signals to trace... 704 */ 705 if (pwtab == (uid2home_t *) NULL) --- 102 unchanged lines hidden --- |