#include <ac/socket.h>
#include <ac/string.h>
+#include <ac/ctype.h>
#include <ac/time.h>
#include "ldap-int.h"
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},
{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)},
{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")
static void openldap_ldap_init_w_conf(const char *file)
{
- char buf[MAX_LDAP_ATTR_LEN];
char linebuf[128];
FILE *fp;
int i;
char *cmd, *opt;
char *start, *end;
+ if (file == NULL) {
+ /* no file name */
+ return;
+ }
+
fp = fopen(file, "r");
if(fp == NULL) {
/* could not open file */
case ATTR_STRING:
if (* (char**) p != NULL) free(* (char**) p);
- * (char**) p = strdup(opt);
+ * (char**) p = ldap_strdup(opt);
break;
}
}
static void openldap_ldap_init_w_userconf(const char *file)
{
- char *home = getenv("HOME");
- char *path = malloc(strlen(home) + strlen(file) + 3);
+ char *home;
+ char *path;
+
+ if (file == NULL) {
+ /* no file name */
+ return;
+ }
+
+ home = getenv("HOME");
- /* try ~/file */
- sprintf(path, "%s/%s", home, file);
- openldap_ldap_init_w_conf(path);
+ if (home != NULL) {
+ path = malloc(strlen(home) + strlen(file) + 3);
+ } else {
+ path = malloc(strlen(file) + 3);
+ }
- /* try ~/.file */
- sprintf(path, "%s/.%s", home, file);
- openldap_ldap_init_w_conf(path);
+ 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);
+
+ /* try ~/.file */
+ sprintf(path, "%s/.%s", home, file);
+ openldap_ldap_init_w_conf(path);
+ }
+
+ if(path != NULL) {
+ free(path);
+ }
/* try file */
openldap_ldap_init_w_conf(file);
-
- /* try .file */
- sprintf(path, "%s/.%s", home, file);
- openldap_ldap_init_w_conf(path);
}
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;
}
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;
openldap_ldap_init_w_conf(DEFAULT_LDAP_CONF_FILE);
openldap_ldap_init_w_userconf(DEFAULT_LDAP_USERRC_FILE);
+
+ {
+ char *altfile = getenv("LDAPRC");
+
+ if( altfile != NULL ) {
+ openldap_ldap_init_w_conf( altfile );
+ }
+ }
+
openldap_ldap_init_w_env(NULL);
openldap_ldap_initialized = 1;