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

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