[email protected]
[Top] [All Lists]

PERFORCE change 115063 for review

Subject: PERFORCE change 115063 for review
From: Michael Bushkov
Date: Mon, 26 Feb 2007 14:48:08 GMT
http://perforce.freebsd.org/chv.cgi?CH=115063

Change 115063 by [email protected]_nss_ldap_cached on 2007/02/26 14:47:33

        IFC

Affected files ...

.. 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapconf.c#4
 integrate
.. 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapconf.h#3
 integrate
.. 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapsearch.c#3
 integrate
.. 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/nss_ldap.c#5
 integrate
.. 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/nss_ldap.h#4
 integrate

Differences ...

==== 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapconf.c#4
 (text+ko) ====

@@ -415,9 +415,28 @@
                    }
                }
                break;
+       case 'm':
+       case 'M':
+               if (strcasecmp(fields[0], "max_conntries") == 0) {
+                   if ((field_count == 2) && 
+                       (get_number(fields[1], 0, -1, &value) ==
+                       NSS_LDAP_SUCCESS)) {
+                           conf->max_conntries = value;
+                           return (NSS_LDAP_SUCCESS);
+                   }
+               } else if (strcasecmp(fields[0], 
+                   "max_reconnect_conntries") == 0) {
+                   if ((field_count == 2) && 
+                       (get_number(fields[1], 0, -1, &value) ==
+                       NSS_LDAP_SUCCESS)) {
+                           conf->max_reconnect_conntries = value;
+                           return (NSS_LDAP_SUCCESS);
+                   }                      
+               }
+               break;
        case 'n':
        case 'N':               
