From: Stefan Metzmacher Date: Fri, 23 Mar 2018 06:47:38 +0000 (+0100) Subject: smbd: add smbd_impersonate_debug_create() helper X-Git-Tag: ldb-1.5.0~344 X-Git-Url: http://git.samba.org/samba.git/?p=kai%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=23319ef5a2eff4811b685d4ab54179efc49bac99 smbd: add smbd_impersonate_debug_create() helper This will be used to implement no-op impersonation for the create_conn_struct_as_root() case were we don't really have other unrelated events in the loop and only need a valid tevent wrapper context to avoid double free on the raw event context on teardown. This also adds useful debugging instead of being a full no-op wrapper. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index cbb43829fe0..f31ef98624c 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1189,6 +1189,12 @@ void reply_transs2(struct smb_request *req); /* The following definitions come from smbd/uid.c */ +#define smbd_impersonate_debug_create(main_ev, name, dbg_lvl) \ + _smbd_impersonate_debug_create(main_ev, name, dbg_lvl, __location__) +struct tevent_context *_smbd_impersonate_debug_create(struct tevent_context *main_ev, + const char *name, + int dbg_lvl, + const char *location); bool change_to_guest(void); NTSTATUS check_user_share_access(connection_struct *conn, const struct auth_session_info *session_info, diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index c6c4573f9c9..98202b13de1 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -25,6 +25,235 @@ #include "libcli/security/security.h" #include "passdb/lookup_sid.h" #include "auth.h" +#include "lib/util/time_basic.h" + +struct smbd_impersonate_debug_state { + int dbg_lvl; + const char *name; +}; + +static bool smbd_impersonate_debug_before_use(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, location)); + + return true; +} + +static void smbd_impersonate_debug_after_use(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, location)); +} + +static void smbd_impersonate_debug_before_fd_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_fd *fde, + uint16_t flags, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "fde[%p] flags[0x%X] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + fde, flags, handler_name, location)); +} + +static void smbd_impersonate_debug_after_fd_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_fd *fde, + uint16_t flags, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "fde[%p] flags[0x%X] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + fde, flags, handler_name, location)); +} + +static void smbd_impersonate_debug_before_timer_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_timer *te, + struct timeval requested_time, + struct timeval trigger_time, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + struct timeval_buf requested_buf; + struct timeval_buf trigger_buf; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "te[%p] requested_time[%s] trigger_time[%s] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, te, + timeval_str_buf(&requested_time, true, true, &requested_buf), + timeval_str_buf(&trigger_time, true, true, &trigger_buf), + handler_name, location)); +} + +static void smbd_impersonate_debug_after_timer_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_timer *te, + struct timeval requested_time, + struct timeval trigger_time, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + struct timeval_buf requested_buf; + struct timeval_buf trigger_buf; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "te[%p] requested_time[%s] trigger_time[%s] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, te, + timeval_str_buf(&requested_time, true, true, &requested_buf), + timeval_str_buf(&trigger_time, true, true, &trigger_buf), + handler_name, location)); +} + +static void smbd_impersonate_debug_before_immediate_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_immediate *im, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "im[%p] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + im, handler_name, location)); +} + +static void smbd_impersonate_debug_after_immediate_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_immediate *im, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "im[%p] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + im, handler_name, location)); +} + +static void smbd_impersonate_debug_before_signal_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "se[%p] signum[%d] count[%d] siginfo[%p] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + se, signum, count, siginfo, handler_name, location)); +} + +static void smbd_impersonate_debug_after_signal_handler(struct tevent_context *wrap_ev, + void *private_data, + struct tevent_context *main_ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + const char *handler_name, + const char *location) +{ + struct smbd_impersonate_debug_state *state = + (struct smbd_impersonate_debug_state *)private_data; + + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] " + "se[%p] signum[%d] count[%d] siginfo[%p] handler_name[%s] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, + se, signum, count, siginfo, handler_name, location)); +} + +static const struct tevent_wrapper_ops smbd_impersonate_debug_ops = { + .name = "smbd_impersonate_debug", + .before_use = smbd_impersonate_debug_before_use, + .after_use = smbd_impersonate_debug_after_use, + .before_fd_handler = smbd_impersonate_debug_before_fd_handler, + .after_fd_handler = smbd_impersonate_debug_after_fd_handler, + .before_timer_handler = smbd_impersonate_debug_before_timer_handler, + .after_timer_handler = smbd_impersonate_debug_after_timer_handler, + .before_immediate_handler = smbd_impersonate_debug_before_immediate_handler, + .after_immediate_handler = smbd_impersonate_debug_after_immediate_handler, + .before_signal_handler = smbd_impersonate_debug_before_signal_handler, + .after_signal_handler = smbd_impersonate_debug_after_signal_handler, +}; + +struct tevent_context *_smbd_impersonate_debug_create(struct tevent_context *main_ev, + const char *name, + int dbg_lvl, + const char *location) +{ + struct tevent_context *wrap_ev = NULL; + struct smbd_impersonate_debug_state *state = NULL; + + wrap_ev = tevent_context_wrapper_create(main_ev, + main_ev, + &smbd_impersonate_debug_ops, + &state, + struct smbd_impersonate_debug_state); + if (wrap_ev == NULL) { + return NULL; + } + state->name = name; + state->dbg_lvl = dbg_lvl; + DEBUG(state->dbg_lvl, ( + "%s: name[%s] wrap_ev[%p] state[%p] main_ev[%p] location[%s]\n", + __func__, state->name, wrap_ev, state, main_ev, location)); + + return wrap_ev; +} /* what user is current? */ extern struct current_user current_user;