|
Lines 510-515
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 510 |
int status, devnull, p[2], i; |
510 |
int status, devnull, p[2], i; |
| 511 |
pid_t pid; |
511 |
pid_t pid; |
| 512 |
char *username, errmsg[512]; |
512 |
char *username, errmsg[512]; |
|
|
513 |
char *command, *cp, *argv[4]; |
| 514 |
char *key_fp = NULL, *keytext = NULL; |
| 515 |
char *authorized_keys_command_path; |
| 516 |
size_t keytextlen; |
| 513 |
|
517 |
|
| 514 |
if (options.authorized_keys_command == NULL || |
518 |
if (options.authorized_keys_command == NULL || |
| 515 |
options.authorized_keys_command[0] != '/') |
519 |
options.authorized_keys_command[0] != '/') |
|
Lines 533-544
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 533 |
|
537 |
|
| 534 |
temporarily_use_uid(pw); |
538 |
temporarily_use_uid(pw); |
| 535 |
|
539 |
|
| 536 |
if (stat(options.authorized_keys_command, &st) < 0) { |
540 |
if (strstr(options.authorized_keys_command, "%f") != NULL) { |
|
|
541 |
key_fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX); |
| 542 |
if (key_fp == NULL) { |
| 543 |
error("AuthorizedKeysCommand %%f parameter expansion failed"); |
| 544 |
return 0; |
| 545 |
} |
| 546 |
} |
| 547 |
if (strstr(options.authorized_keys_command, "%k") != NULL) { |
| 548 |
if (key_to_base64(key, &keytext, &keytextlen) != 0) { |
| 549 |
error("AuthorizedKeysCommand %%k parameter expansion failed"); |
| 550 |
free(key_fp); |
| 551 |
return 0; |
| 552 |
} |
| 553 |
} |
| 554 |
command = cp = percent_expand(options.authorized_keys_command, |
| 555 |
"u", user_pw->pw_name, "t", key_ssh_name(key), |
| 556 |
"f", key_fp == NULL ? "" : key_fp, |
| 557 |
"k", keytext == NULL ? "" : keytext, (char *)NULL); |
| 558 |
if (keytext != NULL) |
| 559 |
free(keytext); |
| 560 |
if (key_fp != NULL) |
| 561 |
free(key_fp); |
| 562 |
|
| 563 |
authorized_keys_command_path = strdelim(&cp); |
| 564 |
memset(argv, 0, sizeof(argv)); |
| 565 |
for (i = 0; cp != NULL && (size_t)i < sizeof(argv); i++) |
| 566 |
argv[i] = strdelim(&cp); |
| 567 |
if (i == 0) |
| 568 |
argv[0] = user_pw->pw_name; |
| 569 |
|
| 570 |
if (stat(authorized_keys_command_path, &st) < 0) { |
| 537 |
error("Could not stat AuthorizedKeysCommand \"%s\": %s", |
571 |
error("Could not stat AuthorizedKeysCommand \"%s\": %s", |
| 538 |
options.authorized_keys_command, strerror(errno)); |
572 |
authorized_keys_command_path, strerror(errno)); |
| 539 |
goto out; |
573 |
goto out; |
| 540 |
} |
574 |
} |
| 541 |
if (auth_secure_path(options.authorized_keys_command, &st, NULL, 0, |
575 |
if (auth_secure_path(authorized_keys_command_path, &st, NULL, 0, |
| 542 |
errmsg, sizeof(errmsg)) != 0) { |
576 |
errmsg, sizeof(errmsg)) != 0) { |
| 543 |
error("Unsafe AuthorizedKeysCommand: %s", errmsg); |
577 |
error("Unsafe AuthorizedKeysCommand: %s", errmsg); |
| 544 |
goto out; |
578 |
goto out; |
|
Lines 549-556
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 549 |
goto out; |
583 |
goto out; |
| 550 |
} |
584 |
} |
| 551 |
|
585 |
|
| 552 |
debug3("Running AuthorizedKeysCommand: \"%s %s\" as \"%s\"", |
586 |
debug3("Running AuthorizedKeysCommand: \"%s %s%s%s%s%s%s%s\" as \"%s\"", |
| 553 |
options.authorized_keys_command, user_pw->pw_name, pw->pw_name); |
587 |
authorized_keys_command_path, argv[0], |
|
|
588 |
argv[1] == NULL ? "" : " ", argv[1] == NULL ? "" : argv[1], |
| 589 |
argv[2] == NULL ? "" : " ", argv[2] == NULL ? "" : argv[2], |
| 590 |
argv[3] == NULL ? "" : " ", argv[3] == NULL ? "" : argv[3], |
| 591 |
pw->pw_name); |
| 554 |
|
592 |
|
| 555 |
/* |
593 |
/* |
| 556 |
* Don't want to call this in the child, where it can fatal() and |
594 |
* Don't want to call this in the child, where it can fatal() and |
|
Lines 563-568
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 563 |
error("%s: fork: %s", __func__, strerror(errno)); |
601 |
error("%s: fork: %s", __func__, strerror(errno)); |
| 564 |
close(p[0]); |
602 |
close(p[0]); |
| 565 |
close(p[1]); |
603 |
close(p[1]); |
|
|
604 |
free(command); |
| 566 |
return 0; |
605 |
return 0; |
| 567 |
case 0: /* child */ |
606 |
case 0: /* child */ |
| 568 |
for (i = 0; i < NSIG; i++) |
607 |
for (i = 0; i < NSIG; i++) |
|
Lines 598-608
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 598 |
_exit(1); |
637 |
_exit(1); |
| 599 |
} |
638 |
} |
| 600 |
|
639 |
|
| 601 |
execl(options.authorized_keys_command, |
640 |
if (argv[3] != NULL) |
| 602 |
options.authorized_keys_command, user_pw->pw_name, NULL); |
641 |
execl(authorized_keys_command_path, |
|
|
642 |
authorized_keys_command_path, |
| 643 |
argv[0], argv[1], argv[2], argv[3], (char *)NULL); |
| 644 |
else if (argv[2] != NULL) |
| 645 |
execl(authorized_keys_command_path, |
| 646 |
authorized_keys_command_path, |
| 647 |
argv[0], argv[1], argv[2], (char *)NULL); |
| 648 |
else if (argv[1] != NULL) |
| 649 |
execl(authorized_keys_command_path, |
| 650 |
authorized_keys_command_path, |
| 651 |
argv[0], argv[1], (char *)NULL); |
| 652 |
else |
| 653 |
execl(authorized_keys_command_path, |
| 654 |
authorized_keys_command_path, argv[0], (char *)NULL); |
| 603 |
|
655 |
|
| 604 |
error("AuthorizedKeysCommand %s exec failed: %s", |
656 |
error("AuthorizedKeysCommand %s exec failed: %s", |
| 605 |
options.authorized_keys_command, strerror(errno)); |
657 |
authorized_keys_command_path, strerror(errno)); |
| 606 |
_exit(127); |
658 |
_exit(127); |
| 607 |
default: /* parent */ |
659 |
default: /* parent */ |
| 608 |
break; |
660 |
break; |
|
Lines 620-626
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 620 |
; |
672 |
; |
| 621 |
goto out; |
673 |
goto out; |
| 622 |
} |
674 |
} |
| 623 |
ok = check_authkeys_file(f, options.authorized_keys_command, key, pw); |
675 |
ok = check_authkeys_file(f, authorized_keys_command_path, key, pw); |
| 624 |
fclose(f); |
676 |
fclose(f); |
| 625 |
|
677 |
|
| 626 |
while (waitpid(pid, &status, 0) == -1) { |
678 |
while (waitpid(pid, &status, 0) == -1) { |
|
Lines 631-645
user_key_command_allowed2(struct passwd *user_pw, Key *key)
Link Here
|
| 631 |
} |
683 |
} |
| 632 |
if (WIFSIGNALED(status)) { |
684 |
if (WIFSIGNALED(status)) { |
| 633 |
error("AuthorizedKeysCommand %s exited on signal %d", |
685 |
error("AuthorizedKeysCommand %s exited on signal %d", |
| 634 |
options.authorized_keys_command, WTERMSIG(status)); |
686 |
authorized_keys_command_path, WTERMSIG(status)); |
| 635 |
goto out; |
687 |
goto out; |
| 636 |
} else if (WEXITSTATUS(status) != 0) { |
688 |
} else if (WEXITSTATUS(status) != 0) { |
| 637 |
error("AuthorizedKeysCommand %s returned status %d", |
689 |
error("AuthorizedKeysCommand %s returned status %d", |
| 638 |
options.authorized_keys_command, WEXITSTATUS(status)); |
690 |
authorized_keys_command_path, WEXITSTATUS(status)); |
| 639 |
goto out; |
691 |
goto out; |
| 640 |
} |
692 |
} |
| 641 |
found_key = ok; |
693 |
found_key = ok; |
| 642 |
out: |
694 |
out: |
|
|
695 |
free(command); |
| 643 |
restore_uid(); |
696 |
restore_uid(); |
| 644 |
return found_key; |
697 |
return found_key; |
| 645 |
} |
698 |
} |