|
Lines 345-357
Link Here
|
| 345 |
}, to; |
345 |
}, to; |
| 346 |
struct passwd *pw = NULL; |
346 |
struct passwd *pw = NULL; |
| 347 |
fd_set fdset; |
347 |
fd_set fdset; |
| 348 |
char buf[BUFSIZE], *cp = NULL, *p, **av, *osname = NULL, garbage[7], e; |
348 |
char buf[BUFSIZE], *p, **av, *osname = NULL, garbage[7], e; |
| 349 |
char *fallback = NULL; |
349 |
char uidbuf[sizeof "1234567890"]; |
|
|
350 |
char *fallback = NULL, *res; |
| 350 |
socklen_t socklen; |
351 |
socklen_t socklen; |
| 351 |
ssize_t ssize; |
352 |
ssize_t ssize; |
| 352 |
size_t size, bufsiz; |
353 |
size_t size, bufsiz; |
| 353 |
int c, fflag = 0, nflag = 0, rflag = 0, argc = 0, usedfallback = 0; |
354 |
int c, fflag = 0, nflag = 0, rflag = 0, argc = 0; |
| 354 |
int gflag = 0, Fflag = 0, getcredfail = 0, onreadlen; |
355 |
int gflag = 0, Fflag = 0, getcredfail = 0, onreadlen, useuid = 0; |
| 355 |
u_short lport, fport; |
356 |
u_short lport, fport; |
| 356 |
|
357 |
|
| 357 |
inetd_setproctitle(sep->se_service, s); |
358 |
inetd_setproctitle(sep->se_service, s); |
|
Lines 373-379
Link Here
|
| 373 |
size_t i; |
374 |
size_t i; |
| 374 |
u_int32_t random; |
375 |
u_int32_t random; |
| 375 |
|
376 |
|
| 376 |
while ((c = getopt(argc, sep->se_argv, "d:fFgno:rt:")) != -1) |
377 |
while ((c = getopt(argc, sep->se_argv, "d:fFgino:rt:")) != -1) |
| 377 |
switch (c) { |
378 |
switch (c) { |
| 378 |
case 'd': |
379 |
case 'd': |
| 379 |
fallback = optarg; |
380 |
fallback = optarg; |
|
Lines 410-415
Link Here
|
| 410 |
} |
411 |
} |
| 411 |
garbage[i] = '\0'; |
412 |
garbage[i] = '\0'; |
| 412 |
break; |
413 |
break; |
|
|
414 |
case 'i': |
| 415 |
useuid = 1; |
| 416 |
break; |
| 413 |
case 'n': |
417 |
case 'n': |
| 414 |
nflag = 1; |
418 |
nflag = 1; |
| 415 |
break; |
419 |
break; |
|
Lines 494-500
Link Here
|
| 494 |
if (sscanf(buf, "%hu , %hu%c", &lport, &fport, &e) != 3 || isdigit(e)) |
498 |
if (sscanf(buf, "%hu , %hu%c", &lport, &fport, &e) != 3 || isdigit(e)) |
| 495 |
iderror(0, 0, s, 0); |
499 |
iderror(0, 0, s, 0); |
| 496 |
if (gflag) { |
500 |
if (gflag) { |
| 497 |
cp = garbage; |
501 |
res = garbage; |
| 498 |
goto printit; |
502 |
goto printit; |
| 499 |
} |
503 |
} |
| 500 |
|
504 |
|
|
Lines 506-515
Link Here
|
| 506 |
if (!rflag) { |
510 |
if (!rflag) { |
| 507 |
if (fallback == NULL) |
511 |
if (fallback == NULL) |
| 508 |
iderror(lport, fport, s, -1); |
512 |
iderror(lport, fport, s, -1); |
| 509 |
else { |
513 |
res = fallback; |
| 510 |
cp = fallback; |
514 |
goto printit; |
| 511 |
goto printit; |
|
|
| 512 |
} |
| 513 |
} |
515 |
} |
| 514 |
|
516 |
|
| 515 |
/* |
517 |
/* |
|
Lines 552-570
Link Here
|
| 552 |
if (getcredfail != 0) { |
554 |
if (getcredfail != 0) { |
| 553 |
if (fallback == NULL) /* Use a default, if asked to */ |
555 |
if (fallback == NULL) /* Use a default, if asked to */ |
| 554 |
iderror(lport, fport, s, getcredfail); |
556 |
iderror(lport, fport, s, getcredfail); |
| 555 |
usedfallback = 1; |
557 |
res = fallback; |
| 556 |
} else { |
558 |
goto printit; |
| 557 |
/* Look up the pw to get the username */ |
559 |
} |
| 558 |
errno = 0; |
560 |
|
| 559 |
pw = getpwuid(uc.cr_uid); |
561 |
/* Look up the pw to get the username */ |
| 560 |
} |
562 |
errno = 0; |
| 561 |
if (pw == NULL && !usedfallback) /* No such user... */ |
563 |
pw = getpwuid(uc.cr_uid); |
|
|
564 |
if (pw == NULL) /* No such user... */ |
| 562 |
iderror(lport, fport, s, errno != 0 ? errno : ENOENT); |
565 |
iderror(lport, fport, s, errno != 0 ? errno : ENOENT); |
|
|
566 |
|
| 567 |
if (useuid){ |
| 568 |
snprintf(uidbuf, sizeof uidbuf, "%u", pw->pw_uid); |
| 569 |
res = uidbuf; |
| 570 |
} else |
| 571 |
res = pw->pw_name; |
| 572 |
|
| 563 |
/* |
573 |
/* |
| 564 |
* If enabled, we check for a file named ".noident" in the user's |
574 |
* If enabled, we check for a file named ".noident" in the user's |
| 565 |
* home directory. If found, we return HIDDEN-USER. |
575 |
* home directory. If found, we return HIDDEN-USER. |
| 566 |
*/ |
576 |
*/ |
| 567 |
if (nflag && !usedfallback) { |
577 |
if (nflag) { |
| 568 |
if (asprintf(&p, "%s/.noident", pw->pw_dir) == -1) |
578 |
if (asprintf(&p, "%s/.noident", pw->pw_dir) == -1) |
| 569 |
iderror(lport, fport, s, errno); |
579 |
iderror(lport, fport, s, errno); |
| 570 |
if (lstat(p, &sb) == 0) { |
580 |
if (lstat(p, &sb) == 0) { |
|
Lines 578-584
Link Here
|
| 578 |
* home directory. It consists of a line containing the name |
588 |
* home directory. It consists of a line containing the name |
| 579 |
* they want. |
589 |
* they want. |
| 580 |
*/ |
590 |
*/ |
| 581 |
if (fflag && !usedfallback) { |
591 |
if (fflag) { |
| 582 |
FILE *fakeid = NULL; |
592 |
FILE *fakeid = NULL; |
| 583 |
int fakeid_fd; |
593 |
int fakeid_fd; |
| 584 |
|
594 |
|
|
Lines 604-612
Link Here
|
| 604 |
if (fakeid_fd != -1 && fstat(fakeid_fd, &sb) != -1 && |
614 |
if (fakeid_fd != -1 && fstat(fakeid_fd, &sb) != -1 && |
| 605 |
S_ISREG(sb.st_mode) && |
615 |
S_ISREG(sb.st_mode) && |
| 606 |
(fakeid = fdopen(fakeid_fd, "r")) != NULL) { |
616 |
(fakeid = fdopen(fakeid_fd, "r")) != NULL) { |
|
|
617 |
char *cp; |
| 607 |
buf[sizeof(buf) - 1] = '\0'; |
618 |
buf[sizeof(buf) - 1] = '\0'; |
| 608 |
if (fgets(buf, sizeof(buf), fakeid) == NULL) { |
619 |
if (fgets(buf, sizeof(buf), fakeid) == NULL) { |
| 609 |
cp = pw->pw_name; |
|
|
| 610 |
fclose(fakeid); |
620 |
fclose(fakeid); |
| 611 |
goto printit; |
621 |
goto printit; |
| 612 |
} |
622 |
} |
|
Lines 626-658
Link Here
|
| 626 |
if (strlen(cp) > 16) |
636 |
if (strlen(cp) > 16) |
| 627 |
cp[16] = '\0'; |
637 |
cp[16] = '\0'; |
| 628 |
/* |
638 |
/* |
| 629 |
* If the name is a zero-length string or matches |
639 |
* If the name is a non-empty string and it |
| 630 |
* the name of another user, it's invalid, so |
640 |
* doesn't match the the name of another |
| 631 |
* we will return their real identity instead. |
641 |
* user ( unless so permitted by -F option ), |
|
|
642 |
* it is used for reply. Otherwise the real |
| 643 |
* identity is used. |
| 632 |
*/ |
644 |
*/ |
| 633 |
|
645 |
if (*cp && (Fflag || !getpwnam(cp))) |
| 634 |
if (!*cp || (!Fflag && getpwnam(cp))) { |
646 |
res = cp; |
| 635 |
errno = 0; |
|
|
| 636 |
pw = getpwuid(uc.cr_uid); |
| 637 |
if (pw == NULL) |
| 638 |
iderror(lport, fport, s, |
| 639 |
errno != 0 ? errno : ENOENT); |
| 640 |
cp = pw->pw_name; |
| 641 |
} |
| 642 |
} else |
| 643 |
cp = pw->pw_name; |
| 644 |
if (fakeid != NULL) |
| 645 |
fclose(fakeid); |
647 |
fclose(fakeid); |
| 646 |
else if (fakeid_fd != -1) |
648 |
} |
|
|
649 |
if (fakeid_fd != -1) |
| 647 |
close(fakeid_fd); |
650 |
close(fakeid_fd); |
| 648 |
} else if (!usedfallback) |
651 |
} |
| 649 |
cp = pw->pw_name; |
|
|
| 650 |
else |
| 651 |
cp = fallback; |
| 652 |
printit: |
652 |
printit: |
| 653 |
/* Finally, we make and send the reply. */ |
653 |
/* Finally, we make and send the reply. */ |
| 654 |
if (asprintf(&p, "%d , %d : USERID : %s : %s\r\n", lport, fport, osname, |
654 |
if (asprintf(&p, "%d , %d : USERID : %s : %s\r\n", lport, fport, osname, |
| 655 |
cp) == -1) { |
655 |
res) == -1) { |
| 656 |
syslog(LOG_ERR, "asprintf: %m"); |
656 |
syslog(LOG_ERR, "asprintf: %m"); |
| 657 |
exit(EX_OSERR); |
657 |
exit(EX_OSERR); |
| 658 |
} |
658 |
} |