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/ldapconfig.h>
29 #include <atalk/logger.h>
33 /* Parse one line. Return result in pref and val */
34 static int getpref(char *buf, char **R_pref, char **R_val)
38 /* a little pre-processing to get rid of spaces and end-of-lines */
40 while (p && isspace(*p))
42 if (!p || (*p == '\0'))
45 if ((val = strchr(p, '=')) == NULL)
47 while ((*val == '=') || (*val == ' '))
49 if ((val = strtok(val, " \n")) == NULL)
51 if ((pref = strtok(p, " =")) == NULL)
53 if ((val = strdup(val)) == NULL)
61 /* Parse the afp_ldap.conf file */
62 int acl_ldap_readconfig(char *name)
76 /* read a line from file */
77 if (!fgets(buf, LINESIZE, f) || buf[0] == '#')
80 /* parse and return pref and value */
81 if ((getpref(buf, &pref, &val)) != 0)
85 /* now see if its a correct pref */
86 while(ldap_prefs[i].pref != NULL) {
87 if ((strcmp(ldap_prefs[i].name, pref)) == 0) {
88 /* ok, found a valid pref */
90 /* check if we have pre-defined values */
91 if (0 == ldap_prefs[i].intfromarray) {
92 /* no, its just a string */
93 ldap_prefs[i].valid = 0;
94 if (0 == ldap_prefs[i].strorint)
95 /* store string as string */
96 *((char **)(ldap_prefs[i].pref)) = val;
99 *((int *)(ldap_prefs[i].pref)) = atoi(val);
101 /* ok, we have string to int mapping for this pref
102 eg. "none", "simple", "sasl" map to 0, 128, 129 */
104 while(prefs_array[j].pref != NULL) {
105 if (((strcmp(prefs_array[j].pref, pref)) == 0) &&
106 ((strcmp(prefs_array[j].valuestring, val)) == 0)) {
107 ldap_prefs[i].valid = 0;
108 *((int *)(ldap_prefs[i].pref)) = prefs_array[j].value;
112 } /* if else 0 == ldap_prefs*/
117 if (ldap_prefs[i].pref == NULL)
118 LOG(log_error, logtype_afpd,"afp_ldap.conf: Unknown option: \"%s\"", pref);
121 /* check if the config is sane and complete */
123 ldap_config_valid = 1;
125 while(ldap_prefs[i].pref != NULL) {
126 if ( ldap_prefs[i].valid != 0) {
127 LOG(log_debug, logtype_afpd,"afp_ldap.conf: Missing option: \"%s\"", ldap_prefs[i].name);
128 ldap_config_valid = 0;
134 if (ldap_config_valid) {
135 if (ldap_auth_method == LDAP_AUTH_NONE)
136 LOG(log_debug, logtype_afpd,"afp_ldap.conf: Using anonymous bind.");
137 else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
138 LOG(log_debug, logtype_afpd,"afp_ldap.conf: Using simple bind.");
140 ldap_config_valid = 0;
141 LOG(log_error, logtype_afpd,"afp_ldap.conf: SASL not yet supported.");
144 LOG(log_info, logtype_afpd,"afp_ldap.conf: not used");
148 #endif /* HAVE_LDAP */