]> andersk Git - openssh.git/blobdiff - sshconnect2.c
- itojun@cvs.openbsd.org 2002/05/13 02:37:39
[openssh.git] / sshconnect2.c
index ea8cfa6da2774561a8f362de0c4cd52e4d81f9e4..1ee92ab0d740d2d9f507415ef82688a3a7da58a9 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshconnect2.c,v 1.95 2002/02/03 17:59:23 markus Exp $");
+RCSID("$OpenBSD: sshconnect2.c,v 1.99 2002/03/26 15:58:46 markus Exp $");
 
 #include "ssh.h"
 #include "ssh2.h"
@@ -138,7 +138,7 @@ typedef struct Authmethod Authmethod;
 
 typedef int sign_cb_fn(
     Authctxt *authctxt, Key *key,
-    u_char **sigp, int *lenp, u_char *data, int datalen);
+    u_char **sigp, u_int *lenp, u_char *data, u_int datalen);
 
 struct Authctxt {
        const char *server_user;
@@ -172,6 +172,7 @@ void        input_userauth_banner(int, u_int32_t, void *);
 void   input_userauth_error(int, u_int32_t, void *);
 void   input_userauth_info_req(int, u_int32_t, void *);
 void   input_userauth_pk_ok(int, u_int32_t, void *);
+void   input_userauth_passwd_changereq(int, u_int32_t, void *);
 
 int    userauth_none(Authctxt *);
 int    userauth_pubkey(Authctxt *);
@@ -353,8 +354,10 @@ input_userauth_pk_ok(int type, u_int32_t seq, void *ctxt)
        Authctxt *authctxt = ctxt;
        Key *key = NULL;
        Buffer b;
-       int pktype, alen, blen, sent = 0;
-       char *pkalg, *pkblob, *fp;
+       int pktype, sent = 0;
+       u_int alen, blen;
+       char *pkalg, *fp;
+       u_char *pkblob;
 
        if (authctxt == NULL)
                fatal("input_userauth_pk_ok: no authentication context");
@@ -389,7 +392,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, void *ctxt)
                        debug("no key from blob. pkalg %s", pkalg);
                        break;
                }
-               if (key->type != pktype) { 
+               if (key->type != pktype) {
                        error("input_userauth_pk_ok: type mismatch "
                            "for decoded key (received %d, expected %d)",
                             key->type, pktype);
@@ -437,7 +440,7 @@ int
 userauth_passwd(Authctxt *authctxt)
 {
        static int attempt = 0;
-       char prompt[80];
+       char prompt[150];
        char *password;
 
        if (attempt++ >= options.number_of_password_prompts)
@@ -459,13 +462,85 @@ userauth_passwd(Authctxt *authctxt)
        xfree(password);
        packet_add_padding(64);
        packet_send();
+
+       dispatch_set(SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ, 
+           &input_userauth_passwd_changereq);
+
        return 1;
 }
+/*
+ * parse PASSWD_CHANGEREQ, prompt user and send SSH2_MSG_USERAUTH_REQUEST
+ */
+void
+input_userauth_passwd_changereq(int type, u_int32_t seqnr, void *ctxt)
+{
+       Authctxt *authctxt = ctxt;
+       char *info, *lang, *password = NULL, *retype = NULL;
+       char prompt[150];
+
+       debug2("input_userauth_passwd_changereq");
+
+       if (authctxt == NULL)
+               fatal("input_userauth_passwd_changereq: "
+                   "no authentication context");
+
+       info = packet_get_string(NULL);
+       lang = packet_get_string(NULL);
+       if (strlen(info) > 0)
+               log("%s", info);
+       xfree(info);
+       xfree(lang);
+       packet_start(SSH2_MSG_USERAUTH_REQUEST);
+       packet_put_cstring(authctxt->server_user);
+       packet_put_cstring(authctxt->service);
+       packet_put_cstring(authctxt->method->name);
+       packet_put_char(1);                     /* additional info */
+       snprintf(prompt, sizeof(prompt), 
+           "Enter %.30s@%.128s's old password: ",
+           authctxt->server_user, authctxt->host);
+       password = read_passphrase(prompt, 0);
+       packet_put_cstring(password);
+       memset(password, 0, strlen(password));
+       xfree(password);
+       password = NULL;
+       while (password == NULL) {
+               snprintf(prompt, sizeof(prompt), 
+                   "Enter %.30s@%.128s's new password: ",
+                   authctxt->server_user, authctxt->host);
+               password = read_passphrase(prompt, RP_ALLOW_EOF);
+               if (password == NULL) {
+                       /* bail out */
+                       return;
+               }
+               snprintf(prompt, sizeof(prompt), 
+                   "Retype %.30s@%.128s's new password: ",
+                   authctxt->server_user, authctxt->host);
+               retype = read_passphrase(prompt, 0);
+               if (strcmp(password, retype) != 0) {
+                       memset(password, 0, strlen(password));
+                       xfree(password);
+                       log("Mismatch; try again, EOF to quit.");
+                       password = NULL;
+               }
+               memset(retype, 0, strlen(retype));
+               xfree(retype);
+       }
+       packet_put_cstring(password);
+       memset(password, 0, strlen(password));
+       xfree(password);
+       packet_add_padding(64);
+       packet_send();
+       
+       dispatch_set(SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ, 
+           &input_userauth_passwd_changereq);
+}
 
 static void
 clear_auth_state(Authctxt *authctxt)
 {
        /* XXX clear authentication state */
+       dispatch_set(SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ, NULL);
+
        if (authctxt->last_key != NULL && authctxt->last_key_hint == -1) {
                debug3("clear_auth_state: key_free %p", authctxt->last_key);
                key_free(authctxt->last_key);
@@ -480,7 +555,7 @@ sign_and_send_pubkey(Authctxt *authctxt, Key *k, sign_cb_fn *sign_callback)
 {
        Buffer b;
        u_char *blob, *signature;
-       int bloblen, slen;
+       u_int bloblen, slen;
        int skip = 0;
        int ret = -1;
        int have_sig = 1;
@@ -565,7 +640,7 @@ send_pubkey_test(Authctxt *authctxt, Key *k, sign_cb_fn *sign_callback,
     int hint)
 {
        u_char *blob;
-       int bloblen, have_sig = 0;
+       u_int bloblen, have_sig = 0;
 
        debug3("send_pubkey_test");
 
@@ -632,8 +707,8 @@ load_identity_file(char *filename)
 }
 
 static int
-identity_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
-    u_char *data, int datalen)
+identity_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, u_int *lenp,
+    u_char *data, u_int datalen)
 {
        Key *private;
        int idx, ret;
@@ -655,15 +730,15 @@ identity_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
 }
 
 static int
-agent_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
-    u_char *data, int datalen)
+agent_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, u_int *lenp,
+    u_char *data, u_int datalen)
 {
        return ssh_agent_sign(authctxt->agent, key, sigp, lenp, data, datalen);
 }
 
 static int
-key_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
-    u_char *data, int datalen)
+key_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, u_int *lenp,
+    u_char *data, u_int datalen)
 {
        return key_sign(key, sigp, lenp, data, datalen);
 }
@@ -954,7 +1029,7 @@ authmethod_get(char *authlist)
 {
 
        char *name = NULL;
-       int next;
+       u_int next;
 
        /* Use a suitable default if we're passed a nil list.  */
        if (authlist == NULL || strlen(authlist) == 0)
This page took 0.034369 seconds and 4 git commands to generate.