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.83 2002/03/21 22:44:05 rees 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"
45 #include <openssl/evp.h>
46 #include <openssl/md5.h>
60 #include <openssl/engine.h>
77 u_int sockets_alloc = 0;
78 SocketEntry *sockets = NULL;
80 typedef struct identity {
81 TAILQ_ENTRY(identity) next;
88 TAILQ_HEAD(idqueue, identity) idlist;
91 /* private key table, one per protocol version */
96 /* pid of shell == parent of agent */
97 pid_t parent_pid = -1;
99 /* pathname and directory for AUTH_SOCKET */
100 char socket_name[1024];
101 char socket_dir[1024];
103 #ifdef HAVE___PROGNAME
104 extern char *__progname;
113 for (i = 0; i <=2; i++) {
114 TAILQ_INIT(&idtable[i].idlist);
115 idtable[i].nentries = 0;
119 /* return private key table for requested protocol version */
121 idtab_lookup(int version)
123 if (version < 1 || version > 2)
124 fatal("internal error, bad protocol version %d", version);
125 return &idtable[version];
128 /* return matching private key for given public key */
130 lookup_identity(Key *key, int version)
134 Idtab *tab = idtab_lookup(version);
135 TAILQ_FOREACH(id, &tab->idlist, next) {
136 if (key_equal(key, id->key))
143 free_identity(Identity *id)
150 /* send list of supported public keys to 'client' */
152 process_request_identities(SocketEntry *e, int version)
154 Idtab *tab = idtab_lookup(version);
159 buffer_put_char(&msg, (version == 1) ?
160 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
161 buffer_put_int(&msg, tab->nentries);
162 TAILQ_FOREACH(id, &tab->idlist, next) {
163 if (id->key->type == KEY_RSA1) {
164 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
165 buffer_put_bignum(&msg, id->key->rsa->e);
166 buffer_put_bignum(&msg, id->key->rsa->n);
170 key_to_blob(id->key, &blob, &blen);
171 buffer_put_string(&msg, blob, blen);
174 buffer_put_cstring(&msg, id->comment);
176 buffer_put_int(&e->output, buffer_len(&msg));
177 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
183 process_authentication_challenge1(SocketEntry *e)
191 u_char buf[32], mdbuf[16], session_id[16];
195 key = key_new(KEY_RSA1);
196 if ((challenge = BN_new()) == NULL)
197 fatal("process_authentication_challenge1: BN_new failed");
199 buffer_get_int(&e->input); /* ignored */
200 buffer_get_bignum(&e->input, key->rsa->e);
201 buffer_get_bignum(&e->input, key->rsa->n);
202 buffer_get_bignum(&e->input, challenge);
204 /* Only protocol 1.1 is supported */
205 if (buffer_len(&e->input) == 0)
207 buffer_get(&e->input, session_id, 16);
208 response_type = buffer_get_int(&e->input);
209 if (response_type != 1)
212 id = lookup_identity(key, 1);
214 Key *private = id->key;
215 /* Decrypt the challenge using the private key. */
216 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
219 /* The response is MD5 of decrypted challenge plus session id. */
220 len = BN_num_bytes(challenge);
221 if (len <= 0 || len > 32) {
222 log("process_authentication_challenge: bad challenge length %d", len);
226 BN_bn2bin(challenge, buf + 32 - len);
228 MD5_Update(&md, buf, 32);
229 MD5_Update(&md, session_id, 16);
230 MD5_Final(mdbuf, &md);
232 /* Send the response. */
233 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
234 for (i = 0; i < 16; i++)
235 buffer_put_char(&msg, mdbuf[i]);
240 /* Unknown identity or protocol error. Send failure. */
241 buffer_put_char(&msg, SSH_AGENT_FAILURE);
243 buffer_put_int(&e->output, buffer_len(&msg));
244 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
246 BN_clear_free(challenge);
252 process_sign_request2(SocketEntry *e)
254 extern int datafellows;
256 u_char *blob, *data, *signature = NULL;
257 u_int blen, dlen, slen = 0;
264 blob = buffer_get_string(&e->input, &blen);
265 data = buffer_get_string(&e->input, &dlen);
267 flags = buffer_get_int(&e->input);
268 if (flags & SSH_AGENT_OLD_SIGNATURE)
269 datafellows = SSH_BUG_SIGBLOB;
271 key = key_from_blob(blob, blen);
273 Identity *id = lookup_identity(key, 2);
275 ok = key_sign(id->key, &signature, &slen, data, dlen);
280 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
281 buffer_put_string(&msg, signature, slen);
283 buffer_put_char(&msg, SSH_AGENT_FAILURE);
285 buffer_put_int(&e->output, buffer_len(&msg));
286 buffer_append(&e->output, buffer_ptr(&msg),
291 if (signature != NULL)
297 process_remove_identity(SocketEntry *e, int version)
307 key = key_new(KEY_RSA1);
308 bits = buffer_get_int(&e->input);
309 buffer_get_bignum(&e->input, key->rsa->e);
310 buffer_get_bignum(&e->input, key->rsa->n);
312 if (bits != key_size(key))
313 log("Warning: identity keysize mismatch: actual %d, announced %d",
314 key_size(key), bits);
317 blob = buffer_get_string(&e->input, &blen);
318 key = key_from_blob(blob, blen);
323 Identity *id = lookup_identity(key, version);
326 * We have this key. Free the old key. Since we
327 * don\'t want to leave empty slots in the middle of
328 * the array, we actually free the key there and move
329 * all the entries between the empty slot and the end
332 Idtab *tab = idtab_lookup(version);
333 if (tab->nentries < 1)
334 fatal("process_remove_identity: "
335 "internal error: tab->nentries %d",
337 TAILQ_REMOVE(&tab->idlist, id, next);
344 buffer_put_int(&e->output, 1);
345 buffer_put_char(&e->output,
346 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
350 process_remove_all_identities(SocketEntry *e, int version)
352 Idtab *tab = idtab_lookup(version);
355 /* Loop over all identities and clear the keys. */
356 for (id = TAILQ_FIRST(&tab->idlist); id;
357 id = TAILQ_FIRST(&tab->idlist)) {
358 TAILQ_REMOVE(&tab->idlist, id, next);
362 /* Mark that there are no identities. */
366 buffer_put_int(&e->output, 1);
367 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
372 process_add_identity(SocketEntry *e, int version)
377 int type, success = 0;
378 Idtab *tab = idtab_lookup(version);
382 k = key_new_private(KEY_RSA1);
383 buffer_get_int(&e->input); /* ignored */
384 buffer_get_bignum(&e->input, k->rsa->n);
385 buffer_get_bignum(&e->input, k->rsa->e);
386 buffer_get_bignum(&e->input, k->rsa->d);
387 buffer_get_bignum(&e->input, k->rsa->iqmp);
389 /* SSH and SSL have p and q swapped */
390 buffer_get_bignum(&e->input, k->rsa->q); /* p */
391 buffer_get_bignum(&e->input, k->rsa->p); /* q */
393 /* Generate additional parameters */
394 rsa_generate_additional_parameters(k->rsa);
397 type_name = buffer_get_string(&e->input, NULL);
398 type = key_type_from_name(type_name);
402 k = key_new_private(type);
403 buffer_get_bignum2(&e->input, k->dsa->p);
404 buffer_get_bignum2(&e->input, k->dsa->q);
405 buffer_get_bignum2(&e->input, k->dsa->g);
406 buffer_get_bignum2(&e->input, k->dsa->pub_key);
407 buffer_get_bignum2(&e->input, k->dsa->priv_key);
410 k = key_new_private(type);
411 buffer_get_bignum2(&e->input, k->rsa->n);
412 buffer_get_bignum2(&e->input, k->rsa->e);
413 buffer_get_bignum2(&e->input, k->rsa->d);
414 buffer_get_bignum2(&e->input, k->rsa->iqmp);
415 buffer_get_bignum2(&e->input, k->rsa->p);
416 buffer_get_bignum2(&e->input, k->rsa->q);
418 /* Generate additional parameters */
419 rsa_generate_additional_parameters(k->rsa);
422 buffer_clear(&e->input);
427 comment = buffer_get_string(&e->input, NULL);
433 if (lookup_identity(k, version) == NULL) {
434 Identity *id = xmalloc(sizeof(Identity));
436 id->comment = comment;
437 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
438 /* Increment the number of identities. */
445 buffer_put_int(&e->output, 1);
446 buffer_put_char(&e->output,
447 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
453 process_add_smartcard_key (SocketEntry *e)
456 Key *n = NULL, *k = NULL;
457 char *sc_reader_id = NULL, *pin;
460 sc_reader_id = buffer_get_string(&e->input, NULL);
461 pin = buffer_get_string(&e->input, NULL);
462 k = sc_get_key(sc_reader_id, pin);
467 error("sc_get_pubkey failed");
472 tab = idtab_lookup(1);
474 if (lookup_identity(k, 1) == NULL) {
475 Identity *id = xmalloc(sizeof(Identity));
476 n = key_new(KEY_RSA1);
477 BN_copy(n->rsa->n, k->rsa->n);
478 BN_copy(n->rsa->e, k->rsa->e);
479 RSA_set_method(n->rsa, sc_get_engine());
481 id->comment = xstrdup("rsa1 smartcard");
482 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
486 tab = idtab_lookup(2);
487 if (lookup_identity(k, 2) == NULL) {
488 Identity *id = xmalloc(sizeof(Identity));
489 n = key_new(KEY_RSA);
490 BN_copy(n->rsa->n, k->rsa->n);
491 BN_copy(n->rsa->e, k->rsa->e);
492 RSA_set_method(n->rsa, sc_get_engine());
494 id->comment = xstrdup("rsa smartcard");
495 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
500 buffer_put_int(&e->output, 1);
501 buffer_put_char(&e->output,
502 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
506 process_remove_smartcard_key(SocketEntry *e)
510 char *sc_reader_id = NULL, *pin;
512 sc_reader_id = buffer_get_string(&e->input, NULL);
513 pin = buffer_get_string(&e->input, NULL);
514 k = sc_get_key(sc_reader_id, pin);
519 error("sc_get_pubkey failed");
523 id = lookup_identity(k, 1);
525 Idtab *tab = idtab_lookup(1);
526 TAILQ_REMOVE(&tab->idlist, id, next);
532 id = lookup_identity(k, 2);
534 Idtab *tab = idtab_lookup(2);
535 TAILQ_REMOVE(&tab->idlist, id, next);
543 buffer_put_int(&e->output, 1);
544 buffer_put_char(&e->output,
545 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
547 #endif /* SMARTCARD */
549 /* dispatch incoming messages */
552 process_message(SocketEntry *e)
557 if (buffer_len(&e->input) < 5)
558 return; /* Incomplete message. */
559 cp = buffer_ptr(&e->input);
560 msg_len = GET_32BIT(cp);
561 if (msg_len > 256 * 1024) {
562 shutdown(e->fd, SHUT_RDWR);
564 e->type = AUTH_UNUSED;
567 if (buffer_len(&e->input) < msg_len + 4)
569 buffer_consume(&e->input, 4);
570 type = buffer_get_char(&e->input);
572 debug("type %d", type);
575 case SSH_AGENTC_RSA_CHALLENGE:
576 process_authentication_challenge1(e);
578 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
579 process_request_identities(e, 1);
581 case SSH_AGENTC_ADD_RSA_IDENTITY:
582 process_add_identity(e, 1);
584 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
585 process_remove_identity(e, 1);
587 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
588 process_remove_all_identities(e, 1);
591 case SSH2_AGENTC_SIGN_REQUEST:
592 process_sign_request2(e);
594 case SSH2_AGENTC_REQUEST_IDENTITIES:
595 process_request_identities(e, 2);
597 case SSH2_AGENTC_ADD_IDENTITY:
598 process_add_identity(e, 2);
600 case SSH2_AGENTC_REMOVE_IDENTITY:
601 process_remove_identity(e, 2);
603 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
604 process_remove_all_identities(e, 2);
607 case SSH_AGENTC_ADD_SMARTCARD_KEY:
608 process_add_smartcard_key(e);
610 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
611 process_remove_smartcard_key(e);
613 #endif /* SMARTCARD */
615 /* Unknown message. Respond with failure. */
616 error("Unknown message %d", type);
617 buffer_clear(&e->input);
618 buffer_put_int(&e->output, 1);
619 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
625 new_socket(sock_type type, int fd)
628 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
629 error("fcntl O_NONBLOCK: %s", strerror(errno));
634 for (i = 0; i < sockets_alloc; i++)
635 if (sockets[i].type == AUTH_UNUSED) {
637 sockets[i].type = type;
638 buffer_init(&sockets[i].input);
639 buffer_init(&sockets[i].output);
642 old_alloc = sockets_alloc;
645 sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0]));
647 sockets = xmalloc(sockets_alloc * sizeof(sockets[0]));
648 for (i = old_alloc; i < sockets_alloc; i++)
649 sockets[i].type = AUTH_UNUSED;
650 sockets[old_alloc].type = type;
651 sockets[old_alloc].fd = fd;
652 buffer_init(&sockets[old_alloc].input);
653 buffer_init(&sockets[old_alloc].output);
657 prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, int *nallocp)
662 for (i = 0; i < sockets_alloc; i++) {
663 switch (sockets[i].type) {
665 case AUTH_CONNECTION:
666 n = MAX(n, sockets[i].fd);
671 fatal("Unknown socket type %d", sockets[i].type);
676 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
677 if (*fdrp == NULL || sz > *nallocp) {
687 debug("XXX shrink: %d < %d", n, *fdl);
689 memset(*fdrp, 0, sz);
690 memset(*fdwp, 0, sz);
692 for (i = 0; i < sockets_alloc; i++) {
693 switch (sockets[i].type) {
695 case AUTH_CONNECTION:
696 FD_SET(sockets[i].fd, *fdrp);
697 if (buffer_len(&sockets[i].output) > 0)
698 FD_SET(sockets[i].fd, *fdwp);
708 after_select(fd_set *readset, fd_set *writeset)
714 struct sockaddr_un sunaddr;
716 for (i = 0; i < sockets_alloc; i++)
717 switch (sockets[i].type) {
721 if (FD_ISSET(sockets[i].fd, readset)) {
722 slen = sizeof(sunaddr);
723 sock = accept(sockets[i].fd,
724 (struct sockaddr *) &sunaddr, &slen);
726 error("accept from AUTH_SOCKET: %s",
730 new_socket(AUTH_CONNECTION, sock);
733 case AUTH_CONNECTION:
734 if (buffer_len(&sockets[i].output) > 0 &&
735 FD_ISSET(sockets[i].fd, writeset)) {
737 len = write(sockets[i].fd,
738 buffer_ptr(&sockets[i].output),
739 buffer_len(&sockets[i].output));
740 if (len == -1 && (errno == EAGAIN ||
746 shutdown(sockets[i].fd, SHUT_RDWR);
747 close(sockets[i].fd);
748 sockets[i].type = AUTH_UNUSED;
749 buffer_free(&sockets[i].input);
750 buffer_free(&sockets[i].output);
753 buffer_consume(&sockets[i].output, len);
755 if (FD_ISSET(sockets[i].fd, readset)) {
757 len = read(sockets[i].fd, buf, sizeof(buf));
758 if (len == -1 && (errno == EAGAIN ||
764 shutdown(sockets[i].fd, SHUT_RDWR);
765 close(sockets[i].fd);
766 sockets[i].type = AUTH_UNUSED;
767 buffer_free(&sockets[i].input);
768 buffer_free(&sockets[i].output);
771 buffer_append(&sockets[i].input, buf, len);
772 process_message(&sockets[i]);
776 fatal("Unknown type %d", sockets[i].type);
781 cleanup_socket(void *p)
792 cleanup_socket(NULL);
797 cleanup_handler(int sig)
799 cleanup_socket(NULL);
804 check_parent_exists(int sig)
806 int save_errno = errno;
808 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
809 /* printf("Parent has died - Authentication agent exiting.\n"); */
810 cleanup_handler(sig); /* safe */
812 signal(SIGALRM, check_parent_exists);
820 fprintf(stderr, "Usage: %s [options] [command [args ...]]\n",
822 fprintf(stderr, "Options:\n");
823 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
824 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
825 fprintf(stderr, " -k Kill the current agent.\n");
826 fprintf(stderr, " -d Debug mode.\n");
831 main(int ac, char **av)
833 int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch, nalloc;
834 struct sockaddr_un sunaddr;
835 #ifdef HAVE_SETRLIMIT
842 char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
844 fd_set *readsetp = NULL, *writesetp = NULL;
846 SSLeay_add_all_algorithms();
848 __progname = get_progname(av[0]);
852 #ifdef __GNU_LIBRARY__
853 while ((ch = getopt(ac, av, "+cdks")) != -1) {
854 #else /* __GNU_LIBRARY__ */
855 while ((ch = getopt(ac, av, "cdks")) != -1) {
856 #endif /* __GNU_LIBRARY__ */
883 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
886 if (ac == 0 && !c_flag && !k_flag && !s_flag && !d_flag) {
887 shell = getenv("SHELL");
888 if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0)
892 pidstr = getenv(SSH_AGENTPID_ENV_NAME);
893 if (pidstr == NULL) {
894 fprintf(stderr, "%s not set, cannot kill agent\n",
895 SSH_AGENTPID_ENV_NAME);
900 fprintf(stderr, "%s=\"%s\", which is not a good PID\n",
901 SSH_AGENTPID_ENV_NAME, pidstr);
904 if (kill(pid, SIGTERM) == -1) {
908 format = c_flag ? "unsetenv %s;\n" : "unset %s;\n";
909 printf(format, SSH_AUTHSOCKET_ENV_NAME);
910 printf(format, SSH_AGENTPID_ENV_NAME);
911 printf("echo Agent pid %d killed;\n", pid);
914 parent_pid = getpid();
916 /* Create private directory for agent socket */
917 strlcpy(socket_dir, "/tmp/ssh-XXXXXXXX", sizeof socket_dir);
918 if (mkdtemp(socket_dir) == NULL) {
919 perror("mkdtemp: private socket dir");
922 snprintf(socket_name, sizeof socket_name, "%s/agent.%d", socket_dir,
926 * Create socket early so it will exist before command gets run from
929 sock = socket(AF_UNIX, SOCK_STREAM, 0);
934 memset(&sunaddr, 0, sizeof(sunaddr));
935 sunaddr.sun_family = AF_UNIX;
936 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
938 prev_mask = umask(0177);
940 if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0) {
950 if (listen(sock, 5) < 0) {
956 * Fork, and have the parent execute the command, if any, or present
957 * the socket data. The child continues as the authentication agent.
960 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
961 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
962 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
963 SSH_AUTHSOCKET_ENV_NAME);
964 printf("echo Agent pid %d;\n", parent_pid);
972 if (pid != 0) { /* Parent - execute the given command. */
974 snprintf(pidstrbuf, sizeof pidstrbuf, "%d", pid);
976 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
977 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
978 SSH_AUTHSOCKET_ENV_NAME);
979 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
980 SSH_AGENTPID_ENV_NAME);
981 printf("echo Agent pid %d;\n", pid);
984 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
985 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
994 log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
996 if (setsid() == -1) {
997 error("setsid: %s", strerror(errno));
1006 #ifdef HAVE_SETRLIMIT
1007 /* deny core dumps, since memory contains unencrypted private keys */
1008 rlim.rlim_cur = rlim.rlim_max = 0;
1009 if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
1010 error("setrlimit RLIMIT_CORE: %s", strerror(errno));
1016 fatal_add_cleanup(cleanup_socket, NULL);
1017 new_socket(AUTH_SOCKET, sock);
1019 signal(SIGALRM, check_parent_exists);
1024 signal(SIGINT, SIG_IGN);
1025 signal(SIGPIPE, SIG_IGN);
1026 signal(SIGHUP, cleanup_handler);
1027 signal(SIGTERM, cleanup_handler);
1031 prepare_select(&readsetp, &writesetp, &max_fd, &nalloc);
1032 if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
1035 fatal("select: %s", strerror(errno));
1037 after_select(readsetp, writesetp);