s3-dsgetdcname: always pass in messaging context.
authorGünther Deschner <gd@samba.org>
Wed, 22 Sep 2010 03:56:23 +0000 (20:56 -0700)
committerGünther Deschner <gd@samba.org>
Thu, 23 Sep 2010 17:26:25 +0000 (10:26 -0700)
Volker, please check.

Guenther

source3/lib/netapi/getdc.c
source3/lib/netapi/joindomain.c
source3/lib/netapi/netapi_private.h
source3/libnet/libnet_samsync.c
source3/libnet/libnet_samsync.h
source3/libnet/libnet_samsync_keytab.c
source3/libsmb/dsgetdcname.c
source3/utils/net.c
source3/utils/net.h
source3/utils/net_ads.c
source3/utils/net_lookup.c

index 565ccbc14b8fbd45564f355dbf2aea7668a8834c..904270242adb50fd188234f0933d040a94658471 100644 (file)
@@ -112,9 +112,13 @@ WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
                     struct DsGetDcName *r)
 {
        NTSTATUS status;
+       struct libnetapi_private_ctx *priv;
+
+       priv = talloc_get_type_abort(ctx->private_data,
+               struct libnetapi_private_ctx);
 
        status = dsgetdcname(ctx,
-                            NULL,
+                            priv->msg_ctx,
                             r->in.domain_name,
                             r->in.domain_guid,
                             r->in.site_name,
index 89a7c93d5e2123df86715d73f04469576a7bf152..e5777a0d3345174402c39b0c648e29c246b9734f 100644 (file)
@@ -36,8 +36,12 @@ WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx,
                       struct NetJoinDomain *r)
 {
        struct libnet_JoinCtx *j = NULL;
+       struct libnetapi_private_ctx *priv;
        WERROR werr;
 
+       priv = talloc_get_type_abort(mem_ctx->private_data,
+               struct libnetapi_private_ctx);
+
        if (!r->in.domain) {
                return WERR_INVALID_PARAM;
        }
@@ -55,7 +59,7 @@ WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx,
                uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
                                 DS_WRITABLE_REQUIRED |
                                 DS_RETURN_DNS_NAME;
-               status = dsgetdcname(mem_ctx, NULL, r->in.domain,
+               status = dsgetdcname(mem_ctx, priv->msg_ctx, r->in.domain,
                                     NULL, NULL, flags, &info);
                if (!NT_STATUS_IS_OK(status)) {
                        libnetapi_set_error_string(mem_ctx,
@@ -154,6 +158,10 @@ WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx,
        struct dom_sid domain_sid;
        const char *domain = NULL;
        WERROR werr;
+       struct libnetapi_private_ctx *priv;
+
+       priv = talloc_get_type_abort(mem_ctx->private_data,
+               struct libnetapi_private_ctx);
 
        if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) {
                return WERR_SETUP_NOT_JOINED;
@@ -178,7 +186,7 @@ WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx,
                uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
                                 DS_WRITABLE_REQUIRED |
                                 DS_RETURN_DNS_NAME;
-               status = dsgetdcname(mem_ctx, NULL, domain,
+               status = dsgetdcname(mem_ctx, priv->msg_ctx, domain,
                                     NULL, NULL, flags, &info);
                if (!NT_STATUS_IS_OK(status)) {
                        libnetapi_set_error_string(mem_ctx,
@@ -348,8 +356,12 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx,
        const char *dc = NULL;
        uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
                         DS_RETURN_DNS_NAME;
+       struct libnetapi_private_ctx *priv;
+
+       priv = talloc_get_type_abort(ctx->private_data,
+               struct libnetapi_private_ctx);
 
-       status = dsgetdcname(ctx, NULL, r->in.domain,
+       status = dsgetdcname(ctx, priv->msg_ctx, r->in.domain,
                             NULL, NULL, flags, &info);
        if (!NT_STATUS_IS_OK(status)) {
                libnetapi_set_error_string(ctx, "%s",
index d0f7756d162457731b31ed9cb3298d01b6e2563f..859c0642239e6d46d4f8caf435f0b897eede6074 100644 (file)
@@ -44,6 +44,8 @@ struct libnetapi_private_ctx {
        } samr;
 
        struct client_ipc_connection *ipc_connections;
+
+       struct messaging_context *msg_ctx;
 };
 
 NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password);
index 1b5b9c3b2f52dff4204391a9f7194e53e3af9abd..6e416af180ce0c46ed7a8c5e193854c5fc9f07a7 100644 (file)
@@ -80,6 +80,10 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx,
                NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid_str);
        }
 
+       ctx->msg_ctx = messaging_init(ctx, procid_self(),
+                                     event_context_init(ctx));
+       NT_STATUS_HAVE_NO_MEMORY(ctx->msg_ctx);
+
        *ctx_p = ctx;
 
        return NT_STATUS_OK;
index cc3334050f3752ff912c452bda0597aa791187c8..efdbb372bd1876aa56dd45a6b89919b8e65e0d79 100644 (file)
@@ -75,6 +75,7 @@ struct samsync_context {
        struct samsync_object *objects;
 
        struct rpc_pipe_client *cli;
+       struct messaging_context *msg_ctx;
 
        const struct samsync_ops *ops;
 
index 0f7c5afac6abd57242f45dbc99114f7fee714f0a..3f7e895928fe34dd88df0860307146ba21d6ef21 100644 (file)
 
 static NTSTATUS keytab_ad_connect(TALLOC_CTX *mem_ctx,
                                  const char *domain_name,
+                                 const char *dc,
                                  const char *username,
                                  const char *password,
                                  struct libnet_keytab_context *ctx)
 {
-       NTSTATUS status;
        ADS_STATUS ad_status;
        ADS_STRUCT *ads;
-       struct netr_DsRGetDCNameInfo *info = NULL;
-       const char *dc;
-
-       status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, NULL, 0, &info);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       dc = strip_hostname(info->dc_unc);
 
        ads = ads_init(NULL, domain_name, dc);
        NT_STATUS_HAVE_NO_MEMORY(ads);
@@ -119,17 +110,28 @@ static NTSTATUS init_keytab(TALLOC_CTX *mem_ctx,
        struct libnet_keytab_entry *entry;
        uint64_t old_sequence_num = 0;
        const char *principal = NULL;
+       struct netr_DsRGetDCNameInfo *info = NULL;
+       const char *dc;
 
        ret = libnet_keytab_init(mem_ctx, ctx->output_filename, &keytab_ctx);
        if (ret) {
                return krb5_to_nt_status(ret);
        }
 
+       status = dsgetdcname(mem_ctx, ctx->msg_ctx,
+                            ctx->domain_name, NULL, NULL, 0, &info);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       dc = strip_hostname(info->dc_unc);
+
        keytab_ctx->clean_old_entries = ctx->clean_old_entries;
        ctx->private_data = keytab_ctx;
 
        status = keytab_ad_connect(mem_ctx,
                                   ctx->domain_name,
+                                  dc,
                                   ctx->username,
                                   ctx->password,
                                   keytab_ctx);
index 2803e74b66b85343a3bfbde48cbb6d4c14bd7f5c..4d0310fd7cfc29f1babb3b57038f821a99e8e62a 100644 (file)
@@ -900,30 +900,6 @@ static NTSTATUS process_dc_dns(TALLOC_CTX *mem_ctx,
 /****************************************************************
 ****************************************************************/
 
-static struct event_context *ev_context(void)
-{
-       static struct event_context *ctx;
-
-       if (!ctx && !(ctx = event_context_init(NULL))) {
-               smb_panic("Could not init event context");
-       }
-       return ctx;
-}
-
-/****************************************************************
-****************************************************************/
-
-static struct messaging_context *msg_context(TALLOC_CTX *mem_ctx)
-{
-       static struct messaging_context *ctx;
-
-       if (!ctx && !(ctx = messaging_init(mem_ctx, procid_self(),
-                                          ev_context()))) {
-               smb_panic("Could not init messaging context");
-       }
-       return ctx;
-}
-
 /****************************************************************
 ****************************************************************/
 
@@ -948,8 +924,8 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx,
                              NETLOGON_NT_VERSION_5 |
                              NETLOGON_NT_VERSION_5EX_WITH_IP;
 
-       if (!msg_ctx) {
-               msg_ctx = msg_context(mem_ctx);
+       if (msg_ctx == NULL) {
+               return NT_STATUS_INVALID_PARAMETER;
        }
 
        if (flags & DS_PDC_REQUIRED) {
index eea13ea138e73b2023745cbb94d9810509e2446e..6c2fbad59a44f0c7e8590442adfca93a7da947a0 100644 (file)
@@ -929,6 +929,12 @@ static struct functable net_func[] = {
                c->opt_password = getenv("PASSWD");
        }
 
+       c->msg_ctx = messaging_init(c, procid_self(),
+                                   event_context_init(c));
+       if (c->msg_ctx == NULL) {
+               exit(1);
+       }
+
        rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
 
        DEBUG(2,("return code = %d\n", rc));
index fc6addf231c60b593881314fb323d7db7eca45fb..d09d9905d7f64d959f2d69ea56fdcfa708a7ace7 100644 (file)
@@ -78,6 +78,7 @@ struct net_context {
        struct sockaddr_storage opt_dest_ip;
        bool smb_encrypt;
        struct libnetapi_ctx *netapi_ctx;
+       struct messaging_context *msg_ctx;
 
        bool display_usage;
        void *private_data;
index 08bb9d1f60709d4cde22b6d072e77a837862ab1b..a07e6c56eaaaa2bf237145ed708a8e5427a2a504 100644 (file)
@@ -986,6 +986,7 @@ static int net_ads_leave(struct net_context *c, int argc, const char **argv)
        r->in.unjoin_flags      = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
                                  WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE;
        r->in.delete_machine_account = true;
+       r->in.msg_ctx           = c->msg_ctx;
 
        werr = libnet_Unjoin(ctx, r);
        if (!W_ERROR_IS_OK(werr)) {
@@ -1357,6 +1358,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        r->in.join_flags        = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
                                  WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE |
                                  WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED;
+       r->in.msg_ctx           = c->msg_ctx;
 
        werr = libnet_Join(ctx, r);
        if (!W_ERROR_IS_OK(werr)) {
index 5ff62398f2918c77e66109c7909dbb36cb2c6425..3609eacdf8c583a0d55cbffb20c6b5a291dc9e96 100644 (file)
@@ -409,7 +409,7 @@ static int net_lookup_dsgetdcname(struct net_context *c, int argc, const char **
                site_name = argv[2];
        }
 
-       status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, site_name,
+       status = dsgetdcname(mem_ctx, c->msg_ctx, domain_name, NULL, site_name,
                             flags, &info);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf(_("failed with: %s\n"), nt_errstr(status));