]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_authnz_ldap: Allow using exec: callouts like SSLPassphraseDialog
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 26 Jun 2013 21:03:33 +0000 (21:03 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 26 Jun 2013 21:03:33 +0000 (21:03 +0000)
for AuthLDAPBindPassword.

Backports: r1433478, r1467523, r1467792
Submitted by: druggeri
Reviewed by: minfrin. wrowe

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1497095 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mod_authnz_ldap.xml
include/ap_mmn.h
include/httpd.h
modules/aaa/mod_authnz_ldap.c
server/util.c

diff --git a/CHANGES b/CHANGES
index da8578489e13938aa6b561d29aa7cd05b0bfdc32..2be12e5b6c424a9db56c48f4aa0369b66008e311 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -68,6 +68,9 @@ Changes with Apache 2.2.24
   *) mod_ssl: Add new directive SSLCompression to disable TLS-level
      compression. PR 53219. [Björn Jacke <bjoern j3e de>, Stefan Fritsch]
 
+  *) mod_authnz_ldap: Allow using exec: calls to obtain LDAP bind
+     password.  [Daniel Ruggeri]
+
 Changes with Apache 2.2.23
 
   *) SECURITY: CVE-2012-0883 (cve.mitre.org)
diff --git a/STATUS b/STATUS
index 71c6f8937a8d156b5f29b075981f82e5163ab83f..bef913714aaf6a7951df27b72432b133b9d700e5 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -114,17 +114,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
   
-  
-   * mod_authnz_ldap: Allow using exec: callouts like SSLPassphraseDialog
-     for AuthLDAPBindPassword.
-     trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1433478
-                  http://svn.apache.org/viewvc?view=revision&revision=1467523
-                  http://svn.apache.org/viewvc?view=revision&revision=1467792
-     2.2.x patch: http://people.apache.org/~druggeri/patches/AuthLDAPBindPasswordExec-2.2.patch
-                  (20130119 - updated to include minor mmn bump)
-                  (20130412 - updated to not use static var - thx, wrowe)
-     +1: druggeri, minfrin. wrowe
-
   * mod_ssl: Catch missing, mismatched or encrypted client cert/key pairs
     with SSLProxyMachineCertificateFile/Path directives. PR 52212, PR 54698.
     (check at startup, to prevent segfaults at proxy request time)
@@ -221,6 +210,12 @@ PATCHES PROPOSED TO BACKPORT FROM TRUNK:
     2.2.x patch: trunk patch works modulo CHANGES
     +1: trawick, wrowe
 
+   * mod_authnz_ldap: Allow using exec: callouts like SSLPassphraseDialog
+     for AuthLDAPBindPassword.
+     trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1433478
+     2.4.x patch: http://people.apache.org/~druggeri/patches/AuthLDAPBindPasswordExec-2.4.patch
+     +1: druggeri
+
 PATCHES/ISSUES THAT ARE STALLED
 
   * mod_cache: Realign the cache_quick_handler() to behave identically
index 4a4196252f139bba2f61a4d9771f2e92d89441d6..325e7f9d2b11c280a2022b57d7a4b7f44901b47c 100644 (file)
@@ -731,6 +731,21 @@ authenticating the user if this one fails</description>
     module="mod_authnz_ldap">AuthLDAPBindDN</directive> and <directive
     module="mod_authnz_ldap">AuthLDAPBindPassword</directive> if you
     absolutely need them to search the directory.</p> 
+
+    <p>If the value begins with exec: the resulting command will be
+    executed and the first line returned to standard output by the
+    program will be used as the password.</p>
+<example><pre>
+#Password used as-is
+AuthLDAPBindPassword secret
+
+#Run /path/to/program to get my password
+AuthLDAPBindPassword exec:/path/to/program
+
+#Run /path/to/otherProgram and provide arguments
+AuthLDAPBindPassword "exec:/path/to/otherProgram argument1"
+</pre></example>
+
 </usage>
 </directivesynopsis>
 
index f8ebeb7fae4598dde185cc2976e569f9ed273129..1b2cfa02a621aef5e8f1bbb0d9dac5a4b35547e4 100644 (file)
  * 20051115.29 (2.2.21) add max_ranges to core_dir_config
  * 20051115.30 (2.2.21) add ap_set_accept_ranges()
  * 20051115.31 (2.2.23) Add forcerecovery to proxy_balancer_shared struct
+ # 20051115.32 (2.2.24) Add ap_get_exec_line
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503232UL /* "AP22" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20051115
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 31                    /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 32                    /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index f20c87332d8a80b89f45fc35976be691bac50e37..5bf2cfe71357010578f1fee20a92c79ca9901150 100644 (file)
@@ -1867,6 +1867,19 @@ extern int raise_sigstop_flags;
  */
 AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r);
 
