2 $Id: ldap_config.c,v 1.4 2009-11-28 11:10:37 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 */
29 #include <atalk/ldapconfig.h>
30 #include <atalk/logger.h>
34 /* Parse one line. Return result in pref and val */
35 static int getpref(char *buf, char **R_pref, char **R_val)
39 /* a little pre-processing to get rid of spaces and end-of-lines */
41 while (p && isspace(*p))
43 if (!p || (*p == '\0'))
46 if ((val = strchr(p, '=')) == NULL)
48 while ((*val == '=') || (*val == ' '))
50 if ((val = strtok(val, " \n")) == NULL)
52 if ((val = strdup(val)) == NULL)
54 if ((pref = strtok(p, " =")) == NULL)
62 /* Parse the afp_ldap.conf file */
63 int acl_ldap_readconfig(char *name)
77 /* read a line from file */
78 if (!fgets(buf, LINESIZE, f) || buf[0] == '#')
81 /* parse and return pref and value */
82 if ((getpref(buf, &pref, &val)) != 0)
86 /* now see if its a correct pref */
87 while(ldap_prefs[i].pref != NULL) {
88 if ((strcmp(ldap_prefs[i].name, pref)) == 0) {
89 /* ok, found a valid pref */
91 /* check if we have pre-defined values */
92 if (0 == ldap_prefs[i].intfromarray) {
93 /* no, its just a string */
94 ldap_prefs[i].valid = 0;
95 if (0 == ldap_prefs[i].strorint)
96 /* store string as string */
97 *((char **)(ldap_prefs[i].pref)) = val;
100 *((int *)(ldap_prefs[i].pref)) = atoi(val);
102 /* ok, we have string to int mapping for this pref
103 eg. "none", "simple", "sasl" map to 0, 128, 129 */
105 while(prefs_array[j].pref != NULL) {
106 if (((strcmp(prefs_array[j].pref, pref)) == 0) &&
107 ((strcmp(prefs_array[j].valuestring, val)) == 0)) {
108 ldap_prefs[i].valid = 0;
109 *((int *)(ldap_prefs[i].pref)) = prefs_array[j].value;
113 } /* if else 0 == ldap_prefs*/
118 if (ldap_prefs[i].pref == NULL)
119 LOG(log_error, logtype_afpd,"afp_ldap.conf: Unknown option: \"%s\"", pref);
122 /* check if the config is sane and complete */
124 ldap_config_valid = 1;
126 while(ldap_prefs[i].pref != NULL) {
127 if ( ldap_prefs[i].valid != 0) {
128 LOG(log_error, logtype_afpd,"afp_ldap.conf: Missing option: \"%s\"", ldap_prefs[i].name);
129 ldap_config_valid = 0;
135 if (ldap_config_valid) {
136 if (ldap_auth_method == LDAP_AUTH_NONE)
137 LOG(log_debug, logtype_afpd,"ldappref: Pref is ok. Using anonymous bind.");
138 else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
139 LOG(log_debug, logtype_afpd,"ldappref: Pref is ok. Using simple bind.");
141 ldap_config_valid = 0;
142 LOG(log_error, logtype_afpd,"ldappref: Pref not ok. SASL not yet supported.");
145 LOG(log_error, logtype_afpd,"ldappref: Pref is not ok.");
149 #endif /* HAVE_ACLS */