]> andersk Git - gssapi-openssh.git/blame - openssh/ssh-agent.c
Import of OpenSSH 4.9p1
[gssapi-openssh.git] / openssh / ssh-agent.c
CommitLineData
47686178 1/* $OpenBSD: ssh-agent.c,v 1.157 2007/09/25 23:48:57 canacar Exp $ */
3c0ef626 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
6 * The authentication agent program.
7 *
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
13 *
14 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "includes.h"
9108f8d9 38
39#include <sys/types.h>
40#include <sys/param.h>
41#include <sys/resource.h>
42#include <sys/stat.h>
43#include <sys/socket.h>
44#ifdef HAVE_SYS_TIME_H
45# include <sys/time.h>
46#endif
47#ifdef HAVE_SYS_UN_H
48# include <sys/un.h>
49#endif
41b2f314 50#include "openbsd-compat/sys-queue.h"
3c0ef626 51
52#include <openssl/evp.h>
53#include <openssl/md5.h>
47686178 54#include "openbsd-compat/openssl-compat.h"
3c0ef626 55
9108f8d9 56#include <errno.h>
57#include <fcntl.h>
58#ifdef HAVE_PATHS_H
59# include <paths.h>
60#endif
61#include <signal.h>
62#include <stdarg.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <time.h>
66#include <string.h>
67#include <unistd.h>
68
69#include "xmalloc.h"
3c0ef626 70#include "ssh.h"
71#include "rsa.h"
72#include "buffer.h"
3c0ef626 73#include "key.h"
74#include "authfd.h"
3c0ef626 75#include "compat.h"
76#include "log.h"
6a9b3198 77#include "misc.h"
3c0ef626 78
79#ifdef SMARTCARD
3c0ef626 80#include "scard.h"
81#endif
82
99be0775 83#if defined(HAVE_SYS_PRCTL_H)
84#include <sys/prctl.h> /* For prctl() and PR_SET_DUMPABLE */
85#endif
86
e9a17296 87typedef enum {
88 AUTH_UNUSED,
89 AUTH_SOCKET,
90 AUTH_CONNECTION
91} sock_type;
92
3c0ef626 93typedef struct {
94 int fd;
e9a17296 95 sock_type type;
3c0ef626 96 Buffer input;
97 Buffer output;
f5799ae1 98 Buffer request;
3c0ef626 99} SocketEntry;
100
101u_int sockets_alloc = 0;
102SocketEntry *sockets = NULL;
103
e9a17296 104typedef struct identity {
105 TAILQ_ENTRY(identity) next;
3c0ef626 106 Key *key;
107 char *comment;
f5799ae1 108 u_int death;
6a9b3198 109 u_int confirm;
3c0ef626 110} Identity;
111
112typedef struct {
113 int nentries;
e9a17296 114 TAILQ_HEAD(idqueue, identity) idlist;
3c0ef626 115} Idtab;
116
117/* private key table, one per protocol version */
118Idtab idtable[3];
119
120int max_fd = 0;
121
122/* pid of shell == parent of agent */
123pid_t parent_pid = -1;
d4487008 124u_int parent_alive_interval = 0;
3c0ef626 125
126/* pathname and directory for AUTH_SOCKET */
9108f8d9 127char socket_name[MAXPATHLEN];
128char socket_dir[MAXPATHLEN];
3c0ef626 129
f5799ae1 130/* locking */
131int locked = 0;
132char *lock_passwd = NULL;
133
3c0ef626 134extern char *__progname;
3c0ef626 135
6a9b3198 136/* Default lifetime (0 == forever) */
137static int lifetime = 0;
138
41b2f314 139static void
140close_socket(SocketEntry *e)
141{
142 close(e->fd);
143 e->fd = -1;
144 e->type = AUTH_UNUSED;
145 buffer_free(&e->input);
146 buffer_free(&e->output);
147 buffer_free(&e->request);
148}
149
3c0ef626 150static void
151idtab_init(void)
152{
153 int i;
680cee3b 154
e9a17296 155 for (i = 0; i <=2; i++) {
156 TAILQ_INIT(&idtable[i].idlist);
3c0ef626 157 idtable[i].nentries = 0;
158 }
159}
160
161/* return private key table for requested protocol version */
162static Idtab *
163idtab_lookup(int version)
164{
165 if (version < 1 || version > 2)
166 fatal("internal error, bad protocol version %d", version);
167 return &idtable[version];
168}
169
f5799ae1 170static void
171free_identity(Identity *id)
172{
173 key_free(id->key);
174 xfree(id->comment);
175 xfree(id);
176}
177
3c0ef626 178/* return matching private key for given public key */
e9a17296 179static Identity *
180lookup_identity(Key *key, int version)
3c0ef626 181{
e9a17296 182 Identity *id;
183
3c0ef626 184 Idtab *tab = idtab_lookup(version);
e9a17296 185 TAILQ_FOREACH(id, &tab->idlist, next) {
186 if (key_equal(key, id->key))
187 return (id);
3c0ef626 188 }
e9a17296 189 return (NULL);
190}
191
6a9b3198 192/* Check confirmation of keysign request */
193static int
194confirm_key(Identity *id)
195{
996d5e62 196 char *p;
6a9b3198 197 int ret = -1;
198
199 p = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX);
996d5e62 200 if (ask_permission("Allow use of key %s?\nKey fingerprint %s.",
201 id->comment, p))
202 ret = 0;
6a9b3198 203 xfree(p);
996d5e62 204
6a9b3198 205 return (ret);
206}
207
3c0ef626 208/* send list of supported public keys to 'client' */
209static void
210process_request_identities(SocketEntry *e, int version)
211{
212 Idtab *tab = idtab_lookup(version);
e9a17296 213 Identity *id;
680cee3b 214 Buffer msg;
3c0ef626 215
216 buffer_init(&msg);
217 buffer_put_char(&msg, (version == 1) ?
218 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
219 buffer_put_int(&msg, tab->nentries);
e9a17296 220 TAILQ_FOREACH(id, &tab->idlist, next) {
3c0ef626 221 if (id->key->type == KEY_RSA1) {
222 buffer_put_int(&msg, BN_num_bits(id->key->rsa->n));
223 buffer_put_bignum(&msg, id->key->rsa->e);
224 buffer_put_bignum(&msg, id->key->rsa->n);
225 } else {
226 u_char *blob;
227 u_int blen;
228 key_to_blob(id->key, &blob, &blen);
229 buffer_put_string(&msg, blob, blen);
230 xfree(blob);
231 }
232 buffer_put_cstring(&msg, id->comment);
233 }
234 buffer_put_int(&e->output, buffer_len(&msg));
235 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
236 buffer_free(&msg);
237}
238
239/* ssh1 only */
240static void
241process_authentication_challenge1(SocketEntry *e)
242{
680cee3b 243 u_char buf[32], mdbuf[16], session_id[16];
244 u_int response_type;
3c0ef626 245 BIGNUM *challenge;
680cee3b 246 Identity *id;
3c0ef626 247 int i, len;
248 Buffer msg;
249 MD5_CTX md;
680cee3b 250 Key *key;
3c0ef626 251
252 buffer_init(&msg);
253 key = key_new(KEY_RSA1);
e9a17296 254 if ((challenge = BN_new()) == NULL)
255 fatal("process_authentication_challenge1: BN_new failed");
3c0ef626 256
680cee3b 257 (void) buffer_get_int(&e->request); /* ignored */
f5799ae1 258 buffer_get_bignum(&e->request, key->rsa->e);
259 buffer_get_bignum(&e->request, key->rsa->n);
260 buffer_get_bignum(&e->request, challenge);
3c0ef626 261
262 /* Only protocol 1.1 is supported */
f5799ae1 263 if (buffer_len(&e->request) == 0)
3c0ef626 264 goto failure;
f5799ae1 265 buffer_get(&e->request, session_id, 16);
266 response_type = buffer_get_int(&e->request);
3c0ef626 267 if (response_type != 1)
268 goto failure;
269
e9a17296 270 id = lookup_identity(key, 1);
6a9b3198 271 if (id != NULL && (!id->confirm || confirm_key(id) == 0)) {
e9a17296 272 Key *private = id->key;
3c0ef626 273 /* Decrypt the challenge using the private key. */
274 if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
275 goto failure;
276
277 /* The response is MD5 of decrypted challenge plus session id. */
278 len = BN_num_bytes(challenge);
279 if (len <= 0 || len > 32) {
0fff78ff 280 logit("process_authentication_challenge: bad challenge length %d", len);
3c0ef626 281 goto failure;
282 }
283 memset(buf, 0, 32);
284 BN_bn2bin(challenge, buf + 32 - len);
285 MD5_Init(&md);
286 MD5_Update(&md, buf, 32);
287 MD5_Update(&md, session_id, 16);
288 MD5_Final(mdbuf, &md);
289
290 /* Send the response. */
291 buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE);
292 for (i = 0; i < 16; i++)
293 buffer_put_char(&msg, mdbuf[i]);
294 goto send;
295 }
296
297failure:
298 /* Unknown identity or protocol error. Send failure. */
299 buffer_put_char(&msg, SSH_AGENT_FAILURE);
300send:
301 buffer_put_int(&e->output, buffer_len(&msg));
302 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
303 key_free(key);
304 BN_clear_free(challenge);
305 buffer_free(&msg);
306}
307
308/* ssh2 only */
309static void
310process_sign_request2(SocketEntry *e)
311{
3c0ef626 312 u_char *blob, *data, *signature = NULL;
313 u_int blen, dlen, slen = 0;
680cee3b 314 extern int datafellows;
315 int ok = -1, flags;
3c0ef626 316 Buffer msg;
680cee3b 317 Key *key;
3c0ef626 318
319 datafellows = 0;
320
f5799ae1 321 blob = buffer_get_string(&e->request, &blen);
322 data = buffer_get_string(&e->request, &dlen);
3c0ef626 323
f5799ae1 324 flags = buffer_get_int(&e->request);
3c0ef626 325 if (flags & SSH_AGENT_OLD_SIGNATURE)
326 datafellows = SSH_BUG_SIGBLOB;
327
328 key = key_from_blob(blob, blen);
329 if (key != NULL) {
e9a17296 330 Identity *id = lookup_identity(key, 2);
6a9b3198 331 if (id != NULL && (!id->confirm || confirm_key(id) == 0))
e9a17296 332 ok = key_sign(id->key, &signature, &slen, data, dlen);
9108f8d9 333 key_free(key);
3c0ef626 334 }
3c0ef626 335 buffer_init(&msg);
336 if (ok == 0) {
337 buffer_put_char(&msg, SSH2_AGENT_SIGN_RESPONSE);
338 buffer_put_string(&msg, signature, slen);
339 } else {
340 buffer_put_char(&msg, SSH_AGENT_FAILURE);
341 }
342 buffer_put_int(&e->output, buffer_len(&msg));
343 buffer_append(&e->output, buffer_ptr(&msg),
344 buffer_len(&msg));
345 buffer_free(&msg);
346 xfree(data);
347 xfree(blob);
348 if (signature != NULL)
349 xfree(signature);
350}
351
352/* shared */
353static void
354process_remove_identity(SocketEntry *e, int version)
355{
680cee3b 356 u_int blen, bits;
357 int success = 0;
e9a17296 358 Key *key = NULL;
3c0ef626 359 u_char *blob;
3c0ef626 360
e9a17296 361 switch (version) {
3c0ef626 362 case 1:
363 key = key_new(KEY_RSA1);
f5799ae1 364 bits = buffer_get_int(&e->request);
365 buffer_get_bignum(&e->request, key->rsa->e);
366 buffer_get_bignum(&e->request, key->rsa->n);
3c0ef626 367
368 if (bits != key_size(key))
0fff78ff 369 logit("Warning: identity keysize mismatch: actual %u, announced %u",
3c0ef626 370 key_size(key), bits);
371 break;
372 case 2:
f5799ae1 373 blob = buffer_get_string(&e->request, &blen);
3c0ef626 374 key = key_from_blob(blob, blen);
375 xfree(blob);
376 break;
377 }
378 if (key != NULL) {
e9a17296 379 Identity *id = lookup_identity(key, version);
380 if (id != NULL) {
3c0ef626 381 /*
382 * We have this key. Free the old key. Since we
2c06c99b 383 * don't want to leave empty slots in the middle of
3c0ef626 384 * the array, we actually free the key there and move
385 * all the entries between the empty slot and the end
386 * of the array.
387 */
388 Idtab *tab = idtab_lookup(version);
3c0ef626 389 if (tab->nentries < 1)
390 fatal("process_remove_identity: "
391 "internal error: tab->nentries %d",
392 tab->nentries);
e9a17296 393 TAILQ_REMOVE(&tab->idlist, id, next);
394 free_identity(id);
3c0ef626 395 tab->nentries--;
396 success = 1;
397 }
398 key_free(key);
399 }
400 buffer_put_int(&e->output, 1);
401 buffer_put_char(&e->output,
402 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
403}
404
405static void
406process_remove_all_identities(SocketEntry *e, int version)
407{
3c0ef626 408 Idtab *tab = idtab_lookup(version);
e9a17296 409 Identity *id;
3c0ef626 410
411 /* Loop over all identities and clear the keys. */
e9a17296 412 for (id = TAILQ_FIRST(&tab->idlist); id;
413 id = TAILQ_FIRST(&tab->idlist)) {
414 TAILQ_REMOVE(&tab->idlist, id, next);
415 free_identity(id);
3c0ef626 416 }
417
418 /* Mark that there are no identities. */
419 tab->nentries = 0;
420
421 /* Send success. */
422 buffer_put_int(&e->output, 1);
423 buffer_put_char(&e->output, SSH_AGENT_SUCCESS);
f5799ae1 424}
425
d4487008 426/* removes expired keys and returns number of seconds until the next expiry */
427static u_int
f5799ae1 428reaper(void)
429{
d4487008 430 u_int deadline = 0, now = time(NULL);
f5799ae1 431 Identity *id, *nxt;
432 int version;
680cee3b 433 Idtab *tab;
f5799ae1 434
435 for (version = 1; version < 3; version++) {
436 tab = idtab_lookup(version);
437 for (id = TAILQ_FIRST(&tab->idlist); id; id = nxt) {
438 nxt = TAILQ_NEXT(id, next);
d4487008 439 if (id->death == 0)
440 continue;
441 if (now >= id->death) {
799ae497 442 debug("expiring key '%s'", id->comment);
f5799ae1 443 TAILQ_REMOVE(&tab->idlist, id, next);
444 free_identity(id);
445 tab->nentries--;
d4487008 446 } else
447 deadline = (deadline == 0) ? id->death :
448 MIN(deadline, id->death);
f5799ae1 449 }
450 }
d4487008 451 if (deadline == 0 || deadline <= now)
452 return 0;
453 else
454 return (deadline - now);
3c0ef626 455}
456
457static void
458process_add_identity(SocketEntry *e, int version)
459{
3c0ef626 460 Idtab *tab = idtab_lookup(version);
47686178 461 Identity *id;
6a9b3198 462 int type, success = 0, death = 0, confirm = 0;
680cee3b 463 char *type_name, *comment;
464 Key *k = NULL;
3c0ef626 465
466 switch (version) {
467 case 1:
468 k = key_new_private(KEY_RSA1);
680cee3b 469 (void) buffer_get_int(&e->request); /* ignored */
f5799ae1 470 buffer_get_bignum(&e->request, k->rsa->n);
471 buffer_get_bignum(&e->request, k->rsa->e);
472 buffer_get_bignum(&e->request, k->rsa->d);
473 buffer_get_bignum(&e->request, k->rsa->iqmp);
3c0ef626 474
475 /* SSH and SSL have p and q swapped */
f5799ae1 476 buffer_get_bignum(&e->request, k->rsa->q); /* p */
477 buffer_get_bignum(&e->request, k->rsa->p); /* q */
3c0ef626 478
479 /* Generate additional parameters */
480 rsa_generate_additional_parameters(k->rsa);
481 break;
482 case 2:
f5799ae1 483 type_name = buffer_get_string(&e->request, NULL);
3c0ef626 484 type = key_type_from_name(type_name);
485 xfree(type_name);
e9a17296 486 switch (type) {
3c0ef626 487 case KEY_DSA:
488 k = key_new_private(type);
f5799ae1 489 buffer_get_bignum2(&e->request, k->dsa->p);
490 buffer_get_bignum2(&e->request, k->dsa->q);
491 buffer_get_bignum2(&e->request, k->dsa->g);
492 buffer_get_bignum2(&e->request, k->dsa->pub_key);
493 buffer_get_bignum2(&e->request, k->dsa->priv_key);
3c0ef626 494 break;
495 case KEY_RSA:
496 k = key_new_private(type);
f5799ae1 497 buffer_get_bignum2(&e->request, k->rsa->n);
498 buffer_get_bignum2(&e->request, k->rsa->e);
499 buffer_get_bignum2(&e->request, k->rsa->d);
500 buffer_get_bignum2(&e->request, k->rsa->iqmp);
501 buffer_get_bignum2(&e->request, k->rsa->p);
502 buffer_get_bignum2(&e->request, k->rsa->q);
3c0ef626 503
504 /* Generate additional parameters */
505 rsa_generate_additional_parameters(k->rsa);
506 break;
507 default:
f5799ae1 508 buffer_clear(&e->request);
3c0ef626 509 goto send;
510 }
511 break;
512 }
6a9b3198 513 /* enable blinding */
514 switch (k->type) {
515 case KEY_RSA:
516 case KEY_RSA1:
517 if (RSA_blinding_on(k->rsa, NULL) != 1) {
518 error("process_add_identity: RSA_blinding_on failed");
519 key_free(k);
520 goto send;
521 }
522 break;
523 }
f5799ae1 524 comment = buffer_get_string(&e->request, NULL);
3c0ef626 525 if (k == NULL) {
526 xfree(comment);
527 goto send;
528 }
529 success = 1;
f5799ae1 530 while (buffer_len(&e->request)) {
531 switch (buffer_get_char(&e->request)) {
532 case SSH_AGENT_CONSTRAIN_LIFETIME:
533 death = time(NULL) + buffer_get_int(&e->request);
534 break;
6a9b3198 535 case SSH_AGENT_CONSTRAIN_CONFIRM:
536 confirm = 1;
537 break;
f5799ae1 538 default:
539 break;
540 }
541 }
6a9b3198 542 if (lifetime && !death)
543 death = time(NULL) + lifetime;
47686178 544 if ((id = lookup_identity(k, version)) == NULL) {
545 id = xmalloc(sizeof(Identity));
e9a17296 546 id->key = k;
e9a17296 547 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
3c0ef626 548 /* Increment the number of identities. */
549 tab->nentries++;
550 } else {
551 key_free(k);
47686178 552 xfree(id->comment);
3c0ef626 553 }
47686178 554 id->comment = comment;
555 id->death = death;
556 id->confirm = confirm;
3c0ef626 557send:
558 buffer_put_int(&e->output, 1);
559 buffer_put_char(&e->output,
560 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
561}
562
f5799ae1 563/* XXX todo: encrypt sensitive data with passphrase */
564static void
565process_lock_agent(SocketEntry *e, int lock)
566{
f5799ae1 567 int success = 0;
680cee3b 568 char *passwd;
f5799ae1 569
570 passwd = buffer_get_string(&e->request, NULL);
571 if (locked && !lock && strcmp(passwd, lock_passwd) == 0) {
572 locked = 0;
573 memset(lock_passwd, 0, strlen(lock_passwd));
574 xfree(lock_passwd);
575 lock_passwd = NULL;
576 success = 1;
577 } else if (!locked && lock) {
578 locked = 1;
579 lock_passwd = xstrdup(passwd);
580 success = 1;
581 }
582 memset(passwd, 0, strlen(passwd));
583 xfree(passwd);
584
585 buffer_put_int(&e->output, 1);
586 buffer_put_char(&e->output,
587 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
588}
589
590static void
591no_identities(SocketEntry *e, u_int type)
592{
593 Buffer msg;
594
595 buffer_init(&msg);
596 buffer_put_char(&msg,
597 (type == SSH_AGENTC_REQUEST_RSA_IDENTITIES) ?
598 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
599 buffer_put_int(&msg, 0);
600 buffer_put_int(&e->output, buffer_len(&msg));
601 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
602 buffer_free(&msg);
603}
3c0ef626 604
605#ifdef SMARTCARD
606static void
607process_add_smartcard_key (SocketEntry *e)
608{
700318f3 609 char *sc_reader_id = NULL, *pin;
0fff78ff 610 int i, version, success = 0, death = 0, confirm = 0;
680cee3b 611 Key **keys, *k;
612 Identity *id;
613 Idtab *tab;
e9a17296 614
f5799ae1 615 sc_reader_id = buffer_get_string(&e->request, NULL);
616 pin = buffer_get_string(&e->request, NULL);
0fff78ff 617
618 while (buffer_len(&e->request)) {
619 switch (buffer_get_char(&e->request)) {
620 case SSH_AGENT_CONSTRAIN_LIFETIME:
621 death = time(NULL) + buffer_get_int(&e->request);
622 break;
623 case SSH_AGENT_CONSTRAIN_CONFIRM:
624 confirm = 1;
625 break;
626 default:
627 break;
628 }
629 }
630 if (lifetime && !death)
631 death = time(NULL) + lifetime;
632
700318f3 633 keys = sc_get_keys(sc_reader_id, pin);
3c0ef626 634 xfree(sc_reader_id);
700318f3 635 xfree(pin);
3c0ef626 636
700318f3 637 if (keys == NULL || keys[0] == NULL) {
638 error("sc_get_keys failed");
3c0ef626 639 goto send;
640 }
700318f3 641 for (i = 0; keys[i] != NULL; i++) {
642 k = keys[i];
643 version = k->type == KEY_RSA1 ? 1 : 2;
644 tab = idtab_lookup(version);
645 if (lookup_identity(k, version) == NULL) {
646 id = xmalloc(sizeof(Identity));
647 id->key = k;
0fff78ff 648 id->comment = sc_get_key_label(k);
649 id->death = death;
650 id->confirm = confirm;
700318f3 651 TAILQ_INSERT_TAIL(&tab->idlist, id, next);
652 tab->nentries++;
653 success = 1;
654 } else {
655 key_free(k);
656 }
657 keys[i] = NULL;
3c0ef626 658 }
700318f3 659 xfree(keys);
3c0ef626 660send:
661 buffer_put_int(&e->output, 1);
662 buffer_put_char(&e->output,
663 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
664}
665
666static void
667process_remove_smartcard_key(SocketEntry *e)
668{
700318f3 669 char *sc_reader_id = NULL, *pin;
670 int i, version, success = 0;
680cee3b 671 Key **keys, *k = NULL;
672 Identity *id;
673 Idtab *tab;
3c0ef626 674
f5799ae1 675 sc_reader_id = buffer_get_string(&e->request, NULL);
676 pin = buffer_get_string(&e->request, NULL);
700318f3 677 keys = sc_get_keys(sc_reader_id, pin);
3c0ef626 678 xfree(sc_reader_id);
700318f3 679 xfree(pin);
3c0ef626 680
700318f3 681 if (keys == NULL || keys[0] == NULL) {
682 error("sc_get_keys failed");
683 goto send;
684 }
685 for (i = 0; keys[i] != NULL; i++) {
686 k = keys[i];
687 version = k->type == KEY_RSA1 ? 1 : 2;
688 if ((id = lookup_identity(k, version)) != NULL) {
689 tab = idtab_lookup(version);
f5799ae1 690 TAILQ_REMOVE(&tab->idlist, id, next);
3c0ef626 691 tab->nentries--;
e9a17296 692 free_identity(id);
3c0ef626 693 success = 1;
694 }
695 key_free(k);
700318f3 696 keys[i] = NULL;
3c0ef626 697 }
700318f3 698 xfree(keys);
699send:
3c0ef626 700 buffer_put_int(&e->output, 1);
701 buffer_put_char(&e->output,
702 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
703}
704#endif /* SMARTCARD */
705
706/* dispatch incoming messages */
707
708static void
709process_message(SocketEntry *e)
710{
680cee3b 711 u_int msg_len, type;
3c0ef626 712 u_char *cp;
f5799ae1 713
3c0ef626 714 if (buffer_len(&e->input) < 5)
715 return; /* Incomplete message. */
e9a17296 716 cp = buffer_ptr(&e->input);
9108f8d9 717 msg_len = get_u32(cp);
3c0ef626 718 if (msg_len > 256 * 1024) {
41b2f314 719 close_socket(e);
3c0ef626 720 return;
721 }
722 if (buffer_len(&e->input) < msg_len + 4)
723 return;
f5799ae1 724
725 /* move the current input to e->request */
3c0ef626 726 buffer_consume(&e->input, 4);
f5799ae1 727 buffer_clear(&e->request);
728 buffer_append(&e->request, buffer_ptr(&e->input), msg_len);
729 buffer_consume(&e->input, msg_len);
730 type = buffer_get_char(&e->request);
731
732 /* check wheter agent is locked */
733 if (locked && type != SSH_AGENTC_UNLOCK) {
734 buffer_clear(&e->request);
735 switch (type) {
736 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
737 case SSH2_AGENTC_REQUEST_IDENTITIES:
738 /* send empty lists */
739 no_identities(e, type);
740 break;
741 default:
742 /* send a fail message for all other request types */
743 buffer_put_int(&e->output, 1);
744 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
745 }
746 return;
747 }
3c0ef626 748
749 debug("type %d", type);
750 switch (type) {
f5799ae1 751 case SSH_AGENTC_LOCK:
752 case SSH_AGENTC_UNLOCK:
753 process_lock_agent(e, type == SSH_AGENTC_LOCK);
754 break;
3c0ef626 755 /* ssh1 */
756 case SSH_AGENTC_RSA_CHALLENGE:
757 process_authentication_challenge1(e);
758 break;
759 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
760 process_request_identities(e, 1);
761 break;
762 case SSH_AGENTC_ADD_RSA_IDENTITY:
f5799ae1 763 case SSH_AGENTC_ADD_RSA_ID_CONSTRAINED:
3c0ef626 764 process_add_identity(e, 1);
765 break;
766 case SSH_AGENTC_REMOVE_RSA_IDENTITY:
767 process_remove_identity(e, 1);
768 break;
769 case SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES:
770 process_remove_all_identities(e, 1);
771 break;
772 /* ssh2 */
773 case SSH2_AGENTC_SIGN_REQUEST:
774 process_sign_request2(e);
775 break;
776 case SSH2_AGENTC_REQUEST_IDENTITIES:
777 process_request_identities(e, 2);
778 break;
779 case SSH2_AGENTC_ADD_IDENTITY:
f5799ae1 780 case SSH2_AGENTC_ADD_ID_CONSTRAINED:
3c0ef626 781 process_add_identity(e, 2);
782 break;
783 case SSH2_AGENTC_REMOVE_IDENTITY:
784 process_remove_identity(e, 2);
785 break;
786 case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
787 process_remove_all_identities(e, 2);
788 break;
789#ifdef SMARTCARD
790 case SSH_AGENTC_ADD_SMARTCARD_KEY:
0fff78ff 791 case SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED:
3c0ef626 792 process_add_smartcard_key(e);
e9a17296 793 break;
3c0ef626 794 case SSH_AGENTC_REMOVE_SMARTCARD_KEY:
795 process_remove_smartcard_key(e);
e9a17296 796 break;
3c0ef626 797#endif /* SMARTCARD */
798 default:
799 /* Unknown message. Respond with failure. */
800 error("Unknown message %d", type);
f5799ae1 801 buffer_clear(&e->request);
3c0ef626 802 buffer_put_int(&e->output, 1);
803 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
804 break;
805 }
806}
807
808static void
e9a17296 809new_socket(sock_type type, int fd)
3c0ef626 810{
acc3d05e 811 u_int i, old_alloc, new_alloc;
680cee3b 812
c9f39d2c 813 set_nonblock(fd);
3c0ef626 814
815 if (fd > max_fd)
816 max_fd = fd;
817
818 for (i = 0; i < sockets_alloc; i++)
819 if (sockets[i].type == AUTH_UNUSED) {
820 sockets[i].fd = fd;
3c0ef626 821 buffer_init(&sockets[i].input);
822 buffer_init(&sockets[i].output);
f5799ae1 823 buffer_init(&sockets[i].request);
acc3d05e 824 sockets[i].type = type;
3c0ef626 825 return;
826 }
827 old_alloc = sockets_alloc;
acc3d05e 828 new_alloc = sockets_alloc + 10;
9108f8d9 829 sockets = xrealloc(sockets, new_alloc, sizeof(sockets[0]));
acc3d05e 830 for (i = old_alloc; i < new_alloc; i++)
3c0ef626 831 sockets[i].type = AUTH_UNUSED;
acc3d05e 832 sockets_alloc = new_alloc;
3c0ef626 833 sockets[old_alloc].fd = fd;
834 buffer_init(&sockets[old_alloc].input);
835 buffer_init(&sockets[old_alloc].output);
f5799ae1 836 buffer_init(&sockets[old_alloc].request);
acc3d05e 837 sockets[old_alloc].type = type;
3c0ef626 838}
839
840static int
d4487008 841prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, u_int *nallocp,
842 struct timeval **tvpp)
3c0ef626 843{
d4487008 844 u_int i, sz, deadline;
3c0ef626 845 int n = 0;
d4487008 846 static struct timeval tv;
3c0ef626 847
848 for (i = 0; i < sockets_alloc; i++) {
849 switch (sockets[i].type) {
850 case AUTH_SOCKET:
851 case AUTH_CONNECTION:
852 n = MAX(n, sockets[i].fd);
853 break;
854 case AUTH_UNUSED:
855 break;
856 default:
857 fatal("Unknown socket type %d", sockets[i].type);
858 break;
859 }
860 }
861
862 sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
863 if (*fdrp == NULL || sz > *nallocp) {
864 if (*fdrp)
865 xfree(*fdrp);
866 if (*fdwp)
867 xfree(*fdwp);
868 *fdrp = xmalloc(sz);
869 *fdwp = xmalloc(sz);
870 *nallocp = sz;
871 }
872 if (n < *fdl)
873 debug("XXX shrink: %d < %d", n, *fdl);
874 *fdl = n;
875 memset(*fdrp, 0, sz);
876 memset(*fdwp, 0, sz);
877
878 for (i = 0; i < sockets_alloc; i++) {
879 switch (sockets[i].type) {
880 case AUTH_SOCKET:
881 case AUTH_CONNECTION:
882 FD_SET(sockets[i].fd, *fdrp);
883 if (buffer_len(&sockets[i].output) > 0)
884 FD_SET(sockets[i].fd, *fdwp);
885 break;
886 default:
887 break;
888 }
889 }
d4487008 890 deadline = reaper();
891 if (parent_alive_interval != 0)
892 deadline = (deadline == 0) ? parent_alive_interval :
893 MIN(deadline, parent_alive_interval);
894 if (deadline == 0) {
895 *tvpp = NULL;
896 } else {
897 tv.tv_sec = deadline;
898 tv.tv_usec = 0;
899 *tvpp = &tv;
900 }
3c0ef626 901 return (1);
902}
903
904static void
905after_select(fd_set *readset, fd_set *writeset)
906{
680cee3b 907 struct sockaddr_un sunaddr;
3c0ef626 908 socklen_t slen;
909 char buf[1024];
680cee3b 910 int len, sock;
911 u_int i;
41b2f314 912 uid_t euid;
913 gid_t egid;
3c0ef626 914
915 for (i = 0; i < sockets_alloc; i++)
916 switch (sockets[i].type) {
917 case AUTH_UNUSED:
918 break;
919 case AUTH_SOCKET:
920 if (FD_ISSET(sockets[i].fd, readset)) {
921 slen = sizeof(sunaddr);
922 sock = accept(sockets[i].fd,
9108f8d9 923 (struct sockaddr *)&sunaddr, &slen);
3c0ef626 924 if (sock < 0) {
e9a17296 925 error("accept from AUTH_SOCKET: %s",
926 strerror(errno));
3c0ef626 927 break;
928 }
41b2f314 929 if (getpeereid(sock, &euid, &egid) < 0) {
930 error("getpeereid %d failed: %s",
931 sock, strerror(errno));
932 close(sock);
933 break;
934 }
935 if ((euid != 0) && (getuid() != euid)) {
936 error("uid mismatch: "
937 "peer euid %u != uid %u",
938 (u_int) euid, (u_int) getuid());
939 close(sock);
940 break;
941 }
3c0ef626 942 new_socket(AUTH_CONNECTION, sock);
943 }
944 break;
945 case AUTH_CONNECTION:
946 if (buffer_len(&sockets[i].output) > 0 &&
947 FD_ISSET(sockets[i].fd, writeset)) {
948 do {
949 len = write(sockets[i].fd,
950 buffer_ptr(&sockets[i].output),
951 buffer_len(&sockets[i].output));
952 if (len == -1 && (errno == EAGAIN ||
953 errno == EINTR))
954 continue;
955 break;
956 } while (1);
957 if (len <= 0) {
41b2f314 958 close_socket(&sockets[i]);
3c0ef626 959 break;
960 }
961 buffer_consume(&sockets[i].output, len);
962 }
963 if (FD_ISSET(sockets[i].fd, readset)) {
964 do {
965 len = read(sockets[i].fd, buf, sizeof(buf));
966 if (len == -1 && (errno == EAGAIN ||
967 errno == EINTR))
968 continue;
969 break;
970 } while (1);
971 if (len <= 0) {
41b2f314 972 close_socket(&sockets[i]);
3c0ef626 973 break;
974 }
975 buffer_append(&sockets[i].input, buf, len);
976 process_message(&sockets[i]);
977 }
978 break;
979 default:
980 fatal("Unknown type %d", sockets[i].type);
981 }
982}
983
984static void
cdd66111 985cleanup_socket(void)
3c0ef626 986{
987 if (socket_name[0])
988 unlink(socket_name);
989 if (socket_dir[0])
990 rmdir(socket_dir);
991}
992
cdd66111 993void
3c0ef626 994cleanup_exit(int i)
995{
cdd66111 996 cleanup_socket();
997 _exit(i);
3c0ef626 998}
999
9108f8d9 1000/*ARGSUSED*/
3c0ef626 1001static void
1002cleanup_handler(int sig)
1003{
cdd66111 1004 cleanup_socket();
3c0ef626 1005 _exit(2);
1006}
1007
1008static void
d4487008 1009check_parent_exists(void)
3c0ef626 1010{
3c0ef626 1011 if (parent_pid != -1 && kill(parent_pid, 0) < 0) {
1012 /* printf("Parent has died - Authentication agent exiting.\n"); */
d4487008 1013 cleanup_socket();
1014 _exit(2);
3c0ef626 1015 }
3c0ef626 1016}
1017
1018static void
1019usage(void)
1020{
47686178 1021 fprintf(stderr, "usage: %s [options] [command [arg ...]]\n",
3c0ef626 1022 __progname);
1023 fprintf(stderr, "Options:\n");
1024 fprintf(stderr, " -c Generate C-shell commands on stdout.\n");
1025 fprintf(stderr, " -s Generate Bourne shell commands on stdout.\n");
1026 fprintf(stderr, " -k Kill the current agent.\n");
1027 fprintf(stderr, " -d Debug mode.\n");
f5799ae1 1028 fprintf(stderr, " -a socket Bind agent socket to given name.\n");
6a9b3198 1029 fprintf(stderr, " -t life Default identity lifetime (seconds).\n");
3c0ef626 1030 exit(1);
1031}
1032
1033int
1034main(int ac, char **av)
1035{
6a9b3198 1036 int c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0;
799ae497 1037 int sock, fd, ch, result, saved_errno;
c9f39d2c 1038 u_int nalloc;
680cee3b 1039 char *shell, *format, *pidstr, *agentsocket = NULL;
1040 fd_set *readsetp = NULL, *writesetp = NULL;
3c0ef626 1041 struct sockaddr_un sunaddr;
1042#ifdef HAVE_SETRLIMIT
1043 struct rlimit rlim;
1044#endif
3c0ef626 1045 int prev_mask;
3c0ef626 1046 extern int optind;
680cee3b 1047 extern char *optarg;
1048 pid_t pid;
1049 char pidstrbuf[1 + 3 * sizeof pid];
d4487008 1050 struct timeval *tvp = NULL;
3c0ef626 1051
2c06c99b 1052 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
1053 sanitise_stdfd();
1054
41b2f314 1055 /* drop */
1056 setegid(getgid());
1057 setgid(getgid());
1058
99be0775 1059#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
1060 /* Disable ptrace on Linux without sgid bit */
1061 prctl(PR_SET_DUMPABLE, 0);
1062#endif
1063
3c0ef626 1064 SSLeay_add_all_algorithms();
1065
0fff78ff 1066 __progname = ssh_get_progname(av[0]);
3c0ef626 1067 init_rng();
1068 seed_rng();
1069
6a9b3198 1070 while ((ch = getopt(ac, av, "cdksa:t:")) != -1) {
3c0ef626 1071 switch (ch) {
1072 case 'c':
1073 if (s_flag)
1074 usage();
1075 c_flag++;
1076 break;
1077 case 'k':
1078 k_flag++;
1079 break;
1080 case 's':
1081 if (c_flag)
1082 usage();
1083 s_flag++;
1084 break;
1085 case 'd':
1086 if (d_flag)
1087 usage();
1088 d_flag++;
1089 break;
f5799ae1 1090 case 'a':
1091 agentsocket = optarg;
1092 break;
6a9b3198 1093 case 't':
1094 if ((lifetime = convtime(optarg)) == -1) {
1095 fprintf(stderr, "Invalid lifetime\n");
1096 usage();
1097 }
1098 break;
3c0ef626 1099 default:
1100 usage();
1101 }
1102 }
1103 ac -= optind;
1104 av += optind;
1105
1106 if (ac > 0 && (c_flag || k_flag || s_flag || d_flag))
1107 usage();
1108
700318f3 1109 if (ac == 0 && !c_flag && !s_flag) {
3c0ef626 1110 shell = getenv("SHELL");
9108f8d9 1111 if (shell != NULL &&
1112 strncmp(shell + strlen(shell) - 3, "csh", 3) == 0)
3c0ef626 1113 c_flag = 1;
1114 }
1115 if (k_flag) {
9108f8d9 1116 const char *errstr = NULL;
1117
3c0ef626 1118 pidstr = getenv(SSH_AGENTPID_ENV_NAME);
1119 if (pidstr == NULL) {
1120 fprintf(stderr, "%s not set, cannot kill agent\n",
1121 SSH_AGENTPID_ENV_NAME);
1122 exit(1);
1123 }
9108f8d9 1124 pid = (int)strtonum(pidstr, 2, INT_MAX, &errstr);
1125 if (errstr) {
1126 fprintf(stderr,
1127 "%s=\"%s\", which is not a good PID: %s\n",
1128 SSH_AGENTPID_ENV_NAME, pidstr, errstr);
3c0ef626 1129 exit(1);
1130 }
1131 if (kill(pid, SIGTERM) == -1) {
1132 perror("kill");
1133 exit(1);
1134 }
1135 format = c_flag ? "unsetenv %s;\n" : "unset %s;\n";
1136 printf(format, SSH_AUTHSOCKET_ENV_NAME);
1137 printf(format, SSH_AGENTPID_ENV_NAME);
f5799ae1 1138 printf("echo Agent pid %ld killed;\n", (long)pid);
3c0ef626 1139 exit(0);
1140 }
1141 parent_pid = getpid();
1142
f5799ae1 1143 if (agentsocket == NULL) {
1144 /* Create private directory for agent socket */
cdd66111 1145 strlcpy(socket_dir, "/tmp/ssh-XXXXXXXXXX", sizeof socket_dir);
f5799ae1 1146 if (mkdtemp(socket_dir) == NULL) {
1147 perror("mkdtemp: private socket dir");
1148 exit(1);
1149 }
1150 snprintf(socket_name, sizeof socket_name, "%s/agent.%ld", socket_dir,
1151 (long)parent_pid);
1152 } else {
1153 /* Try to use specified agent socket */
1154 socket_dir[0] = '\0';
1155 strlcpy(socket_name, agentsocket, sizeof socket_name);
3c0ef626 1156 }
3c0ef626 1157
1158 /*
1159 * Create socket early so it will exist before command gets run from
1160 * the parent.
1161 */
1162 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1163 if (sock < 0) {
1164 perror("socket");
996d5e62 1165 *socket_name = '\0'; /* Don't unlink any existing file */
3c0ef626 1166 cleanup_exit(1);
1167 }
1168 memset(&sunaddr, 0, sizeof(sunaddr));
1169 sunaddr.sun_family = AF_UNIX;
1170 strlcpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
3c0ef626 1171 prev_mask = umask(0177);
9108f8d9 1172 if (bind(sock, (struct sockaddr *) &sunaddr, sizeof(sunaddr)) < 0) {
3c0ef626 1173 perror("bind");
996d5e62 1174 *socket_name = '\0'; /* Don't unlink any existing file */
3c0ef626 1175 umask(prev_mask);
3c0ef626 1176 cleanup_exit(1);
1177 }
3c0ef626 1178 umask(prev_mask);
cdd66111 1179 if (listen(sock, SSH_LISTEN_BACKLOG) < 0) {
3c0ef626 1180 perror("listen");
1181 cleanup_exit(1);
1182 }
1183
1184 /*
1185 * Fork, and have the parent execute the command, if any, or present
1186 * the socket data. The child continues as the authentication agent.
1187 */
1188 if (d_flag) {
1189 log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
1190 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
1191 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
1192 SSH_AUTHSOCKET_ENV_NAME);
f5799ae1 1193 printf("echo Agent pid %ld;\n", (long)parent_pid);
3c0ef626 1194 goto skip;
1195 }
1196 pid = fork();
1197 if (pid == -1) {
1198 perror("fork");
e9a17296 1199 cleanup_exit(1);
3c0ef626 1200 }
1201 if (pid != 0) { /* Parent - execute the given command. */
1202 close(sock);
f5799ae1 1203 snprintf(pidstrbuf, sizeof pidstrbuf, "%ld", (long)pid);
3c0ef626 1204 if (ac == 0) {
1205 format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
1206 printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
1207 SSH_AUTHSOCKET_ENV_NAME);
1208 printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
1209 SSH_AGENTPID_ENV_NAME);
f5799ae1 1210 printf("echo Agent pid %ld;\n", (long)pid);
3c0ef626 1211 exit(0);
1212 }
1213 if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||
1214 setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) {
1215 perror("setenv");
1216 exit(1);
1217 }
1218 execvp(av[0], av);
1219 perror(av[0]);
1220 exit(1);
1221 }
e9a17296 1222 /* child */
1223 log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
3c0ef626 1224
1225 if (setsid() == -1) {
e9a17296 1226 error("setsid: %s", strerror(errno));
3c0ef626 1227 cleanup_exit(1);
1228 }
1229
1230 (void)chdir("/");
6a9b3198 1231 if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
1232 /* XXX might close listen socket */
1233 (void)dup2(fd, STDIN_FILENO);
1234 (void)dup2(fd, STDOUT_FILENO);
1235 (void)dup2(fd, STDERR_FILENO);
1236 if (fd > 2)
1237 close(fd);
1238 }
3c0ef626 1239
1240#ifdef HAVE_SETRLIMIT
1241 /* deny core dumps, since memory contains unencrypted private keys */
1242 rlim.rlim_cur = rlim.rlim_max = 0;
1243 if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
e9a17296 1244 error("setrlimit RLIMIT_CORE: %s", strerror(errno));
3c0ef626 1245 cleanup_exit(1);
1246 }
1247#endif
1248
1249skip:
3c0ef626 1250 new_socket(AUTH_SOCKET, sock);
d4487008 1251 if (ac > 0)
1252 parent_alive_interval = 10;
3c0ef626 1253 idtab_init();
1254 if (!d_flag)
1255 signal(SIGINT, SIG_IGN);
1256 signal(SIGPIPE, SIG_IGN);
1257 signal(SIGHUP, cleanup_handler);
1258 signal(SIGTERM, cleanup_handler);
1259 nalloc = 0;
1260
1261 while (1) {
d4487008 1262 prepare_select(&readsetp, &writesetp, &max_fd, &nalloc, &tvp);
1263 result = select(max_fd + 1, readsetp, writesetp, NULL, tvp);
799ae497 1264 saved_errno = errno;
d4487008 1265 if (parent_alive_interval != 0)
1266 check_parent_exists();
1267 (void) reaper(); /* remove expired keys */
799ae497 1268 if (result < 0) {
1269 if (saved_errno == EINTR)
3c0ef626 1270 continue;
799ae497 1271 fatal("select: %s", strerror(saved_errno));
1272 } else if (result > 0)
1273 after_select(readsetp, writesetp);
3c0ef626 1274 }
1275 /* NOTREACHED */
1276}
This page took 0.295035 seconds and 5 git commands to generate.