* Added "Base DN" "Bind DN" and "Bind DN password" config options
authorArt Cancro <ajc@citadel.org>
Sat, 17 Jan 2004 22:57:54 +0000 (22:57 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 17 Jan 2004 22:57:54 +0000 (22:57 +0000)
* serv_ldap.c: added.  (New module implementing the LDAP Connector)
* Upon startup, connect to LDAP directory and bind to it.  Unbind at exit.

citadel/ChangeLog
citadel/Makefile.in
citadel/citadel.h
citadel/control.c
citadel/routines2.c
citadel/serv_chat.c
citadel/serv_extensions.c
citadel/serv_extensions.h
citadel/serv_ldap.c [new file with mode: 0644]
citadel/serv_vandelay.c

index 029ac20ae99c0e987c72dbdabaa26f58a2e8e244..bb35ff26977a6e2ebbd628f204658ff17c5d2b24 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 614.5  2004/01/17 22:57:54  ajc
+ * Added "Base DN" "Bind DN" and "Bind DN password" config options
+ * serv_ldap.c: added.  (New module implementing the LDAP Connector)
+ * Upon startup, connect to LDAP directory and bind to it.  Unbind at exit.
+
  Revision 614.4  2004/01/17 04:23:28  ajc
  * Sysconfig commands for specifying where the LDAP server lives
 
@@ -5225,4 +5230,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index e5754cd681b9478aeb4f1c91dc6c1e937ca4d1bb..27bd186406d5f0fef2149b6d044214470559bef2 100644 (file)
@@ -42,7 +42,9 @@ SERV_MODULES=serv_chat.o \
        serv_bio.o \
        serv_expire.o \
        serv_vandelay.o \
-       serv_calendar.o ical_dezonify.o
+       serv_calendar.o \
+       ical_dezonify.o \
+       serv_ldap.o
 
 UTIL_TARGETS=aidepost msgform \
        citmail userlist sendcommand \
index b88dc9d4e37b13d945448f7ac55460dc56ea3b16..e2565f4dc7ab31dbbf9a038f6522de0ca1e6aa99 100644 (file)
@@ -132,6 +132,9 @@ struct config {
        struct ExpirePolicy c_mbxep;    /* Expire policy for mailbox rooms  */
        char c_ldap_host[128];          /* Host where LDAP service lives    */
        int c_ldap_port;                /* Port on host where LDAP lives    */
+       char c_ldap_base_dn[256];       /* LDAP base DN                     */
+       char c_ldap_bind_dn[256];       /* LDAP bind DN                     */
+       char c_ldap_bind_pw[256];       /* LDAP bind password               */
 };
 
 /*
index 207291faf45be9bf7a4f91c01c658b04d2a3ea71..86533a8ee4e0fa38fa7f1803e48607c9ae7d8679 100644 (file)
@@ -199,9 +199,15 @@ void cmd_conf(char *argbuf)
 #ifdef HAVE_LDAP
                cprintf("%s\n", config.c_ldap_host);
                cprintf("%d\n", config.c_ldap_port);
+               cprintf("%s\n", config.c_ldap_base_dn);
+               cprintf("%s\n", config.c_ldap_bind_dn);
+               cprintf("%s\n", config.c_ldap_bind_pw);
 #else
                cprintf("\n");
                cprintf("0\n");
+               cprintf("\n");
+               cprintf("\n");
+               cprintf("\n");
 #endif
                cprintf("000\n");
        }
@@ -350,6 +356,18 @@ void cmd_conf(char *argbuf)
                        case 33:
                                config.c_ldap_port = atoi(buf);
                                break;
+                       case 34:
+                               safestrncpy(config.c_ldap_base_dn, buf,
+                                           sizeof config.c_ldap_base_dn);
+                               break;
+                       case 35:
+                               safestrncpy(config.c_ldap_bind_dn, buf,
+                                           sizeof config.c_ldap_bind_dn);
+                               break;
+                       case 36:
+                               safestrncpy(config.c_ldap_bind_pw, buf,
+                                           sizeof config.c_ldap_bind_pw);
+                               break;
 #endif
                        }
                        ++a;
index 640a16e68f53ffe49dbe5cd20bd974b676e232e8..3b264211fc611bbc5b495bf2c8d9cc236c486188 100644 (file)
@@ -643,7 +643,7 @@ void read_bio(CtdlIPC *ipc)
 void do_system_configuration(CtdlIPC *ipc)
 {
 
-#define NUM_CONFIGS 34
+#define NUM_CONFIGS 37
 
        char buf[SIZ];
        char sc[NUM_CONFIGS][SIZ];
@@ -751,7 +751,7 @@ void do_system_configuration(CtdlIPC *ipc)
        snprintf(sc[25], sizeof sc[25], "%d", a);
 
        /* LDAP settings */
-       if (serv_info.serv_supports_qnop) {
+       if (serv_info.serv_supports_ldap) {
                a = strlen(&sc[32][0]);
                a = (a ? 1 : 0);        /* Set only to 1 or 0 */
                a = boolprompt("Connect this Citadel to an LDAP directory", a);
@@ -760,6 +760,9 @@ void do_system_configuration(CtdlIPC *ipc)
                                &sc[32][0], 127);
                        strprompt("Port number of LDAP service",
                                &sc[33][0], 5);
+                       strprompt("Base DN", &sc[34][0], 255);
+                       strprompt("Bind DN", &sc[35][0], 255);
+                       strprompt("Password for bind DN", &sc[36][0], 255);
                }
                else {
                        strcpy(&sc[32][0], "");
index acd867e0f8782973067427b18a46d4b17f44caf8..d7d85b735a62fdd6b8404ae81622f6184eed9aec 100644 (file)
@@ -749,7 +749,7 @@ void cmd_reqt(char *argbuf) {
 
 
 
-char *serv_inithat_init(void)
+char *serv_chat_init(void)
 {
        CtdlRegisterProtoHook(cmd_chat, "CHAT", "Begin real-time chat");
        CtdlRegisterProtoHook(cmd_pexp, "PEXP", "Poll for express messages");
index 29c92587ea847e2d8fa876dec54f350c9b68411d..3ff6d2c282222e6010e75cf4f01c81f666ac8a6d 100644 (file)
@@ -104,7 +104,8 @@ void initialize_server_extensions(void)
 {
        serv_bio_init();
        serv_calendar_init();
-       serv_inithat_init();
+       serv_ldap_init();
+       serv_chat_init();
        serv_expire_init();
        serv_imap_init();
        serv_inetcfg_init();
index 1f55607d0ff35534263e3e075c89d4e04e46da4b..71713bf1d401f60078b90855054f9afd12339678 100644 (file)
@@ -12,7 +12,8 @@
  */
 char *serv_bio_init(void);
 char *serv_calendar_init(void);
-char *serv_inithat_init(void);
+char *serv_ldap_init(void);
+char *serv_chat_init(void);
 char *serv_expire_init(void);
 char *serv_imap_init(void);
 char *serv_inetcfg_init(void);
diff --git a/citadel/serv_ldap.c b/citadel/serv_ldap.c
new file mode 100644 (file)
index 0000000..d97e64c
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ *
+ * A module which implements the LDAP connector for Citadel.
+ *
+ */
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include "citadel.h"
+#include "server.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "serv_extensions.h"
+#include "room_ops.h"
+#include "policy.h"
+#include "database.h"
+#include "msgbase.h"
+
+#ifdef HAVE_LDAP
+
+#include <ldap.h>
+
+LDAP *dirserver = NULL;
+
+/*
+ * LDAP connector cleanup function
+ */
+void serv_ldap_cleanup(void)
+{
+       if (!dirserver) return;
+
+       lprintf(7, "Unbinding from directory server\n");
+       ldap_unbind(dirserver);
+       dirserver = NULL;
+}
+
+#endif                         /* HAVE_LDAP */
+
+
+void CtdlConnectToLdap(void) {
+       int i;
+       int ldap_version = 3;
+
+       lprintf(7, "Connecting to LDAP server %s:%d...\n",
+               config.c_ldap_host, config.c_ldap_port);
+
+       dirserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
+       if (dirserver == NULL) {
+               lprintf(3, "Could not connect to %s:%d : %s\n",
+                       config.c_ldap_host,
+                       config.c_ldap_port,
+                       strerror(errno));
+               return;
+       }
+
+       ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
+
+       lprintf(7, "Binding to %s\n", config.c_ldap_bind_dn);
+
+       i = ldap_simple_bind_s(dirserver,
+                               config.c_ldap_bind_dn,
+                               config.c_ldap_bind_pw
+       );
+       if (i != LDAP_SUCCESS) {
+               lprintf(3, "Cannot bind: %s (%d)\n", ldap_err2string(i), i);
+               dirserver = NULL;       /* FIXME disconnect from ldap */
+       }
+}
+
+
+/*
+ * Initialize the LDAP connector module ... or don't, if we don't have LDAP.
+ */
+char *serv_ldap_init(void)
+{
+#ifdef HAVE_LDAP
+       CtdlRegisterCleanupHook(serv_ldap_cleanup);
+
+       if (strlen(config.c_ldap_host) > 0) {
+               CtdlConnectToLdap();
+       }
+
+#endif                         /* HAVE_LDAP */
+       return "$Id$";
+}
index 4dc0a2c390783a5a66a6b7b95a5bcd667c9eee31..1e1addde87eb326974e4056923fd80e9a7d67ae5 100644 (file)
@@ -287,6 +287,9 @@ void artv_do_export(void) {
        cprintf("%d\n", config.c_mbxep.expire_value);
        cprintf("%s\n", config.c_ldap_host);
        cprintf("%d\n", config.c_ldap_port);
+       cprintf("%s\n", config.c_ldap_base_dn);
+       cprintf("%s\n", config.c_ldap_bind_dn);
+       cprintf("%s\n", config.c_ldap_bind_pw);
 
        /* Export the control file */
        get_control();
@@ -348,6 +351,9 @@ void artv_import_config(void) {
        client_gets(buf);       config.c_mbxep.expire_value = atoi(buf);
        client_gets(config.c_ldap_host);
        client_gets(buf);       config.c_ldap_port = atoi(buf);
+       client_gets(config.c_ldap_base_dn);
+       client_gets(config.c_ldap_bind_dn);
+       client_gets(config.c_ldap_bind_pw);
        put_config();
        lprintf(7, "Imported config file\n");
 }