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