r26401: Don't cache interfaces context in libnetif.
[samba.git] / source4 / kdc / kdc.c
index c58f73824374f00f327bad2a19a3dacee6936722..0301a4c264149c9c4778727b1f4afd809493f7de 100644 (file)
@@ -38,6 +38,7 @@
 #include "heimdal/kdc/windc_plugin.h"
 #include "heimdal/lib/krb5/krb5_locl.h"
 #include "heimdal/kdc/kdc_locl.h"
+#include "param/param.h"
 
 
 /* Disgusting hack to get a mem_ctx into the hdb plugin, when used as a keytab */
@@ -50,7 +51,7 @@ struct kdc_reply {
        DATA_BLOB packet;
 };
 
-typedef BOOL (*kdc_process_fn_t)(struct kdc_server *kdc,
+typedef bool (*kdc_process_fn_t)(struct kdc_server *kdc,
                                 TALLOC_CTX *mem_ctx, 
                                 DATA_BLOB *input, 
                                 DATA_BLOB *reply,
@@ -310,7 +311,7 @@ static void kdc_tcp_send(struct stream_connection *conn, uint16_t flags)
    calling conventions
 */
 
-static BOOL kdc_process(struct kdc_server *kdc,
+static bool kdc_process(struct kdc_server *kdc,
                        TALLOC_CTX *mem_ctx, 
                        DATA_BLOB *input, 
                        DATA_BLOB *reply,
@@ -336,7 +337,7 @@ static BOOL kdc_process(struct kdc_server *kdc,
                                            datagram_reply);
        if (ret == -1) {
                *reply = data_blob(NULL, 0);
-               return False;
+               return false;
        }
        if (k5_reply.length) {
                *reply = data_blob_talloc(mem_ctx, k5_reply.data, k5_reply.length);
@@ -344,7 +345,7 @@ static BOOL kdc_process(struct kdc_server *kdc,
        } else {
                *reply = data_blob(NULL, 0);    
        }
-       return True;
+       return true;
 }
 
 /*
@@ -407,15 +408,14 @@ static const struct stream_server_ops kpasswdd_tcp_stream_ops = {
 /*
   start listening on the given address
 */
-static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address)
+static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address,
+                              uint16_t kdc_port, uint16_t kpasswd_port)
 {
        const struct model_ops *model_ops;
        struct kdc_socket *kdc_socket;
        struct kdc_socket *kpasswd_socket;
        struct socket_address *kdc_address, *kpasswd_address;
        NTSTATUS status;
-       uint16_t kdc_port = lp_krb5_port();
-       uint16_t kpasswd_port = lp_kpasswd_port();
 
        kdc_socket = talloc(kdc, struct kdc_socket);
        NT_STATUS_HAVE_NO_MEMORY(kdc_socket);
@@ -491,7 +491,9 @@ static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address)
 
        status = stream_setup_socket(kdc->task->event_ctx, model_ops, 
                                     &kdc_tcp_stream_ops, 
-                                    "ip", address, &kdc_port, kdc);
+                                    "ip", address, &kdc_port, 
+                                    lp_socket_options(kdc->task->lp_ctx), 
+                                    kdc);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to bind to %s:%u TCP - %s\n",
                         address, kdc_port, nt_errstr(status)));
@@ -501,7 +503,9 @@ static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address)
 
        status = stream_setup_socket(kdc->task->event_ctx, model_ops, 
                                     &kpasswdd_tcp_stream_ops, 
-                                    "ip", address, &kpasswd_port, kdc);
+                                    "ip", address, &kpasswd_port, 
+                                    lp_socket_options(kdc->task->lp_ctx), 
+                                    kdc);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to bind to %s:%u TCP - %s\n",
                         address, kpasswd_port, nt_errstr(status)));
@@ -516,17 +520,20 @@ static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address)
 /*
   setup our listening sockets on the configured network interfaces
 */
-static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc)
+static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx,
+                                      struct interface *ifaces)
 {
-       int num_interfaces = iface_count();
+       int num_interfaces;
        TALLOC_CTX *tmp_ctx = talloc_new(kdc);
        NTSTATUS status;
-       
        int i;
+
+       num_interfaces = iface_count(ifaces);
        
        for (i=0; i<num_interfaces; i++) {
-               const char *address = talloc_strdup(tmp_ctx, iface_n_ip(i));
-               status = kdc_add_socket(kdc, address);
+               const char *address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i));
+               status = kdc_add_socket(kdc, address, lp_krb5_port(lp_ctx), 
+                                       lp_kpasswd_port(lp_ctx));
                NT_STATUS_NOT_OK_RETURN(status);
        }
 
@@ -553,8 +560,9 @@ static void kdc_task_init(struct task_server *task)
        struct kdc_server *kdc;
        NTSTATUS status;
        krb5_error_code ret;
+       struct interface *ifaces;
 
-       switch (lp_server_role()) {
+       switch (lp_server_role(task->lp_ctx)) {
        case ROLE_STANDALONE:
                task_server_terminate(task, "kdc: no KDC required in standalone configuration");
                return;
@@ -566,7 +574,9 @@ static void kdc_task_init(struct task_server *task)
                break;
        }
 
-       if (iface_count() == 0) {
+       load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+
+       if (iface_count(ifaces) == 0) {
                task_server_terminate(task, "kdc: no network interfaces configured");
                return;
        }
@@ -583,7 +593,7 @@ static void kdc_task_init(struct task_server *task)
 
        initialize_krb5_error_table();
 
-       ret = smb_krb5_init_context(kdc, task->event_ctx, &kdc->smb_krb5_context);
+       ret = smb_krb5_init_context(kdc, task->event_ctx, task->lp_ctx, &kdc->smb_krb5_context);
        if (ret) {
                DEBUG(1,("kdc_task_init: krb5_init_context failed (%s)\n", 
                         error_message(ret)));
@@ -608,7 +618,8 @@ static void kdc_task_init(struct task_server *task)
        }
        kdc->config->num_db = 1;
                
-       status = kdc_hdb_ldb_create(kdc, kdc->smb_krb5_context->krb5_context, 
+       status = kdc_hdb_ldb_create(kdc, task->lp_ctx, 
+                                   kdc->smb_krb5_context->krb5_context, 
                                    &kdc->config->db[0], NULL);
        if (!NT_STATUS_IS_OK(status)) {
                task_server_terminate(task, "kdc: hdb_ldb_create (setup KDC database) failed");
@@ -635,7 +646,7 @@ static void kdc_task_init(struct task_server *task)
        kdc_mem_ctx = kdc->smb_krb5_context;
 
        /* start listening on the configured network interfaces */
-       status = kdc_startup_interfaces(kdc);
+       status = kdc_startup_interfaces(kdc, task->lp_ctx, ifaces);
        if (!NT_STATUS_IS_OK(status)) {
                task_server_terminate(task, "kdc failed to setup interfaces");
                return;
@@ -649,6 +660,7 @@ static void kdc_task_init(struct task_server *task)
   called on startup of the KDC service 
 */
 static NTSTATUS kdc_init(struct event_context *event_ctx, 
+                        struct loadparm_context *lp_ctx,
                         const struct model_ops *model_ops)
 {      
        return task_server_startup(event_ctx, model_ops, kdc_task_init);