version 1.9, 1999/10/04 20:45:01 |
version 1.10, 1999/10/05 22:18:52 |
|
|
|
|
int max_fd = 0; |
int max_fd = 0; |
|
|
|
/* pid of agent == parent of shell */ |
|
int parent_pid = -1; |
|
|
|
/* pathname and directory for AUTH_SOCKET */ |
|
char socket_name[1024]; |
|
char socket_dir[1024]; |
|
|
void |
void |
process_request_identity(SocketEntry *e) |
process_request_identity(SocketEntry *e) |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
int parent_pid = -1; |
|
char socket_name[1024]; |
|
|
|
void |
void |
check_parent_exists(int sig) |
check_parent_exists(int sig) |
{ |
{ |
if (kill(parent_pid, 0) < 0) |
if (kill(parent_pid, 0) < 0) |
{ |
{ |
remove(socket_name); |
|
/* printf("Parent has died - Authentication agent exiting.\n"); */ |
/* printf("Parent has died - Authentication agent exiting.\n"); */ |
exit(1); |
exit(1); |
} |
} |
|
|
alarm(10); |
alarm(10); |
} |
} |
|
|
|
void cleanup_socket(void) { |
|
remove(socket_name); |
|
rmdir(socket_dir); |
|
} |
|
|
int |
int |
main(int ac, char **av) |
main(int ac, char **av) |
{ |
{ |
fd_set readset, writeset; |
fd_set readset, writeset; |
char buf[1024]; |
|
int pfd; |
|
int sock; |
int sock; |
struct sockaddr_un sunaddr; |
struct sockaddr_un sunaddr; |
|
|
int sockets[2], i; |
|
int *dups; |
|
|
|
/* check if RSA support exists */ |
/* check if RSA support exists */ |
if (rsa_alive() == 0) { |
if (rsa_alive() == 0) { |
extern char *__progname; |
extern char *__progname; |
|
|
fprintf(stderr, |
fprintf(stderr, |
"%s: no RSA support in libssl and libcrypto. See ssl(8).\n", |
"%s: no RSA support in libssl and libcrypto. See ssl(8).\n", |
__progname); |
__progname); |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
/* The agent uses SSH_AUTHENTICATION_SOCKET. */ |
|
|
|
parent_pid = getpid(); |
parent_pid = getpid(); |
|
|
|
/* Create private directory for agent socket */ |
|
strlcpy(socket_dir, "/tmp/ssh-XXXXXXXX", sizeof socket_dir); |
|
if (mkdtemp(socket_dir) == NULL) { |
|
perror("mkdtemp: private socket dir"); |
|
exit(1); |
|
} |
|
snprintf(socket_name, sizeof socket_name, "%s/agent.%d", socket_dir, parent_pid); |
|
|
snprintf(socket_name, sizeof socket_name, SSH_AGENT_SOCKET, parent_pid); |
|
|
|
/* Fork, and have the parent execute the command. The child continues as |
/* Fork, and have the parent execute the command. The child continues as |
the authentication agent. */ |
the authentication agent. */ |
if (fork() != 0) |
if (fork() != 0) |
{ /* Parent - execute the given command. */ |
{ /* Parent - execute the given command. */ |
snprintf(buf, sizeof buf, "SSH_AUTHENTICATION_SOCKET=%s", socket_name); |
setenv("SSH_AUTHENTICATION_SOCKET", socket_name, 1); |
putenv(buf); |
|
execvp(av[1], av + 1); |
execvp(av[1], av + 1); |
perror(av[1]); |
perror(av[1]); |
exit(1); |
exit(1); |
} |
} |
|
|
|
if (atexit(cleanup_socket) < 0) { |
|
perror("atexit"); |
|
cleanup_socket(); |
|
exit(1); |
|
} |
|
|
sock = socket(AF_UNIX, SOCK_STREAM, 0); |
sock = socket(AF_UNIX, SOCK_STREAM, 0); |
if (sock < 0) |
if (sock < 0) |
{ |
{ |
|
|
if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) |
if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) |
{ |
{ |
perror("bind"); |
perror("bind"); |
exit(1); |
|
} |
|
if (chmod(socket_name, 0700) < 0) |
|
{ |
|
perror("chmod"); |
|
exit(1); |
exit(1); |
} |
} |
if (listen(sock, 5) < 0) |
if (listen(sock, 5) < 0) |