]> andersk Git - openssh.git/blobdiff - ssh-agent.c
- (stevesk) [auth1.c] fix password auth for protocol 1 when
[openssh.git] / ssh-agent.c
index ce283c8ccdb69cca3e5e529c082f0ffd97a6d082..f8183b40032eb73f41c0f03115f4f7ca4dd142e3 100644 (file)
@@ -1,5 +1,3 @@
-/*     $OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $  */
-
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -36,7 +34,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $");
+RCSID("$OpenBSD: ssh-agent.c,v 1.84 2002/03/25 17:34:27 markus Exp $");
 
 #if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
 #include <sys/queue.h>
@@ -44,7 +42,6 @@ RCSID("$OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $");
 #include "openbsd-compat/fake-queue.h"
 #endif
 
-
 #include <openssl/evp.h>
 #include <openssl/md5.h>
 
@@ -53,18 +50,13 @@ RCSID("$OpenBSD: ssh-agent.c,v 1.79 2002/01/18 18:14:17 stevesk Exp $");
 #include "buffer.h"
 #include "bufaux.h"
 #include "xmalloc.h"
-#include "packet.h"
 #include "getput.h"
-#include "mpaux.h"
 #include "key.h"
 #include "authfd.h"
-#include "cipher.h"
-#include "kex.h"
 #include "compat.h"
 #include "log.h"
 
 #ifdef SMARTCARD
-#include <openssl/engine.h>
 #include "scard.h"
 #endif
 
