1 /* $OpenBSD: ssh-agent.c,v 1.80 2002/02/04 00:53:39 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.80 2002/02/04 00:53:39 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>
63 #include <openssl/engine.h>
80 u_int sockets_alloc = 0;
81 SocketEntry *sockets = NULL;
83 typedef struct identity {
84 TAILQ_ENTRY(identity) next;
91 TAILQ_HEAD(idqueue, identity) idlist;
94 /* private key table, one per protocol version */
99 /* pid of shell == parent of agent */
100 pid_t parent_pid = -1;
102 /* pathname and directory for AUTH_SOCKET */
103 char socket_name[1024];
104 char socket_dir[1024];
106 #ifdef HAVE___PROGNAME
107 extern char *__progname;
116 for (i = 0; i <=2; i++) {
117 TAILQ_INIT(&idtable[i].idlist);
118 idtable[i].nentries = 0;
122 /* return private key table for requested protocol version */
124 idtab_lookup(int version)
126 if (version < 1 || version > 2)
127 fatal("internal error, bad protocol version %d", version);
128 return &idtable[version];
131 /* return matching private key for given public key */
133 lookup_identity(Key *key, int version)
137 Idtab *tab = idtab_lookup(version);
138 TAILQ_FOREACH(id, &tab->idlist, next) {
139 if (key_equal(key, id->key))
146 free_identity(Identity *id)
153 /* send list of supported public keys to 'client' */
155 process_request_identities(SocketEntry *e, int version)
157 Idtab *tab = idtab_lookup(version);
162 buffer_put_char(&msg, (version == 1) ?
163 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
164 buffer_put_int(&msg, tab->nentries);
165 TAILQ_FOREACH(id, &tab->idlist, next) {
166 if (id->key->type == KEY_RSA1) {
167 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
168 buffer_put_bignum(&msg, id->key->rsa->e);
169 buffer_put_bignum(&msg, id->key->rsa->n);
173 key_to_blob(id->key, &blob, &blen);
174 buffer_put_string(&msg, blob, blen);
177 buffer_put_cstring(&msg, id->comment);
179 buffer_put_int(&e->output, buffer_len(&msg));
180 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
186 process_authentication_challenge1(SocketEntry *e)
194 u_char buf[32], mdbuf[16], session_id[16];
198 key = key_new(KEY_RSA1);
199 if ((challenge = BN_new()) == NULL)
200 fatal("process_authentication_challenge1: BN_new failed");
202 buffer_get_int(&e->input); /* ignored */
203 buffer_get_bignum(&e->input, key->rsa->e);
204 buffer_get_bignum(&e->input, key->rsa->n);
205 buffer_get_bignum(&e->input, challenge);
207 /* Only protocol 1.1 is supported */
208 if (buffer_len(&e->input) == 0)
210 buffer_get(&e->input, session_id, 16);
211 response_type = buffer_get_int(&e->input);
212 if (response_type != 1)
215 id = lookup_identity(key, 1);
217 Key *private = id->key;
218 /* Decrypt the challenge using the private key. */
219 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
222 /* The response is MD5 of decrypted challenge plus session id. */
223 len = BN_num_bytes(challenge);
224 if (len <= 0 || len > 32) {
225 log("process_authentication_challenge: bad challenge length %d", len);
229 BN_bn2bin(challenge, buf + 32 - len);
231 MD5_Update(&md, buf, 32);
232 MD5_Update(&md, session_id, 16);
233 MD5_Final(mdbuf, &md);
235 /* Send the response. */
236 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
237 for (i = 0; i < 16; i++)
238 buffer_put_char(&msg, mdbuf[i]);
243 /* Unknown identity or protocol error. Send failure. */
244 buffer_put_char(&msg, SSH_AGENT_FAILURE);
246 buffer_put_int(&e->output, buffer_len(&msg));
247 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
249 BN_clear_free(challenge);
255 process_sign_request2(SocketEntry *e)
257 extern int datafellows;
259 u_char *blob, *data, *signature = NULL;
260 u_int blen, dlen, slen = 0;
267 blob = buffer_get_string(&e->input, &blen);
268 data = buffer_get_string(&e->input, &dlen);
270 flags = buffer_get_int(&e->input);
271 if (flags & SSH_AGENT_OLD_SIGNATURE)
272 datafellows = SSH_BUG_SIGBLOB;
274 key = key_from_blob(blob, blen);
276 Identity *id = lookup_identity(key, 2);
278 ok = key_sign(id->key, &signature, &slen, data, dlen);
283 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
284 buffer_put_string(&msg, signature, slen);
286 buffer_put_char(&msg, SSH_AGENT_FAILURE);
288 buffer_put_int(&e->output, buffer_len(&msg));
289 buffer_append(&e->output, buffer_ptr(&msg),
294 if (signature != NULL)
300 process_remove_identity(SocketEntry *e, int version)
310 key = key_new(KEY_RSA1);
311 bits = buffer_get_int(&e->input);
312 buffer_get_bignum(&e->input, key->rsa->e);
313 buffer_get_bignum(&e->input, key->rsa->n);
315 if (bits != key_size(key))
316 log("Warning: identity keysize mismatch: actual %d, announced %d",
317 key_size(key), bits);
320 blob = buffer_get_string(&e->input, &blen);
321 key = key_from_blob(blob, blen);
326 Identity *id = lookup_identity(key, version);
329 * We have this key. Free the old key. Since we
330 * don\'t want to leave empty slots in the middle of
331 * the array, we actually free the key there and move
332 * all the entries between the empty slot and the end
335 Idtab *tab = idtab_lookup(version);
336 if (tab->nentries < 1)
337 fatal("process_remove_identity: "
338 "internal error: tab->nentries %d",
340 TAILQ_REMOVE(&tab->idlist, id, next);
347 buffer_put_int(&e->output, 1);
348 buffer_put_char(&e->output,
349 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
353 process_remove_all_identities(SocketEntry *e, int version)
355 Idtab *tab = idtab_lookup(version);
358 /* Loop over all identities and clear the keys. */
359 for (id = TAILQ_FIRST(&tab->idlist); id;
360 id = TAILQ_FIRST(&tab->idlist)) {
361 TAILQ_REMOVE(&tab->idlist, id, next);
365 /* Mark that there are no identities. */
369 buffer_put_int(&e->output, 1);
370 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
375 process_add_identity(SocketEntry *e, int version)
380 int type, success = 0;
381 Idtab *tab = idtab_lookup(version);
385 k = key_new_private(KEY_RSA1);
386 buffer_get_int(&e->input); /* ignored */
387 buffer_get_bignum(&e->input, k->rsa->n);
388 buffer_get_bignum(&e->input, k->rsa->e);
389 buffer_get_bignum(&e->input, k->rsa->d);
390 buffer_get_bignum(&e->input, k->rsa->iqmp);
392 /* SSH and SSL have p and q swapped */
393 buffer_get_bignum(&e->input, k->rsa->q); /* p */
394 buffer_get_bignum(&e->input, k->rsa->p); /* q */
396 /* Generate additional parameters */
397 rsa_generate_additional_parameters(k->rsa);
400 type_name = buffer_get_string(&e->input, NULL);
401 type = key_type_from_name(type_name);
405 k = key_new_private(type);
406 buffer_get_bignum2(&e->input, k->dsa->p);
407 buffer_get_bignum2(&e->input, k->dsa->q);
408 buffer_get_bignum2(&e->input, k->dsa->g);
409 buffer_get_bignum2(&e->input, k->dsa->pub_key);
410 buffer_get_bignum2(&e->input, k->dsa->priv_key);
413 k = key_new_private(type);
414 buffer_get_bignum2(&e->input, k->rsa->n);
415 buffer_get_bignum2(&e->input, k->rsa->e);
416 buffer_get_bignum2(&e->input, k->rsa->d);
417 buffer_get_bignum2(&e->input, k->rsa->iqmp);
418 buffer_get_bignum2(&e->input, k->rsa->p);
419 buffer_get_bignum2(&e->input, k->rsa->q);
421 /* Generate additional parameters */
422 rsa_generate_additional_parameters(k->rsa);
425 buffer_clear(&e->input);
430 comment = buffer_get_string(&e->input, NULL);
436 if (lookup_identity(k, version) == NULL) {
437 Identity *id = xmalloc(sizeof(Identity));
439 id->comment = comment;
440 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
441 /* Increment the number of identities. */
448 buffer_put_int(&e->output, 1);
449 buffer_put_char(&e->output,
450 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
456 process_add_smartcard_key (SocketEntry *e)
459 Key *n = NULL, *k = NULL;
460 char *sc_reader_id = NULL;
463 sc_reader_id = buffer_get_string(&e->input, NULL);
464 k = sc_get_key(sc_reader_id);
468 error("sc_get_pubkey failed");
473 tab = idtab_lookup(1);
475 if (lookup_identity(k, 1) == NULL) {
476 Identity *id = xmalloc(sizeof(Identity));
477 n = key_new(KEY_RSA1);
478 BN_copy(n->rsa->n, k->rsa->n);
479 BN_copy(n->rsa->e, k->rsa->e);
480 RSA_set_method(n->rsa, sc_get_engine());
482 id->comment = xstrdup("rsa1 smartcard");
483 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
487 tab = idtab_lookup(2);
488 if (lookup_identity(k, 2) == NULL) {
489 Identity *id = xmalloc(sizeof(Identity));
490 n = key_new(KEY_RSA);
491 BN_copy(n->rsa->n, k->rsa->n);
492 BN_copy(n->rsa->e, k->rsa->e);
493 RSA_set_method(n->rsa, sc_get_engine());
495 id->comment = xstrdup("rsa smartcard");
496 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
501 buffer_put_int(&e->output, 1);
502 buffer_put_char(&e->output,
503 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
507 process_remove_smartcard_key(SocketEntry *e)
511 char *sc_reader_id = NULL;
513 sc_reader_id = buffer_get_string(&e->input, NULL);
514 k = sc_get_key(sc_reader_id);
518 error("sc_get_pubkey failed");
522 id = lookup_identity(k, 1);
524 Idtab *tab = idtab_lookup(1);
525 TAILQ_REMOVE(&tab->idlist, id, next);
531 id = lookup_identity(k, 2);
533 Idtab *tab = idtab_lookup(2);
534 TAILQ_REMOVE(&tab->idlist, id, next);
542 buffer_put_int(&e->output, 1);
543 buffer_put_char(&e->output,
544 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
546 #endif /* SMARTCARD */
548 /* dispatch incoming messages */
551 process_message(SocketEntry *e)
556 if (buffer_len(&e->input) < 5)
557 return; /* Incomplete message. */
558 cp = buffer_ptr(&e->input);
559 msg_len = GET_32BIT(cp);
560 if (msg_len > 256 * 1024) {
561 shutdown(e->fd, SHUT_RDWR);
563 e->type = AUTH_UNUSED;
566 if (buffer_len(&e->input) < msg_len + 4)
568 buffer_consume(&e->input, 4);
569 type = buffer_get_char(&e->input);
571 debug("type %d", type);
574 case SSH_AGENTC_RSA_CHALLENGE:
575 process_authentication_challenge1(e);
577 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
578 process_request_identities(e, 1);
580 case SSH_AGENTC_ADD_RSA_IDENTITY:
581 process_add_identity(e, 1);
583 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
584 process_remove_identity(e, 1);
586 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
587 process_remove_all_identities(e, 1);
590 case SSH2_AGENTC_SIGN_REQUEST:
591 process_sign_request2(e);
593 case SSH2_AGENTC_REQUEST_IDENTITIES:
594 process_request_identities(e, 2);
596 case SSH2_AGENTC_ADD_IDENTITY:
597 process_add_identity(e, 2);
599 case SSH2_AGENTC_REMOVE_IDENTITY:
600 process_remove_identity(e, 2);
602 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
603 process_remove_all_identities(e, 2);
606 case SSH_AGENTC_ADD_SMARTCARD_KEY:
607 process_add_smartcard_key(e);
609 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
610 process_remove_smartcard_key(e);
612 #endif /* SMARTCARD */
614 /* Unknown message. Respond with failure. */
615 error("Unknown message %d", type);
616 buffer_clear(&e->input);
617 buffer_put_int(&e->output, 1);
618 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
624 new_socket(sock_type type, int fd)
627 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
628 error("fcntl O_NONBLOCK: %s", strerror(errno));
633 for (i = 0; i < sockets_alloc; i++)
634 if (sockets[i].type == AUTH_UNUSED) {
636 sockets[i].type = type;
637 buffer_init(&sockets[i].input);
638 buffer_init(&sockets[i].output);
641 old_alloc = sockets_alloc;
644 sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0]));
646 sockets = xmalloc(sockets_alloc * sizeof(sockets[0]));
647 for (i = old_alloc; i < sockets_alloc; i++)
648 sockets[i].type = AUTH_UNUSED;
649 sockets[old_alloc].type = type;
650 sockets[old_alloc].fd = fd;
651 buffer_init(&sockets[old_alloc].input);
652 buffer_init(&sockets[old_alloc].output);
656 prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, int *nallocp)
661 for (i = 0; i < sockets_alloc; i++) {
662 switch (sockets[i].type) {
664 case AUTH_CONNECTION:
665 n = MAX(n, sockets[i].fd);
670 fatal("Unknown socket type %d", sockets[i].type);
675 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
676 if (*fdrp == NULL || sz > *nallocp) {
686 debug("XXX shrink: %d < %d", n, *fdl);
688 memset(*fdrp, 0, sz);
689 memset(*fdwp, 0, sz);
691 for (i = 0; i < sockets_alloc; i++) {
692 switch (sockets[i].type) {
694 case AUTH_CONNECTION:
695 FD_SET(sockets[i].fd, *fdrp);
696 if (buffer_len(&sockets[i].output) > 0)
697 FD_SET(sockets[i].fd, *fdwp);
707 after_select(fd_set *readset, fd_set *writeset)
713 struct sockaddr_un sunaddr;
715 for (i = 0; i < sockets_alloc; i++)
716 switch (sockets[i].type) {
720 if (FD_ISSET(sockets[i].fd, readset)) {
721 slen = sizeof(sunaddr);
722 sock = accept(sockets[i].fd,
723 (struct sockaddr *) &sunaddr, &slen);
725 perror("accept from AUTH_SOCKET");
728 new_socket(AUTH_CONNECTION, sock);
731 case AUTH_CONNECTION:
732 if (buffer_len(&sockets[i].output) > 0 &&
733 FD_ISSET(sockets[i].fd, writeset)) {
735 len = write(sockets[i].fd,
736 buffer_ptr(&sockets[i].output),
737 buffer_len(&sockets[i].output));
738 if (len == -1 && (errno == EAGAIN ||
744 shutdown(sockets[i].fd, SHUT_RDWR);
745 close(sockets[i].fd);
746 sockets[i].type = AUTH_UNUSED;
747 buffer_free(&sockets[i].input);
748 buffer_free(&sockets[i].output);
751 buffer_consume(&sockets[i].output, len);
753 if (FD_ISSET(sockets[i].fd, readset)) {
755 len = read(sockets[i].fd, buf, sizeof(buf));
756 if (len == -1 && (errno == EAGAIN ||
762 shutdown(sockets[i].fd, SHUT_RDWR);
763 close(sockets[i].fd);
764 sockets[i].type = AUTH_UNUSED;
765 buffer_free(&sockets[i].input);
766 buffer_free(&sockets[i].output);
769 buffer_append(&sockets[i].input, buf, len);
770 process_message(&sockets[i]);
774 fatal("Unknown type %d", sockets[i].type);
795 cleanup_handler(int sig)
802 check_parent_exists(int sig)
804 int save_errno = errno;
806 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
807 /* printf("Parent has died - Authentication agent exiting.\n"); */
808 cleanup_handler(sig); /* safe */
810 signal(SIGALRM, check_parent_exists);
818 fprintf(stderr, "Usage: %s [options] [command [args ...]]\n",
820 fprintf(stderr, "Options:\n");
821 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
822 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
823 fprintf(stderr, " -k Kill the current agent.\n");
824 fprintf(stderr, " -d Debug mode.\n");
829 main(int ac, char **av)
831 int sock, c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, ch, nalloc;
832 struct sockaddr_un sunaddr;
833 #ifdef HAVE_SETRLIMIT
840 char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
842 fd_set *readsetp = NULL, *writesetp = NULL;
844 SSLeay_add_all_algorithms();
846 __progname = get_progname(av[0]);
850 #ifdef __GNU_LIBRARY__
851 while ((ch = getopt(ac, av, "+cdks")) != -1) {
852 #else /* __GNU_LIBRARY__ */
853 while ((ch = getopt(ac, av, "cdks")) != -1) {
854 #endif /* __GNU_LIBRARY__ */
881 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
884 if (ac == 0 && !c_flag && !k_flag && !s_flag && !d_flag) {
885 shell = getenv("SHELL");
886 if (shell != NULL && strncmp(shell + strlen(shell) - 3, "csh", 3) == 0)
890 pidstr = getenv(SSH_AGENTPID_ENV_NAME);
891 if (pidstr == NULL) {
892 fprintf(stderr, "%s not set, cannot kill agent\n",
893 SSH_AGENTPID_ENV_NAME);
898 fprintf(stderr, "%s=\"%s\", which is not a good PID\n",
899 SSH_AGENTPID_ENV_NAME, pidstr);
902 if (kill(pid, SIGTERM) == -1) {
906 format = c_flag ? "unsetenv %s;\n" : "unset %s;\n";
907 printf(format, SSH_AUTHSOCKET_ENV_NAME);
908 printf(format, SSH_AGENTPID_ENV_NAME);
909 printf("echo Agent pid %d killed;\n", pid);
912 parent_pid = getpid();
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,
924 * Create socket early so it will exist before command gets run from
927 sock = socket(AF_UNIX, SOCK_STREAM, 0);
932 memset(&sunaddr, 0, sizeof(sunaddr));
933 sunaddr.sun_family = AF_UNIX;
934 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
936 prev_mask = umask(0177);
938 if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0) {
948 if (listen(sock, 5) < 0) {
954 * Fork, and have the parent execute the command, if any, or present
955 * the socket data. The child continues as the authentication agent.
958 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
959 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
960 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
961 SSH_AUTHSOCKET_ENV_NAME);
962 printf("echo Agent pid %d;\n", parent_pid);
970 if (pid != 0) { /* Parent - execute the given command. */
972 snprintf(pidstrbuf, sizeof pidstrbuf, "%d", pid);
974 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
975 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
976 SSH_AUTHSOCKET_ENV_NAME);
977 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
978 SSH_AGENTPID_ENV_NAME);
979 printf("echo Agent pid %d;\n", pid);
982 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
983 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
992 if (setsid() == -1) {
1002 #ifdef HAVE_SETRLIMIT
1003 /* deny core dumps, since memory contains unencrypted private keys */
1004 rlim.rlim_cur = rlim.rlim_max = 0;
1005 if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
1006 perror("setrlimit rlimit_core failed");
1012 if (atexit(cleanup_socket) < 0) {
1016 new_socket(AUTH_SOCKET, sock);
1018 signal(SIGALRM, check_parent_exists);
1023 signal(SIGINT, SIG_IGN);
1024 signal(SIGPIPE, SIG_IGN);
1025 signal(SIGHUP, cleanup_handler);
1026 signal(SIGTERM, cleanup_handler);
1030 prepare_select(&readsetp, &writesetp, &max_fd, &nalloc);
1031 if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
1036 after_select(readsetp, writesetp);