2005-10-19 17:45:44 +04:00
/*
Unix SMB / CIFS implementation .
Command backend for wbinfo - s
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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
# include "libcli/composite/composite.h"
# include "winbind/wb_server.h"
2006-03-07 14:07:23 +03:00
# include "winbind/wb_helper.h"
2005-10-19 17:45:44 +04:00
# include "smbd/service_task.h"
2006-04-02 16:02:01 +04:00
# include "libcli/security/security.h"
2005-10-19 17:45:44 +04:00
struct cmd_lookupsid_state {
struct composite_context * ctx ;
const struct dom_sid * sid ;
struct wb_sid_object * result ;
} ;
2005-11-05 12:34:07 +03:00
static void lookupsid_recv_domain ( struct composite_context * ctx ) ;
static void lookupsid_recv_names ( struct composite_context * ctx ) ;
2005-10-19 17:45:44 +04:00
2005-10-31 23:28:08 +03:00
struct composite_context * wb_cmd_lookupsid_send ( TALLOC_CTX * mem_ctx ,
struct wbsrv_service * service ,
2005-10-19 17:45:44 +04:00
const struct dom_sid * sid )
{
2005-11-05 12:34:07 +03:00
struct composite_context * result , * ctx ;
2005-10-19 17:45:44 +04:00
struct cmd_lookupsid_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_lookupsid_state ) ;
if ( state = = NULL ) goto failed ;
state - > ctx = result ;
result - > private_data = state ;
2005-10-19 17:45:44 +04:00
state - > sid = dom_sid_dup ( state , sid ) ;
if ( state - > sid = = NULL ) goto failed ;
2005-11-05 12:34:07 +03:00
ctx = wb_sid2domain_send ( state , service , service - > primary_sid ) ;
if ( ctx = = NULL ) goto failed ;
ctx - > async . fn = lookupsid_recv_domain ;
ctx - > async . private_data = state ;
return result ;
2005-10-19 17:45:44 +04:00
failed :
2005-11-05 12:34:07 +03:00
talloc_free ( result ) ;
2005-10-19 17:45:44 +04:00
return NULL ;
}
2005-11-05 12:34:07 +03:00
static void lookupsid_recv_domain ( struct composite_context * ctx )
2005-10-19 17:45:44 +04:00
{
struct cmd_lookupsid_state * state =
2005-11-05 12:34:07 +03:00
talloc_get_type ( ctx - > async . private_data ,
struct cmd_lookupsid_state ) ;
struct wbsrv_domain * domain ;
2005-10-19 17:45:44 +04:00
2005-11-05 12:34:07 +03:00
state - > ctx - > status = wb_sid2domain_recv ( ctx , & domain ) ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
ctx = wb_lsa_lookupsids_send ( state , domain - > lsa_pipe ,
2007-05-25 12:04:39 +04:00
domain - > lsa_policy_handle , 1 , & state - > sid ) ;
2005-11-05 12:34:07 +03:00
composite_continue ( state - > ctx , ctx , lookupsid_recv_names , state ) ;
2005-10-19 17:45:44 +04:00
}
2005-11-05 12:34:07 +03:00
static void lookupsid_recv_names ( struct composite_context * ctx )
2005-10-19 17:45:44 +04:00
{
struct cmd_lookupsid_state * state =
2005-11-05 12:34:07 +03:00
talloc_get_type ( ctx - > async . private_data ,
struct cmd_lookupsid_state ) ;
2005-10-19 17:45:44 +04:00
struct wb_sid_object * * names ;
2005-11-05 12:34:07 +03:00
state - > ctx - > status = wb_lsa_lookupsids_recv ( ctx , state , & names ) ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
state - > result = names [ 0 ] ;
composite_done ( state - > ctx ) ;
2005-10-19 17:45:44 +04:00
}
NTSTATUS wb_cmd_lookupsid_recv ( struct composite_context * c ,
TALLOC_CTX * mem_ctx ,
struct wb_sid_object * * sid )
{
struct cmd_lookupsid_state * state =
talloc_get_type ( c - > private_data , struct cmd_lookupsid_state ) ;
NTSTATUS status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
* sid = talloc_steal ( mem_ctx , state - > result ) ;
}
talloc_free ( state ) ;
return status ;
}
2005-10-31 23:28:08 +03:00
NTSTATUS wb_cmd_lookupsid ( TALLOC_CTX * mem_ctx , struct wbsrv_service * service ,
2005-10-19 17:45:44 +04:00
const struct dom_sid * sid ,
2005-10-31 23:28:08 +03:00
struct wb_sid_object * * name )
2005-10-19 17:45:44 +04:00
{
struct composite_context * c =
2005-10-31 23:28:08 +03:00
wb_cmd_lookupsid_send ( mem_ctx , service , sid ) ;
2005-10-19 17:45:44 +04:00
return wb_cmd_lookupsid_recv ( c , mem_ctx , name ) ;
}