]> arthur.barton.de Git - netatalk.git/blob - libatalk/acl/ldap_config.c
d719cafdfc4a2c66ea32a4297c195fddc93e949b
[netatalk.git] / libatalk / acl / ldap_config.c
1 /*
2   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
3
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.
8
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.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif /* HAVE_CONFIG_H */
18
19 #ifdef HAVE_LDAP
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <ldap.h>
27
28 #include <atalk/ldapconfig.h>
29 #include <atalk/logger.h>
30 #include <atalk/iniparser.h>
31
32 int acl_ldap_readconfig(dictionary *iniconfig)
33 {
34     int i, j;
35     char *val;
36
37     i = 0;
38     /* now see if its a correct pref */
39     for (i = 0; ldap_prefs[i].name != NULL; i++) {
40         if ((val = iniparser_getstring(ldap_prefs[i].name)) != NULL) {
41             /* ok, found a valid pref */
42
43             /* check if we have pre-defined values */
44             if (ldap_prefs[i].intfromarray == 0) {
45                 /* no, its just a string */
46                 ldap_prefs[i].valid = 0;
47                 if (ldap_prefs[i].strorint)
48                     /* store as int */
49                     *((int *)(ldap_prefs[i].pref)) = atoi(val);
50                 else
51                     /* store string as string */
52                     *((char **)(ldap_prefs[i].pref)) = val;
53             } else {
54                 /* ok, we have string to int mapping for this pref
55                    eg. "none", "simple", "sasl" map to 0, 128, 129 */
56                 for (j = 0; prefs_array[j].pref != NULL; j++) {
57                     if ((strcmp(prefs_array[j].pref, ldap_prefs[i].name) == 0)
58                         && (strcmp(prefs_array[j].valuestring, val) == 0)) {
59                         ldap_prefs[i].valid = 0;
60                         *((int *)(ldap_prefs[i].pref)) = prefs_array[j].value;
61                         break;
62                     }
63                 }
64             }
65         }
66     }
67
68     /* check if the config is sane and complete */
69     i = 0;
70     ldap_config_valid = 1;
71
72     while(ldap_prefs[i].pref != NULL) {
73         if ( ldap_prefs[i].valid != 0) {
74             LOG(log_debug, logtype_afpd,"afp_ldap.conf: Missing option: \"%s\"", ldap_prefs[i].name);
75             ldap_config_valid = 0;
76             break;
77         }
78         i++;
79     }
80
81     if (ldap_config_valid) {
82         if (ldap_auth_method == LDAP_AUTH_NONE)
83             LOG(log_debug, logtype_afpd,"afp_ldap.conf: Using anonymous bind.");
84         else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
85             LOG(log_debug, logtype_afpd,"afp_ldap.conf: Using simple bind.");
86         else {
87             ldap_config_valid = 0;
88             LOG(log_error, logtype_afpd,"afp_ldap.conf: SASL not yet supported.");
89         }
90     } else
91         LOG(log_info, logtype_afpd,"afp_ldap.conf: not used");
92     fclose(f);
93     return 0;
94 }
95 #endif /* HAVE_LDAP */