version 1.56, 2001/06/25 08:25:40 |
version 1.57, 2001/06/26 04:07:06 |
|
|
int |
int |
main(int ac, char **av) |
main(int ac, char **av) |
{ |
{ |
int sock, c_flag = 0, k_flag = 0, s_flag = 0, ch; |
int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch; |
struct sockaddr_un sunaddr; |
struct sockaddr_un sunaddr; |
struct rlimit rlim; |
struct rlimit rlim; |
pid_t pid; |
pid_t pid; |
|
|
|
|
SSLeay_add_all_algorithms(); |
SSLeay_add_all_algorithms(); |
|
|
while ((ch = getopt(ac, av, "cks")) != -1) { |
while ((ch = getopt(ac, av, "cdks")) != -1) { |
switch (ch) { |
switch (ch) { |
case 'c': |
case 'c': |
if (s_flag) |
if (s_flag) |
|
|
usage(); |
usage(); |
s_flag++; |
s_flag++; |
break; |
break; |
|
case 'd': |
|
if (d_flag) |
|
usage(); |
|
d_flag++; |
|
break; |
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
ac -= optind; |
ac -= optind; |
av += optind; |
av += optind; |
|
|
if (ac > 0 && (c_flag || k_flag || s_flag)) |
if (ac > 0 && (c_flag || k_flag || s_flag || d_flag)) |
usage(); |
usage(); |
|
|
if (ac == 0 && !c_flag && !k_flag && !s_flag) { |
if (ac == 0 && !c_flag && !k_flag && !s_flag && !d_flag) { |
shell = getenv("SHELL"); |
shell = getenv("SHELL"); |
if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0) |
if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0) |
c_flag = 1; |
c_flag = 1; |
|
|
* Fork, and have the parent execute the command, if any, or present |
* Fork, and have the parent execute the command, if any, or present |
* the socket data. The child continues as the authentication agent. |
* the socket data. The child continues as the authentication agent. |
*/ |
*/ |
|
if (d_flag) { |
|
log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1); |
|
format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n"; |
|
printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name, |
|
SSH_AUTHSOCKET_ENV_NAME); |
|
printf("echo Agent pid %d;\n", parent_pid); |
|
goto skip; |
|
} |
pid = fork(); |
pid = fork(); |
if (pid == -1) { |
if (pid == -1) { |
perror("fork"); |
perror("fork"); |
|
|
perror("setsid"); |
perror("setsid"); |
cleanup_exit(1); |
cleanup_exit(1); |
} |
} |
|
|
|
skip: |
if (atexit(cleanup_socket) < 0) { |
if (atexit(cleanup_socket) < 0) { |
perror("atexit"); |
perror("atexit"); |
cleanup_exit(1); |
cleanup_exit(1); |
|
|
alarm(10); |
alarm(10); |
} |
} |
idtab_init(); |
idtab_init(); |
signal(SIGINT, SIG_IGN); |
if (!d_flag) { |
signal(SIGPIPE, SIG_IGN); |
signal(SIGINT, SIG_IGN); |
|
signal(SIGPIPE, SIG_IGN); |
|
} |
signal(SIGHUP, cleanup_handler); |
signal(SIGHUP, cleanup_handler); |
signal(SIGTERM, cleanup_handler); |
signal(SIGTERM, cleanup_handler); |
while (1) { |
while (1) { |