[PATCH]: NetShareEnum - Removing a loop around smbXsrv_tcon_global.tdb traversal

Richard Sharpe realrichardsharpe at gmail.com
Sun Aug 11 15:11:38 MDT 2013


On Fri, Aug 9, 2013 at 4:18 PM, Jeremy Allison <jra at samba.org> wrote:
> Can I get a second Team reviewer to give me a +1 on
> this one please ?
>
> Original author has already +1'ed on the change.

+1 from me.

> Cheers,
>
>         Jeremy.
>
> On Mon, Aug 05, 2013 at 03:36:17PM -0700, Jeremy Allison wrote:
>> On Mon, Jul 22, 2013 at 07:46:50PM +0530, Shekhar Amlekar wrote:
>> > Hi,
>> >
>> > Please find attached a patch that removes a loop around the traversal of
>> > smbXsrv_tcon_global.tdb in the NetShareEnum call.
>> > Request your review.
>>
>> I'd prefer modifying this patch to move the enumeration
>> functions into source3/rpc_server/srvsvc/srv_srvsvc_nt.c
>> rather than adding them into source3/smbd/connections.c
>>
>> Here's a modified version that does that. Can you confirm
>> you're happy with it ? If so I'll add my +1 review and
>> propose it for master.
>>
>> Cheers,
>>
>>       Jeremy
>
>> From 6a3396a373b596c4f26e45849e40af9719099fea Mon Sep 17 00:00:00 2001
>> From: Shekhar Amlekar <samlekar at in.ibm.com>
>> Date: Sun, 23 Jun 2013 19:44:34 +0530
>> Subject: [PATCH] s3: smbd/connection: added routines to compute share
>>  connections
>>
>> Added routines to compute share connections and used it
>> in srvsvc NetShareEnum call.
>> ---
>>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 48 ++++++++++++++++++++++++++++++-
>>  1 file changed, 47 insertions(+), 1 deletion(-)
>>
>> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
>> index 655b0c7..1af350a 100644
>> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
>> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
>> @@ -250,7 +250,7 @@ static void init_srv_share_info_2(struct pipes_struct *p,
>>       r->comment              = remark ? remark : "";
>>       r->permissions          = 0;
>>       r->max_users            = max_uses;
>> -     r->current_users        = count_current_connections(net_name, false);
>> +     r->current_users        = 0; /* computed later */
>>       r->path                 = path ? path : "";
>>       r->password             = "";
>>  }
>> @@ -464,6 +464,49 @@ static bool is_enumeration_allowed(struct pipes_struct *p,
>>                             FILE_READ_DATA, NULL);
>>  }
>>
>> +/****************************************************************************
>> + Count an entry against the respective service.
>> +****************************************************************************/
>> +
>> +static int count_for_all_fn(struct smbXsrv_tcon_global0 *tcon, void *udp)
>> +{
>> +     union srvsvc_NetShareCtr *ctr = NULL;
>> +     struct srvsvc_NetShareInfo2 *info2 = NULL;
>> +     int share_entries = 0;
>> +     int i = 0;
>> +
>> +     ctr = (union srvsvc_NetShareCtr *) udp;
>> +
>> +     /* for level 2 */
>> +     share_entries  = ctr->ctr2->count;
>> +     info2 = &ctr->ctr2->array[0];
>> +
>> +     for (i = 0; i < share_entries; i++, info2++) {
>> +             if (strequal(tcon->share_name, info2->name)) {
>> +                     info2->current_users++;
>> +                     break;
>> +             }
>> +     }
>> +
>> +     return 0;
>> +}
>> +
>> +/****************************************************************************
>> + Count the entries belonging to all services in the connection db.
>> +****************************************************************************/
>> +
>> +static void count_connections_for_all_shares(union srvsvc_NetShareCtr *ctr)
>> +{
>> +     NTSTATUS status;
>> +     status = smbXsrv_tcon_global_traverse(count_for_all_fn, ctr);
>> +
>> +     if (!NT_STATUS_IS_OK(status)) {
>> +             DEBUG(0,("count_connections_for_all_shares: traverse of "
>> +                     "smbXsrv_tcon_global.tdb failed - %s\n",
>> +                     nt_errstr(status)));
>> +     }
>> +}
>> +
>>  /*******************************************************************
>>   Fill in a share info structure.
>>   ********************************************************************/
>> @@ -568,6 +611,7 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
>>                       }
>>               }
>>
>> +             count_connections_for_all_shares(&ctr);
>>               break;
>>
>>       case 501:
>> @@ -1382,6 +1426,8 @@ WERROR _srvsvc_NetShareGetInfo(struct pipes_struct *p,
>>                       info->info2 = talloc(p->mem_ctx, struct srvsvc_NetShareInfo2);
>>                       W_ERROR_HAVE_NO_MEMORY(info->info2);
>>                       init_srv_share_info_2(p, info->info2, snum);
>> +                     info->info2->current_users =
>> +                       count_current_connections(info->info2->name, false);
>>                       break;
>>               case 501:
>>                       info->info501 = talloc(p->mem_ctx, struct srvsvc_NetShareInfo501);
>> --
>> 1.8.3
>>
>



-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list