1 /* dirmngr.c - LDAP access
2 Copyright (C) 2008 g10 Code GmbH
4 This file is part of DirMngr.
6 DirMngr is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DirMngr is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "ldapserver.h"
29 /* Release the list of SERVERS. As usual it is okay to call this
30 function with SERVERS passed as NULL. */
32 ldapserver_list_free (ldap_server_t servers)
36 ldap_server_t tmp = servers->next;
37 xfree (servers->host);
38 xfree (servers->user);
40 memset (servers->pass, 0, strlen (servers->pass));
41 xfree (servers->pass);
42 xfree (servers->base);
49 /* Parse a single LDAP server configuration line. Returns the server
50 or NULL in case of errors. The configuration line is assumed to be
51 colon seprated with these fields:
59 FILENAME and LINENO are used for diagnostic purposes only.
62 ldapserver_parse_one (char *line,
63 const char *filename, unsigned int lineno)
71 /* Parse the colon separated fields. */
72 server = xcalloc (1, sizeof *server);
73 for (fieldno = 1, p = line; p; p = endp, fieldno++ )
75 endp = strchr (p, ':');
83 server->host = xstrdup (p);
86 log_error (_("%s:%u: no hostname given\n"),
94 server->port = atoi (p);
99 server->user = xstrdup (p);
103 if (*p && !server->user)
105 log_error (_("%s:%u: password given without user\n"),
110 server->pass = xstrdup (p);
115 server->base = xstrdup (p);
119 /* (We silently ignore extra fields.) */
126 log_info (_("%s:%u: skipping this line\n"), filename, lineno);
127 ldapserver_list_free (server);