diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-12 20:30:47 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-12 20:30:47 +0000 |
commit | 9c5cc937bd2b49116fd197a089f221e2ab9b0081 (patch) | |
tree | 20eb49743f4caac0d9550519ca2137d294b2419c | |
parent | 4180897317467713174e698967f321ac0ce64971 (diff) |
set timeout options on LDAP socket to avoid problems when the LDAP library hangs on a read() (e.g. at ldap_unbind())
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1264 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd/myldap.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/nslcd/myldap.c b/nslcd/myldap.c index 9c97244..ac25c35 100644 --- a/nslcd/myldap.c +++ b/nslcd/myldap.c @@ -622,6 +622,8 @@ static void myldap_session_check(MYLDAP_SESSION *session) 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 @@ static int do_open(MYLDAP_SESSION *session) 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; |