2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * The authentication agent program.
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
13 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 RCSID("$OpenBSD: ssh-agent.c,v 1.82 2002/03/04 17:27:39 stevesk Exp $");
39 #if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
40 #include <sys/queue.h>
42 #include "openbsd-compat/fake-queue.h"
46 #include <openssl/evp.h>
47 #include <openssl/md5.h>
61 #include <openssl/engine.h>
78 u_int sockets_alloc = 0;
79 SocketEntry *sockets = NULL;
81 typedef struct identity {
82 TAILQ_ENTRY(identity) next;
89 TAILQ_HEAD(idqueue, identity) idlist;
92 /* private key table, one per protocol version */
97 /* pid of shell == parent of agent */
98 pid_t parent_pid = -1;
100 /* pathname and directory for AUTH_SOCKET */
101 char socket_name[1024];
102 char socket_dir[1024];
104 #ifdef HAVE___PROGNAME
105 extern char *__progname;
114 for (i = 0; i <=2; i++) {
115 TAILQ_INIT(&idtable[i].idlist);
116 idtable[i].nentries = 0;
120 /* return private key table for requested protocol version */
122 idtab_lookup(int version)
124 if (version < 1 || version > 2)
125 fatal("internal error, bad protocol version %d", version);
126 return &idtable[version];
129 /* return matching private key for given public key */
131 lookup_identity(Key *key, int version)
135 Idtab *tab = idtab_lookup(version);
136 TAILQ_FOREACH(id, &tab->idlist, next) {
137 if (key_equal(key, id->key))
144 free_identity(Identity *id)
151 /* send list of supported public keys to 'client' */
153 process_request_identities(SocketEntry *e, int version)
155 Idtab *tab = idtab_lookup(version);
160 buffer_put_char(&msg, (version == 1) ?
161 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
162 buffer_put_int(&msg, tab->nentries);
163 TAILQ_FOREACH(id, &tab->idlist, next) {
164 if (id->key->type == KEY_RSA1) {
165 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
166 buffer_put_bignum(&msg, id->key->rsa->e);
167 buffer_put_bignum(&msg, id->key->rsa->n);
171 key_to_blob(id->key, &blob, &blen);
172 buffer_put_string(&msg, blob, blen);
175 buffer_put_cstring(&msg, id->comment);
177 buffer_put_int(&e->output, buffer_len(&msg));
178 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
184 process_authentication_challenge1(SocketEntry *e)
192 u_char buf[32], mdbuf[16], session_id[16];
196 key = key_new(KEY_RSA1);
197 if ((challenge = BN_new()) == NULL)
198 fatal("process_authentication_challenge1: BN_new failed");
200 buffer_get_int(&e->input); /* ignored */
201 buffer_get_bignum(&e->input, key->rsa->e);
202 buffer_get_bignum(&e->input, key->rsa->n);
203 buffer_get_bignum(&e->input, challenge);
205 /* Only protocol 1.1 is supported */
206 if (buffer_len(&e->input) == 0)
208 buffer_get(&e->input, session_id, 16);
209 response_type = buffer_get_int(&e->input);
210 if (response_type != 1)
213 id = lookup_identity(key, 1);
215 Key *private = id->key;
216 /* Decrypt the challenge using the private key. */
217 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
220 /* The response is MD5 of decrypted challenge plus session id. */
221 len = BN_num_bytes(challenge);
222 if (len <= 0 || len > 32) {
223 log("process_authentication_challenge: bad challenge length %d", len);
227 BN_bn2bin(challenge, buf + 32 - len);
229 MD5_Update(&md, buf, 32);
230 MD5_Update(&md, session_id, 16);
231 MD5_Final(mdbuf, &md);
233 /* Send the response. */
234 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
235 for (i = 0; i < 16; i++)
236 buffer_put_char(&msg, mdbuf[i]);
241 /* Unknown identity or protocol error. Send failure. */
242 buffer_put_char(&msg, SSH_AGENT_FAILURE);
244 buffer_put_int(&e->output, buffer_len(&msg));
245 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
247 BN_clear_free(challenge);
253 process_sign_request2(SocketEntry *e)
255 extern int datafellows;
257 u_char *blob, *data, *signature = NULL;
258 u_int blen, dlen, slen = 0;
265 blob = buffer_get_string(&e->input, &blen);
266 data = buffer_get_string(&e->input, &dlen);
268 flags = buffer_get_int(&e->input);
269 if (flags & SSH_AGENT_OLD_SIGNATURE)
270 datafellows = SSH_BUG_SIGBLOB;
272 key = key_from_blob(blob, blen);
274 Identity *id = lookup_identity(key, 2);
276 ok = key_sign(id->key, &signature, &slen, data, dlen);
281 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
282 buffer_put_string(&msg, signature, slen);
284 buffer_put_char(&msg, SSH_AGENT_FAILURE);
286 buffer_put_int(&e->output, buffer_len(&msg));
287 buffer_append(&e->output, buffer_ptr(&msg),
292 if (signature != NULL)
298 process_remove_identity(SocketEntry *e, int version)
308 key = key_new(KEY_RSA1);
309 bits = buffer_get_int(&e->input);
310 buffer_get_bignum(&e->input, key->rsa->e);
311 buffer_get_bignum(&e->input, key->rsa->n);
313 if (bits != key_size(key))
314 log("Warning: identity keysize mismatch: actual %d, announced %d",
315 key_size(key), bits);
318 blob = buffer_get_string(&e->input, &blen);
319 key = key_from_blob(blob, blen);
324 Identity *id = lookup_identity(key, version);
327 * We have this key. Free the old key. Since we
328 * don\'t want to leave empty slots in the middle of
329 * the array, we actually free the key there and move
330 * all the entries between the empty slot and the end
333 Idtab *tab = idtab_lookup(version);
334 if (tab->nentries < 1)
335 fatal("process_remove_identity: "
336 "internal error: tab->nentries %d",
338 TAILQ_REMOVE(&tab->idlist, id, next);
345 buffer_put_int(&e->output, 1);
346 buffer_put_char(&e->output,
347 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
351 process_remove_all_identities(SocketEntry *e, int version)
353 Idtab *tab = idtab_lookup(version);
356 /* Loop over all identities and clear the keys. */
357 for (id = TAILQ_FIRST(&tab->idlist); id;
358 id = TAILQ_FIRST(&tab->idlist)) {
359 TAILQ_REMOVE(&tab->idlist, id, next);
363 /* Mark that there are no identities. */
367 buffer_put_int(&e->output, 1);
368 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
373 process_add_identity(SocketEntry *e, int version)
378 int type, success = 0;
379 Idtab *tab = idtab_lookup(version);
383 k = key_new_private(KEY_RSA1);
384 buffer_get_int(&e->input); /* ignored */
385 buffer_get_bignum(&e->input, k->rsa->n);
386 buffer_get_bignum(&e->input, k->rsa->e);
387 buffer_get_bignum(&e->input, k->rsa->d);
388 buffer_get_bignum(&e->input, k->rsa->iqmp);
390 /* SSH and SSL have p and q swapped */
391 buffer_get_bignum(&e->input, k->rsa->q); /* p */
392 buffer_get_bignum(&e->input, k->rsa->p); /* q */
394 /* Generate additional parameters */
395 rsa_generate_additional_parameters(k->rsa);
398 type_name = buffer_get_string(&e->input, NULL);
399 type = key_type_from_name(type_name);
403 k = key_new_private(type);
404 buffer_get_bignum2(&e->input, k->dsa->p);
405 buffer_get_bignum2(&e->input, k->dsa->q);
406 buffer_get_bignum2(&e->input, k->dsa->g);
407 buffer_get_bignum2(&e->input, k->dsa->pub_key);
408 buffer_get_bignum2(&e->input, k->dsa->priv_key);
411 k = key_new_private(type);
412 buffer_get_bignum2(&e->input, k->rsa->n);
413 buffer_get_bignum2(&e->input, k->rsa->e);
414 buffer_get_bignum2(&e->input, k->rsa->d);
415 buffer_get_bignum2(&e->input, k->rsa->iqmp);
416 buffer_get_bignum2(&e->input, k->rsa->p);
417 buffer_get_bignum2(&e->input, k->rsa->q);
419 /* Generate additional parameters */
420 rsa_generate_additional_parameters(k->rsa);
423 buffer_clear(&e->input);
428 comment = buffer_get_string(&e->input, NULL);
434 if (lookup_identity(k, version) == NULL) {
435 Identity *id = xmalloc(sizeof(Identity));
437 id->comment = comment;
438 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
439 /* Increment the number of identities. */
446 buffer_put_int(&e->output, 1);
447 buffer_put_char(&e->output,
448 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
454 process_add_smartcard_key (SocketEntry *e)
457 Key *n = NULL, *k = NULL;
458 char *sc_reader_id = NULL;
461 sc_reader_id = buffer_get_string(&e->input, NULL);
462 k = sc_get_key(sc_reader_id);
466 error("sc_get_pubkey failed");
471 tab = idtab_lookup(1);
473 if (lookup_identity(k, 1) == NULL) {
474 Identity *id = xmalloc(sizeof(Identity));
475 n = key_new(KEY_RSA1);
476 BN_copy(n->rsa->n, k->rsa->n);
477 BN_copy(n->rsa->e, k->rsa->e);
478 RSA_set_method(n->rsa, sc_get_engine());
480 id->comment = xstrdup("rsa1 smartcard");
481 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
485 tab = idtab_lookup(2);
486 if (lookup_identity(k, 2) == NULL) {
487 Identity *id = xmalloc(sizeof(Identity));
488 n = key_new(KEY_RSA);
489 BN_copy(n->rsa->n, k->rsa->n);
490 BN_copy(n->rsa->e, k->rsa->e);
491 RSA_set_method(n->rsa, sc_get_engine());
493 id->comment = xstrdup("rsa smartcard");
494 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
499 buffer_put_int(&e->output, 1);
500 buffer_put_char(&e->output,
501 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
505 process_remove_smartcard_key(SocketEntry *e)
509 char *sc_reader_id = NULL;
511 sc_reader_id = buffer_get_string(&e->input, NULL);
512 k = sc_get_key(sc_reader_id);
516 error("sc_get_pubkey failed");
520 id = lookup_identity(k, 1);
522 Idtab *tab = idtab_lookup(1);
523 TAILQ_REMOVE(&tab->idlist, id, next);
529 id = lookup_identity(k, 2);
531 Idtab *tab = idtab_lookup(2);
532 TAILQ_REMOVE(&tab->idlist, id, next);
540 buffer_put_int(&e->output, 1);
541 buffer_put_char(&e->output,
542 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
544 #endif /* SMARTCARD */
546 /* dispatch incoming messages */
549 process_message(SocketEntry *e)
554 if (buffer_len(&e->input) < 5)
555 return; /* Incomplete message. */
556 cp = buffer_ptr(&e->input);
557 msg_len = GET_32BIT(cp);
558 if (msg_len > 256 * 1024) {
559 shutdown(e->fd, SHUT_RDWR);
561 e->type = AUTH_UNUSED;
564 if (buffer_len(&e->input) < msg_len + 4)
566 buffer_consume(&e->input, 4);
567 type = buffer_get_char(&e->input);
569 debug("type %d", type);
572 case SSH_AGENTC_RSA_CHALLENGE:
573 process_authentication_challenge1(e);
575 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
576 process_request_identities(e, 1);
578 case SSH_AGENTC_ADD_RSA_IDENTITY:
579 process_add_identity(e, 1);
581 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
582 process_remove_identity(e, 1);
584 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
585 process_remove_all_identities(e, 1);
588 case SSH2_AGENTC_SIGN_REQUEST:
589 process_sign_request2(e);
591 case SSH2_AGENTC_REQUEST_IDENTITIES:
592 process_request_identities(e, 2);
594 case SSH2_AGENTC_ADD_IDENTITY:
595 process_add_identity(e, 2);
597 case SSH2_AGENTC_REMOVE_IDENTITY:
598 process_remove_identity(e, 2);
600 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
601 process_remove_all_identities(e, 2);
604 case SSH_AGENTC_ADD_SMARTCARD_KEY:
605 process_add_smartcard_key(e);
607 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
608 process_remove_smartcard_key(e);
610 #endif /* SMARTCARD */
612 /* Unknown message. Respond with failure. */
613 error("Unknown message %d", type);
614 buffer_clear(&e->input);
615 buffer_put_int(&e->output, 1);
616 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
622 new_socket(sock_type type, int fd)
625 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
626 error("fcntl O_NONBLOCK: %s", strerror(errno));
631 for (i = 0; i < sockets_alloc; i++)
632 if (sockets[i].type == AUTH_UNUSED) {
634 sockets[i].type = type;
635 buffer_init(&sockets[i].input);
636 buffer_init(&sockets[i].output);
639 old_alloc = sockets_alloc;
642 sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0]));
644 sockets = xmalloc(sockets_alloc * sizeof(sockets[0]));
645 for (i = old_alloc; i < sockets_alloc; i++)
646 sockets[i].type = AUTH_UNUSED;
647 sockets[old_alloc].type = type;
648 sockets[old_alloc].fd = fd;
649 buffer_init(&sockets[old_alloc].input);
650 buffer_init(&sockets[old_alloc].output);
654 prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, int *nallocp)
659 for (i = 0; i < sockets_alloc; i++) {
660 switch (sockets[i].type) {
662 case AUTH_CONNECTION:
663 n = MAX(n, sockets[i].fd);
668 fatal("Unknown socket type %d", sockets[i].type);
673 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
674 if (*fdrp == NULL || sz > *nallocp) {
684 debug("XXX shrink: %d < %d", n, *fdl);
686 memset(*fdrp, 0, sz);
687 memset(*fdwp, 0, sz);
689 for (i = 0; i < sockets_alloc; i++) {
690 switch (sockets[i].type) {
692 case AUTH_CONNECTION:
693 FD_SET(sockets[i].fd, *fdrp);
694 if (buffer_len(&sockets[i].output) > 0)
695 FD_SET(sockets[i].fd, *fdwp);
705 after_select(fd_set *readset, fd_set *writeset)
711 struct sockaddr_un sunaddr;
713 for (i = 0; i < sockets_alloc; i++)
714 switch (sockets[i].type) {
718 if (FD_ISSET(sockets[i].fd, readset)) {
719 slen = sizeof(sunaddr);
720 sock = accept(sockets[i].fd,
721 (struct sockaddr *) &sunaddr, &slen);
723 error("accept from AUTH_SOCKET: %s",
727 new_socket(AUTH_CONNECTION, sock);
730 case AUTH_CONNECTION:
731 if (buffer_len(&sockets[i].output) > 0 &&
732 FD_ISSET(sockets[i].fd, writeset)) {
734 len = write(sockets[i].fd,
735 buffer_ptr(&sockets[i].output),
736 buffer_len(&sockets[i].output));
737 if (len == -1 && (errno == EAGAIN ||
743 shutdown(sockets[i].fd, SHUT_RDWR);
744 close(sockets[i].fd);
745 sockets[i].type = AUTH_UNUSED;
746 buffer_free(&sockets[i].input);
747 buffer_free(&sockets[i].output);
750 buffer_consume(&sockets[i].output, len);
752 if (FD_ISSET(sockets[i].fd, readset)) {
754 len = read(sockets[i].fd, buf, sizeof(buf));
755 if (len == -1 && (errno == EAGAIN ||
761 shutdown(sockets[i].fd, SHUT_RDWR);
762 close(sockets[i].fd);
763 sockets[i].type = AUTH_UNUSED;
764 buffer_free(&sockets[i].input);
765 buffer_free(&sockets[i].output);
768 buffer_append(&sockets[i].input, buf, len);
769 process_message(&sockets[i]);
773 fatal("Unknown type %d", sockets[i].type);
778 cleanup_socket(void *p)
789 cleanup_socket(NULL);
794 cleanup_handler(int sig)
796 cleanup_socket(NULL);
801 check_parent_exists(int sig)
803 int save_errno = errno;
805 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
806 /* printf("Parent has died - Authentication agent exiting.\n"); */
807 cleanup_handler(sig); /* safe */
809 signal(SIGALRM, check_parent_exists);
817 fprintf(stderr, "Usage: %s [options] [command [args ...]]\n",
819 fprintf(stderr, "Options:\n");
820 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
821 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
822 fprintf(stderr, " -k Kill the current agent.\n");
823 fprintf(stderr, " -d Debug mode.\n");
828 main(int ac, char **av)
830 int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch, nalloc;
831 struct sockaddr_un sunaddr;
832 #ifdef HAVE_SETRLIMIT
839 char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
841 fd_set *readsetp = NULL, *writesetp = NULL;
843 SSLeay_add_all_algorithms();
845 __progname = get_progname(av[0]);
849 #ifdef __GNU_LIBRARY__
850 while ((ch = getopt(ac, av, "+cdks")) != -1) {
851 #else /* __GNU_LIBRARY__ */
852 while ((ch = getopt(ac, av, "cdks")) != -1) {
853 #endif /* __GNU_LIBRARY__ */
880 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
883 if (ac == 0 && !c_flag && !k_flag && !s_flag && !d_flag) {
884 shell = getenv("SHELL");
885 if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0)
889 pidstr = getenv(SSH_AGENTPID_ENV_NAME);
890 if (pidstr == NULL) {
891 fprintf(stderr, "%s not set, cannot kill agent\n",
892 SSH_AGENTPID_ENV_NAME);
897 fprintf(stderr, "%s=\"%s\", which is not a good PID\n",
898 SSH_AGENTPID_ENV_NAME, pidstr);
901 if (kill(pid, SIGTERM) == -1) {
905 format = c_flag ? "unsetenv %s;\n" : "unset %s;\n";
906 printf(format, SSH_AUTHSOCKET_ENV_NAME);
907 printf(format, SSH_AGENTPID_ENV_NAME);
908 printf("echo Agent pid %d killed;\n", pid);
911 parent_pid = getpid();
913 /* Create private directory for agent socket */
914 strlcpy(socket_dir, "/tmp/ssh-XXXXXXXX", sizeof socket_dir);
915 if (mkdtemp(socket_dir) == NULL) {
916 perror("mkdtemp: private socket dir");
919 snprintf(socket_name, sizeof socket_name, "%s/agent.%d", socket_dir,
923 * Create socket early so it will exist before command gets run from
926 sock = socket(AF_UNIX, SOCK_STREAM, 0);
931 memset(&sunaddr, 0, sizeof(sunaddr));
932 sunaddr.sun_family = AF_UNIX;
933 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
935 prev_mask = umask(0177);
937 if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0) {
947 if (listen(sock, 5) < 0) {
953 * Fork, and have the parent execute the command, if any, or present
954 * the socket data. The child continues as the authentication agent.
957 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
958 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
959 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
960 SSH_AUTHSOCKET_ENV_NAME);
961 printf("echo Agent pid %d;\n", parent_pid);
969 if (pid != 0) { /* Parent - execute the given command. */
971 snprintf(pidstrbuf, sizeof pidstrbuf, "%d", pid);
973 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
974 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
975 SSH_AUTHSOCKET_ENV_NAME);
976 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
977 SSH_AGENTPID_ENV_NAME);
978 printf("echo Agent pid %d;\n", pid);
981 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
982 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
991 log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
993 if (setsid() == -1) {
994 error("setsid: %s", strerror(errno));
1003 #ifdef HAVE_SETRLIMIT
1004 /* deny core dumps, since memory contains unencrypted private keys */
1005 rlim.rlim_cur = rlim.rlim_max = 0;
1006 if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
1007 error("setrlimit RLIMIT_CORE: %s", strerror(errno));
1013 fatal_add_cleanup(cleanup_socket, NULL);
1014 new_socket(AUTH_SOCKET, sock);
1016 signal(SIGALRM, check_parent_exists);
1021 signal(SIGINT, SIG_IGN);
1022 signal(SIGPIPE, SIG_IGN);
1023 signal(SIGHUP, cleanup_handler);
1024 signal(SIGTERM, cleanup_handler);
1028 prepare_select(&readsetp, &writesetp, &max_fd, &nalloc);
1029 if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
1032 fatal("select: %s", strerror(errno));
1034 after_select(readsetp, writesetp);