Blame SOURCES/0021-backport-the-pam_authc_ppolicy-option.patch

09a3f6
From 4861574af285c3ad0188424a567648673cfd7556 Mon Sep 17 00:00:00 2001
09a3f6
From: Jakub Hrozek <jhrozek@redhat.com>
09a3f6
Date: Wed, 14 Aug 2019 09:33:59 +0200
09a3f6
Subject: [PATCH 21/23] backport the pam_authc_ppolicy option
09a3f6
09a3f6
---
09a3f6
 man/nslcd.conf.5.xml | 12 ++++++++++++
09a3f6
 nslcd/cfg.c          | 11 +++++++++++
09a3f6
 nslcd/cfg.h          |  3 +++
09a3f6
 nslcd/myldap.c       | 19 +++++++++++--------
09a3f6
 4 files changed, 37 insertions(+), 8 deletions(-)
09a3f6
09a3f6
diff --git a/man/nslcd.conf.5.xml b/man/nslcd.conf.5.xml
09a3f6
index d7fa9b8..7c2d45a 100644
09a3f6
--- a/man/nslcd.conf.5.xml
09a3f6
+++ b/man/nslcd.conf.5.xml
09a3f6
@@ -733,6 +733,18 @@
09a3f6
      </listitem>
09a3f6
     </varlistentry>
09a3f6
 
09a3f6
+    <varlistentry id="pam_authc_ppolicy"> 
09a3f6
+     <term><option>pam_authc_ppolicy</option> yes|no</term>
09a3f6
+     <listitem>
09a3f6
+      <para>
09a3f6
+       This option specifies whether password policy controls are requested
09a3f6
+       and handled from the LDAP server when performing
09a3f6
+       user authentication.
09a3f6
+       By default the controls are requested and handled if available.
09a3f6
+      </para>
09a3f6
+     </listitem>
09a3f6
+    </varlistentry>
09a3f6
+
09a3f6
     <varlistentry id="pam_authz_search">
09a3f6
      <term><option>pam_authz_search</option>
09a3f6
            <replaceable>FILTER</replaceable></term>
09a3f6
diff --git a/nslcd/cfg.c b/nslcd/cfg.c
09a3f6
index b821fcd..e11d03a 100644
09a3f6
--- a/nslcd/cfg.c
09a3f6
+++ b/nslcd/cfg.c
09a3f6
@@ -1205,6 +1205,17 @@ static void cfg_read(const char *filename,struct ldap_config *cfg)
09a3f6
     {
09a3f6
       parse_pam_password_prohibit_message_statement(filename,lnr,keyword,line,cfg);
09a3f6
     }
09a3f6
+    else if (strcasecmp(keyword, "pam_authc_ppolicy") == 0)
09a3f6
+    {
09a3f6
+#if defined(HAVE_LDAP_SASL_BIND) && defined(LDAP_SASL_SIMPLE)
09a3f6
+      get_boolean(filename,lnr,keyword,&line,&cfg->pam_authc_ppolicy);
09a3f6
+      get_eol(filename, lnr, keyword, &line);
09a3f6
+#else
09a3f6
+      log_log(LOG_ERR, "%s:%d: value %s not supported on platform",
09a3f6
+              filename, lnr, value);
09a3f6
+      exit(EXIT_FAILURE);
09a3f6
+#endif
09a3f6
+    }
09a3f6
 #ifdef ENABLE_CONFIGFILE_CHECKING
09a3f6
     /* fallthrough */
09a3f6
     else
09a3f6
diff --git a/nslcd/cfg.h b/nslcd/cfg.h
09a3f6
index 5356ace..4c044ca 100644
09a3f6
--- a/nslcd/cfg.h
09a3f6
+++ b/nslcd/cfg.h
09a3f6
@@ -156,6 +156,9 @@ struct ldap_config
09a3f6
   /* whether password changing should be denied and user prompted with
09a3f6
      this message */
09a3f6
   char *pam_password_prohibit_message;
09a3f6
+#if defined(HAVE_LDAP_SASL_BIND) && defined(LDAP_SASL_SIMPLE)
09a3f6
+  int pam_authc_ppolicy;    /* whether to send password policy controls on bind */
09a3f6
+#endif
09a3f6
 };
09a3f6
 
09a3f6
 /* this is a pointer to the global configuration, it should be available
09a3f6
diff --git a/nslcd/myldap.c b/nslcd/myldap.c
09a3f6
index 86a339e..738a782 100644
09a3f6
--- a/nslcd/myldap.c
09a3f6
+++ b/nslcd/myldap.c
09a3f6
@@ -522,18 +522,21 @@ static int do_ppolicy_bind(MYLDAP_SESSION *session, LDAP *ld, const char *uri)
09a3f6
   int rc, parserc;
09a3f6
   struct berval cred;
09a3f6
   LDAPControl passwd_policy_req;
09a3f6
-  LDAPControl *requestctrls[2];
09a3f6
+  LDAPControl *requestctrls[2] = { NULL, NULL };
09a3f6
   LDAPControl **responsectrls;
09a3f6
   int msgid;
09a3f6
   struct timeval timeout;
09a3f6
   LDAPMessage *result;
09a3f6
-  /* build password policy request control */
09a3f6
-  passwd_policy_req.ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYREQUEST;
09a3f6
-  passwd_policy_req.ldctl_value.bv_val = NULL; /* none */
09a3f6
-  passwd_policy_req.ldctl_value.bv_len = 0;
09a3f6
-  passwd_policy_req.ldctl_iscritical = 0; /* not critical */
09a3f6
-  requestctrls[0] = &passwd_policy_req;
09a3f6
-  requestctrls[1] = NULL;
09a3f6
+  /* build policy request if pam_authc_ppolicy is set */
09a3f6
+  if (nslcd_cfg->pam_authc_ppolicy)
09a3f6
+  {
09a3f6
+    passwd_policy_req.ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYREQUEST;
09a3f6
+    passwd_policy_req.ldctl_value.bv_val = NULL; /* none */
09a3f6
+    passwd_policy_req.ldctl_value.bv_len = 0;
09a3f6
+    passwd_policy_req.ldctl_iscritical = 0; /* not critical */
09a3f6
+    requestctrls[0] = &passwd_policy_req;
09a3f6
+    requestctrls[1] = NULL;
09a3f6
+  }
09a3f6
   /* build password berval */
09a3f6
   cred.bv_val = (char *)session->bindpw;
09a3f6
   cred.bv_len = (session->bindpw == NULL) ? 0 : strlen(session->bindpw);
09a3f6
-- 
09a3f6
2.20.1
09a3f6