+
+/**
+ * Short function to execute a command and return the first line of
+ * output minus \r \n. Useful for "obscuring" passwords via exec calls
+ * @param p the pool to allocate from
+ * @param cmd the command to execute
+ * @param argv the arguments to pass to the cmd
+ * @return ptr to characters or NULL on any error
+ */
+AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
+                                    const char *cmd,
+                                    const char * const *argv);
+
 /** strtoul does not exist on sunos4. */
 #ifdef strtoul
 #undef strtoul
index ce1af3db4de82c18408505815fceae0985f32d09..630ca85da7480c144ebb2370b7705ede05e49a88 100644 (file)
@@ -1075,6 +1075,43 @@ static const char *set_charset_config(cmd_parms *cmd, void *config, const char *
     return NULL;
 }
 
+static const char *set_bind_password(cmd_parms *cmd, void *_cfg, const char *arg)
+{
+    authn_ldap_config_t *sec = _cfg;
+    int arglen = strlen(arg);
+    char **argv;
+    char *result;
+
+    if ((arglen > 5) && strncmp(arg, "exec:", 5) == 0) {
+        if (apr_tokenize_to_argv(arg+5, &argv, cmd->temp_pool) != APR_SUCCESS) {
+            return apr_pstrcat(cmd->pool,
+                               "Unable to parse exec arguments from ",
+                               arg+5, NULL);
+        }
+        argv[0] = ap_server_root_relative(cmd->temp_pool, argv[0]);
+
+        if (!argv[0]) {
+            return apr_pstrcat(cmd->pool,
+                               "Invalid AuthLDAPBindPassword exec location:",
+                               arg+5, NULL);
+        }
+        result = ap_get_exec_line(cmd->pool,
+                                  (const char*)argv[0], (const char * const *)argv);
+
+        if(!result) {
+            return apr_pstrcat(cmd->pool,
+                               "Unable to get bind password from exec of ",
+                               arg+5, NULL);
+        }
+        sec->bindpw = result;
+    }
+    else {
+        sec->bindpw = (char *)arg;
+    }
+
+    return NULL;
+}
+
 static const command_rec authnz_ldap_cmds[] =
 {
     AP_INIT_TAKE12("AuthLDAPURL", mod_auth_ldap_parse_url, NULL, OR_AUTHCFG,
@@ -1105,8 +1142,7 @@ static const command_rec authnz_ldap_cmds[] =
                   (void *)APR_OFFSETOF(authn_ldap_config_t, binddn), OR_AUTHCFG,
                   "DN to use to bind to LDAP server. If not provided, will do an anonymous bind."),
 
-    AP_INIT_TAKE1("AuthLDAPBindPassword", ap_set_string_slot,
-                  (void *)APR_OFFSETOF(authn_ldap_config_t, bindpw), OR_AUTHCFG,
+    AP_INIT_TAKE1("AuthLDAPBindPassword", set_bind_password, NULL, OR_AUTHCFG,
                   "Password to use to bind to LDAP server. If not provided, will do an anonymous bind."),
 
     AP_INIT_FLAG("AuthLDAPBindAuthoritative", ap_set_flag_slot,
index a50d0340e5aa0569deb7b399f449929c710e5aa5..b334c964537962431b60c8e4b2475f5a7cbb615b 100644 (file)
@@ -2240,3 +2240,44 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse(
     return APR_SUCCESS;
 }
 
+AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
+                                    const char *cmd,
+                                    const char * const * argv)
+{
+    char buf[MAX_STRING_LEN];
+    apr_procattr_t *procattr;
+    apr_proc_t *proc;
+    apr_file_t *fp;
+    apr_size_t nbytes = 1;
+    char c;
+    int k;
+
+    if (apr_procattr_create(&procattr, p) != APR_SUCCESS)
+        return NULL;
+    if (apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_FULL_BLOCK,
+                            APR_FULL_BLOCK) != APR_SUCCESS)
+        return NULL;
+    if (apr_procattr_dir_set(procattr,
+                             ap_make_dirstr_parent(p, cmd)) != APR_SUCCESS)
+        return NULL;
+    if (apr_procattr_cmdtype_set(procattr, APR_PROGRAM) != APR_SUCCESS)
+        return NULL;
+    proc = apr_pcalloc(p, sizeof(apr_proc_t));
+    if (apr_proc_create(proc, cmd, argv, NULL, procattr, p) != APR_SUCCESS)
+        return NULL;
+    fp = proc->out;
+
+    if (fp == NULL)
+        return NULL;
+    /* XXX: we are reading 1 byte at a time here */
+    for (k = 0; apr_file_read(fp, &c, &nbytes) == APR_SUCCESS
+                && nbytes == 1 && (k < MAX_STRING_LEN-1)     ; ) {
+        if (c == '\n' || c == '\r')
+            break;
+        buf[k++] = c;
+    }
+    buf[k] = '\0';
+    apr_file_close(fp);
+
+    return apr_pstrndup(p, buf, k);
+}