2005-10-16 16:43:09 +04:00
/*
Unix SMB / CIFS implementation .
Command backend for wbinfo - - user - domgroups
Copyright ( C ) Volker Lendecke 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-10-16 16:43:09 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-10-16 16:43:09 +04:00
*/
# include "includes.h"
# include "libcli/composite/composite.h"
2006-04-02 16:02:01 +04:00
# include "libcli/security/security.h"
2005-10-16 16:43:09 +04:00
# include "winbind/wb_server.h"
2006-03-07 14:07:23 +03:00
# include "winbind/wb_helper.h"
2005-11-05 12:34:07 +03:00
# include "smbd/service_task.h"
2005-10-16 16:43:09 +04:00
struct cmd_userdomgroups_state {
struct composite_context * ctx ;
2005-10-19 17:45:44 +04:00
struct dom_sid * dom_sid ;
2005-10-16 16:43:09 +04:00
uint32_t user_rid ;
int num_rids ;
uint32_t * rids ;
} ;
2005-11-05 12:34:07 +03:00
static void userdomgroups_recv_domain ( struct composite_context * ctx ) ;
static void userdomgroups_recv_rids ( struct composite_context * ctx ) ;
2005-10-16 16:43:09 +04:00
2005-11-05 12:34:07 +03:00
struct composite_context * wb_cmd_userdomgroups_send ( TALLOC_CTX * mem_ctx ,
struct wbsrv_service * service ,
2005-10-16 16:43:09 +04:00
const struct dom_sid * sid )
{
2005-11-05 12:34:07 +03:00
struct composite_context * result , * ctx ;
2005-10-16 16:43:09 +04:00
struct cmd_userdomgroups_state * state ;
2007-04-30 20:52:30 +04:00
result = composite_create ( mem_ctx , service - > task - > event_ctx ) ;
2005-11-05 12:34:07 +03:00
if ( result = = NULL ) goto failed ;
state = talloc ( result , struct cmd_userdomgroups_state ) ;
if ( state = = NULL ) goto failed ;
state - > ctx = result ;
result - > private_data = state ;
state - > dom_sid = dom_sid_dup ( state , sid ) ;
if ( state - > dom_sid = = NULL ) goto failed ;
state - > dom_sid - > num_auths - = 1 ;
2005-10-16 16:43:09 +04:00
2005-10-19 17:45:44 +04:00
state - > user_rid = sid - > sub_auths [ sid - > num_auths - 1 ] ;
2005-11-05 12:34:07 +03:00
ctx = wb_sid2domain_send ( state , service , sid ) ;
2007-07-23 06:56:51 +04:00
composite_continue ( state - > ctx , ctx , userdomgroups_recv_domain , state ) ;
if ( ctx ) {
return result ;
}
2005-10-16 16:43:09 +04:00
failed :
2005-11-05 12:34:07 +03:00
talloc_free ( result ) ;
2005-10-16 16:43:09 +04:00
return NULL ;
}
2005-11-05 12:34:07 +03:00
static void userdomgroups_recv_domain ( struct composite_context * ctx )
2005-10-16 16:43:09 +04:00
{
struct cmd_userdomgroups_state * state =
2005-11-05 12:34:07 +03:00
talloc_get_type ( ctx - > async . private_data ,
struct cmd_userdomgroups_state ) ;
struct wbsrv_domain * domain ;
state - > ctx - > status = wb_sid2domain_recv ( ctx , & domain ) ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
2005-10-16 16:43:09 +04:00
2007-07-23 06:56:51 +04:00
ctx = wb_samr_userdomgroups_send ( state , domain - > libnet_ctx - > samr . pipe ,
& domain - > libnet_ctx - > samr . handle ,
2005-11-05 12:34:07 +03:00
state - > user_rid ) ;
composite_continue ( state - > ctx , ctx , userdomgroups_recv_rids , state ) ;
2005-10-16 16:43:09 +04:00
}
2005-11-05 12:34:07 +03:00
static void userdomgroups_recv_rids ( struct composite_context * ctx )
2005-10-16 16:43:09 +04:00
{
struct cmd_userdomgroups_state * state =
2005-11-05 12:34:07 +03:00
talloc_get_type ( ctx - > async . private_data ,
struct cmd_userdomgroups_state ) ;
2005-10-16 16:43:09 +04:00
2005-11-05 12:34:07 +03:00
state - > ctx - > status = wb_samr_userdomgroups_recv ( ctx , state ,
& state - > num_rids ,
& state - > rids ) ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
composite_done ( state - > ctx ) ;
2005-10-16 16:43:09 +04:00
}
NTSTATUS wb_cmd_userdomgroups_recv ( struct composite_context * c ,
TALLOC_CTX * mem_ctx ,
int * num_sids , struct dom_sid * * * sids )
{
struct cmd_userdomgroups_state * state =
talloc_get_type ( c - > private_data ,
struct cmd_userdomgroups_state ) ;
int i ;
NTSTATUS status ;
status = composite_wait ( c ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) goto done ;
* num_sids = state - > num_rids ;
* sids = talloc_array ( mem_ctx , struct dom_sid * , state - > num_rids ) ;
if ( * sids = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto done ;
}
for ( i = 0 ; i < state - > num_rids ; i + + ) {
2005-10-19 17:45:44 +04:00
( * sids ) [ i ] = dom_sid_add_rid ( ( * sids ) , state - > dom_sid ,
2005-10-16 16:43:09 +04:00
state - > rids [ i ] ) ;
if ( ( * sids ) [ i ] = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto done ;
}
}
done :
2005-11-05 12:34:07 +03:00
talloc_free ( c ) ;
2005-10-16 16:43:09 +04:00
return status ;
}
2005-11-05 12:34:07 +03:00
NTSTATUS wb_cmd_userdomgroups ( TALLOC_CTX * mem_ctx ,
struct wbsrv_service * service ,
2005-10-16 16:43:09 +04:00
const struct dom_sid * sid ,
2005-11-05 12:34:07 +03:00
int * num_sids , struct dom_sid * * * sids )
2005-10-16 16:43:09 +04:00
{
struct composite_context * c =
2005-11-05 12:34:07 +03:00
wb_cmd_userdomgroups_send ( mem_ctx , service , sid ) ;
2005-10-16 16:43:09 +04:00
return wb_cmd_userdomgroups_recv ( c , mem_ctx , num_sids , sids ) ;
}