[PATCH] - NetConnEnum implementation
Jeremy Allison
jra at samba.org
Mon Mar 31 17:42:11 MDT 2014
On Mon, Mar 31, 2014 at 04:37:00PM -0700, Jeremy Allison wrote:
> On Tue, Mar 25, 2014 at 06:07:50PM +0530, Shekhar Amlekar wrote:
> > Hi,
> >
> > Please find attached patches that implement the NetConnEnum functionality
> > for computing share connections.
> >
> > Some background - while using MMC to delete a share, MMC uses NetConnEnum
> > call to query the server to find out the active share connections. If
> > there are some, a prompt is displayed to the administrator that asks for
> > confirmation of share deletion. Since Samba does not implement this call,
> > a prompt is displayed every time and the information about active share
> > connections is not provided to the admin. Hence, the need for this
> > implementation.
> >
> > A comment about the implementation. Since the locking tdb does not store
> > the share name or number, and changing tdb format is lot more work, the
> > following implementation is an approximation. However, it does provide
> > important information on share connections and open files to the
> > administrator, and also gets rid of the false prompt.
> >
> > 0001 - Added routines to count share connections.
>
> In 0001 - Added routines to count share connections.
>
> +/****************************************************************************
> + 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->count++;
> + scs->svrid_arr = talloc_realloc(scs->ctx, scs->svrid_arr,
> + struct server_id, scs->count);
> + scs->svrid_arr[scs->count-1] = tcon->server_id;
> + }
> +
> + return 0;
> +}
> +
>
> talloc_realloc needs a NULL check afterwards. Please fix and repost
> the entire patchset. Seems ok to me but I'll re-review the repost.
One most point, the common patter for doing talloc_realloc()'s
in a loop is:
ptr = talloc_realloc(ctx, orig, struct foo, count+1);
if (!ptr) {
// ERRROR
}
ptr[count] = stuff;
count++;
Rather than incrementing count first and using count-1
as the array index. Just looks strange..
More information about the samba-technical
mailing list