lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1264 - nss-pam-ldapd/nslcd

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd commit: r1264 - nss-pam-ldapd/nslcd



Author: arthur
Date: Tue Oct 12 22:30:47 2010
New Revision: 1264
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1264

Log:
set timeout options on LDAP socket to avoid problems when the LDAP library 
hangs on a read() (e.g. at ldap_unbind())

Modified:
   nss-pam-ldapd/nslcd/myldap.c

Modified: nss-pam-ldapd/nslcd/myldap.c
==============================================================================
--- nss-pam-ldapd/nslcd/myldap.c        Mon Oct 11 22:58:05 2010        (r1263)
+++ nss-pam-ldapd/nslcd/myldap.c        Tue Oct 12 22:30:47 2010        (r1264)
@@ -622,6 +622,8 @@
 static int do_open(MYLDAP_SESSION *session)
 {
   int rc,rc2;
+  int sd=-1;
+  struct timeval tv;
   /* check if the idle time for the connection has expired */
   myldap_session_check(session);
   /* if the connection is still there (ie. ldap_unbind() wasn't
@@ -683,6 +685,15 @@
       log_log(LOG_WARNING,"ldap_unbind() failed: %s",ldap_err2string(rc2));
     return rc;
   }
+  /* set timeout options on socket to avoid hang in some cases */
+  if (ldap_get_option(session->ld,LDAP_OPT_DESC,&sd)==LDAP_SUCCESS)
+  {
+    /* ignore errors */
+    tv.tv_sec=nslcd_cfg->ldc_timelimit;
+    tv.tv_usec=500;
+    (void)setsockopt(sd,SOL_SOCKET,SO_RCVTIMEO,(void *)&tv,sizeof(tv));
+    (void)setsockopt(sd,SOL_SOCKET,SO_SNDTIMEO,(void *)&tv,sizeof(tv));
+  }
   /* update last activity and finish off state */
   time(&(session->lastactivity));
   return LDAP_SUCCESS;
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits