s3:locking: allow early return for share_entry_forall()
authorVolker Lendecke <vl@samba.org>
Wed, 24 Sep 2014 18:46:15 +0000 (20:46 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 31 Oct 2014 02:47:40 +0000 (03:47 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/locking/proto.h
source3/locking/share_mode_lock.c
source3/rpc_server/srvsvc/srv_srvsvc_nt.c
source3/utils/status.c

index a5c46c8140e7df6ae0674a988aa07dbd85c6b881..44f3ba13e0839b9a56fd4215ac73567b3c5a11bf 100644 (file)
@@ -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);
index c2f34022ae052986e302895d0010a295fb00da92..da16d1acf02fe7ad3688b0db2272f0992458fc45 100644 (file)
@@ -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; i<data->num_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 };
index d2f05f30ccd10c9d482ffe4bc49d122e570b5b8d..eaa70e784d65aa307ccf2dac53b4bcbd9f5f9563 100644 (file)
@@ -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;
 }
 
 /********************************************************************
index 2c850bb591b79e87106a09319304e4dcc6af5594..b58981329b99b2c0a87e613e51fcca35fa51b5b7 100644 (file)
@@ -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,