2 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
28 #include <atalk/globals.h>
29 #include <atalk/ldapconfig.h>
30 #include <atalk/logger.h>
31 #include <atalk/iniparser.h>
33 void acl_ldap_freeconfig(void)
35 for (int i = 0; ldap_prefs[i].name != NULL; i++) {
36 if (ldap_prefs[i].intfromarray == 0 && ldap_prefs[i].strorint == 0) {
37 free(*((char **)(ldap_prefs[i].pref)));
38 *((char **)(ldap_prefs[i].pref)) = NULL;
40 ldap_prefs[i].valid = ldap_prefs[i].valid_save;
44 int acl_ldap_readconfig(dictionary *iniconfig)
50 /* now see if its a correct pref */
51 for (i = 0; ldap_prefs[i].name != NULL; i++) {
52 if ((val = atalk_iniparser_getstring(iniconfig, INISEC_GLOBAL, ldap_prefs[i].name, NULL))) {
53 /* check if we have pre-defined values */
54 if (ldap_prefs[i].intfromarray == 0) {
55 /* no, its just a string */
56 ldap_prefs[i].valid = 0;
57 if (ldap_prefs[i].strorint)
59 *((int *)(ldap_prefs[i].pref)) = atoi(val);
61 /* store string as string */
62 *((const char **)(ldap_prefs[i].pref)) = strdup(val);
64 /* ok, we have string to int mapping for this pref
65 eg. "none", "simple", "sasl" map to 0, 128, 129 */
66 for (j = 0; prefs_array[j].pref != NULL; j++) {
67 if ((strcmp(prefs_array[j].pref, ldap_prefs[i].name) == 0)
68 && (strcmp(prefs_array[j].valuestring, val) == 0)) {
69 ldap_prefs[i].valid = 0;
70 *((int *)(ldap_prefs[i].pref)) = prefs_array[j].value;
78 /* check if the config is sane and complete */
80 ldap_config_valid = 1;
82 while(ldap_prefs[i].pref != NULL) {
83 if ( ldap_prefs[i].valid != 0) {
84 LOG(log_debug, logtype_afpd,"LDAP: Missing option: \"%s\"", ldap_prefs[i].name);
85 ldap_config_valid = 0;
91 if (ldap_config_valid) {
92 if (ldap_auth_method == LDAP_AUTH_NONE)
93 LOG(log_debug, logtype_afpd,"LDAP: Using anonymous bind.");
94 else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
95 LOG(log_debug, logtype_afpd,"LDAP: Using simple bind.");
97 ldap_config_valid = 0;
98 LOG(log_error, logtype_afpd,"LDAP: SASL not yet supported.");
101 LOG(log_info, logtype_afpd,"LDAP: not used");
104 #endif /* HAVE_LDAP */