jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone

Blame SOURCES/pam_ssh_agent_auth-0.10.2-compat.patch

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