Blame SOURCES/0017-Backport-of-passing-expiration-controls-back-to-PAM-.patch

09a3f6
From 289cd5ab7d125c8eb4a5e85800ab8f5f54dc4519 Mon Sep 17 00:00:00 2001
09a3f6
From: Jakub Hrozek <jhrozek@redhat.com>
09a3f6
Date: Tue, 13 Aug 2019 22:06:12 +0200
09a3f6
Subject: [PATCH 17/23] Backport of passing expiration controls back to PAM
09a3f6
 client
09a3f6
09a3f6
---
09a3f6
 nslcd/myldap.c | 11 +++++++++++
09a3f6
 nslcd/myldap.h |  5 +++++
09a3f6
 nslcd/pam.c    | 15 ++++++++++++---
09a3f6
 3 files changed, 28 insertions(+), 3 deletions(-)
09a3f6
09a3f6
diff --git a/nslcd/myldap.c b/nslcd/myldap.c
09a3f6
index 64b7f13..9f6b4b0 100644
09a3f6
--- a/nslcd/myldap.c
09a3f6
+++ b/nslcd/myldap.c
09a3f6
@@ -1024,6 +1024,17 @@ void myldap_set_credentials(MYLDAP_SESSION *session,const char *dn,
09a3f6
   session->bindpw[sizeof(session->bindpw)-1]='\0';
09a3f6
 }
09a3f6
 
09a3f6
+/* Get bind ppolicy results from the last bind operation. This function
09a3f6
+   returns a NSLCD_PAM_* code and optional message. */
09a3f6
+void myldap_get_policy_response(MYLDAP_SESSION *session, int *response,
09a3f6
+                                const char **message)
09a3f6
+{
09a3f6
+  if (response != NULL)
09a3f6
+    *response = session->policy_response;
09a3f6
+  if (message != NULL)
09a3f6
+    *message = session->policy_message;
09a3f6
+}
09a3f6
+
09a3f6
 static int do_try_search(MYLDAP_SEARCH *search)
09a3f6
 {
09a3f6
   int rc;
09a3f6
diff --git a/nslcd/myldap.h b/nslcd/myldap.h
09a3f6
index f118f72..3a99765 100644
09a3f6
--- a/nslcd/myldap.h
09a3f6
+++ b/nslcd/myldap.h
09a3f6
@@ -72,6 +72,11 @@ MUST_USE MYLDAP_SESSION *myldap_create_session(void);
09a3f6
 void myldap_set_credentials(MYLDAP_SESSION *session,const char *dn,
09a3f6
                             const char *password);
09a3f6
 
09a3f6
+/* Get bind ppolicy results from the last bind operation. This function
09a3f6
+   returns a NSLCD_PAM_* code and optional message. */
09a3f6
+void myldap_get_policy_response(MYLDAP_SESSION *session, int *response,
09a3f6
+                                const char **message);
09a3f6
+
09a3f6
 /* Closes all pending searches and deallocates any memory that is allocated
09a3f6
    with these searches. This does not close the session. */
09a3f6
 void myldap_session_cleanup(MYLDAP_SESSION *session);
09a3f6
diff --git a/nslcd/pam.c b/nslcd/pam.c
09a3f6
index ee28725..40a8687 100644
09a3f6
--- a/nslcd/pam.c
09a3f6
+++ b/nslcd/pam.c
09a3f6
@@ -41,13 +41,15 @@
09a3f6
 
09a3f6
 /* set up a connection and try to bind with the specified DN and password,
09a3f6
    returns an LDAP result code */
09a3f6
-static int try_bind(const char *userdn,const char *password)
09a3f6
+static int try_bind(const char *userdn,const char *password,
09a3f6
+                    int *authzrc, char *authzmsg, size_t authzmsgsz)
09a3f6
 {
09a3f6
   MYLDAP_SESSION *session;
09a3f6
   MYLDAP_SEARCH *search;
09a3f6
   MYLDAP_ENTRY *entry;
09a3f6
   static const char *attrs[2];
09a3f6
   int rc;
09a3f6
+  const char *msg;
09a3f6
   /* set up a new connection */
09a3f6
   session=myldap_create_session();
09a3f6
   if (session==NULL)
09a3f6
@@ -74,6 +76,13 @@ static int try_bind(const char *userdn,const char *password)
09a3f6
       log_log(LOG_WARNING,"%s: lookup failed: %s",userdn,ldap_err2string(rc));
09a3f6
     }
09a3f6
   }
09a3f6
+  /* get any policy response from the bind */
09a3f6
+  myldap_get_policy_response(session, authzrc, &msg;;
09a3f6
+  if ((msg != NULL) && (msg[0] != '\0'))
09a3f6
+  {
09a3f6
+    mysnprintf(authzmsg, authzmsgsz - 1, "%s", msg);
09a3f6
+    log_log(LOG_WARNING, "%s: %s", userdn, authzmsg);
09a3f6
+  }
09a3f6
   /* close the session */
09a3f6
   myldap_session_close(session);
09a3f6
   /* return results */
09a3f6
@@ -297,7 +306,7 @@ int nslcd_pam_authc(TFILE *fp,MYLDAP_SESSION *session,uid_t calleruid)
09a3f6
     update_username(entry,username,sizeof(username));
09a3f6
   }
09a3f6
   /* try authentication */
09a3f6
-  rc=try_bind(userdn,password);
09a3f6
+  rc = try_bind(userdn, password, &authzrc, authzmsg, sizeof(authzmsg));
09a3f6
   if (rc==LDAP_SUCCESS)
09a3f6
     log_log(LOG_DEBUG,"bind successful");
09a3f6
   /* map result code */
09a3f6
@@ -308,7 +317,7 @@ int nslcd_pam_authc(TFILE *fp,MYLDAP_SESSION *session,uid_t calleruid)
09a3f6
     default:                       rc=NSLCD_PAM_AUTH_ERR;
09a3f6
   }
09a3f6
   /* perform shadow attribute checks */
09a3f6
-  if (*username!='\0')
09a3f6
+  if ((*username != '\0') && (authzrc == NSLCD_PAM_SUCCESS))
09a3f6
     authzrc=check_shadow(session,username,authzmsg,sizeof(authzmsg),1,0);
09a3f6
   /* write response */
09a3f6
   WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
09a3f6
-- 
09a3f6
2.20.1
09a3f6