]> andersk Git - openssh.git/blobdiff - ssh-agent.c
- markus@cvs.openbsd.org 2001/04/11 10:59:01
[openssh.git] / ssh-agent.c
index d3713be9ba3d252ed95b011715fb673cbac32c7e..e8362ded0ed0c364637bb004e826cfc8b474231b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ssh-agent.c,v 1.47 2001/01/21 19:05:56 markus Exp $   */
+/*     $OpenBSD: ssh-agent.c,v 1.54 2001/04/03 13:56:11 stevesk Exp $  */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -13,7 +13,7 @@
  * called by a name other than "ssh" or "Secure Shell".
  *
  * SSH2 implementation,
- * Copyright (c) 2000 Markus Friedl. All rights reserved.
+ * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,7 +37,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-agent.c,v 1.47 2001/01/21 19:05:56 markus Exp $");
+RCSID("$OpenBSD: ssh-agent.c,v 1.54 2001/04/03 13:56:11 stevesk Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/md5.h>
@@ -198,7 +198,8 @@ process_authentication_challenge1(SocketEntry *e)
        private = lookup_private_key(key, NULL, 1);
        if (private != NULL) {
                /* Decrypt the challenge using the private key. */
-               rsa_private_decrypt(challenge, challenge, private->rsa);
+               if (rsa_private_decrypt(challenge, challenge, private->rsa) <= 0)
+                       goto failure;
 
                /* The response is MD5 of decrypted challenge plus session id. */
                len = BN_num_bytes(challenge);
@@ -359,25 +360,6 @@ process_remove_all_identities(SocketEntry *e, int version)
        return;
 }
 
-void
-generate_additional_parameters(RSA *rsa)
-{
-       BIGNUM *aux;
-       BN_CTX *ctx;
-       /* Generate additional parameters */
-       aux = BN_new();
-       ctx = BN_CTX_new();
-
-       BN_sub(aux, rsa->q, BN_value_one());
-       BN_mod(rsa->dmq1, rsa->d, aux, ctx);
-
-       BN_sub(aux, rsa->p, BN_value_one());
-       BN_mod(rsa->dmp1, rsa->d, aux, ctx);
-
-       BN_clear_free(aux);
-       BN_CTX_free(ctx);
-}
-
 void
 process_add_identity(SocketEntry *e, int version)
 {
@@ -581,9 +563,9 @@ prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl)
        sz = howmany(n+1, NFDBITS) * sizeof(fd_mask);
        if (*fdrp == NULL || n > *fdl) {
                if (*fdrp)
-                       free(*fdrp);
+                       xfree(*fdrp);
                if (*fdwp)
-                       free(*fdwp);
+                       xfree(*fdwp);
                *fdrp = xmalloc(sz);
                *fdwp = xmalloc(sz);
                *fdl = n;
@@ -634,9 +616,15 @@ after_select(fd_set *readset, fd_set *writeset)
                case AUTH_CONNECTION:
                        if (buffer_len(&sockets[i].output) > 0 &&
                            FD_ISSET(sockets[i].fd, writeset)) {
-                               len = write(sockets[i].fd,
-                                   buffer_ptr(&sockets[i].output),
-                                   buffer_len(&sockets[i].output));
+                               do {
+                                       len = write(sockets[i].fd,
+                                           buffer_ptr(&sockets[i].output),
+                                           buffer_len(&sockets[i].output));
+                                       if (len == -1 && (errno == EAGAIN ||
+                                           errno == EINTR))
+                                               continue;
+                                       break;
+                               } while (1);
                                if (len <= 0) {
                                        shutdown(sockets[i].fd, SHUT_RDWR);
                                        close(sockets[i].fd);
@@ -648,7 +636,13 @@ after_select(fd_set *readset, fd_set *writeset)
                                buffer_consume(&sockets[i].output, len);
                        }
                        if (FD_ISSET(sockets[i].fd, readset)) {
-                               len = read(sockets[i].fd, buf, sizeof(buf));
+                               do {
+                                       len = read(sockets[i].fd, buf, sizeof(buf));
+                                       if (len == -1 && (errno == EAGAIN ||
+                                           errno == EINTR))
+                                               continue;
+                                       break;
+                               } while (1);
                                if (len <= 0) {
                                        shutdown(sockets[i].fd, SHUT_RDWR);
                                        close(sockets[i].fd);
@@ -683,8 +677,10 @@ check_parent_exists(int sig)
 void
 cleanup_socket(void)
 {
-       unlink(socket_name);
-       rmdir(socket_dir);
+       if (socket_name[0])
+               unlink(socket_name);
+       if (socket_dir[0])
+               rmdir(socket_dir);
 }
 
 void
@@ -695,7 +691,14 @@ cleanup_exit(int i)
 }
 
 void
-usage()
+cleanup_handler(int sig)
+{
+       cleanup_socket();
+       _exit(2);
+}
+
+void
+usage(void)
 {
        fprintf(stderr, "ssh-agent version %s\n", SSH_VERSION);
        fprintf(stderr, "Usage: %s [-c | -s] [-k] [command {args...]]\n",
@@ -716,9 +719,12 @@ main(int ac, char **av)
        extern int optind;
        fd_set *readsetp = NULL, *writesetp = NULL;
 
+       SSLeay_add_all_algorithms();
+
        __progname = get_progname(av[0]);
        init_rng();
-       
+       seed_rng();
+
 #ifdef __GNU_LIBRARY__
        while ((ch = getopt(ac, av, "+cks")) != -1) {
 #else /* __GNU_LIBRARY__ */
@@ -866,8 +872,8 @@ main(int ac, char **av)
        idtab_init();
        signal(SIGINT, SIG_IGN);
        signal(SIGPIPE, SIG_IGN);
-       signal(SIGHUP, cleanup_exit);
-       signal(SIGTERM, cleanup_exit);
+       signal(SIGHUP, cleanup_handler);
+       signal(SIGTERM, cleanup_handler);
        while (1) {
                prepare_select(&readsetp, &writesetp, &max_fd);
                if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
This page took 0.062895 seconds and 4 git commands to generate.