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 #include "openbsd-compat/fake-queue.h"
38 RCSID("$OpenBSD: ssh-agent.c,v 1.87 2002/06/05 16:48:54 markus Exp $");
40 #include <openssl/evp.h>
41 #include <openssl/md5.h>
72 u_int sockets_alloc = 0;
73 SocketEntry *sockets = NULL;
75 typedef struct identity {
76 TAILQ_ENTRY(identity) next;
83 TAILQ_HEAD(idqueue, identity) idlist;
86 /* private key table, one per protocol version */
91 /* pid of shell == parent of agent */
92 pid_t parent_pid = -1;
94 /* pathname and directory for AUTH_SOCKET */
95 char socket_name[1024];
96 char socket_dir[1024];
98 #ifdef HAVE___PROGNAME
99 extern char *__progname;
108 for (i = 0; i <=2; i++) {
109 TAILQ_INIT(&idtable[i].idlist);
110 idtable[i].nentries = 0;
114 /* return private key table for requested protocol version */
116 idtab_lookup(int version)
118 if (version < 1 || version > 2)
119 fatal("internal error, bad protocol version %d", version);
120 return &idtable[version];
123 /* return matching private key for given public key */
125 lookup_identity(Key *key, int version)
129 Idtab *tab = idtab_lookup(version);
130 TAILQ_FOREACH(id, &tab->idlist, next) {
131 if (key_equal(key, id->key))
138 free_identity(Identity *id)
145 /* send list of supported public keys to 'client' */
147 process_request_identities(SocketEntry *e, int version)
149 Idtab *tab = idtab_lookup(version);
154 buffer_put_char(&msg, (version == 1) ?
155 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
156 buffer_put_int(&msg, tab->nentries);
157 TAILQ_FOREACH(id, &tab->idlist, next) {
158 if (id->key->type == KEY_RSA1) {
159 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
160 buffer_put_bignum(&msg, id->key->rsa->e);
161 buffer_put_bignum(&msg, id->key->rsa->n);
165 key_to_blob(id->key, &blob, &blen);
166 buffer_put_string(&msg, blob, blen);
169 buffer_put_cstring(&msg, id->comment);
171 buffer_put_int(&e->output, buffer_len(&msg));
172 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
178 process_authentication_challenge1(SocketEntry *e)
186 u_char buf[32], mdbuf[16], session_id[16];
190 key = key_new(KEY_RSA1);
191 if ((challenge = BN_new()) == NULL)
192 fatal("process_authentication_challenge1: BN_new failed");
194 buffer_get_int(&e->request); /* ignored */
195 buffer_get_bignum(&e->request, key->rsa->e);
196 buffer_get_bignum(&e->request, key->rsa->n);
197 buffer_get_bignum(&e->request, challenge);
199 /* Only protocol 1.1 is supported */
200 if (buffer_len(&e->request) == 0)
202 buffer_get(&e->request, session_id, 16);
203 response_type = buffer_get_int(&e->request);
204 if (response_type != 1)
207 id = lookup_identity(key, 1);
209 Key *private = id->key;
210 /* Decrypt the challenge using the private key. */
211 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
214 /* The response is MD5 of decrypted challenge plus session id. */
215 len = BN_num_bytes(challenge);
216 if (len <= 0 || len > 32) {
217 log("process_authentication_challenge: bad challenge length %d", len);
221 BN_bn2bin(challenge, buf + 32 - len);
223 MD5_Update(&md, buf, 32);
224 MD5_Update(&md, session_id, 16);
225 MD5_Final(mdbuf, &md);
227 /* Send the response. */
228 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
229 for (i = 0; i < 16; i++)
230 buffer_put_char(&msg, mdbuf[i]);
235 /* Unknown identity or protocol error. Send failure. */
236 buffer_put_char(&msg, SSH_AGENT_FAILURE);
238 buffer_put_int(&e->output, buffer_len(&msg));
239 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
241 BN_clear_free(challenge);
247 process_sign_request2(SocketEntry *e)
249 extern int datafellows;
251 u_char *blob, *data, *signature = NULL;
252 u_int blen, dlen, slen = 0;
259 blob = buffer_get_string(&e->request, &blen);
260 data = buffer_get_string(&e->request, &dlen);
262 flags = buffer_get_int(&e->request);
263 if (flags & SSH_AGENT_OLD_SIGNATURE)
264 datafellows = SSH_BUG_SIGBLOB;
266 key = key_from_blob(blob, blen);
268 Identity *id = lookup_identity(key, 2);
270 ok = key_sign(id->key, &signature, &slen, data, dlen);
275 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
276 buffer_put_string(&msg, signature, slen);
278 buffer_put_char(&msg, SSH_AGENT_FAILURE);
280 buffer_put_int(&e->output, buffer_len(&msg));
281 buffer_append(&e->output, buffer_ptr(&msg),
286 if (signature != NULL)
292 process_remove_identity(SocketEntry *e, int version)
302 key = key_new(KEY_RSA1);
303 bits = buffer_get_int(&e->request);
304 buffer_get_bignum(&e->request, key->rsa->e);
305 buffer_get_bignum(&e->request, key->rsa->n);
307 if (bits != key_size(key))
308 log("Warning: identity keysize mismatch: actual %d, announced %d",
309 key_size(key), bits);
312 blob = buffer_get_string(&e->request, &blen);
313 key = key_from_blob(blob, blen);
318 Identity *id = lookup_identity(key, version);
321 * We have this key. Free the old key. Since we
322 * don\'t want to leave empty slots in the middle of
323 * the array, we actually free the key there and move
324 * all the entries between the empty slot and the end
327 Idtab *tab = idtab_lookup(version);
328 if (tab->nentries < 1)
329 fatal("process_remove_identity: "
330 "internal error: tab->nentries %d",
332 TAILQ_REMOVE(&tab->idlist, id, next);
339 buffer_put_int(&e->output, 1);
340 buffer_put_char(&e->output,
341 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
345 process_remove_all_identities(SocketEntry *e, int version)
347 Idtab *tab = idtab_lookup(version);
350 /* Loop over all identities and clear the keys. */
351 for (id = TAILQ_FIRST(&tab->idlist); id;
352 id = TAILQ_FIRST(&tab->idlist)) {
353 TAILQ_REMOVE(&tab->idlist, id, next);
357 /* Mark that there are no identities. */
361 buffer_put_int(&e->output, 1);
362 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
367 process_add_identity(SocketEntry *e, int version)
372 int type, success = 0;
373 Idtab *tab = idtab_lookup(version);
377 k = key_new_private(KEY_RSA1);
378 buffer_get_int(&e->request); /* ignored */
379 buffer_get_bignum(&e->request, k->rsa->n);
380 buffer_get_bignum(&e->request, k->rsa->e);
381 buffer_get_bignum(&e->request, k->rsa->d);
382 buffer_get_bignum(&e->request, k->rsa->iqmp);
384 /* SSH and SSL have p and q swapped */
385 buffer_get_bignum(&e->request, k->rsa->q); /* p */
386 buffer_get_bignum(&e->request, k->rsa->p); /* q */
388 /* Generate additional parameters */
389 rsa_generate_additional_parameters(k->rsa);
392 type_name = buffer_get_string(&e->request, NULL);
393 type = key_type_from_name(type_name);
397 k = key_new_private(type);
398 buffer_get_bignum2(&e->request, k->dsa->p);
399 buffer_get_bignum2(&e->request, k->dsa->q);
400 buffer_get_bignum2(&e->request, k->dsa->g);
401 buffer_get_bignum2(&e->request, k->dsa->pub_key);
402 buffer_get_bignum2(&e->request, k->dsa->priv_key);
405 k = key_new_private(type);
406 buffer_get_bignum2(&e->request, k->rsa->n);
407 buffer_get_bignum2(&e->request, k->rsa->e);
408 buffer_get_bignum2(&e->request, k->rsa->d);
409 buffer_get_bignum2(&e->request, k->rsa->iqmp);
410 buffer_get_bignum2(&e->request, k->rsa->p);
411 buffer_get_bignum2(&e->request, k->rsa->q);
413 /* Generate additional parameters */
414 rsa_generate_additional_parameters(k->rsa);
417 buffer_clear(&e->request);
422 comment = buffer_get_string(&e->request, NULL);
428 if (lookup_identity(k, version) == NULL) {
429 Identity *id = xmalloc(sizeof(Identity));
431 id->comment = comment;
432 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
433 /* Increment the number of identities. */
440 buffer_put_int(&e->output, 1);
441 buffer_put_char(&e->output,
442 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
448 process_add_smartcard_key (SocketEntry *e)
453 char *sc_reader_id = NULL, *pin;
454 int i, version, success = 0;
456 sc_reader_id = buffer_get_string(&e->request, NULL);
457 pin = buffer_get_string(&e->request, NULL);
458 keys = sc_get_keys(sc_reader_id, pin);
462 if (keys == NULL || keys[0] == NULL) {
463 error("sc_get_keys failed");
466 for (i = 0; keys[i] != NULL; i++) {
468 version = k->type == KEY_RSA1 ? 1 : 2;
469 tab = idtab_lookup(version);
470 if (lookup_identity(k, version) == NULL) {
471 id = xmalloc(sizeof(Identity));
473 id->comment = xstrdup("smartcard key");
474 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
484 buffer_put_int(&e->output, 1);
485 buffer_put_char(&e->output,
486 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
490 process_remove_smartcard_key(SocketEntry *e)
494 Key **keys, *k = NULL;
495 char *sc_reader_id = NULL, *pin;
496 int i, version, success = 0;
498 sc_reader_id = buffer_get_string(&e->request, NULL);
499 pin = buffer_get_string(&e->request, NULL);
500 keys = sc_get_keys(sc_reader_id, pin);
504 if (keys == NULL || keys[0] == NULL) {
505 error("sc_get_keys failed");
508 for (i = 0; keys[i] != NULL; i++) {
510 version = k->type == KEY_RSA1 ? 1 : 2;
511 if ((id = lookup_identity(k, version)) != NULL) {
512 tab = idtab_lookup(version);
513 TAILQ_REMOVE(&tab->idlist, id, next);
523 buffer_put_int(&e->output, 1);
524 buffer_put_char(&e->output,
525 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
527 #endif /* SMARTCARD */
529 /* dispatch incoming messages */
532 process_message(SocketEntry *e)
537 if (buffer_len(&e->input) < 5)
538 return; /* Incomplete message. */
539 cp = buffer_ptr(&e->input);
540 msg_len = GET_32BIT(cp);
541 if (msg_len > 256 * 1024) {
542 shutdown(e->fd, SHUT_RDWR);
544 e->type = AUTH_UNUSED;
545 buffer_free(&e->input);
546 buffer_free(&e->output);
547 buffer_free(&e->request);
550 if (buffer_len(&e->input) < msg_len + 4)
553 /* move the current input to e->request */
554 buffer_consume(&e->input, 4);
555 buffer_clear(&e->request);
556 buffer_append(&e->request, buffer_ptr(&e->input), msg_len);
557 buffer_consume(&e->input, msg_len);
558 type = buffer_get_char(&e->request);
560 debug("type %d", type);
563 case SSH_AGENTC_RSA_CHALLENGE:
564 process_authentication_challenge1(e);
566 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
567 process_request_identities(e, 1);
569 case SSH_AGENTC_ADD_RSA_IDENTITY:
570 process_add_identity(e, 1);
572 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
573 process_remove_identity(e, 1);
575 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
576 process_remove_all_identities(e, 1);
579 case SSH2_AGENTC_SIGN_REQUEST:
580 process_sign_request2(e);
582 case SSH2_AGENTC_REQUEST_IDENTITIES:
583 process_request_identities(e, 2);
585 case SSH2_AGENTC_ADD_IDENTITY:
586 process_add_identity(e, 2);
588 case SSH2_AGENTC_REMOVE_IDENTITY:
589 process_remove_identity(e, 2);
591 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
592 process_remove_all_identities(e, 2);
595 case SSH_AGENTC_ADD_SMARTCARD_KEY:
596 process_add_smartcard_key(e);
598 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
599 process_remove_smartcard_key(e);
601 #endif /* SMARTCARD */
603 /* Unknown message. Respond with failure. */
604 error("Unknown message %d", type);
605 buffer_clear(&e->request);
606 buffer_put_int(&e->output, 1);
607 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
613 new_socket(sock_type type, int fd)
616 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
617 error("fcntl O_NONBLOCK: %s", strerror(errno));
622 for (i = 0; i < sockets_alloc; i++)
623 if (sockets[i].type == AUTH_UNUSED) {
625 sockets[i].type = type;
626 buffer_init(&sockets[i].input);
627 buffer_init(&sockets[i].output);
628 buffer_init(&sockets[i].request);
631 old_alloc = sockets_alloc;
634 sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0]));
636 sockets = xmalloc(sockets_alloc * sizeof(sockets[0]));
637 for (i = old_alloc; i < sockets_alloc; i++)
638 sockets[i].type = AUTH_UNUSED;
639 sockets[old_alloc].type = type;
640 sockets[old_alloc].fd = fd;
641 buffer_init(&sockets[old_alloc].input);
642 buffer_init(&sockets[old_alloc].output);
643 buffer_init(&sockets[old_alloc].request);
647 prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, int *nallocp)
652 for (i = 0; i < sockets_alloc; i++) {
653 switch (sockets[i].type) {
655 case AUTH_CONNECTION:
656 n = MAX(n, sockets[i].fd);
661 fatal("Unknown socket type %d", sockets[i].type);
666 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
667 if (*fdrp == NULL || sz > *nallocp) {
677 debug("XXX shrink: %d < %d", n, *fdl);
679 memset(*fdrp, 0, sz);
680 memset(*fdwp, 0, sz);
682 for (i = 0; i < sockets_alloc; i++) {
683 switch (sockets[i].type) {
685 case AUTH_CONNECTION:
686 FD_SET(sockets[i].fd, *fdrp);
687 if (buffer_len(&sockets[i].output) > 0)
688 FD_SET(sockets[i].fd, *fdwp);
698 after_select(fd_set *readset, fd_set *writeset)
704 struct sockaddr_un sunaddr;
706 for (i = 0; i < sockets_alloc; i++)
707 switch (sockets[i].type) {
711 if (FD_ISSET(sockets[i].fd, readset)) {
712 slen = sizeof(sunaddr);
713 sock = accept(sockets[i].fd,
714 (struct sockaddr *) &sunaddr, &slen);
716 error("accept from AUTH_SOCKET: %s",
720 new_socket(AUTH_CONNECTION, sock);
723 case AUTH_CONNECTION:
724 if (buffer_len(&sockets[i].output) > 0 &&
725 FD_ISSET(sockets[i].fd, writeset)) {
727 len = write(sockets[i].fd,
728 buffer_ptr(&sockets[i].output),
729 buffer_len(&sockets[i].output));
730 if (len == -1 && (errno == EAGAIN ||
736 shutdown(sockets[i].fd, SHUT_RDWR);
737 close(sockets[i].fd);
738 sockets[i].type = AUTH_UNUSED;
739 buffer_free(&sockets[i].input);
740 buffer_free(&sockets[i].output);
741 buffer_free(&sockets[i].request);
744 buffer_consume(&sockets[i].output, len);
746 if (FD_ISSET(sockets[i].fd, readset)) {
748 len = read(sockets[i].fd, buf, sizeof(buf));
749 if (len == -1 && (errno == EAGAIN ||
755 shutdown(sockets[i].fd, SHUT_RDWR);
756 close(sockets[i].fd);
757 sockets[i].type = AUTH_UNUSED;
758 buffer_free(&sockets[i].input);
759 buffer_free(&sockets[i].output);
760 buffer_free(&sockets[i].request);
763 buffer_append(&sockets[i].input, buf, len);
764 process_message(&sockets[i]);
768 fatal("Unknown type %d", sockets[i].type);
773 cleanup_socket(void *p)
784 cleanup_socket(NULL);
789 cleanup_handler(int sig)
791 cleanup_socket(NULL);
796 check_parent_exists(int sig)
798 int save_errno = errno;
800 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
801 /* printf("Parent has died - Authentication agent exiting.\n"); */
802 cleanup_handler(sig); /* safe */
804 signal(SIGALRM, check_parent_exists);
812 fprintf(stderr, "Usage: %s [options] [command [args ...]]\n",
814 fprintf(stderr, "Options:\n");
815 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
816 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
817 fprintf(stderr, " -k Kill the current agent.\n");
818 fprintf(stderr, " -d Debug mode.\n");
819 fprintf(stderr, " -a socket Bind agent socket to given name.\n");
824 main(int ac, char **av)
826 int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch, nalloc;
827 struct sockaddr_un sunaddr;
828 #ifdef HAVE_SETRLIMIT
835 char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
836 char *agentsocket = NULL;
838 fd_set *readsetp = NULL, *writesetp = NULL;
840 SSLeay_add_all_algorithms();
842 __progname = get_progname(av[0]);
846 #ifdef __GNU_LIBRARY__
847 while ((ch = getopt(ac, av, "+cdksa:")) != -1) {
848 #else /* __GNU_LIBRARY__ */
849 while ((ch = getopt(ac, av, "cdksa:")) != -1) {
850 #endif /* __GNU_LIBRARY__ */
871 agentsocket = optarg;
880 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
883 if (ac == 0 && !c_flag && !s_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 if (agentsocket == NULL) {
914 /* Create private directory for agent socket */
915 strlcpy(socket_dir, "/tmp/ssh-XXXXXXXX", sizeof socket_dir);
916 if (mkdtemp(socket_dir) == NULL) {
917 perror("mkdtemp: private socket dir");
920 snprintf(socket_name, sizeof socket_name, "%s/agent.%d", socket_dir,
923 /* Try to use specified agent socket */
924 socket_dir[0] = '\0';
925 strlcpy(socket_name, agentsocket, sizeof socket_name);
929 * Create socket early so it will exist before command gets run from
932 sock = socket(AF_UNIX, SOCK_STREAM, 0);
937 memset(&sunaddr, 0, sizeof(sunaddr));
938 sunaddr.sun_family = AF_UNIX;
939 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
941 prev_mask = umask(0177);
943 if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0) {
953 if (listen(sock, 5) < 0) {
959 * Fork, and have the parent execute the command, if any, or present
960 * the socket data. The child continues as the authentication agent.
963 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
964 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
965 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
966 SSH_AUTHSOCKET_ENV_NAME);
967 printf("echo Agent pid %d;\n", parent_pid);
975 if (pid != 0) { /* Parent - execute the given command. */
977 snprintf(pidstrbuf, sizeof pidstrbuf, "%d", pid);
979 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
980 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
981 SSH_AUTHSOCKET_ENV_NAME);
982 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
983 SSH_AGENTPID_ENV_NAME);
984 printf("echo Agent pid %d;\n", pid);
987 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
988 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
997 log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
999 if (setsid() == -1) {
1000 error("setsid: %s", strerror(errno));
1009 #ifdef HAVE_SETRLIMIT
1010 /* deny core dumps, since memory contains unencrypted private keys */
1011 rlim.rlim_cur = rlim.rlim_max = 0;
1012 if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
1013 error("setrlimit RLIMIT_CORE: %s", strerror(errno));
1019 fatal_add_cleanup(cleanup_socket, NULL);
1020 new_socket(AUTH_SOCKET, sock);
1022 signal(SIGALRM, check_parent_exists);
1027 signal(SIGINT, SIG_IGN);
1028 signal(SIGPIPE, SIG_IGN);
1029 signal(SIGHUP, cleanup_handler);
1030 signal(SIGTERM, cleanup_handler);
1034 prepare_select(&readsetp, &writesetp, &max_fd, &nalloc);
1035 if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
1038 fatal("select: %s", strerror(errno));
1040 after_select(readsetp, writesetp);