]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/init.c
Don't provide ldap.OpenLDAP.org and dc=OpenLDAP, dc=Org as the defaults.
[openldap] / libraries / libldap / init.c
index 603e510ba38e9627955ea18cfb37c6f1a2185592..3da4d7bf4b2554c943a6d8a0af7cc98236b53a97 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 #include "portable.h"
 
 #include <stdio.h>
@@ -5,12 +9,13 @@
 
 #include <ac/socket.h>
 #include <ac/string.h>
+#include <ac/ctype.h>
 #include <ac/time.h>
 
 #include "ldap-int.h"
 #include "ldapconfig.h"
 
-struct ldapoptions openldap_ldap_global_options; 
+struct ldapoptions openldap_ldap_global_options = { LDAP_DEBUG_NONE };  
 
 #undef gopts
 #define gopts openldap_ldap_global_options
@@ -28,7 +33,7 @@ struct ol_keyvalue {
        int                     value;
 };
 
-struct ol_keyvalue deref_kv[] = {
+static struct ol_keyvalue deref_kv[] = {
        {"never", LDAP_DEREF_NEVER},
        {"searching", LDAP_DEREF_SEARCHING},
        {"finding", LDAP_DEREF_FINDING},
@@ -36,13 +41,13 @@ struct ol_keyvalue deref_kv[] = {
        {NULL, 0}
 };
 
-struct ol_attribute {
+static struct ol_attribute {
        int                     type;
        char*           name;
        void*           data;
        size_t          offset;
 } attrs[] = {
-       {ATTR_KV,               "DEREF",                &deref_kv,
+       {ATTR_KV,               "DEREF",        deref_kv, /* or &deref_kv[0] */
                offsetof(struct ldapoptions, ldo_deref)},
        {ATTR_INT,              "SIZELIMIT",    NULL,
                offsetof(struct ldapoptions, ldo_sizelimit)},
@@ -57,7 +62,7 @@ struct ol_attribute {
        {ATTR_BOOL,             "REFERRALS",    (void *) LDAP_BOOL_REFERRALS, 0},
        {ATTR_BOOL,             "RESTART",              (void *) LDAP_BOOL_RESTART, 0},
        {ATTR_BOOL,             "DNS",                  (void *) LDAP_BOOL_DNS, 0},
-       {ATTR_NONE,     NULL, 0}
+       {ATTR_NONE,             NULL,           NULL,   0}
 };
 
 #define MAX_LDAP_ATTR_LEN  sizeof("SIZELIMIT")
@@ -71,6 +76,11 @@ static void openldap_ldap_init_w_conf(const char *file)
        char *cmd, *opt;
        char *start, *end;
 
+       if (file == NULL) {
+               /* no file name */
+               return;
+       }
+
        fp = fopen(file, "r");
        if(fp == NULL) {
                /* could not open file */
@@ -164,17 +174,25 @@ static void openldap_ldap_init_w_conf(const char *file)
 
 static void openldap_ldap_init_w_userconf(const char *file)
 {
-       char *home = getenv("HOME");
+       char *home;
        char *path;
-       
+
+       if (file == NULL) {
+               /* no file name */
+               return;
+       }
+
+       home = getenv("HOME");
+
        if (home != NULL) {
                path = malloc(strlen(home) + strlen(file) + 3);
        } else {
                path = malloc(strlen(file) + 3);
        }
 
-
        if(home != NULL && path != NULL) {
+               /* we assume UNIX path syntax is used... */
+
                /* try ~/file */
                sprintf(path, "%s/%s", home, file);
                openldap_ldap_init_w_conf(path);
@@ -184,14 +202,12 @@ static void openldap_ldap_init_w_userconf(const char *file)
                openldap_ldap_init_w_conf(path);
        }
 
+       if(path != NULL) {
+               free(path);
+       }
+
        /* try file */
        openldap_ldap_init_w_conf(file);
-
-       if(path == NULL) {
-               /* try .file */
-               sprintf(path, ".%s", file);
-               openldap_ldap_init_w_conf(path);
-       }
 }
 
 static void openldap_ldap_init_w_env(const char *prefix)
@@ -269,11 +285,15 @@ void openldap_ldap_initialize( void )
                return;
        }
 
+       ldap_pvt_init_utils();
+
        gopts.ldo_version =     LDAP_VERSION2;
        gopts.ldo_deref =       LDAP_DEREF_NEVER;
        gopts.ldo_timelimit = LDAP_NO_LIMIT;
        gopts.ldo_sizelimit = LDAP_NO_LIMIT;
 
+       gopts.ldo_debug = 0;
+
        gopts.ldo_defhost = strdup("localhost");
        gopts.ldo_defport = LDAP_PORT;
 
@@ -286,9 +306,30 @@ void openldap_ldap_initialize( void )
        LDAP_BOOL_SET(&gopts, LDAP_BOOL_REFERRALS);
 #endif
 
+       openldap_ldap_initialized = 1;
+
+       if( getenv("LDAPNOINIT") != NULL ) {
+               return;
+       }
+
        openldap_ldap_init_w_conf(DEFAULT_LDAP_CONF_FILE);
        openldap_ldap_init_w_userconf(DEFAULT_LDAP_USERRC_FILE);
-       openldap_ldap_init_w_env(NULL);
 
-       openldap_ldap_initialized = 1;
+       {
+               char *altfile = getenv("LDAPCONF");
+
+               if( altfile != NULL ) {
+                       openldap_ldap_init_w_conf( altfile );
+               }
+       }
+
+       {
+               char *altfile = getenv("LDAPRC");
+
+               if( altfile != NULL ) {
+                       openldap_ldap_init_w_userconf( altfile );
+               }
+       }
+
+       openldap_ldap_init_w_env(NULL);
 }