]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Add LDAP_OPT_KEEPCONN option
authorNadezhda Ivanova <nivanova@symas.com>
Thu, 7 Feb 2019 16:36:17 +0000 (18:36 +0200)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 28 Feb 2019 17:27:54 +0000 (17:27 +0000)
This option instructs try_read1msg to not free the connection on read error
or on Notice of disconnections, but leave it to the caller. It is needed,
for example, by back-asyncmeta, who expects to have control on when
its target connections are freed. Must be used with caution.

doc/man/man3/ldap_get_option.3
include/ldap.h
libraries/libldap/ldap-int.h
libraries/libldap/options.c
libraries/libldap/result.c

index e1ef69754fe3e8e2f9fc317e8b0bb4b960b84129..a7a2c0777e0ac46897dfaa9fd40181f22c2f8af8 100644 (file)
@@ -426,6 +426,12 @@ and the
 .BR port
 fields.
 This option is OpenLDAP specific.
+.TP
+.B LDAP_OPT_KEEPCONN
+Instructs
+.BR ldap_result (3)
+to keep the connection open on read error or if Notice of Disconnection is received. In these cases, the connection should be closed by the caller.
+This option is OpenLDAP specific.
 .SH SASL OPTIONS
 The SASL options are OpenLDAP specific.
 .TP
index 9f3351025b900b1afea2c4217770748a08e0effd..3e37e03397e97abcc123b539062757e67bf81ca0 100644 (file)
@@ -138,6 +138,7 @@ LDAP_BEGIN_DECL
 #define        LDAP_OPT_CONNECT_ASYNC          0x5010  /* create connections asynchronously */
 #define        LDAP_OPT_CONNECT_CB                     0x5011  /* connection callbacks */
 #define        LDAP_OPT_SESSION_REFCNT         0x5012  /* session reference count */
+#define        LDAP_OPT_KEEPCONN               0x5013  /* keep the connection on read error or NoD */
 
 /* OpenLDAP TLS options */
 #define LDAP_OPT_X_TLS                         0x6000
index 0037eeb0e4f28358c6714638d4ca4c8cd44c12cb..a311c7adf362f7e5fe0894ea76e4a7a987572dee 100644 (file)
@@ -146,6 +146,7 @@ LDAP_BEGIN_DECL
 #define LDAP_BOOL_TLS                  3
 #define        LDAP_BOOL_CONNECT_ASYNC         4
 #define        LDAP_BOOL_SASL_NOCANON          5
+#define        LDAP_BOOL_KEEPCONN              6
 
 #define LDAP_BOOLEANS  unsigned long
 #define LDAP_BOOL(n)   ((LDAP_BOOLEANS)1 << (n))
index 4e157ed988b7cda61479f54e0116e6ed39ff4b93..60396002515cae1c0f782deb427ef1a309141309 100644 (file)
@@ -379,6 +379,11 @@ ldap_get_option(
                rc = LDAP_OPT_SUCCESS;
                break;
 
+       case LDAP_OPT_KEEPCONN:
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_KEEPCONN);
+               rc = LDAP_OPT_SUCCESS;
+               break;
+
        case LDAP_OPT_X_KEEPALIVE_IDLE:
                * (int *) outvalue = lo->ldo_keepalive_idle;
                rc = LDAP_OPT_SUCCESS;
@@ -494,6 +499,14 @@ ldap_set_option(
                rc = LDAP_OPT_SUCCESS;
                break;
 
+       case LDAP_OPT_KEEPCONN:
+               if(invalue == LDAP_OPT_OFF) {
+                       LDAP_BOOL_CLR(lo, LDAP_BOOL_KEEPCONN);
+               } else {
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_KEEPCONN);
+               }
+               rc = LDAP_OPT_SUCCESS;
+               break;
        /* options which can withstand invalue == NULL */
        case LDAP_OPT_SERVER_CONTROLS: {
                        LDAPControl *const *controls =
index 3a5969be467d688b6bfb60c6ef66dbc4955e6d44..b42febaa354894ad5a1b8a5c16904d3f4809d278 100644 (file)
@@ -510,7 +510,9 @@ nextresp3:
                if ( err == EWOULDBLOCK ) return LDAP_MSG_X_KEEP_LOOKING;
                if ( err == EAGAIN ) return LDAP_MSG_X_KEEP_LOOKING;
                ld->ld_errno = LDAP_SERVER_DOWN;
-               --lc->lconn_refcnt;
+               if ( !LDAP_BOOL_GET( &ld->ld_options, LDAP_BOOL_KEEPCONN )) {
+                       --lc->lconn_refcnt;
+               }
                lc->lconn_status = 0;
                return -1;
 
@@ -892,7 +894,8 @@ nextresp2:
                         * RFC 4511 unsolicited (id == 0) responses
                         * shouldn't necessarily end the connection
                         */
-                       if ( lc != NULL && id != 0 ) {
+                       if ( lc != NULL && id != 0 &&
+                            !LDAP_BOOL_GET( &ld->ld_options, LDAP_BOOL_KEEPCONN )) {
                                --lc->lconn_refcnt;
                                lc = NULL;
                        }
@@ -959,7 +962,8 @@ nextresp2:
                        }
 
                        /* get rid of the connection... */
-                       if ( lc != NULL ) {
+                       if ( lc != NULL &&
+                            !LDAP_BOOL_GET( &ld->ld_options, LDAP_BOOL_KEEPCONN )) {
                                --lc->lconn_refcnt;
                        }