jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone

Blame SOURCES/pam_ssh_agent_auth-0.10.2-compat.patch

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