From c42219d7352bd2e7a6413f7ae1cd0fd5cded1d95 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 May 2007 08:47:04 +0000 Subject: [PATCH] r22969: fix some more places where we could end up with more than one event context. We now have an event context on the torture_context, and we can also get one from the cli_credentials structure (This used to be commit c0f65eb6562e13530337c23e3447a6aa6eb8fc17) --- source4/auth/credentials/credentials.c | 21 +++++++++++++++++++ source4/auth/credentials/credentials.h | 3 +++ source4/auth/credentials/credentials_krb5.c | 3 ++- source4/auth/gensec/gensec_gssapi.c | 2 ++ source4/auth/kerberos/krb5_init_context.c | 3 +-- source4/auth/kerberos/krb5_init_context.h | 3 ++- source4/client/client.c | 3 ++- source4/dsdb/samdb/cracknames.c | 4 +++- .../dsdb/samdb/ldb_modules/password_hash.c | 8 +++++-- source4/kdc/kdc.c | 2 +- source4/torture/auth/pac.c | 7 +++++-- source4/torture/basic/misc.c | 2 +- source4/torture/libnet/libnet_BecomeDC.c | 2 +- source4/torture/local/irpc.c | 2 +- source4/torture/local/messaging.c | 2 +- source4/torture/local/resolve.c | 2 +- source4/torture/raw/composite.c | 2 +- source4/torture/raw/open.c | 4 +++- source4/torture/rpc/async_bind.c | 8 +++---- source4/torture/torture.c | 7 +++++-- source4/torture/ui.h | 1 + source4/torture/util_smb.c | 4 +++- 22 files changed, 70 insertions(+), 25 deletions(-) diff --git a/source4/auth/credentials/credentials.c b/source4/auth/credentials/credentials.c index c76c170c6db..39b22df729a 100644 --- a/source4/auth/credentials/credentials.c +++ b/source4/auth/credentials/credentials.c @@ -27,6 +27,7 @@ #include "auth/credentials/credentials.h" #include "auth/credentials/credentials_krb5.h" #include "libcli/auth/libcli_auth.h" +#include "lib/events/events.h" /** * Create a new credentials structure @@ -61,6 +62,7 @@ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx) cred->tries = 3; cred->callback_running = False; + cred->ev = NULL; cli_credentials_set_kerberos_state(cred, CRED_AUTO_USE_KERBEROS); cli_credentials_set_gensec_features(cred, 0); @@ -747,3 +749,22 @@ BOOL cli_credentials_wrong_password(struct cli_credentials *cred) return (cred->tries > 0); } + +/* + set the common event context for this set of credentials + */ +void cli_credentials_set_event_context(struct cli_credentials *cred, struct event_context *ev) +{ + cred->ev = ev; +} + +/* + set the common event context for this set of credentials + */ +struct event_context *cli_credentials_get_event_context(struct cli_credentials *cred) +{ + if (cred->ev == NULL) { + cred->ev = event_context_find(cred); + } + return cred->ev; +} diff --git a/source4/auth/credentials/credentials.h b/source4/auth/credentials/credentials.h index ce63a55bb3c..e20c6015e95 100644 --- a/source4/auth/credentials/credentials.h +++ b/source4/auth/credentials/credentials.h @@ -114,6 +114,9 @@ struct cli_credentials { /* Whether any callback is currently running */ BOOL callback_running; + + /* an event context for anyone wanting to use the credentials */ + struct event_context *ev; }; struct ldb_context; diff --git a/source4/auth/credentials/credentials_krb5.c b/source4/auth/credentials/credentials_krb5.c index 69fb9e7b33f..58b5c1df3bf 100644 --- a/source4/auth/credentials/credentials_krb5.c +++ b/source4/auth/credentials/credentials_krb5.c @@ -37,7 +37,8 @@ int cli_credentials_get_krb5_context(struct cli_credentials *cred, return 0; } - ret = smb_krb5_init_context(cred, &cred->smb_krb5_context); + ret = smb_krb5_init_context(cred, cli_credentials_get_event_context(cred), + &cred->smb_krb5_context); if (ret) { return ret; } diff --git a/source4/auth/gensec/gensec_gssapi.c b/source4/auth/gensec/gensec_gssapi.c index 4dd5905480f..b8040df7eb8 100644 --- a/source4/auth/gensec/gensec_gssapi.c +++ b/source4/auth/gensec/gensec_gssapi.c @@ -23,6 +23,7 @@ */ #include "includes.h" +#include "lib/events/events.h" #include "system/kerberos.h" #include "heimdal/lib/gssapi/gssapi/gssapi.h" #include "auth/kerberos/kerberos.h" @@ -226,6 +227,7 @@ static NTSTATUS gensec_gssapi_start(struct gensec_security *gensec_security) } ret = smb_krb5_init_context(gensec_gssapi_state, + gensec_security->event_ctx, &gensec_gssapi_state->smb_krb5_context); if (ret) { DEBUG(1,("gensec_krb5_start: krb5_init_context failed (%s)\n", diff --git a/source4/auth/kerberos/krb5_init_context.c b/source4/auth/kerberos/krb5_init_context.c index 92de176e84e..9eccd459fa8 100644 --- a/source4/auth/kerberos/krb5_init_context.c +++ b/source4/auth/kerberos/krb5_init_context.c @@ -355,11 +355,11 @@ krb5_error_code smb_krb5_send_and_recv_func(krb5_context context, } krb5_error_code smb_krb5_init_context(void *parent_ctx, + struct event_context *ev, struct smb_krb5_context **smb_krb5_context) { krb5_error_code ret; TALLOC_CTX *tmp_ctx; - struct event_context *ev; char **config_files; const char *config_file; @@ -446,7 +446,6 @@ krb5_error_code smb_krb5_init_context(void *parent_ctx, } krb5_set_warn_dest((*smb_krb5_context)->krb5_context, (*smb_krb5_context)->logf); - ev = event_context_find(*smb_krb5_context); /* Set use of our socket lib */ ret = krb5_set_send_to_kdc_func((*smb_krb5_context)->krb5_context, smb_krb5_send_and_recv_func, diff --git a/source4/auth/kerberos/krb5_init_context.h b/source4/auth/kerberos/krb5_init_context.h index 7aad97e2ca5..3c012aa2750 100644 --- a/source4/auth/kerberos/krb5_init_context.h +++ b/source4/auth/kerberos/krb5_init_context.h @@ -23,7 +23,8 @@ struct smb_krb5_context { krb5_log_facility *logf; }; -krb5_error_code smb_krb5_init_context(void *parent_ctx, +struct event_context; +krb5_error_code smb_krb5_init_context(void *parent_ctx, struct event_context *ev, struct smb_krb5_context **smb_krb5_context); void smb_krb5_free_context(struct smb_krb5_context *smb_krb5_context); diff --git a/source4/client/client.c b/source4/client/client.c index 557767022c9..2de071a1958 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -2994,7 +2994,8 @@ static struct smbclient_context *do_connect(TALLOC_CTX *mem_ctx, ctx->remote_cur_dir = talloc_strdup(ctx, "\\"); status = smbcli_full_connection(ctx, &ctx->cli, server, - share, NULL, cred, NULL); + share, NULL, cred, + cli_credentials_get_event_context(cred)); if (!NT_STATUS_IS_OK(status)) { d_printf("Connection to \\\\%s\\%s failed - %s\n", server, share, nt_errstr(status)); diff --git a/source4/dsdb/samdb/cracknames.c b/source4/dsdb/samdb/cracknames.c index eec27c66688..2e26f1c308d 100644 --- a/source4/dsdb/samdb/cracknames.c +++ b/source4/dsdb/samdb/cracknames.c @@ -348,7 +348,9 @@ WERROR DsCrackNameOneName(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx, struct ldb_dn *name_dn = NULL; struct smb_krb5_context *smb_krb5_context; - ret = smb_krb5_init_context(mem_ctx, &smb_krb5_context); + ret = smb_krb5_init_context(mem_ctx, + ldb_get_opaque(sam_ctx, "EventContext"), + &smb_krb5_context); if (ret) { return WERR_NOMEM; diff --git a/source4/dsdb/samdb/ldb_modules/password_hash.c b/source4/dsdb/samdb/ldb_modules/password_hash.c index 780dc69b239..2db76f84395 100644 --- a/source4/dsdb/samdb/ldb_modules/password_hash.c +++ b/source4/dsdb/samdb/ldb_modules/password_hash.c @@ -1430,7 +1430,9 @@ static int password_hash_add_do_add(struct ldb_handle *h) { } /* Some operations below require kerberos contexts */ - if (smb_krb5_init_context(ac->down_req, &smb_krb5_context) != 0) { + if (smb_krb5_init_context(ac->down_req, + ldb_get_opaque(h->module->ldb, "EventContext"), + &smb_krb5_context) != 0) { return LDB_ERR_OPERATIONS_ERROR; } @@ -1760,7 +1762,9 @@ static int password_hash_mod_do_mod(struct ldb_handle *h) { msg->dn = ac->orig_req->op.mod.message->dn; /* Some operations below require kerberos contexts */ - if (smb_krb5_init_context(ac->mod_req, &smb_krb5_context) != 0) { + if (smb_krb5_init_context(ac->mod_req, + ldb_get_opaque(h->module->ldb, "EventContext"), + &smb_krb5_context) != 0) { return LDB_ERR_OPERATIONS_ERROR; } diff --git a/source4/kdc/kdc.c b/source4/kdc/kdc.c index 1cb9ed19814..0cb05dee348 100644 --- a/source4/kdc/kdc.c +++ b/source4/kdc/kdc.c @@ -582,7 +582,7 @@ static void kdc_task_init(struct task_server *task) initialize_krb5_error_table(); - ret = smb_krb5_init_context(kdc, &kdc->smb_krb5_context); + ret = smb_krb5_init_context(kdc, task->event_ctx, &kdc->smb_krb5_context); if (ret) { DEBUG(1,("kdc_task_init: krb5_init_context failed (%s)\n", error_message(ret))); diff --git a/source4/torture/auth/pac.c b/source4/torture/auth/pac.c index d23a9c1b5a6..46690890fa2 100644 --- a/source4/torture/auth/pac.c +++ b/source4/torture/auth/pac.c @@ -56,7 +56,9 @@ static bool torture_pac_self_check(struct torture_context *tctx) TALLOC_CTX *mem_ctx = tctx; - torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, &smb_krb5_context), + torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, + NULL, + &smb_krb5_context), "smb_krb5_init_context"); generate_random_buffer(server_bytes, 16); @@ -282,7 +284,8 @@ static bool torture_pac_saved_check(struct torture_context *tctx) time_t authtime; TALLOC_CTX *mem_ctx = tctx; - torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, &smb_krb5_context), + torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, NULL, + &smb_krb5_context), "smb_krb5_init_context"); pac_kdc_key = torture_setting_string(tctx, "pac_kdc_key", diff --git a/source4/torture/basic/misc.c b/source4/torture/basic/misc.c index 33f0b9eff60..933e4334c03 100644 --- a/source4/torture/basic/misc.c +++ b/source4/torture/basic/misc.c @@ -843,7 +843,7 @@ BOOL run_benchrw(struct torture_context *tctx) torture_numops, torture_nprocs); /*init talloc context*/ - ev = event_context_init(tctx); + ev = tctx->ev; state = talloc_array(tctx, struct benchrw_state *, torture_nprocs); /* init params using lp_parm_xxx */ diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index b164ee4906f..a2b65e260c7 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -755,7 +755,7 @@ BOOL torture_net_become_dc(struct torture_context *torture) return False; } - s->ctx = libnet_context_init(event_context_init(s)); + s->ctx = libnet_context_init(torture->ev); s->ctx->cred = cmdline_credentials; s->ldb = ldb_init(s); diff --git a/source4/torture/local/irpc.c b/source4/torture/local/irpc.c index bd52be09e2f..3c177c4ecee 100644 --- a/source4/torture/local/irpc.c +++ b/source4/torture/local/irpc.c @@ -217,7 +217,7 @@ static BOOL irpc_setup(struct torture_context *tctx, void **_data) lp_set_cmdline("lock dir", "lockdir.tmp"); - data->ev = event_context_init(tctx); + data->ev = tctx->ev; torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, cluster_id(MSG_ID1), data->ev), diff --git a/source4/torture/local/messaging.c b/source4/torture/local/messaging.c index f6ae8a3e8cc..ce9928d91dc 100644 --- a/source4/torture/local/messaging.c +++ b/source4/torture/local/messaging.c @@ -70,7 +70,7 @@ static bool test_ping_speed(struct torture_context *tctx) lp_set_cmdline("pid directory", "piddir.tmp"); - ev = event_context_init(mem_ctx); + ev = tctx->ev; msg_server_ctx = messaging_init(mem_ctx, cluster_id(1), ev); diff --git a/source4/torture/local/resolve.c b/source4/torture/local/resolve.c index 21a7392a147..d3bae211841 100644 --- a/source4/torture/local/resolve.c +++ b/source4/torture/local/resolve.c @@ -35,7 +35,7 @@ static bool test_async_resolve(struct torture_context *tctx) struct timeval tv = timeval_current(); TALLOC_CTX *mem_ctx = tctx; - ev = event_context_init(mem_ctx); + ev = tctx->ev; ZERO_STRUCT(n); n.name = host; diff --git a/source4/torture/raw/composite.c b/source4/torture/raw/composite.c index b551af00b12..e68ebcc824b 100644 --- a/source4/torture/raw/composite.c +++ b/source4/torture/raw/composite.c @@ -164,7 +164,7 @@ static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) printf("testing parallel fetchfile with %d ops\n", torture_numops); - event_ctx = event_context_init(mem_ctx); + event_ctx = cli->transport->socket->event.ctx; c = talloc_array(mem_ctx, struct composite_context *, torture_numops); for (i=0; iui_ops = ui_ops; torture->returncode = true; + torture->ev = cli_credentials_get_event_context(cmdline_credentials); if (ui_ops->init) ui_ops->init(torture); diff --git a/source4/torture/ui.h b/source4/torture/ui.h index 70b86b04247..b41da771381 100644 --- a/source4/torture/ui.h +++ b/source4/torture/ui.h @@ -90,6 +90,7 @@ struct torture_context char *outputdir; int level; + struct event_context *ev; }; /* diff --git a/source4/torture/util_smb.c b/source4/torture/util_smb.c index 4cadbe20fee..23b98fc7b6d 100644 --- a/source4/torture/util_smb.c +++ b/source4/torture/util_smb.c @@ -31,6 +31,7 @@ #include "torture/ui.h" #include "torture/torture.h" #include "util/dlinklist.h" +#include "auth/credentials/credentials.h" /** @@ -541,7 +542,8 @@ _PUBLIC_ bool torture_open_connection_ev(struct smbcli_state **c, _PUBLIC_ bool torture_open_connection(struct smbcli_state **c, int conn_index) { - return torture_open_connection_ev(c, conn_index, NULL); + return torture_open_connection_ev(c, conn_index, + cli_credentials_get_event_context(cmdline_credentials)); } -- 2.34.1