2 $Id: ldap_config.c,v 1.1 2009-02-02 11:55:01 franklahm Exp $
3 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
18 #endif /* HAVE_CONFIG_H */
20 #ifdef HAVE_NFSv4_ACLS
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 ((val = strdup(val)) == NULL)
53 if ((pref = strtok(p, " =")) == NULL)
61 /* Parse the 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;
118 /* check if the config is sane and complete */
120 ldap_config_valid = 1;
122 while(ldap_prefs[i].pref != NULL) {
123 if ( ldap_prefs[i].valid != 0) {
124 ldap_config_valid = 0;
130 if (ldap_config_valid) {
131 if (ldap_auth_method == LDAP_AUTH_NONE)
132 LOG(log_debug, logtype_afpd,"ldappref: Pref is ok. Using anonymous bind.");
133 else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
134 LOG(log_debug, logtype_afpd,"ldappref: Pref is ok. Using simple bind.");
136 ldap_config_valid = 0;
137 LOG(log_error, logtype_afpd,"ldappref: Pref not ok. SASL not yet supported.");
140 LOG(log_error, logtype_afpd,"ldappref: Pref is not ok.");