From 992c86d7154b54ba07dd13c060a870735b09c7f9 Mon Sep 17 00:00:00 2001 From: Shekhar Amlekar Date: Thu, 3 Apr 2014 14:22:58 +0530 Subject: [PATCH] s3: rpc_server/srvsvc: Added routines to count share connections. Added routines count_share_conns() and share_conn_fn() to count connections to a share. Signed-off-by: Shekhar Amlekar Reviewed-by: Jeremy Allison Reviewed-by: Christof Schmitt --- source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c index 4631691e7ef..1c1716c2a0d 100644 --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c @@ -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. ********************************************************************/ -- 2.11.4.GIT