File nss_ldap-getent-retry.dif of Package nss_ldap

bnc#662752, PADL#215

Index: nss_ldap-265/ldap-nss.c
===================================================================
--- nss_ldap-265.orig/ldap-nss.c
+++ nss_ldap-265/ldap-nss.c
@@ -2033,6 +2033,7 @@ _nss_ldap_ent_context_init_locked (ent_c
   ctx->ec_msgid = -1;
   ctx->ec_sd = NULL;
   ctx->ec_eof = 0;
+  ctx->ec_ldaprc = 0;
 
   LS_INIT (ctx->ec_state);
 
@@ -2067,6 +2068,7 @@ do_context_release (ent_context_t * ctx,
 
   ctx->ec_sd = NULL;
   ctx->ec_eof = 0;
+  ctx->ec_ldaprc = 0;
 
   LS_INIT (ctx->ec_state);
 
@@ -2491,6 +2493,7 @@ do_result (ent_context_t * ctx, int all)
 	  syslog (LOG_ERR, "nss_ldap: could not get LDAP result - %s",
 		  ldap_err2string (rc));
 	  do_close();
+          ctx->ec_ldaprc = rc;
 	  stat = NSS_UNAVAIL;
 	  break;
 	case LDAP_RES_SEARCH_ENTRY:
@@ -3395,6 +3398,9 @@ _nss_ldap_getent_ex (ldap_args_t * args,
 		     const char **user_attrs, parser_t parser)
 {
   NSS_STATUS stat = NSS_SUCCESS;
+  int retry;
+
+  retry = (__session.ls_state == LS_CONNECTED_TO_DSA ) ? 1 : 0;
 
   debug ("==> _nss_ldap_getent_ex");
 
@@ -3437,6 +3443,18 @@ next:
 
   stat = do_parse (*ctx, result, buffer, buflen, errnop, parser);
 
+  if (stat == NSS_UNAVAIL && retry &&
+      ( ((*ctx)->ec_ldaprc == LDAP_UNAVAILABLE) ||
+        ((*ctx)->ec_ldaprc == LDAP_SERVER_DOWN) )
+     )
+    {
+      retry = 0;
+      (*ctx)->ec_msgid = -1;
+      syslog (LOG_ERR, "nss_ldap: Server might have closed connection. Retrying.");
+      goto next;
+    }
+
+  retry = 0;
 #ifdef HAVE_LDAP_SEARCH_EXT
   if (stat == NSS_NOTFOUND)
     {
Index: nss_ldap-265/ldap-nss.h
===================================================================
--- nss_ldap-265.orig/ldap-nss.h
+++ nss_ldap-265/ldap-nss.h
@@ -570,6 +570,7 @@ struct ent_context
 {
   ldap_state_t ec_state;	/* eg. for services */
   int ec_msgid;			/* message ID */
+  int ec_ldaprc;		/* LDAP error code */
   LDAPMessage *ec_res;		/* result chain */
   ldap_service_search_descriptor_t *ec_sd;	/* current sd */
   struct berval *ec_cookie;     /* cookie for paged searches */
openSUSE Build Service is sponsored by