[svn] dirmngr - r301 - trunk/src
svn author marcus
cvs at cvs.gnupg.org
Thu Jun 12 16:22:47 CEST 2008
Author: marcus
Date: 2008-06-12 16:22:42 +0200 (Thu, 12 Jun 2008)
New Revision: 301
Added:
trunk/src/ldapserver.c
trunk/src/ldapserver.h
Modified:
trunk/src/ChangeLog
trunk/src/Makefile.am
trunk/src/dirmngr.c
trunk/src/dirmngr.h
trunk/src/ldap.c
trunk/src/server.c
Log:
2008-06-12 Marcus Brinkmann <marcus at g10code.de>
* Makefile.am (dirmngr_SOURCES): Add ldapserver.h and ldapserver.c.
* ldapserver.h, ldapserver.c: New files.
* ldap.c: Include "ldapserver.h".
(url_fetch_ldap): Use iterator to get session servers as well.
(attr_fetch_ldap, start_default_fetch_ldap): Likewise.
* dirmngr.c: Include "ldapserver.h".
(free_ldapservers_list): Removed. Change callers to
ldapserver_list_free.
(parse_ldapserver_file): Use ldapserver_parse_one.
* server.c: Include "ldapserver.h".
(cmd_ldapserver): New command.
(register_commands): Add new command LDAPSERVER.
(reset_notify): New function.
(start_command_handler): Register reset notify handler.
Deallocate session server list.
(lookup_cert_by_pattern): Use iterator to get session servers as well.
(struct server_local_s): Move to ...
* dirmngr.h (struct server_local_s): ... here. Add new member
ldapservers.
[The diff below has been truncated]
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/ChangeLog 2008-06-12 14:22:42 UTC (rev 301)
@@ -1,3 +1,25 @@
+2008-06-12 Marcus Brinkmann <marcus at g10code.de>
+
+ * Makefile.am (dirmngr_SOURCES): Add ldapserver.h and ldapserver.c.
+ * ldapserver.h, ldapserver.c: New files.
+ * ldap.c: Include "ldapserver.h".
+ (url_fetch_ldap): Use iterator to get session servers as well.
+ (attr_fetch_ldap, start_default_fetch_ldap): Likewise.
+ * dirmngr.c: Include "ldapserver.h".
+ (free_ldapservers_list): Removed. Change callers to
+ ldapserver_list_free.
+ (parse_ldapserver_file): Use ldapserver_parse_one.
+ * server.c: Include "ldapserver.h".
+ (cmd_ldapserver): New command.
+ (register_commands): Add new command LDAPSERVER.
+ (reset_notify): New function.
+ (start_command_handler): Register reset notify handler.
+ Deallocate session server list.
+ (lookup_cert_by_pattern): Use iterator to get session servers as well.
+ (struct server_local_s): Move to ...
+ * dirmngr.h (struct server_local_s): ... here. Add new member
+ ldapservers.
+
2008-06-10 Werner Koch <wk at g10code.com>
Support PEM encoded CRLs. Fixes bug#927.
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/Makefile.am 2008-06-12 14:22:42 UTC (rev 301)
@@ -40,12 +40,12 @@
noinst_HEADERS = dirmngr.h crlcache.h crlfetch.h error.h misc.h
-dirmngr_SOURCES = \
- dirmngr.c dirmngr.h server.c crlcache.c crlfetch.c \
- certcache.c certcache.h i18n.h util.h b64dec.c \
- cdb.h cdblib.c ldap.c http.c http.h misc.c ocsp.c ocsp.h \
- estream.c estream.h estream-printf.c estream-printf.h \
- validate.c validate.h exechelp.h exechelp.c get-path.c
+dirmngr_SOURCES = dirmngr.c dirmngr.h server.c crlcache.c crlfetch.c \
+ ldapserver.h ldapserver.c certcache.c certcache.h i18n.h \
+ util.h b64dec.c cdb.h cdblib.c ldap.c http.c http.h misc.c \
+ ocsp.c ocsp.h estream.c estream.h estream-printf.c \
+ estream-printf.h validate.c validate.h exechelp.h exechelp.c \
+ get-path.c
dirmngr_LDADD = ../jnlib/libjnlib.a $(LIBOBJS) $(LIBASSUAN_PTH_LIBS) \
$(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(PTH_LIBS) $(LIBINTL) $(LIBICONV)
Modified: trunk/src/dirmngr.c
===================================================================
--- trunk/src/dirmngr.c 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/dirmngr.c 2008-06-12 14:22:42 UTC (rev 301)
@@ -51,6 +51,7 @@
#include "crlfetch.h"
#include "misc.h"
#include "i18n.h"
+#include "ldapserver.h"
#ifdef HAVE_W32_SYSTEM
#define sleep _sleep
@@ -241,7 +242,6 @@
/* Prototypes. */
static void cleanup (void);
static ldap_server_t parse_ldapserver_file (const char* filename);
-static void free_ldapservers_list (ldap_server_t servers);
static fingerprint_list_t parse_ocsp_signer (const char *string);
static void handle_connections (assuan_fd_t listen_fd);
@@ -1282,7 +1282,7 @@
crl_cache_deinit ();
cert_cache_deinit (1);
- free_ldapservers_list (opt.ldapservers);
+ ldapserver_list_free (opt.ldapservers);
opt.ldapservers = NULL;
if (cleanup_socket)
@@ -1329,12 +1329,11 @@
parse_ldapserver_file (const char* filename)
{
char buffer[1024];
- char *p, *endp;
+ char *p;
ldap_server_t server, serverstart, *serverend;
int c;
unsigned int lineno = 0;
FILE *fp;
- int fieldno;
fp = fopen (filename, "r");
if (!fp)
@@ -1347,8 +1346,6 @@
serverend = &serverstart;
while (fgets (buffer, sizeof buffer, fp))
{
- int fail = 0;
-
lineno++;
if (!*buffer || buffer[strlen(buffer)-1] != '\n')
{
@@ -1370,65 +1367,9 @@
continue;
/* Parse the colon separated fields. */
- server = xcalloc (1, sizeof *server);
- for (fieldno=1, p = buffer; p; p = endp, fieldno++ )
+ server = ldapserver_parse_one (buffer, filename, lineno);
+ if (server)
{
- endp = strchr (p, ':');
- if (endp)
- *endp++ = '\0';
- trim_spaces (p);
- switch (fieldno)
- {
- case 1:
- if (*p)
- server->host = xstrdup (p);
- else
- {
- log_error (_("%s:%u: no hostname given\n"),
- filename, lineno);
- fail = 1;
- }
- break;
-
- case 2:
- if (*p)
- server->port = atoi (p);
- break;
-
- case 3:
- if (*p)
- server->user = xstrdup (p);
- break;
-
- case 4:
- if (*p && !server->user)
- {
- log_error (_("%s:%u: password given without user\n"),
- filename, lineno);
- fail = 1;
- }
- else if (*p)
- server->pass = xstrdup (p);
- break;
-
- case 5:
- if (*p)
- server->base = xstrdup (p);
- break;
-
- default:
- /* (We silently ignore extra fields.) */
- break;
- }
- }
-
- if (fail)
- {
- log_info (_("%s:%u: skipping this line\n"), filename, lineno);
- free_ldapservers_list (server);
- }
- else
- {
*serverend = server;
serverend = &server->next;
}
@@ -1442,26 +1383,6 @@
}
-/* Release the list of SERVERS. As usual it is okay to call this
- fucntion with SERVERS passed as NULL. */
-static void
-free_ldapservers_list (ldap_server_t servers)
-{
- while (servers)
- {
- ldap_server_t tmp = servers->next;
- xfree (servers->host);
- xfree (servers->user);
- if (servers->pass)
- memset (servers->pass, 0, strlen (servers->pass));
- xfree (servers->pass);
- xfree (servers->base);
- xfree (servers);
- servers = tmp;
- }
-}
-
-
static fingerprint_list_t
parse_ocsp_signer (const char *string)
{
Modified: trunk/src/dirmngr.h
===================================================================
--- trunk/src/dirmngr.h 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/dirmngr.h 2008-06-12 14:22:42 UTC (rev 301)
@@ -145,8 +145,16 @@
/* Control structure per connection. */
-struct server_local_s;
+struct server_local_s
+{
+ /* Data used to associate an Assuan context with local server data */
+ assuan_context_t assuan_ctx;
+ /* Per-session LDAP serfver. */
+ ldap_server_t ldapservers;
+};
+
+
struct server_control_s
{
int refcount; /* Count additional references to this object. */
Modified: trunk/src/ldap.c
===================================================================
--- trunk/src/ldap.c 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/ldap.c 2008-06-12 14:22:42 UTC (rev 301)
@@ -34,6 +34,7 @@
#include "exechelp.h"
#include "crlfetch.h"
#include "dirmngr.h"
+#include "ldapserver.h"
#include "misc.h"
#ifdef HAVE_W32_SYSTEM
@@ -820,14 +821,18 @@
again using our default list of servers. */
if (err && !(opt.ldap_proxy && opt.only_ldap_proxy))
{
- ldap_server_t server;
+ struct ldapserver_iter iter;
if (DBG_LOOKUP)
log_debug ("no hostname in URL or query failed; "
"trying all default hostnames\n");
- for (server = opt.ldapservers; err && server; server = server->next)
+ for (ldapserver_iter_begin (&iter, ctrl);
+ err && ! ldapserver_iter_end_p (&iter);
+ ldapserver_iter_next (&iter))
{
+ ldap_server_t server = iter.server;
+
err = run_ldap_wrapper (ctrl,
0,
0,
@@ -852,15 +857,18 @@
attr_fetch_ldap (ctrl_t ctrl,
const char *dn, const char *attr, ksba_reader_t *reader)
{
- struct ldap_server_s *server;
gpg_error_t err = gpg_error (GPG_ERR_CONFIGURATION);
+ struct ldapserver_iter iter;
*reader = NULL;
/* FIXME; we might want to look at the Base SN to try matching
servers first. */
- for (server = opt.ldapservers; server; server = server->next)
+ for (ldapserver_iter_begin (&iter, ctrl); ! ldapserver_iter_end_p (&iter);
+ ldapserver_iter_next (&iter))
{
+ ldap_server_t server = iter.server;
+
err = run_ldap_wrapper (ctrl,
0,
0,
@@ -875,12 +883,7 @@
return err;
}
-
-
-
-
-
/* Parse PATTERN and return a new strlist to be used for the actual
LDAP query. Bit 0 of the flags field is set if that pattern is
actually a base specification. Caller must release the returned
@@ -1051,14 +1054,14 @@
/* Prepare an LDAP query to return the attribute ATTR for the DN. All
- vonfigured default servers are queried until one responds. This
+ configured default servers are queried until one responds. This
function returns an error code or 0 and a CONTEXT on success. */
gpg_error_t
start_default_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
const char *dn, const char *attr)
{
gpg_error_t err;
- struct ldap_server_s *server;
+ struct ldapserver_iter iter;
*context = xtrycalloc (1, sizeof **context);
if (!*context)
@@ -1067,8 +1070,12 @@
/* FIXME; we might want to look at the Base SN to try matching
servers first. */
err = gpg_error (GPG_ERR_CONFIGURATION);
- for (server = opt.ldapservers; server; server = server->next)
+
+ for (ldapserver_iter_begin (&iter, ctrl); ! ldapserver_iter_end_p (&iter);
+ ldapserver_iter_next (&iter))
{
+ ldap_server_t server = iter.server;
+
err = run_ldap_wrapper (ctrl,
0,
1,
Added: trunk/src/ldapserver.c
===================================================================
--- trunk/src/ldapserver.c 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/ldapserver.c 2008-06-12 14:22:42 UTC (rev 301)
@@ -0,0 +1,133 @@
+/* dirmngr.c - LDAP access
+ Copyright (C) 2008 g10 Code GmbH
+
+ This file is part of DirMngr.
+
+ DirMngr 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.
+
+ DirMngr 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "util.h"
+#include "ldapserver.h"
+
+
+/* Release the list of SERVERS. As usual it is okay to call this
+ function with SERVERS passed as NULL. */
+void
+ldapserver_list_free (ldap_server_t servers)
+{
+ while (servers)
+ {
+ ldap_server_t tmp = servers->next;
+ xfree (servers->host);
+ xfree (servers->user);
+ if (servers->pass)
+ memset (servers->pass, 0, strlen (servers->pass));
+ xfree (servers->pass);
+ xfree (servers->base);
+ xfree (servers);
+ servers = tmp;
+ }
+}
+
+
+/* Parse a single LDAP server configuration line. Returns the server
+ or NULL in case of errors. The configuration lineis assumed to be
+ colon seprated with these fields:
+
+ 1. field: Hostname
+ 2. field: Portnumber
+ 3. field: Username
+ 4. field: Password
+ 5. field: Base DN
+
+ FILENAME and LINENO are used for diagnostic purposes only.
+*/
+ldap_server_t
+ldapserver_parse_one (char *line,
+ const char *filename, unsigned int lineno)
+{
+ char *p;
+ char *endp;
+ ldap_server_t server;
+ int fieldno;
+ int fail = 0;
+
+ /* Parse the colon separated fields. */
+ server = xcalloc (1, sizeof *server);
+ for (fieldno = 1, p = line; p; p = endp, fieldno++ )
+ {
+ endp = strchr (p, ':');
+ if (endp)
+ *endp++ = '\0';
+ trim_spaces (p);
+ switch (fieldno)
+ {
+ case 1:
+ if (*p)
+ server->host = xstrdup (p);
+ else
+ {
+ log_error (_("%s:%u: no hostname given\n"),
+ filename, lineno);
+ fail = 1;
+ }
+ break;
+
+ case 2:
+ if (*p)
+ server->port = atoi (p);
+ break;
+
+ case 3:
+ if (*p)
+ server->user = xstrdup (p);
+ break;
+
+ case 4:
+ if (*p && !server->user)
+ {
+ log_error (_("%s:%u: password given without user\n"),
+ filename, lineno);
+ fail = 1;
+ }
+ else if (*p)
+ server->pass = xstrdup (p);
+ break;
+
+ case 5:
+ if (*p)
+ server->base = xstrdup (p);
+ break;
+
+ default:
+ /* (We silently ignore extra fields.) */
+ break;
+ }
+ }
+
+ if (fail)
+ {
+ log_info (_("%s:%u: skipping this line\n"), filename, lineno);
+ ldapserver_list_free (server);
+ }
+
+ return server;
+}
+
+
Added: trunk/src/ldapserver.h
===================================================================
--- trunk/src/ldapserver.h 2008-06-10 10:05:20 UTC (rev 300)
+++ trunk/src/ldapserver.h 2008-06-12 14:22:42 UTC (rev 301)
@@ -0,0 +1,90 @@
+/* ldapserver.h
+ Copyright (C) 2008 g10 Code GmbH
+
+ This file is part of DirMngr.
+
+ DirMngr 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.
+
+ DirMngr 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LDAPSERVER_H
+#define LDAPSERVER_H
+
+#include "dirmngr.h"
+
+/* Release the list of SERVERS. As usual it is okay to call this
+ function with SERVERS passed as NULL. */
+void ldapserver_list_free (ldap_server_t servers);
+
+
+/* Parse a single LDAP server configuration line. Returns the server
+ or NULL in case of errors. The configuration lineis assumed to be
+ colon seprated with these fields:
+
+ 1. field: Hostname
+ 2. field: Portnumber
+ 3. field: Username
+ 4. field: Password
+ 5. field: Base DN
+
+ FILENAME and LINENO are used for diagnostic purposes only.
+*/
+ldap_server_t ldapserver_parse_one (char *line,
+ const char *filename, unsigned int lineno);
+
+
+/* Iterate over all servers. */
+
+struct ldapserver_iter
+{
+ ctrl_t ctrl;
+ enum { LDAPSERVER_SESSION, LDAPSERVER_OPT } group;
+ ldap_server_t server;
+};
+
+
+static inline void
+ldapserver_iter_next (struct ldapserver_iter *iter)
+{
+ if (iter->server)
+ iter->server = iter->server->next;
+
+ if (! iter->server)
+ {
More information about the Gnupg-commits
mailing list