]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/init.c
happy new year
[openldap] / libraries / libldap / init.c
index bea29978139b36e6467f7852f72a415d1b983276..0139c0f7ca329fe70cd581941963c01967355ae1 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,7 @@
 
 #include "ldap-int.h"
 #include "ldap_defaults.h"
+#include "lutil.h"
 
 struct ldapoptions ldap_int_global_options =
        { LDAP_UNINITIALIZED, LDAP_DEBUG_NONE };  
@@ -43,6 +44,9 @@ struct ldapoptions ldap_int_global_options =
 #define ATTR_SASL      6
 #define ATTR_TLS       7
 
+#define ATTR_OPT_TV    8
+#define ATTR_OPT_INT   9
+
 struct ol_keyvalue {
        const char *            key;
        int                     value;
@@ -63,6 +67,9 @@ static const struct ol_attribute {
        const void *    data;
        size_t          offset;
 } attrs[] = {
+       {0, ATTR_OPT_TV,        "TIMEOUT",              NULL,   LDAP_OPT_TIMEOUT},
+       {0, ATTR_OPT_TV,        "NETWORK_TIMEOUT",      NULL,   LDAP_OPT_NETWORK_TIMEOUT},
+       {0, ATTR_OPT_INT,       "VERSION",              NULL,   LDAP_OPT_PROTOCOL_VERSION},
        {0, ATTR_KV,            "DEREF",        deref_kv, /* or &deref_kv[0] */
                offsetof(struct ldapoptions, ldo_deref)},
        {0, ATTR_INT,           "SIZELIMIT",    NULL,
@@ -78,7 +85,10 @@ static const struct ol_attribute {
        {0, ATTR_OPTION,        "HOST",                 NULL,   LDAP_OPT_HOST_NAME}, /* deprecated */
        {0, ATTR_OPTION,        "URI",                  NULL,   LDAP_OPT_URI}, /* replaces HOST/PORT */
        {0, ATTR_BOOL,          "REFERRALS",    NULL,   LDAP_BOOL_REFERRALS},
+#if 0
+       /* This should only be allowed via ldap_set_option(3) */
        {0, ATTR_BOOL,          "RESTART",              NULL,   LDAP_BOOL_RESTART},
+#endif
 
 #ifdef HAVE_CYRUS_SASL
        {0, ATTR_STRING,        "SASL_MECH",            NULL,
@@ -203,10 +213,15 @@ static void openldap_ldap_init_w_conf(
 
                                break;
 
-                       case ATTR_INT:
+                       case ATTR_INT: {
+                               char *next;
+                               long l;
                                p = &((char *) gopts)[attrs[i].offset];
-                               * (int*) p = atoi(opt);
-                               break;
+                               l = strtol( opt, &next, 10 );
+                               if ( next != opt && next[ 0 ] == '\0' ) {
+                                       * (int*) p = l;
+                               }
+                               } break;
 
                        case ATTR_KV: {
                                        const struct ol_keyvalue *kv;
@@ -241,6 +256,25 @@ static void openldap_ldap_init_w_conf(
                                ldap_int_tls_config( NULL, attrs[i].offset, opt );
 #endif
                                break;
+                       case ATTR_OPT_TV: {
+                               struct timeval tv;
+                               char *next;
+                               tv.tv_sec = -1;
+                               tv.tv_usec = 0;
+                               tv.tv_sec = strtol( opt, &next, 10 );
+                               if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
+                                       (void)ldap_set_option( NULL, attrs[i].offset, (const void *)&tv );
+                               }
+                               } break;
+                       case ATTR_OPT_INT: {
+                               long l;
+                               char *next;
+                               l = strtol( opt, &next, 10 );
+                               if ( next != opt && next[ 0 ] == '\0' && l > 0 && (long)((int)l) == l ) {
+                                       int v = (int)l;
+                                       (void)ldap_set_option( NULL, attrs[i].offset, (const void *)&v );
+                               }
+                               } break;
                        }
 
                        break;