-               if (strncmp(fields[0], NSS_BASE_PREFIX,
+               if (strncasecmp(fields[0], NSS_BASE_PREFIX,
                        NSS_BASE_PREFIX_SIZE) == 0) {
 
                    if ((field_count == 2) && (set_base_map(conf,
@@ -559,7 +578,14 @@
                break;
        case 'r':
        case 'R':
-               if (strcasecmp(fields[0], "rootbinddn") == 0) {
+               if (strcasecmp(fields[0], "reconnect_sleeptime") == 0) {
+                   if ((field_count == 2) && 
+                       (get_number(fields[1], 0, -1, &value) ==
+                       NSS_LDAP_SUCCESS)) {
+                           conf->reconnect_sleeptime = value;
+                           return (NSS_LDAP_SUCCESS);
+                   }
+               } else if (strcasecmp(fields[0], "rootbinddn") == 0) {
                    if (field_count == 2) {
                        free(conf->root_bind_dn);
                        conf->root_bind_dn = strdup(fields[1]);
@@ -730,7 +756,6 @@
        conf->idle_timelimit = 0;
        conf->search_timelimit = 0;
        conf->reconnect_sleeptime = 4;
-       conf->max_reconnect_sleeptime = 8;
        conf->max_conntries = 5;
        conf->max_reconnect_conntries = 2;
        conf->deref = NSS_LDAP_DEREF_NEVER;
@@ -738,7 +763,7 @@
        conf->bind_policy = NSS_LDAP_BIND_POLICY_HARD;
        conf->connect_policy = NSS_LDAP_CONNECT_POLICY_PERSIST_PERTHREAD;
        conf->restart = 0;
-       conf->debug = 0;
+       conf->debug = NSS_LDAP_LL_ERR;
        conf->page_results = NSS_LDAP_OPTION_YES;
        conf->results_page_size = NSS_LDAP_DEFAULT_RESULTS_PAGE_SIZE;
        

==== 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapconf.h#3
 (text+ko) ====

@@ -89,7 +89,6 @@
        time_t idle_timelimit;
        time_t search_timelimit;
        time_t reconnect_sleeptime;
-       time_t max_reconnect_sleeptime;
        int max_conntries;
        int max_reconnect_conntries;
        int port;

==== 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/ldapsearch.c#3
 (text+ko) ====

@@ -517,9 +517,8 @@
                case LDAP_RES_SEARCH_RESULT:
                case LDAP_RES_SEARCH_ENTRY:
                        ctx->msg = ldap_first_message(ctx->conn->ld,
-                               ctx->msg_first);
-               
-                       return (NSS_LDAP_SUCCESS);
+                               ctx->msg_first);                
+                       break;
                case LDAP_RES_SEARCH_REFERENCE:
                        /* NOT IMPLEMENTED */
                        __nss_ldap_log(NSS_LDAP_LL_ERR_INT, "search_next_def: "
@@ -539,72 +538,74 @@
                                ctx->search_request.filter);
                        return (NSS_LDAP_GENERIC_ERROR);
                }               
-       } else {
-//             printf("== %s %d\n", __FILE__, __LINE__);
+       } else 
+               ctx->msg = ldap_next_message(ctx->conn->ld, ctx->msg);
+       
+       /* 
+        * Cycling through the list of results, until we find the appropriate 
+        * one
+        */
+       while (ctx->msg != NULL &&
+               ldap_msgtype(ctx->msg) != LDAP_RES_SEARCH_ENTRY)
                ctx->msg = ldap_next_message(ctx->conn->ld, ctx->msg);
-               if (ctx->msg != NULL) {
-//                     printf("== %s %d\n", __FILE__, __LINE__);
-                       return (NSS_LDAP_SUCCESS);
-               } else {
-//                     printf("== %s %d\n", __FILE__, __LINE__);
-                       rv = ldap_parse_result(ctx->conn->ld,
-                               ctx->msg_first, &errcode, &matcheddn,
-                               &errmsg, &referrals, &server_controls,
-                               0);
-                               
-                       ldap_msgfree(ctx->msg_first);
-                       ctx->msg_first = NULL;
+       
+       if (ctx->msg != NULL)
+               return (NSS_LDAP_SUCCESS);
+       else {
+               rv = ldap_parse_result(ctx->conn->ld,
+                       ctx->msg_first, &errcode, &matcheddn,
+                       &errmsg, &referrals, &server_controls,
+                       0);
                        
+               ldap_msgfree(ctx->msg_first);
+               ctx->msg_first = NULL;
+               
 //                     printf("== %s %d\n", __FILE__, __LINE__);
-                       if (rv == LDAP_SUCCESS) {
+               if (rv == LDAP_SUCCESS) {
 //                             printf("== %s %d\n", __FILE__, __LINE__);
-                               if (server_controls != NULL) {
-                                       if (ctx->cookie != NULL) {
-                                               ber_bvfree(ctx->cookie);
-                                               ctx->cookie = NULL;
-                                       }
-                                       
-//                             printf("== %s %d\n", __FILE__, __LINE__);
-                                       rv = __nss_ldap_parse_page_control(
-                                               ctx->conn->ld, server_controls,
-                                               &abs_rescount, &ctx->cookie);   
-                               
-                                       if (rv != LDAP_SUCCESS) {
-//                                             printf("== %s %d\n", __FILE__, 
__LINE__);
-                                               // TODO: write to logs smth 
scary 
-                                       }
-                                       
-                                       ldap_controls_free(server_controls);
+                       if (server_controls != NULL) {
+                               if (ctx->cookie != NULL) {
+                                       ber_bvfree(ctx->cookie);
+                                       ctx->cookie = NULL;
                                }
                                
-//                             printf("== %s %d\n", __FILE__, __LINE__);       
                        
-                               if (errmsg != NULL)
-                                       ldap_memfree(errmsg);
-                               if (matcheddn != NULL)
-                                       ldap_memfree(matcheddn);
-                               if (referrals != NULL)
-                                   ldap_value_free(referrals);
-                       } else {
 //                             printf("== %s %d\n", __FILE__, __LINE__);
-                               // TODO: signal to logs 
-                       }
-                               
-                       if (ctx->cookie && ctx->cookie->bv_val != NULL && 
-                               (strlen(ctx->cookie->bv_val) > 0)) {
-                               rv = do_ldap_search_ext(ctx->conn, ctx->conf, 
-                                   &ctx->search_request, ctx, &ctx->msgid);
+                               rv = __nss_ldap_parse_page_control(
+                                       ctx->conn->ld, server_controls,
+                                       &abs_rescount, &ctx->cookie);   
+                       
                                if (rv != LDAP_SUCCESS) {
 //                                     printf("== %s %d\n", __FILE__, 
__LINE__);
-                                       /* TODO: check this place */
-                                       return (NSS_LDAP_SUCCESS);
-                               }                                       
-
-                               goto st;                                
-                       } else {
+                                       // TODO: write to logs smth scary 
+                               }
+                               
+                               ldap_controls_free(server_controls);
+                       }
+                       
+//                             printf("== %s %d\n", __FILE__, __LINE__);       
                        
+                       if (errmsg != NULL)
+                               ldap_memfree(errmsg);
+                       if (matcheddn != NULL)
+                               ldap_memfree(matcheddn);
+                       if (referrals != NULL)
+                           ldap_value_free(referrals);
+               } else {
 //                             printf("== %s %d\n", __FILE__, __LINE__);
+                       // TODO: signal to logs 
+               }
+                       
+               if (ctx->cookie && ctx->cookie->bv_val != NULL && 
+                       (strlen(ctx->cookie->bv_val) > 0)) {
+                       rv = do_ldap_search_ext(ctx->conn, ctx->conf, 
+                           &ctx->search_request, ctx, &ctx->msgid);
+                       if (rv != LDAP_SUCCESS) {
+                               /* TODO: check this place */
                                return (NSS_LDAP_SUCCESS);
-                       }
-               }
+                       }                                       
+
+                       goto st;                                
+               } else
+                       return (NSS_LDAP_GENERIC_ERROR);
        }
 
        return (NSS_LDAP_GENERIC_ERROR);

==== 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/nss_ldap.c#5
 (text+ko) ====

@@ -120,29 +120,38 @@
 struct nss_ldap_configuration *__nss_ldap_conf = NULL;
 int __nss_ldap_debug_level = 1;
 
-static int nss_ldap_configure();
-static void nss_ldap_atexit();
 
 static void connection_destroy_func(struct nss_ldap_connection *);
-static void parse_context_destroy_func(struct nss_ldap_parse_context *);
-       
+static int init_connection_with_reconnect(
+       struct nss_ldap_connection_method *, struct nss_ldap_connection **,
+       int *, struct nss_ldap_connection_error *);
+static int fill_conn_request_with_host(struct nss_ldap_connection_request *,
+       char const *, struct nss_ldap_configuration *);
+static int fill_conn_request_with_uri(struct nss_ldap_connection_request *,
+       char const *, struct nss_ldap_configuration *);         
+static void nss_ldap_atexit();
+static int nss_ldap_configure();
 static int nss_ldap_connection_init(struct nss_ldap_connection_method *,
        struct nss_ldap_tls_method *, struct nss_ldap_connection **,
-       struct nss_ldap_connection_error *);
+       int *, struct nss_ldap_connection_error *);
 static int nss_ldap_connection_done(struct nss_ldap_tls_method *,
        struct nss_ldap_connection *);
-
+static int nss_ldap_connection_reset(struct nss_ldap_tls_method *,
+       struct nss_ldap_connection *);
 static int nss_ldap_parse_context_init(struct nss_ldap_search_method *,
        struct nss_ldap_tls_method *, int, char const *, 
        struct nss_ldap_parse_context **, struct nss_ldap_connection *,
        struct nss_ldap_parse_context *);
 static void nss_ldap_parse_context_done(struct nss_ldap_search_method *,
        struct nss_ldap_tls_method *, struct nss_ldap_parse_context *, 
-       int);
-
+       int);   
 static int nss_ldap_get_common(int, char const *, void *, char *,
        size_t, nss_ldap_parse_next_fn, nss_ldap_parse_destroy_fn, int);
+static int nss_ldap_set_sigpipe_mask(sigset_t *);
+static int nss_ldap_unset_sigpipe_mask(sigset_t *);
+static void parse_context_destroy_func(struct nss_ldap_parse_context *);
 
+
 static int
 nss_ldap_configure()
 {
@@ -293,28 +302,30 @@
 static int
 init_connection_with_reconnect(
        struct nss_ldap_connection_method *connection_method,
-       struct nss_ldap_connection **conn,
+       struct nss_ldap_connection **conn, int *conn_tries,
        struct nss_ldap_connection_error *conn_error)
 {      
        struct nss_ldap_connection_request conn_request;
        struct nss_ldap_connection_error l_conn_err;
        StringList *cur_sl;
        size_t k;
-       time_t sleep_time;
-       int tries, sleep_tries;
+       int sleep_tries;
        int rv;
        
-       tries = 0;      
-       sleep_time = __nss_ldap_conf->reconnect_sleeptime;
+       /*
+        * We don't set 
+        * *conn_tries = 0; 
+        * here so that we can keep one connection counter for each connection 
+        * session.
+        */
        
        if (__nss_ldap_conf->hosts != NULL)
                cur_sl = __nss_ldap_conf->hosts;
        else
                cur_sl = __nss_ldap_conf->uris;
        
-       sleep_time = __nss_ldap_conf->reconnect_sleeptime;
        rv = NSS_LDAP_CONNECTION_ERROR;
-       while (tries++ < __nss_ldap_conf->max_conntries) {
+       while ((*conn_tries)++ < __nss_ldap_conf->max_conntries) {
                sleep_tries = 0;
                while (sleep_tries++ < 
__nss_ldap_conf->max_reconnect_conntries) {
                        for (k = 0; k < cur_sl->sl_cur; ++k) {
@@ -385,12 +396,11 @@
                if (__nss_ldap_conf->bind_policy == NSS_LDAP_BIND_POLICY_SOFT)
                        break;
                
-               if (sleep_time < __nss_ldap_conf->max_reconnect_sleeptime) {
+               if (*conn_tries < __nss_ldap_conf->max_conntries) {
                        __nss_ldap_log(NSS_LDAP_LL_DEBUG_INT,
                             "init_connection_with_reconnect: sleeping for"
-                            " %d secs", sleep_time);                   
-                       sleep(sleep_time);              
-                       sleep_time *= 2;
+                            " %d secs", __nss_ldap_conf->reconnect_sleeptime); 
                
+                       sleep(__nss_ldap_conf->reconnect_sleeptime);
                }
        }
        
@@ -401,7 +411,7 @@
 static int
 nss_ldap_connection_init(struct nss_ldap_connection_method *connection_method,
        struct nss_ldap_tls_method *tls_method,
-       struct nss_ldap_connection **conn,
+       struct nss_ldap_connection **conn, int *conn_tries,
        struct nss_ldap_connection_error *conn_error)
 {
        int rv;
@@ -436,7 +446,7 @@
                
        if (*conn == NULL) { /* connection is not established yet */
                rv = init_connection_with_reconnect(connection_method,
-                       conn, conn_error);
+                       conn, conn_tries, conn_error);
                if (rv != NSS_LDAP_SUCCESS) {
                        *conn = NULL;
                        rv = NS_UNAVAIL;
@@ -661,7 +671,7 @@
        struct nss_ldap_connection_error conn_error;
        struct nss_ldap_connection *conn;
        struct nss_ldap_parse_context *pctx, pctx_model;
-       int rv, conn_flag, signals_rv;
+       int conn_tries, rv, signals_rv;
        
        assert(map_id < NSS_LDAP_MAP_MAX);
        assert(filter != NULL);
@@ -678,11 +688,11 @@
 
        pctx = NULL;
        conn = NULL;
-       conn_flag = 0;
+       conn_tries = 0;
        memset(&conn_error, 0, sizeof(struct nss_ldap_connection_error));
-       while (conn_flag < 2) {
+       while (conn_tries < __nss_ldap_conf->max_conntries) {
                rv = nss_ldap_connection_init(connection_method, tls_method, 
-                       &conn, &conn_error);
+                       &conn, &conn_tries, &conn_error);
                if (rv != NS_SUCCESS) {
                    __nss_ldap_log(NSS_LDAP_LL_ERR, 
                        "nss_ldap_get_common: can't initialize the connection "
@@ -770,7 +780,7 @@
                        
                        nss_ldap_connection_reset(tls_method, conn);
                        conn = NULL;
-                       ++conn_flag;
+                       ++conn_tries;
                } else
                        break;
        }

==== 
//depot/projects/soc2006/nss_ldap_cached_openldap/nss_ldap_port/src/nss_ldap.h#4
 (text+ko) ====

_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/p4-projects
To unsubscribe, send any mail to "[email protected]"

<Prev in Thread] Current Thread [Next in Thread>
  • PERFORCE change 115063 for review, Michael Bushkov <=