rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/pam_ssh_agent_auth-0.10.3-agent_structure.patch

b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/get_command_line.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/get_command_line.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/get_command_line.c.psaa-agent	2017-02-14 10:19:16.466070259 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/get_command_line.c	2017-02-14 10:26:10.062866980 +0100
b58e57
@@ -65,8 +65,8 @@ proc_pid_cmdline(char *** inargv)
b58e57
                 case EOF:
b58e57
                 case '\0':
b58e57
                     if (len > 0) { 
b58e57
-                        argv = pamsshagentauth_xrealloc(argv, count + 1, sizeof(*argv));
b58e57
-                        argv[count] = pamsshagentauth_xcalloc(len + 1, sizeof(*argv[count]));
b58e57
+                        argv = xrealloc(argv, count + 1, sizeof(*argv));
b58e57
+                        argv[count] = xcalloc(len + 1, sizeof(*argv[count]));
b58e57
                         strncpy(argv[count++], argbuf, len);
b58e57
                         memset(argbuf, '\0', MAX_LEN_PER_CMDLINE_ARG + 1);
b58e57
                         len = 0;
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/identity.h.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/identity.h
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/identity.h.psaa-agent	2016-11-13 04:24:32.000000000 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/identity.h	2017-02-14 10:19:12.225071868 +0100
b58e57
@@ -38,6 +38,12 @@
b58e57
 typedef struct identity Identity;
b58e57
 typedef struct idlist Idlist;
b58e57
 
b58e57
+typedef struct {
b58e57
+       int     fd;
b58e57
+       Buffer  identities;
b58e57
+       int     howmany;
b58e57
+}      AuthenticationConnection;
b58e57
+
b58e57
 struct identity {
b58e57
     TAILQ_ENTRY(identity) next;
b58e57
     AuthenticationConnection *ac;   /* set if agent supports key */
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-agent	2017-02-14 10:19:12.224071868 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -52,12 +52,15 @@
b58e57
 #include <openssl/evp.h>
b58e57
 #include "ssh2.h"
b58e57
 #include "misc.h"
b58e57
+#include "ssherr.h"
b58e57
 
b58e57
 #include "userauth_pubkey_from_id.h"
b58e57
 #include "identity.h"
b58e57
 #include "get_command_line.h"
b58e57
 extern char **environ;
b58e57
 
b58e57
+#define PAM_SSH_AGENT_AUTH_REQUESTv1 101
b58e57
+
b58e57
 static char *
b58e57
 log_action(char ** action, size_t count)
b58e57
 {
b58e57
@@ -67,7 +70,7 @@ log_action(char ** action, size_t count)
b58e57
     if (count == 0)
b58e57
         return NULL;
b58e57
    
b58e57
-    buf = pamsshagentauth_xcalloc((count * MAX_LEN_PER_CMDLINE_ARG) + (count * 3), sizeof(*buf));
b58e57
+    buf = xcalloc((count * MAX_LEN_PER_CMDLINE_ARG) + (count * 3), sizeof(*buf));
b58e57
     for (i = 0; i < count; i++) {
b58e57
         strcat(buf, (i > 0) ? " '" : "'");
b58e57
         strncat(buf, action[i], MAX_LEN_PER_CMDLINE_ARG);
b58e57
@@ -80,12 +83,12 @@ void
b58e57
 agent_action(Buffer *buf, char ** action, size_t count)
b58e57
 {
b58e57
     size_t i;
b58e57
-    pamsshagentauth_buffer_init(buf);
b58e57
+    buffer_init(buf);
b58e57
 
b58e57
-    pamsshagentauth_buffer_put_int(buf, count);
b58e57
+    buffer_put_int(buf, count);
b58e57
 
b58e57
     for (i = 0; i < count; i++) {
b58e57
-        pamsshagentauth_buffer_put_cstring(buf, action[i]);
b58e57
+        buffer_put_cstring(buf, action[i]);
b58e57
     }
b58e57
 }
b58e57
 
b58e57
@@ -109,17 +112,17 @@ pamsshagentauth_session_id2_gen(Buffer *
b58e57
     char * retc;
b58e57
     int32_t reti;
b58e57
 
b58e57
-    rnd = pamsshagentauth_arc4random();
b58e57
+    rnd = arc4random();
b58e57
     cookie_len = ((uint8_t) rnd);
b58e57
     while (cookie_len < 16) { 
b58e57
         cookie_len += 16;                                          /* Add 16 bytes to the size to ensure that while the length is random, the length is always reasonable; ticket #18 */
b58e57
     }
b58e57
 
b58e57
-    cookie = pamsshagentauth_xcalloc(1,cookie_len);
b58e57
+    cookie = xcalloc(1,cookie_len);
b58e57
 
b58e57
     for (i = 0; i < cookie_len; i++) {
b58e57
         if (i % 4 == 0) {
b58e57
-            rnd = pamsshagentauth_arc4random();
b58e57
+            rnd = arc4random();
b58e57
         }
b58e57
         cookie[i] = (char) rnd;
b58e57
         rnd >>= 8;
b58e57
@@ -134,7 +137,7 @@ pamsshagentauth_session_id2_gen(Buffer *
b58e57
     }
b58e57
     else {
b58e57
         action_logbuf = "unknown on this platform";
b58e57
-        pamsshagentauth_buffer_init(&action_agentbuf); /* stays empty, means unavailable */
b58e57
+        buffer_init(&action_agentbuf); /* stays empty, means unavailable */
b58e57
     }
b58e57
     
b58e57
     /*
b58e57
@@ -151,35 +154,35 @@ pamsshagentauth_session_id2_gen(Buffer *
b58e57
     retc = getcwd(pwd, sizeof(pwd) - 1);
b58e57
     time(&ts);
b58e57
 
b58e57
-    pamsshagentauth_buffer_init(session_id2);
b58e57
+    buffer_init(session_id2);
b58e57
 
b58e57
-    pamsshagentauth_buffer_put_int(session_id2, PAM_SSH_AGENT_AUTH_REQUESTv1);
b58e57
-    /* pamsshagentauth_debug3("cookie: %s", pamsshagentauth_tohex(cookie, cookie_len)); */
b58e57
-    pamsshagentauth_buffer_put_string(session_id2, cookie, cookie_len);
b58e57
-    /* pamsshagentauth_debug3("user: %s", user); */
b58e57
-    pamsshagentauth_buffer_put_cstring(session_id2, user);
b58e57
-    /* pamsshagentauth_debug3("ruser: %s", ruser); */
b58e57
-    pamsshagentauth_buffer_put_cstring(session_id2, ruser);
b58e57
-    /* pamsshagentauth_debug3("servicename: %s", servicename); */
b58e57
-    pamsshagentauth_buffer_put_cstring(session_id2, servicename);
b58e57
-    /* pamsshagentauth_debug3("pwd: %s", pwd); */
b58e57
+    buffer_put_int(session_id2, PAM_SSH_AGENT_AUTH_REQUESTv1);
b58e57
+    /* debug3("cookie: %s", tohex(cookie, cookie_len)); */
b58e57
+    buffer_put_string(session_id2, cookie, cookie_len);
b58e57
+    /* debug3("user: %s", user); */
b58e57
+    buffer_put_cstring(session_id2, user);
b58e57
+    /* debug3("ruser: %s", ruser); */
b58e57
+    buffer_put_cstring(session_id2, ruser);
b58e57
+    /* debug3("servicename: %s", servicename); */
b58e57
+    buffer_put_cstring(session_id2, servicename);
b58e57
+    /* debug3("pwd: %s", pwd); */
b58e57
     if(retc)
b58e57
-        pamsshagentauth_buffer_put_cstring(session_id2, pwd);
b58e57
+        buffer_put_cstring(session_id2, pwd);
b58e57
     else
b58e57
-        pamsshagentauth_buffer_put_cstring(session_id2, "");
b58e57
-    /* pamsshagentauth_debug3("action: %s", action_logbuf); */
b58e57
-    pamsshagentauth_buffer_put_string(session_id2, action_agentbuf.buf + action_agentbuf.offset, action_agentbuf.end - action_agentbuf.offset);
b58e57
+        buffer_put_cstring(session_id2, "");
b58e57
+    /* debug3("action: %s", action_logbuf); */
b58e57
+    buffer_put_string(session_id2, sshbuf_ptr(&action_agentbuf), sshbuf_len(&action_agentbuf));
b58e57
     if (free_logbuf) { 
b58e57
         free(action_logbuf);
b58e57
-        pamsshagentauth_buffer_free(&action_agentbuf);
b58e57
+        buffer_free(&action_agentbuf);
b58e57
     }
b58e57
-    /* pamsshagentauth_debug3("hostname: %s", hostname); */
b58e57
+    /* debug3("hostname: %s", hostname); */
b58e57
     if(reti >= 0)
b58e57
-        pamsshagentauth_buffer_put_cstring(session_id2, hostname);
b58e57
+        buffer_put_cstring(session_id2, hostname);
b58e57
     else
b58e57
-        pamsshagentauth_buffer_put_cstring(session_id2, "");
b58e57
-    /* pamsshagentauth_debug3("ts: %ld", ts); */
b58e57
-    pamsshagentauth_buffer_put_int64(session_id2, (uint64_t) ts);
b58e57
+        buffer_put_cstring(session_id2, "");
b58e57
+    /* debug3("ts: %ld", ts); */
b58e57
+    buffer_put_int64(session_id2, (uint64_t) ts);
b58e57
 
b58e57
     free(cookie);
b58e57
     return;
b58e57
@@ -288,39 +291,47 @@ pamsshagentauth_find_authorized_keys(con
b58e57
 {
b58e57
     Buffer session_id2 = { 0 };
b58e57
     Identity *id;
b58e57
-    Key *key;
b58e57
     AuthenticationConnection *ac;
b58e57
-    char *comment;
b58e57
     uint8_t retval = 0;
b58e57
     uid_t uid = getpwnam(ruser)->pw_uid;
b58e57
+    struct ssh_identitylist *idlist;
b58e57
+    int r;
b58e57
+    unsigned int i;
b58e57
 
b58e57
     OpenSSL_add_all_digests();
b58e57
     pamsshagentauth_session_id2_gen(&session_id2, user, ruser, servicename);
b58e57
 
b58e57
     if ((ac = ssh_get_authentication_connection_for_uid(uid))) {
b58e57
-        pamsshagentauth_verbose("Contacted ssh-agent of user %s (%u)", ruser, uid);
b58e57
-        for (key = ssh_get_first_identity(ac, &comment, 2); key != NULL; key = ssh_get_next_identity(ac, &comment, 2)) 
b58e57
+        verbose("Contacted ssh-agent of user %s (%u)", ruser, uid);
b58e57
+		if ((r = ssh_fetch_identitylist(ac->fd, 2,
b58e57
+		    &idlist)) != 0) {
b58e57
+			if (r != SSH_ERR_AGENT_NO_IDENTITIES)
b58e57
+				fprintf(stderr, "error fetching identities for "
b58e57
+				    "protocol %d: %s\n", 2, ssh_err(r));
b58e57
+		} else {
b58e57
+		for (i = 0; i < idlist->nkeys; i++)
b58e57
         {
b58e57
-            if(key != NULL) {
b58e57
-                id = pamsshagentauth_xcalloc(1, sizeof(*id));
b58e57
-                id->key = key;
b58e57
-                id->filename = comment;
b58e57
+            if(idlist->keys[i] != NULL) {
b58e57
+                id = xcalloc(1, sizeof(*id));
b58e57
+                id->key = idlist->keys[i];
b58e57
+                id->filename = idlist->comments[i];
b58e57
                 id->ac = ac;
b58e57
                 if(userauth_pubkey_from_id(ruser, id, &session_id2)) {
b58e57
                     retval = 1;
b58e57
                 }
b58e57
-                free(id->filename);
b58e57
-                pamsshagentauth_key_free(id->key);
b58e57
                 free(id);
b58e57
                 if(retval == 1)
b58e57
                     break;
b58e57
             }
b58e57
         }
b58e57
-        pamsshagentauth_buffer_free(&session_id2);
b58e57
-        ssh_close_authentication_connection(ac);
b58e57
+        buffer_free(&session_id2);
b58e57
+        ssh_free_identitylist(idlist);
b58e57
+        ssh_close_authentication_socket(ac->fd);
b58e57
+        free(ac);
b58e57
+        }
b58e57
     }
b58e57
     else {
b58e57
-        pamsshagentauth_verbose("No ssh-agent could be contacted");
b58e57
+        verbose("No ssh-agent could be contacted");
b58e57
     }
b58e57
     /* pamsshagentauth_xfree(session_id2); */
b58e57
     EVP_cleanup();
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c.psaa-agent	2017-02-14 10:19:12.223071868 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -104,7 +104,7 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
  * a patch 8-)
b58e57
  */
b58e57
 #if ! HAVE___PROGNAME || HAVE_BUNDLE
b58e57
-    __progname = pamsshagentauth_xstrdup(servicename);
b58e57
+    __progname = xstrdup(servicename);
b58e57
 #endif
b58e57
 
b58e57
     for(i = argc, argv_ptr = (char **) argv; i > 0; ++argv_ptr, i--) {
b58e57
@@ -130,11 +130,11 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
 #endif
b58e57
     }
b58e57
 
b58e57
-    pamsshagentauth_log_init(__progname, log_lvl, facility, getenv("PAM_SSH_AGENT_AUTH_DEBUG") ? 1 : 0);
b58e57
+    log_init(__progname, log_lvl, facility, getenv("PAM_SSH_AGENT_AUTH_DEBUG") ? 1 : 0);
b58e57
     pam_get_item(pamh, PAM_USER, (void *) &user);
b58e57
     pam_get_item(pamh, PAM_RUSER, (void *) &ruser_ptr);
b58e57
 
b58e57
-    pamsshagentauth_verbose("Beginning pam_ssh_agent_auth for user %s", user);
b58e57
+    verbose("Beginning pam_ssh_agent_auth for user %s", user);
b58e57
 
b58e57
     if(ruser_ptr) {
b58e57
         strncpy(ruser, ruser_ptr, sizeof(ruser) - 1);
b58e57
@@ -149,12 +149,12 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
 #ifdef ENABLE_SUDO_HACK
b58e57
         if( (strlen(sudo_service_name) > 0) && strncasecmp(servicename, sudo_service_name, sizeof(sudo_service_name) - 1) == 0 && getenv("SUDO_USER") ) {
b58e57
             strncpy(ruser, getenv("SUDO_USER"), sizeof(ruser) - 1 );
b58e57
-            pamsshagentauth_verbose( "Using environment variable SUDO_USER (%s)", ruser );
b58e57
+            verbose( "Using environment variable SUDO_USER (%s)", ruser );
b58e57
         } else
b58e57
 #endif
b58e57
         {
b58e57
             if( ! getpwuid(getuid()) ) {
b58e57
-                pamsshagentauth_verbose("Unable to getpwuid(getuid())");
b58e57
+                verbose("Unable to getpwuid(getuid())");
b58e57
                 goto cleanexit;
b58e57
             }
b58e57
             strncpy(ruser, getpwuid(getuid())->pw_name, sizeof(ruser) - 1);
b58e57
@@ -163,11 +163,11 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
 
b58e57
     /* Might as well explicitely confirm the user exists here */
b58e57
     if(! getpwnam(ruser) ) {
b58e57
-        pamsshagentauth_verbose("getpwnam(%s) failed, bailing out", ruser);
b58e57
+        verbose("getpwnam(%s) failed, bailing out", ruser);
b58e57
         goto cleanexit;
b58e57
     }
b58e57
     if( ! getpwnam(user) ) {
b58e57
-        pamsshagentauth_verbose("getpwnam(%s) failed, bailing out", user);
b58e57
+        verbose("getpwnam(%s) failed, bailing out", user);
b58e57
         goto cleanexit;
b58e57
     }
b58e57
 
b58e57
@@ -177,8 +177,8 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
          */
b58e57
         parse_authorized_key_file(user, authorized_keys_file_input);
b58e57
     } else {
b58e57
-        pamsshagentauth_verbose("Using default file=/etc/security/authorized_keys");
b58e57
-        authorized_keys_file = pamsshagentauth_xstrdup("/etc/security/authorized_keys");
b58e57
+        verbose("Using default file=/etc/security/authorized_keys");
b58e57
+        authorized_keys_file = xstrdup("/etc/security/authorized_keys");
b58e57
     }
b58e57
 
b58e57
     /*
b58e57
@@ -187,19 +187,19 @@ pam_sm_authenticate(pam_handle_t * pamh,
b58e57
      */
b58e57
 
b58e57
     if(user && strlen(ruser) > 0) {
b58e57
-        pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
+        verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
 
b58e57
         /*
b58e57
          * 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
b58e57
          */
b58e57
         if(pamsshagentauth_find_authorized_keys(user, ruser, servicename)) { /* getpwnam(ruser)->pw_uid)) { */
b58e57
-            pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
+            logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
             retval = PAM_SUCCESS;
b58e57
         } else {
b58e57
-            pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
+            logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
b58e57
         }
b58e57
     } else {
b58e57
-        pamsshagentauth_logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
b58e57
+        logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
b58e57
     }
b58e57
 
b58e57
 cleanexit:
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c.psaa-agent	2016-11-13 04:24:32.000000000 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -117,12 +117,12 @@ parse_authorized_key_file(const char *us
b58e57
         } else {
b58e57
             slash_ptr = strchr(auth_keys_file_buf, '/');
b58e57
             if(!slash_ptr)
b58e57
-                pamsshagentauth_fatal
b58e57
+                fatal
b58e57
                     ("cannot expand tilde in path without a `/'");
b58e57
 
b58e57
             owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
b58e57
             if(owner_uname_len > (sizeof(owner_uname) - 1))
b58e57
-                pamsshagentauth_fatal("Username too long");
b58e57
+                fatal("Username too long");
b58e57
 
b58e57
             strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
b58e57
             if(!authorized_keys_file_allowed_owner_uid)
b58e57
@@ -130,11 +130,11 @@ parse_authorized_key_file(const char *us
b58e57
                     getpwnam(owner_uname)->pw_uid;
b58e57
         }
b58e57
         authorized_keys_file =
b58e57
-            pamsshagentauth_tilde_expand_filename(auth_keys_file_buf,
b58e57
+            tilde_expand_filename(auth_keys_file_buf,
b58e57
                                                   authorized_keys_file_allowed_owner_uid);
b58e57
         strncpy(auth_keys_file_buf, authorized_keys_file,
b58e57
                 sizeof(auth_keys_file_buf) - 1);
b58e57
-        pamsshagentauth_xfree(authorized_keys_file)        /* when we
b58e57
+        free(authorized_keys_file)        /* when we
b58e57
                                                               percent_expand
b58e57
                                                               later, we'd step
b58e57
                                                               on this, so free
b58e57
@@ -150,7 +150,7 @@ parse_authorized_key_file(const char *us
b58e57
     strncat(hostname, fqdn, strcspn(fqdn, "."));
b58e57
 #endif
b58e57
     authorized_keys_file =
b58e57
-        pamsshagentauth_percent_expand(auth_keys_file_buf, "h",
b58e57
+        percent_expand(auth_keys_file_buf, "h",
b58e57
                                        getpwnam(user)->pw_dir, "H", hostname,
b58e57
                                        "f", fqdn, "u", user, NULL);
b58e57
 }
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c.psaa-agent	2017-02-14 10:19:12.224071868 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/pam_user_key_allowed2.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -35,6 +35,7 @@
b58e57
 #include <sys/stat.h>
b58e57
 #include <sys/wait.h>
b58e57
 #include <fcntl.h>
b58e57
+#include <unistd.h>
b58e57
 
b58e57
 #include <pwd.h>
b58e57
 #include <stdio.h>
b58e57
@@ -53,6 +54,7 @@
b58e57
 #include "misc.h"
b58e57
 #include "secure_filename.h"
b58e57
 #include "uidswap.h"
b58e57
+#include "digest.h"
b58e57
 
b58e57
 #include "identity.h"
b58e57
 
b58e57
@@ -68,7 +70,7 @@ pamsshagentauth_check_authkeys_file(FILE
b58e57
     char *fp;
b58e57
 
b58e57
     found_key = 0;
b58e57
-    found = pamsshagentauth_key_new(key->type);
b58e57
+    found = key_new(key->type);
b58e57
 
b58e57
     while(read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
b58e57
         char *cp = NULL; /* *key_options = NULL; */
b58e57
@@ -78,11 +80,11 @@ pamsshagentauth_check_authkeys_file(FILE
b58e57
         if(!*cp || *cp == '\n' || *cp == '#')
b58e57
             continue;
b58e57
 
b58e57
-        if(pamsshagentauth_key_read(found, &cp) != 1) {
b58e57
+        if(key_read(found, &cp) != 1) {
b58e57
             /* no key? check if there are options for this key */
b58e57
             int quoted = 0;
b58e57
 
b58e57
-            pamsshagentauth_verbose("user_key_allowed: check options: '%s'", cp);
b58e57
+            verbose("user_key_allowed: check options: '%s'", cp);
b58e57
             /* key_options = cp; */
b58e57
             for(; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
b58e57
                 if(*cp == '\\' && cp[1] == '"')
b58e57
@@ -92,26 +94,26 @@ pamsshagentauth_check_authkeys_file(FILE
b58e57
             }
b58e57
             /* Skip remaining whitespace. */
b58e57
             for(; *cp == ' ' || *cp == '\t'; cp++);
b58e57
-            if(pamsshagentauth_key_read(found, &cp) != 1) {
b58e57
-                pamsshagentauth_verbose("user_key_allowed: advance: '%s'", cp);
b58e57
+            if(key_read(found, &cp) != 1) {
b58e57
+                verbose("user_key_allowed: advance: '%s'", cp);
b58e57
                 /* still no key? advance to next line */
b58e57
                 continue;
b58e57
             }
b58e57
         }
b58e57
-        if(pamsshagentauth_key_equal(found, key)) {
b58e57
+        if(key_equal(found, key)) {
b58e57
             found_key = 1;
b58e57
-            pamsshagentauth_logit("matching key found: file/command %s, line %lu", file,
b58e57
+            logit("matching key found: file/command %s, line %lu", file,
b58e57
                                   linenum);
b58e57
-            fp = pamsshagentauth_key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
b58e57
-            pamsshagentauth_logit("Found matching %s key: %s",
b58e57
-                                  pamsshagentauth_key_type(found), fp);
b58e57
+            fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
b58e57
+            logit("Found matching %s key: %s",
b58e57
+                                  key_type(found), fp);
b58e57
             free(fp);
b58e57
             break;
b58e57
         }
b58e57
     }
b58e57
-    pamsshagentauth_key_free(found);
b58e57
+    key_free(found);
b58e57
     if(!found_key)
b58e57
-        pamsshagentauth_verbose("key not found");
b58e57
+        verbose("key not found");
b58e57
     return found_key;
b58e57
 }
b58e57
 
b58e57
@@ -128,11 +130,11 @@ pamsshagentauth_user_key_allowed2(struct
b58e57
     char buf[SSH_MAX_PUBKEY_BYTES];
b58e57
 
b58e57
     /* Temporarily use the user's uid. */
b58e57
-    pamsshagentauth_verbose("trying public key file %s", file);
b58e57
+    verbose("trying public key file %s", file);
b58e57
 
b58e57
     /* Fail not so quietly if file does not exist */
b58e57
     if(stat(file, &st) < 0) {
b58e57
-        pamsshagentauth_verbose("File not found: %s", file);
b58e57
+        verbose("File not found: %s", file);
b58e57
         return 0;
b58e57
     }
b58e57
 
b58e57
@@ -144,7 +146,7 @@ pamsshagentauth_user_key_allowed2(struct
b58e57
 
b58e57
     if(pamsshagentauth_secure_filename(f, file, pw, buf, sizeof(buf)) != 0) {
b58e57
         fclose(f);
b58e57
-        pamsshagentauth_logit("Authentication refused: %s", buf);
b58e57
+        logit("Authentication refused: %s", buf);
b58e57
         return 0;
b58e57
     }
b58e57
 
b58e57
@@ -187,44 +189,44 @@ pamsshagentauth_user_key_command_allowed
b58e57
     else {
b58e57
         pw = getpwnam(authorized_keys_command_user);
b58e57
         if(pw == NULL) {
b58e57
-            pamsshagentauth_logerror("authorized_keys_command_user \"%s\" not found: %s",
b58e57
+            error("authorized_keys_command_user \"%s\" not found: %s",
b58e57
                  authorized_keys_command_user, strerror(errno));
b58e57
             return 0;
b58e57
         }
b58e57
     }
b58e57
 
b58e57
-    pamsshagentauth_temporarily_use_uid(pw);
b58e57
+    temporarily_use_uid(pw);
b58e57
 
b58e57
     if(stat(authorized_keys_command, &st) < 0) {
b58e57
-        pamsshagentauth_logerror
b58e57
+        error
b58e57
             ("Could not stat AuthorizedKeysCommand \"%s\": %s",
b58e57
              authorized_keys_command, strerror(errno));
b58e57
         goto out;
b58e57
     }
b58e57
     if(pamsshagentauth_auth_secure_path
b58e57
        (authorized_keys_command, &st, NULL, 0, errmsg, sizeof(errmsg)) != 0) {
b58e57
-        pamsshagentauth_logerror("Unsafe AuthorizedKeysCommand: %s", errmsg);
b58e57
+        error("Unsafe AuthorizedKeysCommand: %s", errmsg);
b58e57
         goto out;
b58e57
     }
b58e57
 
b58e57
     /* open the pipe and read the keys */
b58e57
     if(pipe(p) != 0) {
b58e57
-        pamsshagentauth_logerror("%s: pipe: %s", __func__, strerror(errno));
b58e57
+        error("%s: pipe: %s", __func__, strerror(errno));
b58e57
         goto out;
b58e57
     }
b58e57
 
b58e57
-    pamsshagentauth_debug("Running AuthorizedKeysCommand: \"%s\" as \"%s\" with argument: \"%s\"",
b58e57
+    debug("Running AuthorizedKeysCommand: \"%s\" as \"%s\" with argument: \"%s\"",
b58e57
                           authorized_keys_command, pw->pw_name, username);
b58e57
 
b58e57
     /* 
b58e57
      * Don't want to call this in the child, where it can fatal() and
b58e57
      * run cleanup_exit() code.
b58e57
      */
b58e57
-    pamsshagentauth_restore_uid();
b58e57
+    restore_uid();
b58e57
 
b58e57
     switch ((pid = fork())) {
b58e57
     case -1:                                              /* error */
b58e57
-        pamsshagentauth_logerror("%s: fork: %s", __func__, strerror(errno));
b58e57
+        error("%s: fork: %s", __func__, strerror(errno));
b58e57
         close(p[0]);
b58e57
         close(p[1]);
b58e57
         return 0;
b58e57
@@ -234,13 +236,13 @@ pamsshagentauth_user_key_command_allowed
b58e57
 
b58e57
         /* do this before the setresuid so thta they can be logged */
b58e57
         if((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) {
b58e57
-            pamsshagentauth_logerror("%s: open %s: %s", __func__, _PATH_DEVNULL,
b58e57
+            error("%s: open %s: %s", __func__, _PATH_DEVNULL,
b58e57
                                      strerror(errno));
b58e57
             _exit(1);
b58e57
         }
b58e57
         if(dup2(devnull, STDIN_FILENO) == -1 || dup2(p[1], STDOUT_FILENO) == -1
b58e57
            || dup2(devnull, STDERR_FILENO) == -1) {
b58e57
-            pamsshagentauth_logerror("%s: dup2: %s", __func__, strerror(errno));
b58e57
+            error("%s: dup2: %s", __func__, strerror(errno));
b58e57
             _exit(1);
b58e57
         }
b58e57
 #if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID)
b58e57
@@ -248,7 +250,7 @@ pamsshagentauth_user_key_command_allowed
b58e57
 #else
b58e57
         if (setgid(pw->pw_gid) != 0 || setegid(pw->pw_gid) != 0) {
b58e57
 #endif
b58e57
-            pamsshagentauth_logerror("setresgid %u: %s", (u_int) pw->pw_gid,
b58e57
+            error("setresgid %u: %s", (u_int) pw->pw_gid,
b58e57
                                      strerror(errno));
b58e57
             _exit(1);
b58e57
         }
b58e57
@@ -258,7 +260,7 @@ pamsshagentauth_user_key_command_allowed
b58e57
 #else
b58e57
         if (setuid(pw->pw_uid) != 0 || seteuid(pw->pw_uid) != 0) {
b58e57
 #endif
b58e57
-            pamsshagentauth_logerror("setresuid %u: %s", (u_int) pw->pw_uid,
b58e57
+            error("setresuid %u: %s", (u_int) pw->pw_uid,
b58e57
                                      strerror(errno));
b58e57
             _exit(1);
b58e57
         }
b58e57
@@ -270,18 +272,18 @@ pamsshagentauth_user_key_command_allowed
b58e57
 
b58e57
         /* pretty sure this will barf because we are now suid, but since we
b58e57
            should't reach this anyway, I'll leave it here */
b58e57
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s exec failed: %s",
b58e57
+        error("AuthorizedKeysCommand %s exec failed: %s",
b58e57
                                  authorized_keys_command, strerror(errno));
b58e57
         _exit(127);
b58e57
     default:                                              /* parent */
b58e57
         break;
b58e57
     }
b58e57
 
b58e57
-    pamsshagentauth_temporarily_use_uid(pw);
b58e57
+    temporarily_use_uid(pw);
b58e57
 
b58e57
     close(p[1]);
b58e57
     if((f = fdopen(p[0], "r")) == NULL) {
b58e57
-        pamsshagentauth_logerror("%s: fdopen: %s", __func__, strerror(errno));
b58e57
+        error("%s: fdopen: %s", __func__, strerror(errno));
b58e57
         close(p[0]);
b58e57
         /* Don't leave zombie child */
b58e57
         while(waitpid(pid, NULL, 0) == -1 && errno == EINTR);
b58e57
@@ -292,22 +294,22 @@ pamsshagentauth_user_key_command_allowed
b58e57
 
b58e57
     while(waitpid(pid, &status, 0) == -1) {
b58e57
         if(errno != EINTR) {
b58e57
-            pamsshagentauth_logerror("%s: waitpid: %s", __func__,
b58e57
+            error("%s: waitpid: %s", __func__,
b58e57
                                      strerror(errno));
b58e57
             goto out;
b58e57
         }
b58e57
     }
b58e57
     if(WIFSIGNALED(status)) {
b58e57
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s exited on signal %d",
b58e57
+        error("AuthorizedKeysCommand %s exited on signal %d",
b58e57
                                  authorized_keys_command, WTERMSIG(status));
b58e57
         goto out;
b58e57
     } else if(WEXITSTATUS(status) != 0) {
b58e57
-        pamsshagentauth_logerror("AuthorizedKeysCommand %s returned status %d",
b58e57
+        error("AuthorizedKeysCommand %s returned status %d",
b58e57
                                  authorized_keys_command, WEXITSTATUS(status));
b58e57
         goto out;
b58e57
     }
b58e57
     found_key = ok;
b58e57
   out:
b58e57
-    pamsshagentauth_restore_uid();
b58e57
+    restore_uid();
b58e57
     return found_key;
b58e57
 }
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/secure_filename.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/secure_filename.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/secure_filename.c.psaa-agent	2016-11-13 04:24:32.000000000 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/secure_filename.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -80,7 +80,7 @@ pamsshagentauth_auth_secure_path(const c
b58e57
 	int comparehome = 0;
b58e57
 	struct stat st;
b58e57
 
b58e57
-    pamsshagentauth_verbose("auth_secure_filename: checking for uid: %u", uid);
b58e57
+    verbose("auth_secure_filename: checking for uid: %u", uid);
b58e57
 
b58e57
 	if (realpath(name, buf) == NULL) {
b58e57
 		snprintf(err, errlen, "realpath %s failed: %s", name,
b58e57
@@ -115,9 +115,9 @@ pamsshagentauth_auth_secure_path(const c
b58e57
 			snprintf(err, errlen, "dirname() failed");
b58e57
 			return -1;
b58e57
 		}
b58e57
-		pamsshagentauth_strlcpy(buf, cp, sizeof(buf));
b58e57
+		strlcpy(buf, cp, sizeof(buf));
b58e57
 
b58e57
-		pamsshagentauth_verbose("secure_filename: checking '%s'", buf);
b58e57
+		verbose("secure_filename: checking '%s'", buf);
b58e57
 		if (stat(buf, &st) < 0 ||
b58e57
 		    (st.st_uid != 0 && st.st_uid != uid) ||
b58e57
 		    (st.st_mode & 022) != 0) {
b58e57
@@ -128,7 +128,7 @@ pamsshagentauth_auth_secure_path(const c
b58e57
 
b58e57
 		/* If are passed the homedir then we can stop */
b58e57
 		if (comparehome && strcmp(homedir, buf) == 0) {
b58e57
-			pamsshagentauth_verbose("secure_filename: terminating check at '%s'",
b58e57
+			verbose("secure_filename: terminating check at '%s'",
b58e57
 			    buf);
b58e57
 			break;
b58e57
 		}
b58e57
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c.psaa-agent openssh-7.4p1/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c
b58e57
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c.psaa-agent	2017-02-14 10:19:12.224071868 +0100
b58e57
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c	2017-02-14 10:19:12.226071867 +0100
b58e57
@@ -48,6 +48,8 @@
b58e57
 #include "identity.h"
b58e57
 #include "pam_user_authorized_keys.h"
b58e57
 
b58e57
+#define SSH2_MSG_USERAUTH_TRUST_REQUEST          54
b58e57
+
b58e57
 /* extern u_char  *session_id2;
b58e57
 extern uint8_t  session_id_len;
b58e57
  */
b58e57
@@ -58,40 +60,41 @@ userauth_pubkey_from_id(const char *ruse
b58e57
     Buffer          b = { 0 };
b58e57
     char           *pkalg = NULL;
b58e57
     u_char         *pkblob = NULL, *sig = NULL;
b58e57
-    u_int           blen = 0, slen = 0;
b58e57
+    u_int           blen = 0;
b58e57
+    size_t          slen = 0;
b58e57
     int             authenticated = 0;
b58e57
 
b58e57
     pkalg = (char *) key_ssh_name(id->key);
b58e57
 
b58e57
+    /* construct packet to sign and test */
b58e57
+    buffer_init(&b);
b58e57
+
b58e57
     /* first test if this key is even allowed */
b58e57
     if(! pam_user_key_allowed(ruser, id->key))
b58e57
         goto user_auth_clean_exit;
b58e57
 
b58e57
-    if(pamsshagentauth_key_to_blob(id->key, &pkblob, &blen) == 0)
b58e57
+    if(key_to_blob(id->key, &pkblob, &blen) == 0)
b58e57
         goto user_auth_clean_exit;
b58e57
 
b58e57
-    /* construct packet to sign and test */
b58e57
-    pamsshagentauth_buffer_init(&b);
b58e57
-
b58e57
-    pamsshagentauth_buffer_put_string(&b, session_id2->buf + session_id2->offset, session_id2->end - session_id2->offset);
b58e57
-    pamsshagentauth_buffer_put_char(&b, SSH2_MSG_USERAUTH_TRUST_REQUEST); 
b58e57
-    pamsshagentauth_buffer_put_cstring(&b, ruser);
b58e57
-    pamsshagentauth_buffer_put_cstring(&b, "pam_ssh_agent_auth");
b58e57
-    pamsshagentauth_buffer_put_cstring(&b, "publickey");
b58e57
-    pamsshagentauth_buffer_put_char(&b, 1);
b58e57
-    pamsshagentauth_buffer_put_cstring(&b, pkalg);
b58e57
-    pamsshagentauth_buffer_put_string(&b, pkblob, blen);
b58e57
+    buffer_put_string(&b, sshbuf_ptr(session_id2), sshbuf_len(session_id2));
b58e57
+    buffer_put_char(&b, SSH2_MSG_USERAUTH_TRUST_REQUEST); 
b58e57
+    buffer_put_cstring(&b, ruser);
b58e57
+    buffer_put_cstring(&b, "pam_ssh_agent_auth");
b58e57
+    buffer_put_cstring(&b, "publickey");
b58e57
+    buffer_put_char(&b, 1);
b58e57
+    buffer_put_cstring(&b, pkalg);
b58e57
+    buffer_put_string(&b, pkblob, blen);
b58e57
 
b58e57
-    if(ssh_agent_sign(id->ac, id->key, &sig, &slen, pamsshagentauth_buffer_ptr(&b), pamsshagentauth_buffer_len(&b)) != 0)
b58e57
+    if(ssh_agent_sign(id->ac->fd, id->key, &sig, &slen, buffer_ptr(&b), buffer_len(&b), NULL, 0) != 0)
b58e57
         goto user_auth_clean_exit;
b58e57
 
b58e57
     /* test for correct signature */
b58e57
-    if(pamsshagentauth_key_verify(id->key, sig, slen, pamsshagentauth_buffer_ptr(&b), pamsshagentauth_buffer_len(&b)) == 1)
b58e57
+    if(key_verify(id->key, sig, slen, buffer_ptr(&b), buffer_len(&b)) == 1)
b58e57
         authenticated = 1;
b58e57
 
b58e57
   user_auth_clean_exit:
b58e57
     /* if(&b != NULL) */
b58e57
-    pamsshagentauth_buffer_free(&b);
b58e57
+    buffer_free(&b);
b58e57
     if(sig != NULL)
b58e57
         free(sig);
b58e57
     if(pkblob != NULL)