Blame view

libmu_cfg/ldap.c 3.46 KB
1
/* This file is part of GNU Mailutils
2
   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 4 5 6 7 8

   GNU Mailutils 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 3, or (at
   your option) any later version.

9
   GNU Mailutils is distributed in the hope that it will be useful, but
10 11 12 13 14
   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.

   You should have received a copy of the GNU General Public License
15
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
21
#include <stdlib.h>
22
#include "mailutils/libcfg.h"
23
#include "mailutils/util.h"
24 25 26 27 28
#include "mailutils/ldap.h"

static struct mu_ldap_module_config ldap_settings;

static int
29
_cb2_field_map (const char *arg, void *data)
30 31 32 33
{
  int err;
  int rc = mutil_parse_field_map (arg, &ldap_settings.field_map, &err);
  if (rc)
34 35
    /* FIXME: this message can be misleading */
    mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
36 37 38
  return 0;
}

39
static int
40
cb_field_map (void *data, mu_config_value_t *val)
41
{
42
  return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
43 44
}

45
static struct mu_cfg_param mu_ldap_param[] = {
46
  { "enable", mu_cfg_bool, &ldap_settings.enable, 0, NULL,
47
    N_("Enable LDAP lookups.") },
48
  { "url", mu_cfg_string, &ldap_settings.url, 0, NULL,
49 50
    N_("Set URL of the LDAP server."),
    N_("url") },
51
  { "base", mu_cfg_string, &ldap_settings.base, 0, NULL,
52 53
    N_("Base DN for LDAP lookups."),
    N_("dn") },
54
  { "binddn", mu_cfg_string, &ldap_settings.binddn, 0, NULL,
55 56
    N_("DN for accessing LDAP database."),
    N_("dn") },
57
  { "passwd", mu_cfg_string, &ldap_settings.passwd, 0, NULL,
58
    N_("Password for use with binddn.") },
59
  { "tls", mu_cfg_bool, &ldap_settings.tls, 0, NULL,
60
    N_("Use TLS encryption.") },
61
  { "debug", mu_cfg_int, &ldap_settings.debug, 0, NULL,
62
    N_("Set LDAP debugging level.") },
63
  { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
64 65 66 67 68 69
    N_("Set a field-map for parsing LDAP replies.  The map is a "
       "column-separated list of definitions.  Each definition has the "
       "following form:\n"
       "   <name: string>=<attr: string>\n"
       "where <name> is one of the following: name, passwd, uid, gid, "
       "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
70
       "the corresponding LDAP attribute."),
71
    N_("map") },
72
  { "getpwnam", mu_cfg_string, &ldap_settings.getpwnam_filter, 0, NULL,
73 74
    N_("LDAP filter to use for getpwnam requests."),
    N_("filter") },
75
  { "getpwuid", mu_cfg_string, &ldap_settings.getpwuid_filter, 0, NULL,
76 77
    N_("LDAP filter to use for getpwuid requests."),
    N_("filter") },
78 79 80 81 82 83
  { NULL }
};

int									      
mu_ldap_section_parser
   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,	      
84 85
    const char *section_label, void **section_data,
    void *call_data, mu_cfg_tree_t *tree)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
{									      
  switch (stage)							      
    {									      
    case mu_cfg_section_start:
      ldap_settings.enable = 1;
      break;								      
      									      
    case mu_cfg_section_end:						      
      mu_gocs_store ("ldap", &ldap_settings);	      
    }									      
  return 0;								      
}

struct mu_cfg_capa mu_ldap_cfg_capa = {                
  "ldap",  mu_ldap_param, mu_ldap_section_parser
};