From 9010bbeb00264f4476c3be7d2e8c8420c695cfbb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 24 Sep 2014 20:46:15 +0200 Subject: [PATCH] s3:locking: allow early return for share_entry_forall() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Reviewed-by: Stefan Metzmacher --- source3/locking/proto.h | 4 +- source3/locking/share_mode_lock.c | 23 +++++++----- source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 46 +++++++++++++---------- source3/utils/status.c | 12 +++--- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/source3/locking/proto.h b/source3/locking/proto.h index a5c46c8140e..44f3ba13e08 100644 --- a/source3/locking/proto.h +++ b/source3/locking/proto.h @@ -194,8 +194,8 @@ int share_mode_forall(int (*fn)(struct file_id fid, const struct share_mode_data *data, void *private_data), void *private_data); -int share_entry_forall(void (*fn)(const struct share_mode_entry *, const char *, - const char *, void *), +int share_entry_forall(int (*fn)(const struct share_mode_entry *, const char *, + const char *, void *), void *private_data); bool share_mode_cleanup_disconnected(struct file_id id, uint64_t open_persistent_id); diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c index c2f34022ae0..da16d1acf02 100644 --- a/source3/locking/share_mode_lock.c +++ b/source3/locking/share_mode_lock.c @@ -522,9 +522,9 @@ int share_mode_forall(int (*fn)(struct file_id fid, } struct share_entry_forall_state { - void (*fn)(const struct share_mode_entry *e, - const char *service_path, const char *base_name, - void *private_data); + int (*fn)(const struct share_mode_entry *e, + const char *service_path, const char *base_name, + void *private_data); void *private_data; }; @@ -536,9 +536,14 @@ static int share_entry_traverse_fn(struct file_id fid, uint32_t i; for (i=0; inum_share_modes; i++) { - state->fn(&data->share_modes[i], - data->servicepath, data->base_name, - state->private_data); + int ret; + + ret = state->fn(&data->share_modes[i], + data->servicepath, data->base_name, + state->private_data); + if (ret != 0) { + return ret; + } } return 0; @@ -549,9 +554,9 @@ static int share_entry_traverse_fn(struct file_id fid, share mode system. ********************************************************************/ -int share_entry_forall(void (*fn)(const struct share_mode_entry *, - const char *, const char *, void *), - void *private_data) +int share_entry_forall(int (*fn)(const struct share_mode_entry *, + const char *, const char *, void *), + void *private_data) { struct share_entry_forall_state state = { .fn = fn, .private_data = private_data }; diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c index d2f05f30ccd..eaa70e784d6 100644 --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c @@ -79,9 +79,9 @@ struct share_conn_stat { /******************************************************************* ********************************************************************/ -static void enum_file_fn( const struct share_mode_entry *e, - const char *sharepath, const char *fname, - void *private_data ) +static int enum_file_fn(const struct share_mode_entry *e, + const char *sharepath, const char *fname, + void *private_data) { struct file_enum_count *fenum = (struct file_enum_count *)private_data; @@ -98,21 +98,21 @@ static void enum_file_fn( const struct share_mode_entry *e, /* If the pid was not found delete the entry from connections.tdb */ if ( !process_exists(e->pid) ) { - return; + return 0; } username = uidtoname(e->uid); if ((fenum->username != NULL) && !strequal(username, fenum->username)) { - return; + return 0; } f = talloc_realloc(fenum->ctx, fenum->ctr3->array, struct srvsvc_NetFileInfo3, i+1); if ( !f ) { DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1)); - return; + return 0; } fenum->ctr3->array = f; @@ -133,7 +133,7 @@ static void enum_file_fn( const struct share_mode_entry *e, sharepath, fname ); } if (!fullpath) { - return; + return 0; } string_replace( fullpath, '/', '\\' ); @@ -150,6 +150,8 @@ static void enum_file_fn( const struct share_mode_entry *e, fenum->ctr3->array[i].user = username; fenum->ctr3->count++; + + return 0; } /******************************************************************* @@ -826,9 +828,9 @@ static WERROR init_srv_sess_info_0(struct pipes_struct *p, * find out the session on which this file is open and bump up its count **********************************************************************/ -static void count_sess_files_fn(const struct share_mode_entry *e, - const char *sharepath, const char *fname, - void *data) +static int count_sess_files_fn(const struct share_mode_entry *e, + const char *sharepath, const char *fname, + void *data) { struct sess_file_info *info = data; uint32_t rh = info->resume_handle; @@ -846,9 +848,10 @@ static void count_sess_files_fn(const struct share_mode_entry *e, serverid_equal(&e->pid, &sess->pid)) { info->ctr->array[i].num_open++; - return; + return 0; } } + return 0; } /******************************************************************* @@ -950,9 +953,9 @@ static WERROR init_srv_sess_info_1(struct pipes_struct *p, find the share connection on which this open exists. ********************************************************************/ -static void share_file_fn(const struct share_mode_entry *e, - const char *sharepath, const char *fname, - void *data) +static int share_file_fn(const struct share_mode_entry *e, + const char *sharepath, const char *fname, + void *data) { struct share_file_stat *sfs = data; uint32_t i; @@ -962,10 +965,11 @@ static void share_file_fn(const struct share_mode_entry *e, for (i=0; i < sfs->resp_entries; i++) { if (serverid_equal(&e->pid, &sfs->svrid_arr[offset + i])) { sfs->netconn_arr[i].num_open ++; - return; + return 0; } } } + return 0; } /******************************************************************* @@ -2690,9 +2694,9 @@ struct enum_file_close_state { struct messaging_context *msg_ctx; }; -static void enum_file_close_fn( const struct share_mode_entry *e, - const char *sharepath, const char *fname, - void *private_data ) +static int enum_file_close_fn(const struct share_mode_entry *e, + const char *sharepath, const char *fname, + void *private_data) { char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE]; struct enum_file_close_state *state = @@ -2700,11 +2704,11 @@ static void enum_file_close_fn( const struct share_mode_entry *e, uint32_t fid = (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id); if (fid != state->r->in.fid) { - return; /* Not this file. */ + return 0; /* Not this file. */ } if (!process_exists(e->pid) ) { - return; + return 0; } /* Ok - send the close message. */ @@ -2718,6 +2722,8 @@ static void enum_file_close_fn( const struct share_mode_entry *e, messaging_send_buf(state->msg_ctx, e->pid, MSG_SMB_CLOSE_FILE, (uint8 *)msg, sizeof(msg))); + + return 0; } /******************************************************************** diff --git a/source3/utils/status.c b/source3/utils/status.c index 2c850bb591b..b58981329b9 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -115,10 +115,10 @@ static bool Ucrit_addPid( struct server_id pid ) return True; } -static void print_share_mode(const struct share_mode_entry *e, - const char *sharepath, - const char *fname, - void *dummy) +static int print_share_mode(const struct share_mode_entry *e, + const char *sharepath, + const char *fname, + void *dummy) { static int count; @@ -135,7 +135,7 @@ static void print_share_mode(const struct share_mode_entry *e, if (do_checks && !serverid_exists(&e->pid)) { /* the process for this entry does not exist any more */ - return; + return 0; } if (Ucrit_checkPid(e->pid)) { @@ -183,6 +183,8 @@ static void print_share_mode(const struct share_mode_entry *e, d_printf(" %s %s %s",sharepath, fname, time_to_asc((time_t)e->time.tv_sec)); } + + return 0; } static void print_brl(struct file_id id, -- 2.34.1