1 /* $OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $ */
4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
5 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7 * The authentication agent program.
9 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose. Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is
12 * incompatible with the protocol description in the RFC file, it must be
13 * called by a name other than "ssh" or "Secure Shell".
15 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 RCSID("$OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $");
41 #if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
42 #include <sys/queue.h>
44 #include "openbsd-compat/fake-queue.h"
48 #include <openssl/evp.h>
49 #include <openssl/md5.h>
67 #include <openssl/engine.h>
84 u_int sockets_alloc = 0;
85 SocketEntry *sockets = NULL;
87 typedef struct identity {
88 TAILQ_ENTRY(identity) next;
95 TAILQ_HEAD(idqueue, identity) idlist;
98 /* private key table, one per protocol version */
103 /* pid of shell == parent of agent */
104 pid_t parent_pid = -1;
106 /* pathname and directory for AUTH_SOCKET */
107 char socket_name[1024];
108 char socket_dir[1024];
110 #ifdef HAVE___PROGNAME
111 extern char *__progname;
120 for (i = 0; i <=2; i++) {
121 TAILQ_INIT(&idtable[i].idlist);
122 idtable[i].nentries = 0;
126 /* return private key table for requested protocol version */
128 idtab_lookup(int version)
130 if (version < 1 || version > 2)
131 fatal("internal error, bad protocol version %d", version);
132 return &idtable[version];
135 /* return matching private key for given public key */
137 lookup_identity(Key *key, int version)
141 Idtab *tab = idtab_lookup(version);
142 TAILQ_FOREACH(id, &tab->idlist, next) {
143 if (key_equal(key, id->key))
150 free_identity(Identity *id)
157 /* send list of supported public keys to 'client' */
159 process_request_identities(SocketEntry *e, int version)
161 Idtab *tab = idtab_lookup(version);
166 buffer_put_char(&msg, (version == 1) ?
167 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
168 buffer_put_int(&msg, tab->nentries);
169 TAILQ_FOREACH(id, &tab->idlist, next) {
170 if (id->key->type == KEY_RSA1) {
171 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
172 buffer_put_bignum(&msg, id->key->rsa->e);
173 buffer_put_bignum(&msg, id->key->rsa->n);
177 key_to_blob(id->key, &blob, &blen);
178 buffer_put_string(&msg, blob, blen);
181 buffer_put_cstring(&msg, id->comment);
183 buffer_put_int(&e->output, buffer_len(&msg));
184 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
190 process_authentication_challenge1(SocketEntry *e)
198 u_char buf[32], mdbuf[16], session_id[16];
202 key = key_new(KEY_RSA1);
203 if ((challenge = BN_new()) == NULL)
204 fatal("process_authentication_challenge1: BN_new failed");
206 buffer_get_int(&e->input); /* ignored */
207 buffer_get_bignum(&e->input, key->rsa->e);
208 buffer_get_bignum(&e->input, key->rsa->n);
209 buffer_get_bignum(&e->input, challenge);
211 /* Only protocol 1.1 is supported */
212 if (buffer_len(&e->input) == 0)
214 buffer_get(&e->input, session_id, 16);
215 response_type = buffer_get_int(&e->input);
216 if (response_type != 1)
219 id = lookup_identity(key, 1);
221 Key *private = id->key;
222 /* Decrypt the challenge using the private key. */
223 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
226 /* The response is MD5 of decrypted challenge plus session id. */
227 len = BN_num_bytes(challenge);
228 if (len <= 0 || len > 32) {
229 log("process_authentication_challenge: bad challenge length %d", len);
233 BN_bn2bin(challenge, buf + 32 - len);
235 MD5_Update(&md, buf, 32);
236 MD5_Update(&md, session_id, 16);
237 MD5_Final(mdbuf, &md);
239 /* Send the response. */
240 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
241 for (i = 0; i < 16; i++)
242 buffer_put_char(&msg, mdbuf[i]);
247 /* Unknown identity or protocol error. Send failure. */
248 buffer_put_char(&msg, SSH_AGENT_FAILURE);
250 buffer_put_int(&e->output, buffer_len(&msg));
251 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
253 BN_clear_free(challenge);
259 process_sign_request2(SocketEntry *e)
261 extern int datafellows;
263 u_char *blob, *data, *signature = NULL;
264 u_int blen, dlen, slen = 0;
271 blob = buffer_get_string(&e->input, &blen);
272 data = buffer_get_string(&e->input, &dlen);
274 flags = buffer_get_int(&e->input);
275 if (flags & SSH_AGENT_OLD_SIGNATURE)
276 datafellows = SSH_BUG_SIGBLOB;
278 key = key_from_blob(blob, blen);
280 Identity *id = lookup_identity(key, 2);
282 ok = key_sign(id->key, &signature, &slen, data, dlen);
287 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
288 buffer_put_string(&msg, signature, slen);
290 buffer_put_char(&msg, SSH_AGENT_FAILURE);
292 buffer_put_int(&e->output, buffer_len(&msg));
293 buffer_append(&e->output, buffer_ptr(&msg),
298 if (signature != NULL)
304 process_remove_identity(SocketEntry *e, int version)
314 key = key_new(KEY_RSA1);
315 bits = buffer_get_int(&e->input);
316 buffer_get_bignum(&e->input, key->rsa->e);
317 buffer_get_bignum(&e->input, key->rsa->n);
319 if (bits != key_size(key))
320 log("Warning: identity keysize mismatch: actual %d, announced %d",
321 key_size(key), bits);
324 blob = buffer_get_string(&e->input, &blen);
325 key = key_from_blob(blob, blen);
330 Identity *id = lookup_identity(key, version);
333 * We have this key. Free the old key. Since we
334 * don\'t want to leave empty slots in the middle of
335 * the array, we actually free the key there and move
336 * all the entries between the empty slot and the end
339 Idtab *tab = idtab_lookup(version);
340 if (tab->nentries < 1)
341 fatal("process_remove_identity: "
342 "internal error: tab->nentries %d",
344 TAILQ_REMOVE(&tab->idlist, id, next);
351 buffer_put_int(&e->output, 1);
352 buffer_put_char(&e->output,
353 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
357 process_remove_all_identities(SocketEntry *e, int version)
359 Idtab *tab = idtab_lookup(version);
362 /* Loop over all identities and clear the keys. */
363 for (id = TAILQ_FIRST(&tab->idlist); id;
364 id = TAILQ_FIRST(&tab->idlist)) {
365 TAILQ_REMOVE(&tab->idlist, id, next);
369 /* Mark that there are no identities. */
373 buffer_put_int(&e->output, 1);
374 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
379 process_add_identity(SocketEntry *e, int version)
384 int type, success = 0;
385 Idtab *tab = idtab_lookup(version);
389 k = key_new_private(KEY_RSA1);
390 buffer_get_int(&e->input); /* ignored */
391 buffer_get_bignum(&e->input, k->rsa->n);
392 buffer_get_bignum(&e->input, k->rsa->e);
393 buffer_get_bignum(&e->input, k->rsa->d);
394 buffer_get_bignum(&e->input, k->rsa->iqmp);
396 /* SSH and SSL have p and q swapped */
397 buffer_get_bignum(&e->input, k->rsa->q); /* p */
398 buffer_get_bignum(&e->input, k->rsa->p); /* q */
400 /* Generate additional parameters */
401 rsa_generate_additional_parameters(k->rsa);
404 type_name = buffer_get_string(&e->input, NULL);
405 type = key_type_from_name(type_name);
409 k = key_new_private(type);
410 buffer_get_bignum2(&e->input, k->dsa->p);
411 buffer_get_bignum2(&e->input, k->dsa->q);
412 buffer_get_bignum2(&e->input, k->dsa->g);
413 buffer_get_bignum2(&e->input, k->dsa->pub_key);
414 buffer_get_bignum2(&e->input, k->dsa->priv_key);
417 k = key_new_private(type);
418 buffer_get_bignum2(&e->input, k->rsa->n);
419 buffer_get_bignum2(&e->input, k->rsa->e);
420 buffer_get_bignum2(&e->input, k->rsa->d);
421 buffer_get_bignum2(&e->input, k->rsa->iqmp);
422 buffer_get_bignum2(&e->input, k->rsa->p);
423 buffer_get_bignum2(&e->input, k->rsa->q);
425 /* Generate additional parameters */
426 rsa_generate_additional_parameters(k->rsa);
429 buffer_clear(&e->input);
434 comment = buffer_get_string(&e->input, NULL);
440 if (lookup_identity(k, version) == NULL) {
441 Identity *id = xmalloc(sizeof(Identity));
443 id->comment = comment;
444 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
445 /* Increment the number of identities. */
452 buffer_put_int(&e->output, 1);
453 buffer_put_char(&e->output,
454 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
460 process_add_smartcard_key (SocketEntry *e)
463 Key *n = NULL, *k = NULL;
464 char *sc_reader_id = NULL;
467 sc_reader_id = buffer_get_string(&e->input, NULL);
468 k = sc_get_key(sc_reader_id);
472 error("sc_get_pubkey failed");
477 tab = idtab_lookup(1);
479 if (lookup_identity(k, 1) == NULL) {
480 Identity *id = xmalloc(sizeof(Identity));
481 n = key_new(KEY_RSA1);
482 BN_copy(n->rsa->n, k->rsa->n);
483 BN_copy(n->rsa->e, k->rsa->e);
484 RSA_set_method(n->rsa, sc_get_engine());
486 id->comment = xstrdup("rsa1 smartcard");
487 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
491 tab = idtab_lookup(2);
492 if (lookup_identity(k, 2) == NULL) {
493 Identity *id = xmalloc(sizeof(Identity));
494 n = key_new(KEY_RSA);
495 BN_copy(n->rsa->n, k->rsa->n);
496 BN_copy(n->rsa->e, k->rsa->e);
497 RSA_set_method(n->rsa, sc_get_engine());
499 id->comment = xstrdup("rsa smartcard");
500 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
505 buffer_put_int(&e->output, 1);
506 buffer_put_char(&e->output,
507 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
511 process_remove_smartcard_key(SocketEntry *e)
515 char *sc_reader_id = NULL;
517 sc_reader_id = buffer_get_string(&e->input, NULL);
518 k = sc_get_key(sc_reader_id);
522 error("sc_get_pubkey failed");
526 id = lookup_identity(k, 1);
528 Idtab *tab = idtab_lookup(1);
529 TAILQ_REMOVE(&tab->idlist, id, next);
535 id = lookup_identity(k, 2);
537 Idtab *tab = idtab_lookup(2);
538 TAILQ_REMOVE(&tab->idlist, id, next);
546 buffer_put_int(&e->output, 1);
547 buffer_put_char(&e->output,
548 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
550 #endif /* SMARTCARD */
552 /* dispatch incoming messages */
555 process_message(SocketEntry *e)
560 if (buffer_len(&e->input) < 5)
561 return; /* Incomplete message. */
562 cp = buffer_ptr(&e->input);
563 msg_len = GET_32BIT(cp);
564 if (msg_len > 256 * 1024) {
565 shutdown(e->fd, SHUT_RDWR);
567 e->type = AUTH_UNUSED;
570 if (buffer_len(&e->input) < msg_len + 4)
572 buffer_consume(&e->input, 4);
573 type = buffer_get_char(&e->input);
575 debug("type %d", type);
578 case SSH_AGENTC_RSA_CHALLENGE:
579 process_authentication_challenge1(e);
581 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
582 process_request_identities(e, 1);
584 case SSH_AGENTC_ADD_RSA_IDENTITY:
585 process_add_identity(e, 1);
587 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
588 process_remove_identity(e, 1);
590 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
591 process_remove_all_identities(e, 1);
594 case SSH2_AGENTC_SIGN_REQUEST:
595 process_sign_request2(e);
597 case SSH2_AGENTC_REQUEST_IDENTITIES:
598 process_request_identities(e, 2);
600 case SSH2_AGENTC_ADD_IDENTITY:
601 process_add_identity(e, 2);
603 case SSH2_AGENTC_REMOVE_IDENTITY:
604 process_remove_identity(e, 2);
606 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
607 process_remove_all_identities(e, 2);
610 case SSH_AGENTC_ADD_SMARTCARD_KEY:
611 process_add_smartcard_key(e);
613 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
614 process_remove_smartcard_key(e);
616 #endif /* SMARTCARD */
618 /* Unknown message. Respond with failure. */
619 error("Unknown message %d", type);
620 buffer_clear(&e->input);
621 buffer_put_int(&e->output, 1);
622 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
628 new_socket(sock_type type, int fd)
631 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
632 error("fcntl O_NONBLOCK: %s", strerror(errno));
637 for (i = 0; i < sockets_alloc; i++)
638 if (sockets[i].type == AUTH_UNUSED) {
640 sockets[i].type = type;
641 buffer_init(&sockets[i].input);
642 buffer_init(&sockets[i].output);
645 old_alloc = sockets_alloc;
648 sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0]));
650 sockets = xmalloc(sockets_alloc * sizeof(sockets[0]));
651 for (i = old_alloc; i < sockets_alloc; i++)
652 sockets[i].type = AUTH_UNUSED;
653 sockets[old_alloc].type = type;
654 sockets[old_alloc].fd = fd;
655 buffer_init(&sockets[old_alloc].input);
656 buffer_init(&sockets[old_alloc].output);
660 prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, int *nallocp)
665 for (i = 0; i < sockets_alloc; i++) {
666 switch (sockets[i].type) {
668 case AUTH_CONNECTION:
669 n = MAX(n, sockets[i].fd);
674 fatal("Unknown socket type %d", sockets[i].type);
679 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
680 if (*fdrp == NULL || sz > *nallocp) {
690 debug("XXX shrink: %d < %d", n, *fdl);
692 memset(*fdrp, 0, sz);
693 memset(*fdwp, 0, sz);
695 for (i = 0; i < sockets_alloc; i++) {
696 switch (sockets[i].type) {
698 case AUTH_CONNECTION:
699 FD_SET(sockets[i].fd, *fdrp);
700 if (buffer_len(&sockets[i].output) > 0)
701 FD_SET(sockets[i].fd, *fdwp);
711 after_select(fd_set *readset, fd_set *writeset)
717 struct sockaddr_un sunaddr;
719 for (i = 0; i < sockets_alloc; i++)
720 switch (sockets[i].type) {
724 if (FD_ISSET(sockets[i].fd, readset)) {
725 slen = sizeof(sunaddr);
726 sock = accept(sockets[i].fd,
727 (struct sockaddr *) &sunaddr, &slen);
729 perror("accept from AUTH_SOCKET");
732 new_socket(AUTH_CONNECTION, sock);
735 case AUTH_CONNECTION:
736 if (buffer_len(&sockets[i].output) > 0 &&
737 FD_ISSET(sockets[i].fd, writeset)) {
739 len = write(sockets[i].fd,
740 buffer_ptr(&sockets[i].output),
741 buffer_len(&sockets[i].output));
742 if (len == -1 && (errno == EAGAIN ||
748 shutdown(sockets[i].fd, SHUT_RDWR);
749 close(sockets[i].fd);
750 sockets[i].type = AUTH_UNUSED;
751 buffer_free(&sockets[i].input);
752 buffer_free(&sockets[i].output);
755 buffer_consume(&sockets[i].output, len);
757 if (FD_ISSET(sockets[i].fd, readset)) {
759 len = read(sockets[i].fd, buf, sizeof(buf));
760 if (len == -1 && (errno == EAGAIN ||
766 shutdown(sockets[i].fd, SHUT_RDWR);
767 close(sockets[i].fd);
768 sockets[i].type = AUTH_UNUSED;
769 buffer_free(&sockets[i].input);
770 buffer_free(&sockets[i].output);
773 buffer_append(&sockets[i].input, buf, len);
774 process_message(&sockets[i]);
778 fatal("Unknown type %d", sockets[i].type);
799 cleanup_handler(int sig)
806 check_parent_exists(int sig)
808 int save_errno = errno;
810 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
811 /* printf("Parent has died - Authentication agent exiting.\n"); */
812 cleanup_handler(sig); /* safe */
814 signal(SIGALRM, check_parent_exists);
822 fprintf(stderr, "Usage: %s [options] [command [args ...]]\n",
824 fprintf(stderr, "Options:\n");
825 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
826 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
827 fprintf(stderr, " -k Kill the current agent.\n");
828 fprintf(stderr, " -d Debug mode.\n");
833 main(int ac, char **av)
835 int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch, nalloc;
836 struct sockaddr_un sunaddr;
837 #ifdef HAVE_SETRLIMIT
844 char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
846 fd_set *readsetp = NULL, *writesetp = NULL;
848 SSLeay_add_all_algorithms();
850 __progname = get_progname(av[0]);
854 #ifdef __GNU_LIBRARY__
855 while ((ch = getopt(ac, av, "+cdks")) != -1) {
856 #else /* __GNU_LIBRARY__ */
857 while ((ch = getopt(ac, av, "cdks")) != -1) {
858 #endif /* __GNU_LIBRARY__ */
885 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
888 if (ac == 0 && !c_flag && !k_flag && !s_flag && !d_flag) {
889 shell = getenv("SHELL");
890 if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0)
894 pidstr = getenv(SSH_AGENTPID_ENV_NAME);
895 if (pidstr == NULL) {
896 fprintf(stderr, "%s not set, cannot kill agent\n",
897 SSH_AGENTPID_ENV_NAME);
902 fprintf(stderr, "%s=\"%s\", which is not a good PID\n",
903 SSH_AGENTPID_ENV_NAME, pidstr);
906 if (kill(pid, SIGTERM) == -1) {
910 format = c_flag ? "unsetenv %s;\n" : "unset %s;\n";
911 printf(format, SSH_AUTHSOCKET_ENV_NAME);
912 printf(format, SSH_AGENTPID_ENV_NAME);
913 printf("echo Agent pid %d killed;\n", pid);
916 parent_pid = getpid();
918 /* Create private directory for agent socket */
919 strlcpy(socket_dir, "/tmp/ssh-XXXXXXXX", sizeof socket_dir);
920 if (mkdtemp(socket_dir) == NULL) {
921 perror("mkdtemp: private socket dir");
924 snprintf(socket_name, sizeof socket_name, "%s/agent.%d", socket_dir,
928 * Create socket early so it will exist before command gets run from
931 sock = socket(AF_UNIX, SOCK_STREAM, 0);
936 memset(&sunaddr, 0, sizeof(sunaddr));
937 sunaddr.sun_family = AF_UNIX;
938 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
940 prev_mask = umask(0177);
942 if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0) {
952 if (listen(sock, 5) < 0) {
958 * Fork, and have the parent execute the command, if any, or present
959 * the socket data. The child continues as the authentication agent.
962 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
963 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
964 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
965 SSH_AUTHSOCKET_ENV_NAME);
966 printf("echo Agent pid %d;\n", parent_pid);
974 if (pid != 0) { /* Parent - execute the given command. */
976 snprintf(pidstrbuf, sizeof pidstrbuf, "%d", pid);
978 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
979 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
980 SSH_AUTHSOCKET_ENV_NAME);
981 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
982 SSH_AGENTPID_ENV_NAME);
983 printf("echo Agent pid %d;\n", pid);
986 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
987 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
996 if (setsid() == -1) {
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 perror("setrlimit rlimit_core failed");
1016 if (atexit(cleanup_socket) < 0) {
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) {
1040 after_select(readsetp, writesetp);