rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/pam_ssh_agent_auth-0.10.2-compat.patch

f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/get_command_line.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/get_command_line.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/get_command_line.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/get_command_line.c	2018-08-24 10:22:56.281930322 +0200
f5835d
@@ -27,6 +27,7 @@
f5835d
  * or implied, of Jamie Beverly.
f5835d
  */
f5835d
 
f5835d
+#include <stdlib.h>
f5835d
 #include <stdio.h>
f5835d
 #include <errno.h>
f5835d
 #include <string.h>
f5835d
@@ -65,8 +66,8 @@ proc_pid_cmdline(char *** inargv)
f5835d
                 case EOF:
f5835d
                 case '\0':
f5835d
                     if (len > 0) { 
f5835d
-                        argv = pamsshagentauth_xrealloc(argv, count + 1, sizeof(*argv));
f5835d
-                        argv[count] = pamsshagentauth_xcalloc(len + 1, sizeof(*argv[count]));
f5835d
+                        argv = xreallocarray(argv, count + 1, sizeof(*argv));
f5835d
+                        argv[count] = xcalloc(len + 1, sizeof(*argv[count]));
f5835d
                         strncpy(argv[count++], argbuf, len);
f5835d
                         memset(argbuf, '\0', MAX_LEN_PER_CMDLINE_ARG + 1);
f5835d
                         len = 0;
f5835d
@@ -105,9 +106,9 @@ pamsshagentauth_free_command_line(char *
f5835d
 {
f5835d
     size_t i;
f5835d
     for (i = 0; i < n_args; i++)
f5835d
-        pamsshagentauth_xfree(argv[i]);
f5835d
+        free(argv[i]);
f5835d
 
f5835d
-    pamsshagentauth_xfree(argv);
f5835d
+    free(argv);
f5835d
     return;
f5835d
 }
f5835d
 
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/identity.h.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/identity.h
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/identity.h.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/identity.h	2018-08-24 10:18:05.009393312 +0200
f5835d
@@ -30,8 +30,8 @@
f5835d
 #include "openbsd-compat/sys-queue.h"
f5835d
 #include "xmalloc.h"
f5835d
 #include "log.h"
f5835d
-#include "buffer.h"
f5835d
-#include "key.h"
f5835d
+#include "sshbuf.h"
f5835d
+#include "sshkey.h"
f5835d
 #include "authfd.h"
f5835d
 #include <stdio.h>
f5835d
 
f5835d
@@ -41,7 +41,7 @@ typedef struct idlist Idlist;
f5835d
 struct identity {
f5835d
     TAILQ_ENTRY(identity) next;
f5835d
     AuthenticationConnection *ac;   /* set if agent supports key */
f5835d
-    Key *key;           /* public/private key */
f5835d
+    struct sshkey *key;           /* public/private key */
f5835d
     char    *filename;      /* comment for agent-only keys */
f5835d
     int tried;
f5835d
     int isprivate;      /* key points to the private key */
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-compat	2018-08-24 10:18:05.007393297 +0200
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2018-08-24 10:18:32.937612513 +0200
f5835d
@@ -36,8 +36,8 @@
f5835d
 #include "openbsd-compat/sys-queue.h"
f5835d
 #include "xmalloc.h"
f5835d
 #include "log.h"
f5835d
-#include "buffer.h"
f5835d
-#include "key.h"
f5835d
+#include "sshbuf.h"
f5835d
+#include "sshkey.h"
f5835d
 #include "authfd.h"
f5835d
 #include <stdio.h>
f5835d
 #include <openssl/evp.h>
f5835d
@@ -58,6 +58,8 @@
f5835d
 #include "get_command_line.h"
f5835d
 extern char **environ;
f5835d
 
f5835d
+#define PAM_SSH_AGENT_AUTH_REQUESTv1 101
f5835d
+
f5835d
 /* 
f5835d
  * Added by Jamie Beverly, ensure socket fd points to a socket owned by the user 
f5835d
  * A cursory check is done, but to avoid race conditions, it is necessary 
f5835d
@@ -77,7 +79,7 @@ log_action(char ** action, size_t count)
f5835d
     if (count == 0)
f5835d
         return NULL;
f5835d
    
f5835d
-    buf = pamsshagentauth_xcalloc((count * MAX_LEN_PER_CMDLINE_ARG) + (count * 3), sizeof(*buf));
f5835d
+    buf = xcalloc((count * MAX_LEN_PER_CMDLINE_ARG) + (count * 3), sizeof(*buf));
f5835d
     for (i = 0; i < count; i++) {
f5835d
         strcat(buf, (i > 0) ? " '" : "'");
f5835d
         strncat(buf, action[i], MAX_LEN_PER_CMDLINE_ARG);
f5835d
@@ -87,21 +89,25 @@ log_action(char ** action, size_t count)
f5835d
 }
f5835d
 
f5835d
 void
f5835d
-agent_action(Buffer *buf, char ** action, size_t count)
f5835d
+agent_action(struct sshbuf **buf, char ** action, size_t count)
f5835d
 {
f5835d
     size_t i;
f5835d
-    pamsshagentauth_buffer_init(buf);
f5835d
+    int r;
f5835d
 
f5835d
-    pamsshagentauth_buffer_put_int(buf, count);
f5835d
+    if ((*buf = sshbuf_new()) == NULL)
f5835d
+        fatal("%s: sshbuf_new failed", __func__);
f5835d
+    if ((r = sshbuf_put_u32(*buf, count)) != 0)
f5835d
+        fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
 
f5835d
     for (i = 0; i < count; i++) {
f5835d
-        pamsshagentauth_buffer_put_cstring(buf, action[i]);
f5835d
+        if ((r = sshbuf_put_cstring(*buf, action[i])) != 0)
f5835d
+            fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
     }
f5835d
 }
f5835d
 
f5835d
 
f5835d
-void
f5835d
-pamsshagentauth_session_id2_gen(Buffer * session_id2, const char * user,
f5835d
+static void
f5835d
+pamsshagentauth_session_id2_gen(struct sshbuf ** session_id2, const char * user,
f5835d
                                 const char * ruser, const char * servicename)
f5835d
 {
f5835d
     u_char *cookie = NULL;
f5835d
@@ -114,22 +116,23 @@ pamsshagentauth_session_id2_gen(Buffer *
f5835d
     char ** reported_argv = NULL;
f5835d
     size_t count = 0;
f5835d
     char * action_logbuf = NULL;
f5835d
-    Buffer action_agentbuf;
f5835d
+    struct sshbuf *action_agentbuf = NULL;
f5835d
     uint8_t free_logbuf = 0;
f5835d
     char * retc;
f5835d
     int32_t reti;
f5835d
+    int r;
f5835d
 
f5835d
-    rnd = pamsshagentauth_arc4random();
f5835d
+    rnd = arc4random();
f5835d
     cookie_len = ((uint8_t) rnd);
f5835d
     while (cookie_len < 16) { 
f5835d
         cookie_len += 16;                                          /* Add 16 bytes to the size to ensure that while the length is random, the length is always reasonable; ticket #18 */
f5835d
     }
f5835d
 
f5835d
-    cookie = pamsshagentauth_xcalloc(1,cookie_len);
f5835d
+    cookie = xcalloc(1, cookie_len);
f5835d
 
f5835d
     for (i = 0; i < cookie_len; i++) {
f5835d
         if (i % 4 == 0) {
f5835d
-            rnd = pamsshagentauth_arc4random();
f5835d
+            rnd = arc4random();
f5835d
         }
f5835d
         cookie[i] = (u_char) rnd;
f5835d
         rnd >>= 8;
f5835d
@@ -139,12 +141,13 @@ pamsshagentauth_session_id2_gen(Buffer *
f5835d
     if (count > 0) { 
f5835d
         free_logbuf = 1;
f5835d
         action_logbuf = log_action(reported_argv, count);
f5835d
-        agent_action(&action_agentbuf, reported_argv, count);
f5835d
+        agent_action(&action_agentbuf, reported_argv, count);
f5835d
         pamsshagentauth_free_command_line(reported_argv, count);
f5835d
     }
f5835d
     else {
f5835d
         action_logbuf = "unknown on this platform";
f5835d
-        pamsshagentauth_buffer_init(&action_agentbuf); /* stays empty, means unavailable */
f5835d
+        if ((action_agentbuf = sshbuf_new()) == NULL) /* stays empty, means unavailable */
f5835d
+            fatal("%s: sshbuf_new failed", __func__);
f5835d
     }
f5835d
     
f5835d
     /*
f5835d
@@ -161,35 +163,39 @@ pamsshagentauth_session_id2_gen(Buffer *
f5835d
     retc = getcwd(pwd, sizeof(pwd) - 1);
f5835d
     time(&ts);
f5835d
 
f5835d
-    pamsshagentauth_buffer_init(session_id2);
f5835d
+    if ((*session_id2 = sshbuf_new()) == NULL)
f5835d
+        fatal("%s: sshbuf_new failed", __func__);
f5835d
 
f5835d
-    pamsshagentauth_buffer_put_int(session_id2, PAM_SSH_AGENT_AUTH_REQUESTv1);
f5835d
-    /* pamsshagentauth_debug3("cookie: %s", pamsshagentauth_tohex(cookie, cookie_len)); */
f5835d
-    pamsshagentauth_buffer_put_string(session_id2, cookie, cookie_len);
f5835d
-    /* pamsshagentauth_debug3("user: %s", user); */
f5835d
-    pamsshagentauth_buffer_put_cstring(session_id2, user);
f5835d
-    /* pamsshagentauth_debug3("ruser: %s", ruser); */
f5835d
-    pamsshagentauth_buffer_put_cstring(session_id2, ruser);
f5835d
-    /* pamsshagentauth_debug3("servicename: %s", servicename); */
f5835d
-    pamsshagentauth_buffer_put_cstring(session_id2, servicename);
f5835d
-    /* pamsshagentauth_debug3("pwd: %s", pwd); */
f5835d
-    if(retc)
f5835d
-        pamsshagentauth_buffer_put_cstring(session_id2, pwd);
f5835d
-    else
f5835d
-        pamsshagentauth_buffer_put_cstring(session_id2, "");
f5835d
-    /* pamsshagentauth_debug3("action: %s", action_logbuf); */
f5835d
-    pamsshagentauth_buffer_put_string(session_id2, action_agentbuf.buf + action_agentbuf.offset, action_agentbuf.end - action_agentbuf.offset);
f5835d
+    if ((r = sshbuf_put_u32(*session_id2, PAM_SSH_AGENT_AUTH_REQUESTv1)) != 0 ||
f5835d
+        (r = sshbuf_put_string(*session_id2, cookie, cookie_len)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(*session_id2, user)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(*session_id2, ruser)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(*session_id2, servicename)) != 0)
f5835d
+        fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
+    if (retc) {
f5835d
+        if ((r = sshbuf_put_cstring(*session_id2, pwd)) != 0)
f5835d
+            fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
+    } else {
f5835d
+        if ((r = sshbuf_put_cstring(*session_id2, "")) != 0)
f5835d
+            fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
+    }
f5835d
+    if ((r = sshbuf_put_stringb(*session_id2, action_agentbuf)) != 0)
f5835d
+        fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
     if (free_logbuf) { 
f5835d
-        pamsshagentauth_xfree(action_logbuf);
f5835d
-        pamsshagentauth_buffer_free(&action_agentbuf);
f5835d
+        free(action_logbuf);
f5835d
+        sshbuf_free(action_agentbuf);
f5835d
     }
f5835d
-    /* pamsshagentauth_debug3("hostname: %s", hostname); */
f5835d
-    if(reti >= 0)
f5835d
-        pamsshagentauth_buffer_put_cstring(session_id2, hostname);
f5835d
-    else
f5835d
-        pamsshagentauth_buffer_put_cstring(session_id2, "");
f5835d
-    /* pamsshagentauth_debug3("ts: %ld", ts); */
f5835d
-    pamsshagentauth_buffer_put_int64(session_id2, (uint64_t) ts);
f5835d
+    /* debug3("hostname: %s", hostname); */
f5835d
+    if (reti >= 0) {
f5835d
+        if ((r = sshbuf_put_cstring(*session_id2, hostname)) != 0)
f5835d
+            fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
+    } else {
f5835d
+        if ((r = sshbuf_put_cstring(*session_id2, "")) != 0)
f5835d
+            fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
+    }
f5835d
+    /* debug3("ts: %ld", ts); */
f5835d
+    if ((r = sshbuf_put_u64(*session_id2, (uint64_t) ts)) != 0)
f5835d
+        fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
 
f5835d
     free(cookie);
f5835d
     return;
f5835d
@@ -278,7 +280,8 @@ ssh_get_authentication_connection_for_ui
f5835d
 
f5835d
 	auth = xmalloc(sizeof(*auth));
f5835d
 	auth->fd = sock;
f5835d
-	buffer_init(&auth->identities);
f5835d
+	if ((auth->identities = sshbuf_new()) == NULL)
f5835d
+           fatal("%s: sshbuf_new failed", __func__);
f5835d
 	auth->howmany = 0;
f5835d
 
f5835d
 	return auth;
f5835d
@@ -287,43 +289,42 @@ ssh_get_authentication_connection_for_ui
f5835d
 int
f5835d
 pamsshagentauth_find_authorized_keys(const char * user, const char * ruser, const char * servicename)
f5835d
 {
f5835d
-    Buffer session_id2 = { 0 };
f5835d
+    struct sshbuf *session_id2 = NULL;
f5835d
     Identity *id;
f5835d
-    Key *key;
f5835d
+    struct sshkey *key;
f5835d
     AuthenticationConnection *ac;
f5835d
     char *comment;
f5835d
     uint8_t retval = 0;
f5835d
     uid_t uid = getpwnam(ruser)->pw_uid;
f5835d
 
f5835d
     OpenSSL_add_all_digests();
f5835d
-    pamsshagentauth_session_id2_gen(&session_id2, user, ruser, servicename);
f5835d
+    pamsshagentauth_session_id2_gen(&session_id2, user, ruser, servicename);
f5835d
 
f5835d
     if ((ac = ssh_get_authentication_connection_for_uid(uid))) {
f5835d
-        pamsshagentauth_verbose("Contacted ssh-agent of user %s (%u)", ruser, uid);
f5835d
+        verbose("Contacted ssh-agent of user %s (%u)", ruser, uid);
f5835d
         for (key = ssh_get_first_identity(ac, &comment, 2); key != NULL; key = ssh_get_next_identity(ac, &comment, 2)) 
f5835d
         {
f5835d
             if(key != NULL) {
f5835d
-                id = pamsshagentauth_xcalloc(1, sizeof(*id));
f5835d
+                id = xcalloc(1, sizeof(*id));
f5835d
                 id->key = key;
f5835d
                 id->filename = comment;
f5835d
                 id->ac = ac;
f5835d
-                if(userauth_pubkey_from_id(ruser, id, &session_id2)) {
f5835d
+                if(userauth_pubkey_from_id(ruser, id, session_id2)) {
f5835d
                     retval = 1;
f5835d
                 }
f5835d
-                pamsshagentauth_xfree(id->filename);
f5835d
-                pamsshagentauth_key_free(id->key);
f5835d
-                pamsshagentauth_xfree(id);
f5835d
+                free(id->filename);
f5835d
+                key_free(id->key);
f5835d
+                free(id);
f5835d
                 if(retval == 1)
f5835d
                     break;
f5835d
             }
f5835d
         }
f5835d
-        pamsshagentauth_buffer_free(&session_id2);
f5835d
+        sshbuf_free(session_id2);
f5835d
         ssh_close_authentication_connection(ac);
f5835d
     }
f5835d
     else {
f5835d
-        pamsshagentauth_verbose("No ssh-agent could be contacted");
f5835d
+        verbose("No ssh-agent could be contacted");
f5835d
     }
f5835d
-    /* pamsshagentauth_xfree(session_id2); */
f5835d
     EVP_cleanup();
f5835d
     return retval;
f5835d
 }
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c.psaa-compat	2018-08-24 10:18:05.008393305 +0200
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c	2018-08-24 10:18:05.009393312 +0200
f5835d
@@ -104,7 +104,7 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
  * a patch 8-)
f5835d
  */
f5835d
 #if ! HAVE___PROGNAME || HAVE_BUNDLE
f5835d
-    __progname = pamsshagentauth_xstrdup(servicename);
f5835d
+    __progname = xstrdup(servicename);
f5835d
 #endif
f5835d
 
f5835d
     for(i = argc, argv_ptr = (char **) argv; i > 0; ++argv_ptr, i--) {
f5835d
@@ -130,11 +130,11 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
 #endif
f5835d
     }
f5835d
 
f5835d
-    pamsshagentauth_log_init(__progname, log_lvl, facility, getenv("PAM_SSH_AGENT_AUTH_DEBUG") ? 1 : 0);
f5835d
+    log_init(__progname, log_lvl, facility, getenv("PAM_SSH_AGENT_AUTH_DEBUG") ? 1 : 0);
f5835d
     pam_get_item(pamh, PAM_USER, (void *) &user);
f5835d
     pam_get_item(pamh, PAM_RUSER, (void *) &ruser_ptr);
f5835d
 
f5835d
-    pamsshagentauth_verbose("Beginning pam_ssh_agent_auth for user %s", user);
f5835d
+    verbose("Beginning pam_ssh_agent_auth for user %s", user);
f5835d
 
f5835d
     if(ruser_ptr) {
f5835d
         strncpy(ruser, ruser_ptr, sizeof(ruser) - 1);
f5835d
@@ -149,12 +149,12 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
 #ifdef ENABLE_SUDO_HACK
f5835d
         if( (strlen(sudo_service_name) > 0) && strncasecmp(servicename, sudo_service_name, sizeof(sudo_service_name) - 1) == 0 && getenv("SUDO_USER") ) {
f5835d
             strncpy(ruser, getenv("SUDO_USER"), sizeof(ruser) - 1 );
f5835d
-            pamsshagentauth_verbose( "Using environment variable SUDO_USER (%s)", ruser );
f5835d
+            verbose( "Using environment variable SUDO_USER (%s)", ruser );
f5835d
         } else
f5835d
 #endif
f5835d
         {
f5835d
             if( ! getpwuid(getuid()) ) {
f5835d
-                pamsshagentauth_verbose("Unable to getpwuid(getuid())");
f5835d
+                verbose("Unable to getpwuid(getuid())");
f5835d
                 goto cleanexit;
f5835d
             }
f5835d
             strncpy(ruser, getpwuid(getuid())->pw_name, sizeof(ruser) - 1);
f5835d
@@ -163,11 +163,11 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
 
f5835d
     /* Might as well explicitely confirm the user exists here */
f5835d
     if(! getpwnam(ruser) ) {
f5835d
-        pamsshagentauth_verbose("getpwnam(%s) failed, bailing out", ruser);
f5835d
+        verbose("getpwnam(%s) failed, bailing out", ruser);
f5835d
         goto cleanexit;
f5835d
     }
f5835d
     if( ! getpwnam(user) ) {
f5835d
-        pamsshagentauth_verbose("getpwnam(%s) failed, bailing out", user);
f5835d
+        verbose("getpwnam(%s) failed, bailing out", user);
f5835d
         goto cleanexit;
f5835d
     }
f5835d
 
f5835d
@@ -177,8 +177,8 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
          */
f5835d
         parse_authorized_key_file(user, authorized_keys_file_input);
f5835d
     } else {
f5835d
-        pamsshagentauth_verbose("Using default file=/etc/security/authorized_keys");
f5835d
-        authorized_keys_file = pamsshagentauth_xstrdup("/etc/security/authorized_keys");
f5835d
+        verbose("Using default file=/etc/security/authorized_keys");
f5835d
+        authorized_keys_file = xstrdup("/etc/security/authorized_keys");
f5835d
     }
f5835d
 
f5835d
     /*
f5835d
@@ -187,19 +187,19 @@ pam_sm_authenticate(pam_handle_t * pamh,
f5835d
      */
f5835d
 
f5835d
     if(user && strlen(ruser) > 0) {
f5835d
-        pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
+        verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
 
f5835d
         /*
f5835d
          * this pw_uid is used to validate the SSH_AUTH_SOCK, and so must be the uid of the ruser invoking the program, not the target-user
f5835d
          */
f5835d
         if(pamsshagentauth_find_authorized_keys(user, ruser, servicename)) { /* getpwnam(ruser)->pw_uid)) { */
f5835d
-            pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
+            logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
             retval = PAM_SUCCESS;
f5835d
         } else {
f5835d
-            pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
+            logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
f5835d
         }
f5835d
     } else {
f5835d
-        pamsshagentauth_logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
f5835d
+        logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
f5835d
     }
f5835d
 
f5835d
 cleanexit:
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c	2018-08-24 10:18:05.009393312 +0200
f5835d
@@ -66,8 +66,8 @@
f5835d
 #include "xmalloc.h"
f5835d
 #include "match.h"
f5835d
 #include "log.h"
f5835d
-#include "buffer.h"
f5835d
-#include "key.h"
f5835d
+#include "sshbuf.h"
f5835d
+#include "sshkey.h"
f5835d
 #include "misc.h"
f5835d
 
f5835d
 #include "xmalloc.h"
f5835d
@@ -77,7 +77,6 @@
f5835d
 #include "pathnames.h"
f5835d
 #include "secure_filename.h"
f5835d
 
f5835d
-#include "identity.h"
f5835d
 #include "pam_user_key_allowed2.h"
f5835d
 
f5835d
 extern char *authorized_keys_file;
f5835d
@@ -117,12 +116,12 @@ parse_authorized_key_file(const char *us
f5835d
         } else {
f5835d
             slash_ptr = strchr(auth_keys_file_buf, '/');
f5835d
             if(!slash_ptr)
f5835d
-                pamsshagentauth_fatal
f5835d
+                fatal
f5835d
                     ("cannot expand tilde in path without a `/'");
f5835d
 
f5835d
             owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
f5835d
             if(owner_uname_len > (sizeof(owner_uname) - 1))
f5835d
-                pamsshagentauth_fatal("Username too long");
f5835d
+                fatal("Username too long");
f5835d
 
f5835d
             strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
f5835d
             if(!authorized_keys_file_allowed_owner_uid)
f5835d
@@ -130,11 +129,11 @@ parse_authorized_key_file(const char *us
f5835d
                     getpwnam(owner_uname)->pw_uid;
f5835d
         }
f5835d
         authorized_keys_file =
f5835d
-            pamsshagentauth_tilde_expand_filename(auth_keys_file_buf,
f5835d
+            tilde_expand_filename(auth_keys_file_buf,
f5835d
                                                   authorized_keys_file_allowed_owner_uid);
f5835d
         strncpy(auth_keys_file_buf, authorized_keys_file,
f5835d
                 sizeof(auth_keys_file_buf) - 1);
f5835d
-        pamsshagentauth_xfree(authorized_keys_file)        /* when we
f5835d
+        free(authorized_keys_file)        /* when we
f5835d
                                                               percent_expand
f5835d
                                                               later, we'd step
f5835d
                                                               on this, so free
f5835d
@@ -150,13 +149,13 @@ parse_authorized_key_file(const char *us
f5835d
     strncat(hostname, fqdn, strcspn(fqdn, "."));
f5835d
 #endif
f5835d
     authorized_keys_file =
f5835d
-        pamsshagentauth_percent_expand(auth_keys_file_buf, "h",
f5835d
+        percent_expand(auth_keys_file_buf, "h",
f5835d
                                        getpwnam(user)->pw_dir, "H", hostname,
f5835d
                                        "f", fqdn, "u", user, NULL);
f5835d
 }
f5835d
 
f5835d
 int
f5835d
-pam_user_key_allowed(const char *ruser, Key * key)
f5835d
+pam_user_key_allowed(const char *ruser, struct sshkey * key)
f5835d
 {
f5835d
     return
f5835d
         pamsshagentauth_user_key_allowed2(getpwuid(authorized_keys_file_allowed_owner_uid),
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -32,7 +32,7 @@
f5835d
 #define _PAM_USER_KEY_ALLOWED_H
f5835d
 
f5835d
 #include "identity.h"
f5835d
-int pam_user_key_allowed(const char *, Key *);
f5835d
+int pam_user_key_allowed(const char *, struct sshkey *);
f5835d
 void parse_authorized_key_file(const char *, const char *);
f5835d
 
f5835d
 #endif
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -45,44 +45,46 @@
f5835d
 #include "xmalloc.h"
f5835d
 #include "ssh.h"
f5835d
 #include "ssh2.h"
f5835d
-#include "buffer.h"
f5835d
+#include "sshbuf.h"
f5835d
 #include "log.h"
f5835d
 #include "compat.h"
f5835d
-#include "key.h"
f5835d
+#include "digest.h"
f5835d
+#include "sshkey.h"
f5835d
 #include "pathnames.h"
f5835d
 #include "misc.h"
f5835d
 #include "secure_filename.h"
f5835d
 #include "uidswap.h"
f5835d
-
f5835d
-#include "identity.h"
f5835d
+#include <unistd.h>
f5835d
 
f5835d
 /* return 1 if user allows given key */
f5835d
 /* Modified slightly from original found in auth2-pubkey.c */
f5835d
 static int
f5835d
-pamsshagentauth_check_authkeys_file(FILE * f, char *file, Key * key)
f5835d
+pamsshagentauth_check_authkeys_file(FILE * f, char *file, struct sshkey * key)
f5835d
 {
f5835d
-    char line[SSH_MAX_PUBKEY_BYTES];
f5835d
+    char *line = NULL;
f5835d
     int found_key = 0;
f5835d
     u_long linenum = 0;
f5835d
-    Key *found;
f5835d
+    struct sshkey *found;
f5835d
     char *fp;
f5835d
+    size_t linesize = 0;
f5835d
 
f5835d
     found_key = 0;
f5835d
-    found = pamsshagentauth_key_new(key->type);
f5835d
+    found = sshkey_new(key->type);
f5835d
 
f5835d
-    while(read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
f5835d
+    while ((getline(&line, &linesize, f)) != -1) {
f5835d
         char *cp = NULL; /* *key_options = NULL; */
f5835d
 
f5835d
+        linenum++;
f5835d
         /* Skip leading whitespace, empty and comment lines. */
f5835d
         for(cp = line; *cp == ' ' || *cp == '\t'; cp++);
f5835d
         if(!*cp || *cp == '\n' || *cp == '#')
f5835d
             continue;
f5835d
 
f5835d
-        if(pamsshagentauth_key_read(found, &cp) != 1) {
f5835d
+        if (sshkey_read(found, &cp) != 0) {
f5835d
             /* no key? check if there are options for this key */
f5835d
             int quoted = 0;
f5835d
 
f5835d
-            pamsshagentauth_verbose("user_key_allowed: check options: '%s'", cp);
f5835d
+            verbose("user_key_allowed: check options: '%s'", cp);
f5835d
             /* key_options = cp; */
f5835d
             for(; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
f5835d
                 if(*cp == '\\' && cp[1] == '"')
f5835d
@@ -92,26 +94,27 @@ pamsshagentauth_check_authkeys_file(FILE
f5835d
             }
f5835d
             /* Skip remaining whitespace. */
f5835d
             for(; *cp == ' ' || *cp == '\t'; cp++);
f5835d
-            if(pamsshagentauth_key_read(found, &cp) != 1) {
f5835d
-                pamsshagentauth_verbose("user_key_allowed: advance: '%s'", cp);
f5835d
+            if(sshkey_read(found, &cp) != 0) {
f5835d
+                verbose("user_key_allowed: advance: '%s'", cp);
f5835d
                 /* still no key? advance to next line */
f5835d
                 continue;
f5835d
             }
f5835d
         }
f5835d
-        if(pamsshagentauth_key_equal(found, key)) {
f5835d
+        if(sshkey_equal(found, key)) {
f5835d
             found_key = 1;
f5835d
-            pamsshagentauth_logit("matching key found: file/command %s, line %lu", file,
f5835d
+            logit("matching key found: file/command %s, line %lu", file,
f5835d
                                   linenum);
f5835d
-            fp = pamsshagentauth_key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
f5835d
-            pamsshagentauth_logit("Found matching %s key: %s",
f5835d
-                                  pamsshagentauth_key_type(found), fp);
f5835d
-            pamsshagentauth_xfree(fp);
f5835d
+            fp = sshkey_fingerprint(found, SSH_DIGEST_SHA256, SSH_FP_BASE64);
f5835d
+            logit("Found matching %s key: %s",
f5835d
+                                  sshkey_type(found), fp);
f5835d
+            free(fp);
f5835d
             break;
f5835d
         }
f5835d
     }
f5835d
-    pamsshagentauth_key_free(found);
f5835d
+    free(line);
f5835d
+    sshkey_free(found);
f5835d
     if(!found_key)
f5835d
-        pamsshagentauth_verbose("key not found");
f5835d
+        verbose("key not found");
f5835d
     return found_key;
f5835d
 }
f5835d
 
f5835d
@@ -120,19 +123,19 @@ pamsshagentauth_check_authkeys_file(FILE
f5835d
  * returns 1 if the key is allowed or 0 otherwise.
f5835d
  */
f5835d
 int
f5835d
-pamsshagentauth_user_key_allowed2(struct passwd *pw, Key * key, char *file)
f5835d
+pamsshagentauth_user_key_allowed2(struct passwd *pw, struct sshkey * key, char *file)
f5835d
 {
f5835d
     FILE *f;
f5835d
     int found_key = 0;
f5835d
     struct stat st;
f5835d
-    char buf[SSH_MAX_PUBKEY_BYTES];
f5835d
+    char buf[256];
f5835d
 
f5835d
     /* Temporarily use the user's uid. */
f5835d
-    pamsshagentauth_verbose("trying public key file %s", file);
f5835d
+    verbose("trying public key file %s", file);
f5835d
 
f5835d
     /* Fail not so quietly if file does not exist */
f5835d
     if(stat(file, &st) < 0) {
f5835d
-        pamsshagentauth_verbose("File not found: %s", file);
f5835d
+        verbose("File not found: %s", file);
f5835d
         return 0;
f5835d
     }
f5835d
 
f5835d
@@ -144,7 +147,7 @@ pamsshagentauth_user_key_allowed2(struct
f5835d
 
f5835d
     if(pamsshagentauth_secure_filename(f, file, pw, buf, sizeof(buf)) != 0) {
f5835d
         fclose(f);
f5835d
-        pamsshagentauth_logit("Authentication refused: %s", buf);
f5835d
+        logit("Authentication refused: %s", buf);
f5835d
         return 0;
f5835d
     }
f5835d
 
f5835d
@@ -160,7 +163,7 @@ pamsshagentauth_user_key_allowed2(struct
f5835d
 int
f5835d
 pamsshagentauth_user_key_command_allowed2(char *authorized_keys_command,
f5835d
                           char *authorized_keys_command_user,
f5835d
-                          struct passwd *user_pw, Key * key)
f5835d
+                          struct passwd *user_pw, struct sshkey * key)
f5835d
 {
f5835d
     FILE *f;
f5835d
     int ok, found_key = 0;
f5835d
@@ -187,44 +190,44 @@ pamsshagentauth_user_key_command_allowed
f5835d
     else {
f5835d
         pw = getpwnam(authorized_keys_command_user);
f5835d
         if(pw == NULL) {
f5835d
-            pamsshagentauth_logerror("authorized_keys_command_user \"%s\" not found: %s",
f5835d
+            error("authorized_keys_command_user \"%s\" not found: %s",
f5835d
                  authorized_keys_command_user, strerror(errno));
f5835d
             return 0;
f5835d
         }
f5835d
     }
f5835d
 
f5835d
-    pamsshagentauth_temporarily_use_uid(pw);
f5835d
+    temporarily_use_uid(pw);
f5835d
 
f5835d
     if(stat(authorized_keys_command, &st) < 0) {
f5835d
-        pamsshagentauth_logerror
f5835d
+        error
f5835d
             ("Could not stat AuthorizedKeysCommand \"%s\": %s",
f5835d
              authorized_keys_command, strerror(errno));
f5835d
         goto out;
f5835d
     }
f5835d
     if(pamsshagentauth_auth_secure_path
f5835d
        (authorized_keys_command, &st, NULL, 0, errmsg, sizeof(errmsg)) != 0) {
f5835d
-        pamsshagentauth_logerror("Unsafe AuthorizedKeysCommand: %s", errmsg);
f5835d
+        error("Unsafe AuthorizedKeysCommand: %s", errmsg);
f5835d
         goto out;
f5835d
     }
f5835d
 
f5835d
     /* open the pipe and read the keys */
f5835d
     if(pipe(p) != 0) {
f5835d
-        pamsshagentauth_logerror("%s: pipe: %s", __func__, strerror(errno));
f5835d
+        error("%s: pipe: %s", __func__, strerror(errno));
f5835d
         goto out;
f5835d
     }
f5835d
 
f5835d
-    pamsshagentauth_debug("Running AuthorizedKeysCommand: \"%s\" as \"%s\" with argument: \"%s\"",
f5835d
+    debug("Running AuthorizedKeysCommand: \"%s\" as \"%s\" with argument: \"%s\"",
f5835d
                           authorized_keys_command, pw->pw_name, username);
f5835d
 
f5835d
     /* 
f5835d
      * Don't want to call this in the child, where it can fatal() and
f5835d
      * run cleanup_exit() code.
f5835d
      */
f5835d
-    pamsshagentauth_restore_uid();
f5835d
+    restore_uid();
f5835d
 
f5835d
     switch ((pid = fork())) {
f5835d
     case -1:                                              /* error */
f5835d
-        pamsshagentauth_logerror("%s: fork: %s", __func__, strerror(errno));
f5835d
+        error("%s: fork: %s", __func__, strerror(errno));
f5835d
         close(p[0]);
f5835d
         close(p[1]);
f5835d
         return 0;
f5835d
@@ -234,13 +237,13 @@ pamsshagentauth_user_key_command_allowed
f5835d
 
f5835d
         /* do this before the setresuid so thta they can be logged */
f5835d
         if((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) {
f5835d
-            pamsshagentauth_logerror("%s: open %s: %s", __func__, _PATH_DEVNULL,
f5835d
+            error("%s: open %s: %s", __func__, _PATH_DEVNULL,
f5835d
                                      strerror(errno));
f5835d
             _exit(1);
f5835d
         }
f5835d
         if(dup2(devnull, STDIN_FILENO) == -1 || dup2(p[1], STDOUT_FILENO) == -1
f5835d
            || dup2(devnull, STDERR_FILENO) == -1) {
f5835d
-            pamsshagentauth_logerror("%s: dup2: %s", __func__, strerror(errno));
f5835d
+            error("%s: dup2: %s", __func__, strerror(errno));
f5835d
             _exit(1);
f5835d
         }
f5835d
 #if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID)
f5835d
@@ -248,7 +251,7 @@ pamsshagentauth_user_key_command_allowed
f5835d
 #else
f5835d
         if (setgid(pw->pw_gid) != 0 || setegid(pw->pw_gid) != 0) {
f5835d
 #endif
f5835d
-            pamsshagentauth_logerror("setresgid %u: %s", (u_int) pw->pw_gid,
f5835d
+            error("setresgid %u: %s", (u_int) pw->pw_gid,
f5835d
                                      strerror(errno));
f5835d
             _exit(1);
f5835d
         }
f5835d
@@ -258,7 +261,7 @@ pamsshagentauth_user_key_command_allowed
f5835d
 #else
f5835d
         if (setuid(pw->pw_uid) != 0 || seteuid(pw->pw_uid) != 0) {
f5835d
 #endif
f5835d
-            pamsshagentauth_logerror("setresuid %u: %s", (u_int) pw->pw_uid,
f5835d
+            error("setresuid %u: %s", (u_int) pw->pw_uid,
f5835d
                                      strerror(errno));
f5835d
             _exit(1);
f5835d
         }
f5835d
@@ -270,18 +273,18 @@ pamsshagentauth_user_key_command_allowed
f5835d
 
f5835d
         /* pretty sure this will barf because we are now suid, but since we
f5835d
            should't reach this anyway, I'll leave it here */
f5835d
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s exec failed: %s",
f5835d
+        error("AuthorizedKeysCommand %s exec failed: %s",
f5835d
                                  authorized_keys_command, strerror(errno));
f5835d
         _exit(127);
f5835d
     default:                                              /* parent */
f5835d
         break;
f5835d
     }
f5835d
 
f5835d
-    pamsshagentauth_temporarily_use_uid(pw);
f5835d
+    temporarily_use_uid(pw);
f5835d
 
f5835d
     close(p[1]);
f5835d
     if((f = fdopen(p[0], "r")) == NULL) {
f5835d
-        pamsshagentauth_logerror("%s: fdopen: %s", __func__, strerror(errno));
f5835d
+        error("%s: fdopen: %s", __func__, strerror(errno));
f5835d
         close(p[0]);
f5835d
         /* Don't leave zombie child */
f5835d
         while(waitpid(pid, NULL, 0) == -1 && errno == EINTR);
f5835d
@@ -292,22 +295,22 @@ pamsshagentauth_user_key_command_allowed
f5835d
 
f5835d
     while(waitpid(pid, &status, 0) == -1) {
f5835d
         if(errno != EINTR) {
f5835d
-            pamsshagentauth_logerror("%s: waitpid: %s", __func__,
f5835d
+            error("%s: waitpid: %s", __func__,
f5835d
                                      strerror(errno));
f5835d
             goto out;
f5835d
         }
f5835d
     }
f5835d
     if(WIFSIGNALED(status)) {
f5835d
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s exited on signal %d",
f5835d
+        error("AuthorizedKeysCommand %s exited on signal %d",
f5835d
                                  authorized_keys_command, WTERMSIG(status));
f5835d
         goto out;
f5835d
     } else if(WEXITSTATUS(status) != 0) {
f5835d
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s returned status %d",
f5835d
+        error("AuthorizedKeysCommand %s returned status %d",
f5835d
                                  authorized_keys_command, WEXITSTATUS(status));
f5835d
         goto out;
f5835d
     }
f5835d
     found_key = ok;
f5835d
   out:
f5835d
-    pamsshagentauth_restore_uid();
f5835d
+    restore_uid();
f5835d
     return found_key;
f5835d
 }
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.h.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.h
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.h.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.h	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -32,7 +32,7 @@
f5835d
 #define _PAM_USER_KEY_ALLOWED_H
f5835d
 
f5835d
 #include "identity.h"
f5835d
-int pamsshagentauth_user_key_allowed2(struct passwd *, Key *, char *);
f5835d
-int pamsshagentauth_user_key_command_allowed2(char *, char *, struct passwd *, Key *);
f5835d
+int pamsshagentauth_user_key_allowed2(struct passwd *, struct sshkey *, char *);
f5835d
+int pamsshagentauth_user_key_command_allowed2(char *, char *, struct passwd *, struct sshkey *);
f5835d
 
f5835d
 #endif
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/secure_filename.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/secure_filename.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/secure_filename.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/secure_filename.c	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -53,8 +53,8 @@
f5835d
 #include "xmalloc.h"
f5835d
 #include "match.h"
f5835d
 #include "log.h"
f5835d
-#include "buffer.h"
f5835d
-#include "key.h"
f5835d
+#include "sshbuf.h"
f5835d
+#include "sshkey.h"
f5835d
 #include "misc.h"
f5835d
 
f5835d
 
f5835d
@@ -80,7 +80,7 @@ pamsshagentauth_auth_secure_path(const c
f5835d
 	int comparehome = 0;
f5835d
 	struct stat st;
f5835d
 
f5835d
-    pamsshagentauth_verbose("auth_secure_filename: checking for uid: %u", uid);
f5835d
+    verbose("auth_secure_filename: checking for uid: %u", uid);
f5835d
 
f5835d
 	if (realpath(name, buf) == NULL) {
f5835d
 		snprintf(err, errlen, "realpath %s failed: %s", name,
f5835d
@@ -115,9 +115,9 @@ pamsshagentauth_auth_secure_path(const c
f5835d
 			snprintf(err, errlen, "dirname() failed");
f5835d
 			return -1;
f5835d
 		}
f5835d
-		pamsshagentauth_strlcpy(buf, cp, sizeof(buf));
f5835d
+		strlcpy(buf, cp, sizeof(buf));
f5835d
 
f5835d
-		pamsshagentauth_verbose("secure_filename: checking '%s'", buf);
f5835d
+		verbose("secure_filename: checking '%s'", buf);
f5835d
 		if (stat(buf, &st) < 0 ||
f5835d
 		    (st.st_uid != 0 && st.st_uid != uid) ||
f5835d
 		    (st.st_mode & 022) != 0) {
f5835d
@@ -128,7 +128,7 @@ pamsshagentauth_auth_secure_path(const c
f5835d
 
f5835d
 		/* If are passed the homedir then we can stop */
f5835d
 		if (comparehome && strcmp(homedir, buf) == 0) {
f5835d
-			pamsshagentauth_verbose("secure_filename: terminating check at '%s'",
f5835d
+			verbose("secure_filename: terminating check at '%s'",
f5835d
 			    buf);
f5835d
 			break;
f5835d
 		}
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c	2018-08-24 10:22:13.202657025 +0200
f5835d
@@ -37,10 +37,11 @@
f5835d
 #include "xmalloc.h"
f5835d
 #include "ssh.h"
f5835d
 #include "ssh2.h"
f5835d
-#include "buffer.h"
f5835d
+#include "sshbuf.h"
f5835d
 #include "log.h"
f5835d
 #include "compat.h"
f5835d
-#include "key.h"
f5835d
+#include "sshkey.h"
f5835d
+#include "ssherr.h"
f5835d
 #include "pathnames.h"
f5835d
 #include "misc.h"
f5835d
 #include "secure_filename.h"
f5835d
@@ -48,54 +48,59 @@
f5835d
 #include "identity.h"
f5835d
 #include "pam_user_authorized_keys.h"
f5835d
 
f5835d
+#define SSH2_MSG_USERAUTH_TRUST_REQUEST          54
f5835d
+
f5835d
 /* extern u_char  *session_id2;
f5835d
 extern uint8_t  session_id_len;
f5835d
  */
f5835d
 
f5835d
 int
f5835d
-userauth_pubkey_from_id(const char *ruser, Identity * id, Buffer * session_id2)
f5835d
+userauth_pubkey_from_id(const char *ruser, Identity * id, struct sshbuf * session_id2)
f5835d
 {
f5835d
-    Buffer          b = { 0 };
f5835d
+    struct sshbuf  *b = NULL;
f5835d
     char           *pkalg = NULL;
f5835d
     u_char         *pkblob = NULL, *sig = NULL;
f5835d
-    u_int           blen = 0, slen = 0;
f5835d
+    size_t          blen = 0, slen = 0;
f5835d
-    int             authenticated = 0;
f5835d
+    int             r, authenticated = 0;
f5835d
 
f5835d
-    pkalg = (char *) key_ssh_name(id->key);
f5835d
+    pkalg = (char *) sshkey_ssh_name(id->key);
f5835d
 
f5835d
     /* first test if this key is even allowed */
f5835d
     if(! pam_user_key_allowed(ruser, id->key))
f5835d
-        goto user_auth_clean_exit;
f5835d
+        goto user_auth_clean_exit_without_buffer;
f5835d
 
f5835d
-    if(pamsshagentauth_key_to_blob(id->key, &pkblob, &blen) == 0)
f5835d
-        goto user_auth_clean_exit;
f5835d
+    if(sshkey_to_blob(id->key, &pkblob, &blen) != 0)
f5835d
+        goto user_auth_clean_exit_without_buffer;
f5835d
 
f5835d
     /* construct packet to sign and test */
f5835d
-    pamsshagentauth_buffer_init(&b);
f5835d
+    if ((b = sshbuf_new()) == NULL)
f5835d
+        fatal("%s: sshbuf_new failed", __func__);
f5835d
 
f5835d
-    pamsshagentauth_buffer_put_string(&b, session_id2->buf + session_id2->offset, session_id2->end - session_id2->offset);
f5835d
-    pamsshagentauth_buffer_put_char(&b, SSH2_MSG_USERAUTH_TRUST_REQUEST); 
f5835d
-    pamsshagentauth_buffer_put_cstring(&b, ruser);
f5835d
-    pamsshagentauth_buffer_put_cstring(&b, "pam_ssh_agent_auth");
f5835d
-    pamsshagentauth_buffer_put_cstring(&b, "publickey");
f5835d
-    pamsshagentauth_buffer_put_char(&b, 1);
f5835d
-    pamsshagentauth_buffer_put_cstring(&b, pkalg);
f5835d
-    pamsshagentauth_buffer_put_string(&b, pkblob, blen);
f5835d
+    if ((r = sshbuf_put_string(b, sshbuf_ptr(session_id2), sshbuf_len(session_id2))) != 0 ||
f5835d
+        (r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_TRUST_REQUEST)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(b, ruser)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(b, "pam_ssh_agent_auth")) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(b, "publickey")) != 0 ||
f5835d
+        (r = sshbuf_put_u8(b, 1)) != 0 ||
f5835d
+        (r = sshbuf_put_cstring(b, pkalg)) != 0 ||
f5835d
+        (r = sshbuf_put_string(b, pkblob, blen)) != 0)
f5835d
+        fatal("%s: buffer error: %s", __func__, ssh_err(r));
f5835d
 
f5835d
-    if(ssh_agent_sign(id->ac, id->key, &sig, &slen, pamsshagentauth_buffer_ptr(&b), pamsshagentauth_buffer_len(&b)) != 0)
f5835d
+    if (ssh_agent_sign(id->ac, id->key, &sig, &slen, sshbuf_ptr(b), sshbuf_len(b)) != 0)
f5835d
         goto user_auth_clean_exit;
f5835d
 
f5835d
     /* test for correct signature */
f5835d
-    if(pamsshagentauth_key_verify(id->key, sig, slen, pamsshagentauth_buffer_ptr(&b), pamsshagentauth_buffer_len(&b)) == 1)
f5835d
+    if (sshkey_verify(id->key, sig, slen, sshbuf_ptr(b), sshbuf_len(b), NULL, 0) == 0)
f5835d
         authenticated = 1;
f5835d
 
f5835d
   user_auth_clean_exit:
f5835d
     /* if(&b != NULL) */
f5835d
-    pamsshagentauth_buffer_free(&b);
f5835d
+    sshbuf_free(b);
f5835d
+  user_auth_clean_exit_without_buffer:
f5835d
     if(sig != NULL)
f5835d
-        pamsshagentauth_xfree(sig);
f5835d
+        free(sig);
f5835d
     if(pkblob != NULL)
f5835d
-        pamsshagentauth_xfree(pkblob);
f5835d
+        free(pkblob);
f5835d
     CRYPTO_cleanup_all_ex_data();
f5835d
     return authenticated;
f5835d
 }
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -31,7 +31,7 @@
f5835d
 #ifndef _USERAUTH_PUBKEY_FROM_ID_H
f5835d
 #define _USERAUTH_PUBKEY_FROM_ID_H
f5835d
 
f5835d
-#include <identity.h>
f5835d
-int userauth_pubkey_from_id(const char *, Identity *, Buffer *);
f5835d
+#include "identity.h"
f5835d
+int userauth_pubkey_from_id(const char *, Identity *, struct sshbuf *);
f5835d
 
f5835d
 #endif
f5835d
diff -up openssh/pam_ssh_agent_auth-0.10.3/uuencode.c.psaa-compat openssh/pam_ssh_agent_auth-0.10.3/uuencode.c
f5835d
--- openssh/pam_ssh_agent_auth-0.10.3/uuencode.c.psaa-compat	2016-11-13 04:24:32.000000000 +0100
f5835d
+++ openssh/pam_ssh_agent_auth-0.10.3/uuencode.c	2018-08-24 10:18:05.010393320 +0200
f5835d
@@ -56,7 +56,7 @@ pamsshagentauth_uudecode(const char *src
f5835d
 	/* and remove trailing whitespace because __b64_pton needs this */
f5835d
 	*p = '\0';
f5835d
 	len = pamsshagentauth___b64_pton(encoded, target, targsize);
f5835d
-	pamsshagentauth_xfree(encoded);
f5835d
+	xfree(encoded);
f5835d
 	return len;
f5835d
 }
f5835d
 
f5835d
@@ -70,7 +70,7 @@ pamsshagentauth_dump_base64(FILE *fp, co
f5835d
 		fprintf(fp, "dump_base64: len > 65536\n");
f5835d
 		return;
f5835d
 	}
f5835d
-	buf = pamsshagentauth_xmalloc(2*len);
f5835d
+	buf = malloc(2*len);
f5835d
 	n = pamsshagentauth_uuencode(data, len, buf, 2*len);
f5835d
 	for (i = 0; i < n; i++) {
f5835d
 		fprintf(fp, "%c", buf[i]);
f5835d
@@ -79,5 +79,5 @@ pamsshagentauth_dump_base64(FILE *fp, co
f5835d
 	}
f5835d
 	if (i % 70 != 69)
f5835d
 		fprintf(fp, "\n");
f5835d
-	pamsshagentauth_xfree(buf);
f5835d
+	free(buf);
f5835d
 }