File: ldap_config.c

package info (click to toggle)
netatalk 3.1.12~ds-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,756 kB
  • sloc: ansic: 104,976; sh: 8,247; xml: 7,394; perl: 1,936; makefile: 1,430; python: 1,342; yacc: 309; lex: 49
file content (104 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
  Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#ifdef HAVE_LDAP

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <ldap.h>

#include <atalk/globals.h>
#include <atalk/ldapconfig.h>
#include <atalk/logger.h>
#include <atalk/iniparser.h>

void acl_ldap_freeconfig(void)
{
    for (int i = 0; ldap_prefs[i].name != NULL; i++) {
        if (ldap_prefs[i].intfromarray == 0 && ldap_prefs[i].strorint == 0) {
            free(*((char **)(ldap_prefs[i].pref)));
            *((char **)(ldap_prefs[i].pref)) = NULL;
        }
        ldap_prefs[i].valid = ldap_prefs[i].valid_save;
    }
}

int acl_ldap_readconfig(dictionary *iniconfig)
{
    int i, j;
    const char *val;

    i = 0;
    /* now see if its a correct pref */
    for (i = 0; ldap_prefs[i].name != NULL; i++) {
        if ((val = atalk_iniparser_getstring(iniconfig, INISEC_GLOBAL, ldap_prefs[i].name, NULL))) {
            /* check if we have pre-defined values */
            if (ldap_prefs[i].intfromarray == 0) {
                /* no, its just a string */
                ldap_prefs[i].valid = 0;
                if (ldap_prefs[i].strorint)
                    /* store as int */
                    *((int *)(ldap_prefs[i].pref)) = atoi(val);
                else
                    /* store string as string */
                    *((const char **)(ldap_prefs[i].pref)) = strdup(val);
            } else {
                /* ok, we have string to int mapping for this pref
                   e.g. "none", "simple", "sasl" map to 0, 128, 129 */
                for (j = 0; prefs_array[j].pref != NULL; j++) {
                    if ((strcmp(prefs_array[j].pref, ldap_prefs[i].name) == 0)
                        && (strcmp(prefs_array[j].valuestring, val) == 0)) {
                        ldap_prefs[i].valid = 0;
                        *((int *)(ldap_prefs[i].pref)) = prefs_array[j].value;
                        break;
                    }
                }
            }
        }
    }

    /* check if the config is sane and complete */
    i = 0;
    ldap_config_valid = 1;

    while(ldap_prefs[i].pref != NULL) {
        if ( ldap_prefs[i].valid != 0) {
            LOG(log_debug, logtype_afpd,"LDAP: Missing option: \"%s\"", ldap_prefs[i].name);
            ldap_config_valid = 0;
            break;
        }
        i++;
    }

    if (ldap_config_valid) {
        if (ldap_auth_method == LDAP_AUTH_NONE)
            LOG(log_debug, logtype_afpd,"LDAP: Using anonymous bind.");
        else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
            LOG(log_debug, logtype_afpd,"LDAP: Using simple bind.");
        else {
            ldap_config_valid = 0;
            LOG(log_error, logtype_afpd,"LDAP: SASL not yet supported.");
        }
    } else
        LOG(log_info, logtype_afpd,"LDAP: not used");
    return 0;
}
#endif /* HAVE_LDAP */