[Samba] Lookup sid with libsmbclient (invoked from c# on mono)

Aurélien Aptel aaptel at suse.com
Mon Oct 12 16:23:21 UTC 2020

Vincent Le Toux via samba <samba at lists.samba.org> writes:
> Indeed, rpcclient is the program I looked for the first time.
> I cannot invoke it in a command line because I have at least 1000 SID to
> resolve
> (I discover them one by one so I'll have to run rpcclient at least 1000
> times)

You can pass multiples SID at a time to these commands. But you would
have to batch the resolving in your app.

> I looked at rpcclient source code, but there is no easy function such as
> "connect" that can be used easily from libsmbclient
> Thinking about Smb_negox for example. I cannot just call structure->member
> because I'll to translate all structure.
> Working with pointer (IntPtr in c#) is much simpler.

You can write a very simple C wrapper and call the wrapper from C#.

So you would have:

    void* init_connection(const char *user, const char *pw)
        // establish connection and return handle
    const char* name_to_sid(void *con, const char *name)
        // use con to resolve and return sid
    const char* sid_to_name(void *con, const char *sid)
        // use con to resolve and return name
    void free_connection(void *con)
        // release con handle

This wrapper would link against the same libs as rpcclient binary and
would compile to librpcwrapper.so. From C you can #include all the
struct definitions you need or copy them from the source code.

Then from C# you just load librpcwrapper.so and call those simple functions.

Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)

More information about the samba mailing list