Aurélien Aptel
2020-Oct-12 16:23 UTC
[Samba] Lookup sid with libsmbclient (invoked from c# on mono)
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: rpcwrapper.c: 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. Cheers, -- 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)
Vincent Le Toux
2020-Oct-12 16:36 UTC
[Samba] Lookup sid with libsmbclient (invoked from c# on mono)
This wrapper, I know how to make it in c# (Rewriting stdin and stdout is not possible because I?m discovering one sid after having examined another one) What I?m missing is the api calls (in order) that I need to do to create this connection. Many exports that rpcclient is using are not included in libsmbdlient. I can find the final rpc function, but not the functions to establish the right context. Rpcclient is using cli_ functions that are not found in other examples. I need to know which c api to call in order to build the binding that the c function you quote needs (the first input arg) Br Vincent Le lun. 12 oct. 2020 ? 18:23, Aur?lien Aptel <aaptel at suse.com> a ?crit :> 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: > > > > rpcwrapper.c: > > 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. > > > > Cheers, > > -- > > Aur?lien Aptel / SUSE Labs Samba Team > > GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3 > > SUSE Software Solutions Germany GmbH, Maxfeldstr > <https://www.google.com/maps/search/tions+Germany+GmbH,+Maxfeldstr?entry=gmail&source=g>. > 5, 90409 N?rnberg, DE > > GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah HRB 247165 (AG M?nchen) > > ----- Vincent
Vincent Le Toux
2020-Oct-12 16:59 UTC
[Samba] Lookup sid with libsmbclient (invoked from c# on mono)
Typical example: Here is some search & export for libsmbclient: adiant at ubuntu:/usr/lib/x86_64-linux-gnu$ nm -D libsmbclient.so.0 |grep cli_rpc_pipe_open_noauth_transport <nothing> adiant at ubuntu:/usr/lib/x86_64-linux-gnu$ nm -D libsmbclient.so.0 |grep cli_rpc_pipe_open U cli_rpc_pipe_open_noauth adiant at ubuntu:/usr/lib/x86_64-linux-gnu$ nm -D libsmbclient.so.0 |grep lsa U ndr_table_lsarpc U rpccli_lsa_lookup_names U rpccli_lsa_lookup_sids U rpccli_lsa_open_policy So I need to call rpccli_lsa_open_policy you need struct rpc_pipe_client *lsa_pipe (ex: https://gitlab.com/samba-team/devel/samba/-/blob/master/source3/lib/netapi/localgroup.c ) This structure is transformed from struct cli_state *cli, into struct rpc_pipe_client *rpccli; you may call cli_rpc_pipe_open_noauth_transport to do that ( https://gitlab.com/samba-team/devel/samba/-/blob/master/examples/winexe/winexe.c#L458 ) cli_rpc_pipe_open_noauth_transport is not exported. maybe i should use cli_rpc_pipe_open_noauth which is closed, but exported. Also another example. Sometimes the cli api is called, sometimes the dcerpc one. Typical example here: https://gitlab.com/samba-team/devel/samba/-/blob/master/source3/lib/netapi/localgroup.c#L1028-1045 Do you understand my problem ? I have to explore all the possible ways to build that call stack by starting from the end. That's why I'm asking if there is an easier way to proceed. br Vincent Le lun. 12 oct. 2020 ? 18:36, Vincent Le Toux <vincent.letoux at gmail.com> a ?crit :> This wrapper, I know how to make it in c# > (Rewriting stdin and stdout is not possible because I?m discovering one > sid after having examined another one) > > What I?m missing is the api calls (in order) that I need to do to create > this connection. > Many exports that rpcclient is using are not included in libsmbdlient. > I can find the final rpc function, but not the functions to establish the > right context. > Rpcclient is using cli_ functions that are not found in other examples. > > I need to know which c api to call in order to build the binding that the > c function you quote needs (the first input arg) > > Br > Vincent > > Le lun. 12 oct. 2020 ? 18:23, Aur?lien Aptel <aaptel at suse.com> a ?crit : > >> 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: >> >> >> >> rpcwrapper.c: >> >> 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. >> >> >> >> Cheers, >> >> -- >> >> Aur?lien Aptel / SUSE Labs Samba Team >> >> GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3 >> >> SUSE Software Solutions Germany GmbH, Maxfeldstr >> <https://www.google.com/maps/search/tions+Germany+GmbH,+Maxfeldstr?entry=gmail&source=g>. >> 5, 90409 N?rnberg, DE >> >> GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah HRB 247165 (AG M?nchen) >> >> -- > --- > Vincent >-- --- Vincent
Possibly Parallel Threads
- Lookup sid with libsmbclient (invoked from c# on mono)
- Lookup sid with libsmbclient (invoked from c# on mono)
- Lookup sid with libsmbclient (invoked from c# on mono)
- Lookup sid with libsmbclient (invoked from c# on mono)
- Lookup sid with libsmbclient (invoked from c# on mono)