rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/pam_ssh_agent_auth-0.10.2-compat.patch

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