]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/init.c
LDAP C-API changes
[openldap] / libraries / libldap / init.c
index 57f6d2423f0fc3a7edff2be57b91137c12049d66..c79bdb93cfa3b9bdc77f9be3461842cff0ceeb85 100644 (file)
@@ -72,6 +72,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 */
@@ -156,7 +161,7 @@ static void openldap_ldap_init_w_conf(const char *file)
 
                        case ATTR_STRING:
                                if (* (char**) p != NULL) free(* (char**) p);
-                               * (char**) p = strdup(opt);
+                               * (char**) p = ldap_strdup(opt);
                                break;
                        }
                }
@@ -165,17 +170,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);
@@ -185,6 +198,10 @@ 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);
 }
@@ -251,7 +268,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
                        if (*value == '\0') {
                                * (char**) p = NULL;
                        } else {
-                               * (char**) p = strdup(value);
+                               * (char**) p = ldap_strdup(value);
                        }
                        break;
                }
@@ -269,7 +286,7 @@ void openldap_ldap_initialize( void )
        gopts.ldo_timelimit = LDAP_NO_LIMIT;
        gopts.ldo_sizelimit = LDAP_NO_LIMIT;
 
-       gopts.ldo_defhost = strdup("localhost");
+       gopts.ldo_defhost = ldap_strdup("localhost");
        gopts.ldo_defport = LDAP_PORT;
 
        gopts.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;