]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/init.c
Insert missing ')'...
[openldap] / libraries / libldap / init.c
index 527f4e876b12340f1e6d501e1937d002afda6de8..81f31a1d8927c383dd9f8e5586b56ca84e01a2d5 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>
@@ -72,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 */
@@ -165,18 +174,25 @@ static void openldap_ldap_init_w_conf(const char *file)
 
 static void openldap_ldap_init_w_userconf(const char *file)
 {
-    if (file[file[0] == '.'] != '/') {
-       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);
@@ -185,8 +201,10 @@ static void openldap_ldap_init_w_userconf(const char *file)
                sprintf(path, "%s/.%s", home, file);
                openldap_ldap_init_w_conf(path);
        }
-       free(path);
-    }
+
+       if(path != NULL) {
+               free(path);
+       }
 
        /* try file */
        openldap_ldap_init_w_conf(file);
@@ -272,6 +290,8 @@ void openldap_ldap_initialize( void )
        gopts.ldo_timelimit = LDAP_NO_LIMIT;
        gopts.ldo_sizelimit = LDAP_NO_LIMIT;
 
+       gopts.ldo_debug = 0;
+
        gopts.ldo_defhost = ldap_strdup("localhost");
        gopts.ldo_defport = LDAP_PORT;
 
@@ -284,6 +304,12 @@ 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);
 
@@ -296,6 +322,4 @@ void openldap_ldap_initialize( void )
        }
 
        openldap_ldap_init_w_env(NULL);
-
-       openldap_ldap_initialized = 1;
 }