r6725: the beginnings of a cldap server
authorAndrew Tridgell <tridge@samba.org>
Wed, 11 May 2005 04:49:18 +0000 (04:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:38 +0000 (13:16 -0500)
source/build/smb_build/main.pm
source/cldap_server/cldap_server.c [new file with mode: 0644]
source/cldap_server/cldap_server.h [new file with mode: 0644]
source/cldap_server/config.mk [new file with mode: 0644]
source/include/structs.h
source/smbd/config.mk

index 3598d49f29925533eef2af60b0f784a007733c7c..8057fa20957b8ef037a7ca9f528de2acbdf142eb 100644 (file)
@@ -45,6 +45,7 @@ sub smb_build_main($)
                "ldap_server/config.mk",
                "winbind/config.mk",
                "nbt_server/config.mk",
+               "cldap_server/config.mk",
                "auth/gensec/gensec.mk",
                "auth/kerberos/kerberos.mk",
                "auth/ntlmssp/ntlmssp.mk",
diff --git a/source/cldap_server/cldap_server.c b/source/cldap_server/cldap_server.c
new file mode 100644 (file)
index 0000000..8397a62
--- /dev/null
@@ -0,0 +1,148 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   CLDAP server task
+
+   Copyright (C) Andrew Tridgell       2005
+   
+   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.
+   
+   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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "libcli/ldap/ldap.h"
+#include "lib/events/events.h"
+#include "lib/socket/socket.h"
+#include "smbd/service_task.h"
+#include "cldap_server/cldap_server.h"
+
+
+/*
+  handle incoming cldap requests
+*/
+static void cldapd_request_handler(struct cldap_socket *cldap, 
+                                  struct ldap_message *ldap_msg, 
+                                  const char *src_address, int src_port)
+{
+       struct cldapd_server *cldapd = talloc_get_type(cldap->incoming.private,
+                                                      struct cldapd_server);
+       if (ldap_msg->type != LDAP_TAG_SearchRequest) {
+               DEBUG(0,("Invalid CLDAP request type %d from %s:%d\n", 
+                        ldap_msg->type, src_address, src_port));
+               return;
+       }
+       DEBUG(0,("CLDAP search for '%s'\n", ldap_msg->r.SearchRequest.filter));
+}
+
+/*
+  start listening on the given address
+*/
+static NTSTATUS cldapd_add_socket(struct cldapd_server *cldapd, const char *address)
+{
+       struct cldap_socket *cldapsock;
+       NTSTATUS status;
+
+       /* listen for unicasts on port 137 */
+       cldapsock = cldap_socket_init(cldapd, cldapd->task->event_ctx);
+       NT_STATUS_HAVE_NO_MEMORY(cldapsock);
+
+       status = socket_listen(cldapsock->sock, address, lp_cldap_port(), 0, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Failed to bind to %s:%d - %s\n", 
+                        address, lp_cldap_port(), nt_errstr(status)));
+               talloc_free(cldapsock);
+               return status;
+       }
+
+       cldap_set_incoming_handler(cldapsock, cldapd_request_handler, cldapd);
+
+       return NT_STATUS_OK;
+}
+
+
+/*
+  setup our listening sockets on the configured network interfaces
+*/
+NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd)
+{
+       int num_interfaces = iface_count();
+       TALLOC_CTX *tmp_ctx = talloc_new(cldapd);
+       NTSTATUS status;
+
+       /* if we are allowing incoming packets from any address, then
+          we also need to bind to the wildcard address */
+       if (!lp_bind_interfaces_only()) {
+               status = cldapd_add_socket(cldapd, "0.0.0.0");
+               NT_STATUS_NOT_OK_RETURN(status);
+       } else {
+               int i;
+
+               for (i=0; i<num_interfaces; i++) {
+                       const char *address = talloc_strdup(tmp_ctx, iface_n_ip(i));
+                       status = cldapd_add_socket(cldapd, address);
+                       NT_STATUS_NOT_OK_RETURN(status);
+               }
+       }
+
+       talloc_free(tmp_ctx);
+
+       return NT_STATUS_OK;
+}
+
+/*
+  startup the cldapd task
+*/
+static void cldapd_task_init(struct task_server *task)
+{
+       struct cldapd_server *cldapd;
+       NTSTATUS status;
+
+       if (iface_count() == 0) {
+               task_terminate(task, "cldapd: no network interfaces configured");
+               return;
+       }
+
+       cldapd = talloc(task, struct cldapd_server);
+       if (cldapd == NULL) {
+               task_terminate(task, "cldapd: out of memory");
+               return;
+       }
+
+       cldapd->task = task;
+
+       /* start listening on the configured network interfaces */
+       status = cldapd_startup_interfaces(cldapd);
+       if (!NT_STATUS_IS_OK(status)) {
+               task_terminate(task, "cldapd failed to setup interfaces");
+               return;
+       }
+}
+
+
+/*
+  initialise the cldapd server
+ */
+static NTSTATUS cldapd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
+{
+       return task_server_startup(event_ctx, model_ops, cldapd_task_init);
+}
+
+
+/*
+  register ourselves as a available server
+*/
+NTSTATUS server_service_cldapd_init(void)
+{
+       return register_server_service("cldap", cldapd_init);
+}
diff --git a/source/cldap_server/cldap_server.h b/source/cldap_server/cldap_server.h
new file mode 100644 (file)
index 0000000..f110d05
--- /dev/null
@@ -0,0 +1,30 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   CLDAP server structures
+
+   Copyright (C) Andrew Tridgell       2005
+   
+   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.
+   
+   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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "libcli/cldap/cldap.h"
+
+/*
+  top level context structure for the cldap server
+*/
+struct cldapd_server {
+       struct task_server *task;
+};
diff --git a/source/cldap_server/config.mk b/source/cldap_server/config.mk
new file mode 100644 (file)
index 0000000..225fb1c
--- /dev/null
@@ -0,0 +1,11 @@
+# CLDAP server subsystem
+
+#######################
+# Start SUBSYSTEM CLDAPD
+[SUBSYSTEM::CLDAPD]
+INIT_OBJ_FILES = \
+               cldap_server/cldap_server.o
+REQUIRED_SUBSYSTEMS = \
+               LIBCLI_CLDAP
+# End SUBSYSTEM CLDAPD
+#######################
index 024dde9bc073d8edba9fb6c9110b7fedc2273445..6fec1ff257fca3c41b9afc1e376adcd5de7b33c5 100644 (file)
@@ -192,6 +192,8 @@ struct nbtd_server;
 struct nbtd_interface;
 struct wins_server;
 
+struct cldapd_server;
+
 struct mutex_ops;
 
 struct ads_struct;
index 39697205f6bfdd252b6feabb6c04347ae4292335..081e8d14950c1ea6b2e3113d503c952994edc65b 100644 (file)
@@ -50,6 +50,16 @@ REQUIRED_SUBSYSTEMS = \
 # End MODULE server_service_nbtd
 ################################################
 
+################################################
+# Start MODULE server_service_cldapd
+[MODULE::server_service_cldap]
+INIT_FUNCTION = server_service_cldapd_init
+SUBSYSTEM = SERVER_SERVICE
+REQUIRED_SUBSYSTEMS = \
+               CLDAPD
+# End MODULE server_service_cldapd
+################################################
+
 #######################
 # Start SUBSYSTEM SERVICE
 [SUBSYSTEM::SERVER_SERVICE]