@@ -459,48 +451,39 @@ send:
 static void
 process_add_smartcard_key (SocketEntry *e)
 {
+       Identity *id;
        Idtab *tab;
-       Key *n = NULL, *k = NULL;
-       char *sc_reader_id = NULL;
-       int success = 0;
+       Key **keys, *k;
+       char *sc_reader_id = NULL, *pin;
+       int i, version, success = 0;
 
        sc_reader_id = buffer_get_string(&e->input, NULL);
-       k = sc_get_key(sc_reader_id);
+       pin = buffer_get_string(&e->input, NULL);
+       keys = sc_get_keys(sc_reader_id, pin);
        xfree(sc_reader_id);
+       xfree(pin);
 
-       if (k == NULL) {
-               error("sc_get_pubkey failed");
+       if (keys == NULL || keys[0] == NULL) {
+               error("sc_get_keys failed");
                goto send;
        }
-       success = 1;
-
-       tab = idtab_lookup(1);
-       k->type = KEY_RSA1;
-       if (lookup_identity(k, 1) == NULL) {
-               Identity *id = xmalloc(sizeof(Identity));
-               n = key_new(KEY_RSA1);
-               BN_copy(n->rsa->n, k->rsa->n);
-               BN_copy(n->rsa->e, k->rsa->e);
-               RSA_set_method(n->rsa, sc_get_engine());
-               id->key = n;
-               id->comment = xstrdup("rsa1 smartcard");
-               TAILQ_INSERT_TAIL(&tab->idlist, id, next);
-               tab->nentries++;
-       }
-       k->type = KEY_RSA;
-       tab = idtab_lookup(2);
-       if (lookup_identity(k, 2) == NULL) {
-               Identity *id = xmalloc(sizeof(Identity));
-               n = key_new(KEY_RSA);
-               BN_copy(n->rsa->n, k->rsa->n);
-               BN_copy(n->rsa->e, k->rsa->e);
-               RSA_set_method(n->rsa, sc_get_engine());
-               id->key = n;
-               id->comment = xstrdup("rsa smartcard");
-               TAILQ_INSERT_TAIL(&tab->idlist, id, next);
-               tab->nentries++;
+       for (i = 0; keys[i] != NULL; i++) {
+               k = keys[i];
+               version = k->type == KEY_RSA1 ? 1 : 2;
+               tab = idtab_lookup(version);
+               if (lookup_identity(k, version) == NULL) {
+                       id = xmalloc(sizeof(Identity));
+                       id->key = k;
+                       id->comment = xstrdup("smartcard key");
+                       TAILQ_INSERT_TAIL(&tab->idlist, id, next);
+                       tab->nentries++;
+                       success = 1;
+               } else {
+                       key_free(k);
+               }
+               keys[i] = NULL;
        }
-       key_free(k);
+       xfree(keys);
 send:
        buffer_put_int(&e->output, 1);
        buffer_put_char(&e->output,
@@ -510,39 +493,37 @@ send:
 static void
 process_remove_smartcard_key(SocketEntry *e)
 {
-       Key *k = NULL;
-       int success = 0;
-       char *sc_reader_id = NULL;
+       Identity *id;
+       Idtab *tab;
+       Key **keys, *k = NULL;
+       char *sc_reader_id = NULL, *pin;
+       int i, version, success = 0;
 
        sc_reader_id = buffer_get_string(&e->input, NULL);
-       k = sc_get_key(sc_reader_id);
+       pin = buffer_get_string(&e->input, NULL);
+       keys = sc_get_keys(sc_reader_id, pin);
        xfree(sc_reader_id);
+       xfree(pin);
 
-       if (k == NULL) {
-               error("sc_get_pubkey failed");
-       } else {
-               Identity *id;
-               k->type = KEY_RSA1;
-               id = lookup_identity(k, 1);
-               if (id != NULL) {
-                       Idtab *tab = idtab_lookup(1);
-                       TAILQ_REMOVE(&tab->idlist, id, next);
-                       free_identity(id);
+       if (keys == NULL || keys[0] == NULL) {
+               error("sc_get_keys failed");
+               goto send;
+       }
+       for (i = 0; keys[i] != NULL; i++) {
+               k = keys[i];
+               version = k->type == KEY_RSA1 ? 1 : 2;
+               if ((id = lookup_identity(k, version)) != NULL) {
+                       tab = idtab_lookup(version);
+                        TAILQ_REMOVE(&tab->idlist, id, next);
                        tab->nentries--;
-                       success = 1;
-               }
-               k->type = KEY_RSA;
-               id = lookup_identity(k, 2);
-               if (id != NULL) {
-                       Idtab *tab = idtab_lookup(2);
-                       TAILQ_REMOVE(&tab->idlist, id, next);
                        free_identity(id);
-                       tab->nentries--;
                        success = 1;
                }
                key_free(k);
+               keys[i] = NULL;
        }
-
+       xfree(keys);
+send:
        buffer_put_int(&e->output, 1);
        buffer_put_char(&e->output,
            success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
@@ -726,7 +707,8 @@ after_select(fd_set *readset, fd_set *writeset)
                                sock = accept(sockets[i].fd,
                                    (struct sockaddr *) &sunaddr, &slen);
                                if (sock < 0) {
-                                       perror("accept from AUTH_SOCKET");
+                                       error("accept from AUTH_SOCKET: %s",
+                                           strerror(errno));
                                        break;
                                }
                                new_socket(AUTH_CONNECTION, sock);
@@ -780,7 +762,7 @@ after_select(fd_set *readset, fd_set *writeset)
 }
 
 static void
-cleanup_socket(void)
+cleanup_socket(void *p)
 {
        if (socket_name[0])
                unlink(socket_name);
@@ -791,14 +773,14 @@ cleanup_socket(void)
 static void
 cleanup_exit(int i)
 {
-       cleanup_socket();
+       cleanup_socket(NULL);
        exit(i);
 }
 
 static void
 cleanup_handler(int sig)
 {
-       cleanup_socket();
+       cleanup_socket(NULL);
        _exit(2);
 }
 
@@ -969,7 +951,7 @@ main(int ac, char **av)
        pid = fork();
        if (pid == -1) {
                perror("fork");
-               exit(1);
+               cleanup_exit(1);
        }
        if (pid != 0) {         /* Parent - execute the given command. */
                close(sock);
@@ -992,9 +974,11 @@ main(int ac, char **av)
                perror(av[0]);
                exit(1);
        }
+       /* child */
+       log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
 
        if (setsid() == -1) {
-               perror("setsid");
+               error("setsid: %s", strerror(errno));
                cleanup_exit(1);
        }
 
@@ -1007,16 +991,13 @@ main(int ac, char **av)
        /* deny core dumps, since memory contains unencrypted private keys */
        rlim.rlim_cur = rlim.rlim_max = 0;
        if (setrlimit(RLIMIT_CORE, &rlim) < 0) {
-               perror("setrlimit rlimit_core failed");
+               error("setrlimit RLIMIT_CORE: %s", strerror(errno));
                cleanup_exit(1);
        }
 #endif
 
 skip:
-       if (atexit(cleanup_socket) < 0) {
-               perror("atexit");
-               cleanup_exit(1);
-       }
+       fatal_add_cleanup(cleanup_socket, NULL);
        new_socket(AUTH_SOCKET, sock);
        if (ac > 0) {
                signal(SIGALRM, check_parent_exists);
@@ -1035,7 +1016,7 @@ skip:
                if (select(max_fd + 1, readsetp, writesetp, NULL, NULL) < 0) {
                        if (errno == EINTR)
                                continue;
-                       exit(1);
+                       fatal("select: %s", strerror(errno));
                }
                after_select(readsetp, writesetp);
        }
This page took 0.102632 seconds and 4 git commands to generate.