diff -urN ./vpopmail-5.4.13.orig/vldap.c ./vpopmail-5.4.13/vldap.c --- ./vpopmail-5.4.13.orig/vldap.c 2004-01-07 17:06:16.000000000 +0100 +++ ./vpopmail-5.4.13/vldap.c 2005-11-28 15:33:36.876644500 +0100 @@ -1335,7 +1335,13 @@ /* Set verror here and unset it when successful, is ok, because if one of these three steps fail the whole auth_connection failed */ verrori = VA_NO_AUTH_CONNECTION; - + + if (ldap_load_config != 0) + { + ldap_perror(ld,"Failed to read LDAP-Configuration"); + return -99; + } + ld = ldap_init(VLDAP_SERVER, VLDAP_PORT); if (ld == NULL) { ldap_perror(ld,"Failed to inititialize LDAP-Connection"); @@ -1404,3 +1410,67 @@ /***************************************************************************/ +int load_ldap_config (void) +{ + char configfile[256]; + char configline[1024]; + char key[1024]; + char *value; + FILE *fp; + + sprintf(configfile, "%s/etc/%s", VPOPMAILDIR, "vpopmail.ldap"); + + fp = fopen(configfile, "r"); + if (fp == NULL) + { + fprintf(stderr, "vldap: can't read settings from %s\n", configfile); + return(VA_NO_AUTH_CONNECTION); + } + + while (fgets(configline, sizeof(configline), fp)) + { + if (configline[0] == '\n' || configline[0] == '#' || configline[0] == ' ') continue; + strcpy(key,configline); + value = strstr(configline,"="); + value++; + value[strlen(value)-1] = '\0'; + strtok(key, " "); + if (strcmp(key,"server") == 0) + { + if (VLDAP_SERVER != NULL) + free (VLDAP_SERVER); + VLDAP_SERVER = (char *) safe_strdup(value); + } + else if (strcmp(key,"port") == 0) + VLDAP_PORT = atoi(value); + else if (strcmp(key,"user") == 0) + { + if (VLDAP_USER != NULL) + free (VLDAP_USER); + VLDAP_USER = (char *) safe_strdup(value); + } + else if (strcmp(key,"password") == 0) + { + if (VLDAP_PASSWORD != NULL) + free (VLDAP_PASSWORD); + VLDAP_PASSWORD = (char *) safe_strdup(value); + } + else if (strcmp(key,"basedn") == 0) + { + if (VLDAP_BASEDN != NULL) + free (VLDAP_BASEDN); + VLDAP_BASEDN = (char *) safe_strdup(value); + } + } + + // check for values + if (VLDAP_SERVER == NULL || VLDAP_USER == NULL || VLDAP_PASSWORD == NULL || VLDAP_BASEDN == NULL) + { + fprintf(stderr, "vldap: some required settings missing in %s\n", configfile); + return(VA_NO_AUTH_CONNECTION); + } + + return 0; +} + +/***************************************************************************/ diff -urN ./vpopmail-5.4.13.orig/vldap.h ./vpopmail-5.4.13/vldap.h --- ./vpopmail-5.4.13.orig/vldap.h 2003-12-22 13:08:10.000000000 +0100 +++ ./vpopmail-5.4.13/vldap.h 2005-11-28 15:29:58.354987750 +0100 @@ -28,11 +28,13 @@ #ifndef VPOPMAIL_LDAP_H #define VPOPMAIL_LDAP_H -#define VLDAP_SERVER "localhost" -#define VLDAP_PORT LDAP_PORT -#define VLDAP_USER "cn=vpopmailuser, o=vpopmail" -#define VLDAP_PASSWORD "vpoppasswd" -#define VLDAP_BASEDN "o=vpopmail" +char *VLDAP_SERVER; +int VLDAP_PORT = 389; +char *VLDAP_USER; +char *VLDAP_PASSWORD; +char *VLDAP_BASEDN; + +int ldap_load_config(); #define MAX_BUFF 500