s3: rpc_server/srvsvc: Added routines to count share connections.
authorShekhar Amlekar <samlekar@in.ibm.com>
Thu, 3 Apr 2014 08:52:58 +0000 (14:22 +0530)
committerJeremy Allison <jra@samba.org>
Thu, 3 Apr 2014 17:01:12 +0000 (19:01 +0200)
Added routines count_share_conns() and share_conn_fn() to count
connections to a share.

Signed-off-by: Shekhar Amlekar <samlekar@in.ibm.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/rpc_server/srvsvc/srv_srvsvc_nt.c

index 4631691e7ef48a2a2713118e54d89e678d87aab7..1c1716c2a0dce95b4afd4b9123d766e1a35dcf98 100644 (file)
@@ -61,6 +61,13 @@ struct sess_file_info {
        uint32_t num_entries;
 };
 
+struct share_conn_stat {
+       TALLOC_CTX *ctx;
+       const char *sharename;
+       struct server_id *svrid_arr;
+       int count;
+};
+
 /*******************************************************************
 ********************************************************************/
 
@@ -930,6 +937,63 @@ static WERROR init_srv_sess_info_1(struct pipes_struct *p,
        return WERR_OK;
 }
 
+/****************************************************************************
+ process an entry from the connection db.
+****************************************************************************/
+
+static int share_conn_fn(struct smbXsrv_tcon_global0 *tcon,
+                         void *data)
+{
+       struct share_conn_stat *scs = data;
+
+       if (!process_exists(tcon->server_id)) {
+               return 0;
+       }
+
+       if (strequal(tcon->share_name, scs->sharename)) {
+               scs->svrid_arr = talloc_realloc(scs->ctx, scs->svrid_arr,
+                                               struct server_id,
+                                               scs->count + 1);
+               if (!scs->svrid_arr) {
+                       return 0;
+               }
+
+               scs->svrid_arr[scs->count] = tcon->server_id;
+               scs->count++;
+       }
+
+       return 0;
+}
+
+/****************************************************************************
+ Count the connections to a share. Build an array of serverid's owning these
+ connections.
+****************************************************************************/
+
+static uint32_t count_share_conns(TALLOC_CTX *ctx, const char *sharename,
+                                 struct server_id **arr)
+{
+       struct share_conn_stat scs;
+       NTSTATUS status;
+
+       scs.ctx = ctx;
+       scs.sharename = sharename;
+       scs.svrid_arr = NULL;
+       scs.count = 0;
+
+       status = smbXsrv_tcon_global_traverse(share_conn_fn, &scs);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("count_share_conns: traverse of "
+                        "smbXsrv_tcon_global.tdb failed - %s\n",
+                        nt_errstr(status)));
+               return 0;
+       }
+
+       *arr = scs.svrid_arr;
+       return scs.count;
+}
+
 /*******************************************************************
  fill in a conn info level 0 structure.
  ********************************************************************/