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