summaryrefslogtreecommitdiff
path: root/source4/cldap_server
diff options
context:
space:
mode:
Diffstat (limited to 'source4/cldap_server')
-rw-r--r--source4/cldap_server/cldap_server.c96
-rw-r--r--source4/cldap_server/netlogon.c23
-rw-r--r--source4/cldap_server/rootdse.c13
3 files changed, 76 insertions, 56 deletions
diff --git a/source4/cldap_server/cldap_server.c b/source4/cldap_server/cldap_server.c
index 240f2b1dc2..1a08cd21f9 100644
--- a/source4/cldap_server/cldap_server.c
+++ b/source4/cldap_server/cldap_server.c
@@ -20,8 +20,8 @@
*/
#include "includes.h"
+#include <talloc.h>
#include "libcli/ldap/ldap.h"
-#include "lib/socket/socket.h"
#include "lib/messaging/irpc.h"
#include "smbd/service_task.h"
#include "smbd/service.h"
@@ -34,50 +34,67 @@
#include "ldb_wrap.h"
#include "auth/auth.h"
#include "param/param.h"
+#include "../lib/tsocket/tsocket.h"
/*
handle incoming cldap requests
*/
-static void cldapd_request_handler(struct cldap_socket *cldap,
- struct ldap_message *ldap_msg,
- struct socket_address *src)
+static void cldapd_request_handler(struct cldap_socket *cldap,
+ void *private_data,
+ struct cldap_incoming *in)
{
+ struct cldapd_server *cldapd = talloc_get_type(private_data,
+ struct cldapd_server);
struct ldap_SearchRequest *search;
- if (ldap_msg->type != LDAP_TAG_SearchRequest) {
- DEBUG(0,("Invalid CLDAP request type %d from %s:%d\n",
- ldap_msg->type, src->addr, src->port));
- cldap_error_reply(cldap, ldap_msg->messageid, src,
+
+ if (in->ldap_msg->type != LDAP_TAG_SearchRequest) {
+ DEBUG(0,("Invalid CLDAP request type %d from %s\n",
+ in->ldap_msg->type,
+ tsocket_address_string(in->src, in)));
+ cldap_error_reply(cldap, in->ldap_msg->messageid, in->src,
LDAP_OPERATIONS_ERROR, "Invalid CLDAP request");
+ talloc_free(in);
return;
}
- search = &ldap_msg->r.SearchRequest;
+ search = &in->ldap_msg->r.SearchRequest;
if (strcmp("", search->basedn) != 0) {
- DEBUG(0,("Invalid CLDAP basedn '%s' from %s:%d\n",
- search->basedn, src->addr, src->port));
- cldap_error_reply(cldap, ldap_msg->messageid, src,
+ DEBUG(0,("Invalid CLDAP basedn '%s' from %s\n",
+ search->basedn,
+ tsocket_address_string(in->src, in)));
+ cldap_error_reply(cldap, in->ldap_msg->messageid, in->src,
LDAP_OPERATIONS_ERROR, "Invalid CLDAP basedn");
+ talloc_free(in);
return;
}
if (search->scope != LDAP_SEARCH_SCOPE_BASE) {
- DEBUG(0,("Invalid CLDAP scope %d from %s:%d\n",
- search->scope, src->addr, src->port));
- cldap_error_reply(cldap, ldap_msg->messageid, src,
+ DEBUG(0,("Invalid CLDAP scope %d from %s\n",
+ search->scope,
+ tsocket_address_string(in->src, in)));
+ cldap_error_reply(cldap, in->ldap_msg->messageid, in->src,
LDAP_OPERATIONS_ERROR, "Invalid CLDAP scope");
+ talloc_free(in);
return;
}
if (search->num_attributes == 1 &&
strcasecmp(search->attributes[0], "netlogon") == 0) {
- cldapd_netlogon_request(cldap, ldap_msg->messageid,
- search->tree, src);
+ cldapd_netlogon_request(cldap,
+ cldapd,
+ in,
+ in->ldap_msg->messageid,
+ search->tree,
+ in->src);
+ talloc_free(in);
return;
}
- cldapd_rootdse_request(cldap, ldap_msg->messageid,
- search, src);
+ cldapd_rootdse_request(cldap, cldapd, in,
+ in->ldap_msg->messageid,
+ search, in->src);
+ talloc_free(in);
}
@@ -88,28 +105,36 @@ static NTSTATUS cldapd_add_socket(struct cldapd_server *cldapd, struct loadparm_
const char *address)
{
struct cldap_socket *cldapsock;
- struct socket_address *socket_address;
+ struct tsocket_address *socket_address;
NTSTATUS status;
-
- /* listen for unicasts on the CLDAP port (389) */
- cldapsock = cldap_socket_init(cldapd, cldapd->task->event_ctx, lp_iconv_convenience(cldapd->task->lp_ctx));
- NT_STATUS_HAVE_NO_MEMORY(cldapsock);
-
- socket_address = socket_address_from_strings(cldapsock, cldapsock->sock->backend_name,
- address, lp_cldap_port(lp_ctx));
- if (!socket_address) {
- talloc_free(cldapsock);
- return NT_STATUS_NO_MEMORY;
+ int ret;
+
+ ret = tsocket_address_inet_from_strings(cldapd,
+ "ip",
+ address,
+ lp_cldap_port(lp_ctx),
+ &socket_address);
+ if (ret != 0) {
+ status = map_nt_error_from_unix(errno);
+ DEBUG(0,("invalid address %s:%d - %s:%s\n",
+ address, lp_cldap_port(lp_ctx),
+ gai_strerror(ret), nt_errstr(status)));
+ return status;
}
- status = socket_listen(cldapsock->sock, socket_address, 0, 0);
+ /* listen for unicasts on the CLDAP port (389) */
+ status = cldap_socket_init(cldapd,
+ cldapd->task->event_ctx,
+ socket_address,
+ NULL,
+ &cldapsock);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("Failed to bind to %s:%d - %s\n",
- address, lp_cldap_port(lp_ctx), nt_errstr(status)));
- talloc_free(cldapsock);
+ DEBUG(0,("Failed to bind to %s - %s\n",
+ tsocket_address_string(socket_address, socket_address),
+ nt_errstr(status)));
+ talloc_free(socket_address);
return status;
}
-
talloc_free(socket_address);
cldap_set_incoming_handler(cldapsock, cldapd_request_handler, cldapd);
@@ -117,7 +142,6 @@ static NTSTATUS cldapd_add_socket(struct cldapd_server *cldapd, struct loadparm_
return NT_STATUS_OK;
}
-
/*
setup our listening sockets on the configured network interfaces
*/
diff --git a/source4/cldap_server/netlogon.c b/source4/cldap_server/netlogon.c
index 0df35be6fd..33c0adc3b1 100644
--- a/source4/cldap_server/netlogon.c
+++ b/source4/cldap_server/netlogon.c
@@ -24,7 +24,6 @@
#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
#include "lib/events/events.h"
-#include "lib/socket/socket.h"
#include "smbd/service_task.h"
#include "cldap_server/cldap_server.h"
#include "librpc/gen_ndr/ndr_misc.h"
@@ -36,6 +35,8 @@
#include "system/network.h"
#include "lib/socket/netif.h"
#include "param/param.h"
+#include "../lib/tsocket/tsocket.h"
+
/*
fill in the cldap netlogon union for a given version
*/
@@ -402,12 +403,13 @@ NTSTATUS fill_netlogon_samlogon_response(struct ldb_context *sam_ctx,
/*
handle incoming cldap requests
*/
-void cldapd_netlogon_request(struct cldap_socket *cldap,
+void cldapd_netlogon_request(struct cldap_socket *cldap,
+ struct cldapd_server *cldapd,
+ TALLOC_CTX *tmp_ctx,
uint32_t message_id,
struct ldb_parse_tree *tree,
- struct socket_address *src)
+ struct tsocket_address *src)
{
- struct cldapd_server *cldapd = talloc_get_type(cldap->incoming.private_data, struct cldapd_server);
int i;
const char *domain = NULL;
const char *host = NULL;
@@ -419,8 +421,6 @@ void cldapd_netlogon_request(struct cldap_socket *cldap,
struct netlogon_samlogon_response netlogon;
NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
- TALLOC_CTX *tmp_ctx = talloc_new(cldap);
-
if (tree->operation != LDB_OP_AND) goto failed;
/* extract the query elements */
@@ -478,24 +478,25 @@ void cldapd_netlogon_request(struct cldap_socket *cldap,
domain, host, user, version, domain_guid));
status = fill_netlogon_samlogon_response(cldapd->samctx, tmp_ctx, domain, NULL, NULL, domain_guid,
- user, acct_control, src->addr,
+ user, acct_control,
+ tsocket_address_inet_addr_string(src, tmp_ctx),
version, cldapd->task->lp_ctx, &netlogon);
if (!NT_STATUS_IS_OK(status)) {
goto failed;
}
- status = cldap_netlogon_reply(cldap, message_id, src, version,
+ status = cldap_netlogon_reply(cldap,
+ lp_iconv_convenience(cldapd->task->lp_ctx),
+ message_id, src, version,
&netlogon);
if (!NT_STATUS_IS_OK(status)) {
goto failed;
}
- talloc_free(tmp_ctx);
return;
failed:
DEBUG(2,("cldap netlogon query failed domain=%s host=%s version=%d - %s\n",
domain, host, version, nt_errstr(status)));
- talloc_free(tmp_ctx);
- cldap_empty_reply(cldap, message_id, src);
+ cldap_empty_reply(cldap, message_id, src);
}
diff --git a/source4/cldap_server/rootdse.c b/source4/cldap_server/rootdse.c
index daa5060d07..7e867deff2 100644
--- a/source4/cldap_server/rootdse.c
+++ b/source4/cldap_server/rootdse.c
@@ -20,19 +20,15 @@
*/
#include "includes.h"
+#include <tevent.h>
#include "libcli/ldap/ldap.h"
#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
-#include "lib/events/events.h"
-#include "lib/socket/socket.h"
#include "smbd/service_task.h"
#include "cldap_server/cldap_server.h"
#include "librpc/gen_ndr/ndr_misc.h"
#include "dsdb/samdb/samdb.h"
-#include "auth/auth.h"
#include "ldb_wrap.h"
-#include "system/network.h"
-#include "lib/socket/netif.h"
static void cldapd_rootdse_fill(struct cldapd_server *cldapd,
TALLOC_CTX *mem_ctx,
@@ -151,15 +147,15 @@ done:
handle incoming cldap requests
*/
void cldapd_rootdse_request(struct cldap_socket *cldap,
+ struct cldapd_server *cldapd,
+ TALLOC_CTX *tmp_ctx,
uint32_t message_id,
struct ldap_SearchRequest *search,
- struct socket_address *src)
+ struct tsocket_address *src)
{
- struct cldapd_server *cldapd = talloc_get_type(cldap->incoming.private_data, struct cldapd_server);
NTSTATUS status;
struct cldap_reply reply;
struct ldap_Result result;
- TALLOC_CTX *tmp_ctx = talloc_new(cldap);
ZERO_STRUCT(result);
@@ -176,6 +172,5 @@ void cldapd_rootdse_request(struct cldap_socket *cldap,
ldb_filter_from_tree(tmp_ctx, search->tree), nt_errstr(status)));
}
- talloc_free(tmp_ctx);
return;
}