2007-08-13 15:27:37 +00:00
/*
Unix SMB / CIFS implementation .
Map a SID to a gid
2008-03-06 00:52:37 +01:00
Copyright ( C ) 2007 - 2008 Kai Blin
2007-08-13 15:27:37 +00:00
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "libcli/composite/composite.h"
# include "winbind/wb_server.h"
# include "smbd/service_task.h"
2009-02-01 16:08:45 +01:00
# include "libcli/security/security.h"
2007-08-13 15:27:37 +00:00
struct sid2gid_state {
struct composite_context * ctx ;
struct wbsrv_service * service ;
gid_t gid ;
} ;
2008-03-06 00:52:37 +01:00
static void sid2gid_recv_gid ( struct composite_context * ctx ) ;
2007-08-13 15:27:37 +00:00
struct composite_context * wb_sid2gid_send ( TALLOC_CTX * mem_ctx ,
struct wbsrv_service * service , const struct dom_sid * sid )
{
2008-03-06 00:52:37 +01:00
struct composite_context * result , * ctx ;
2007-08-13 15:27:37 +00:00
struct sid2gid_state * state ;
2009-04-23 16:37:11 +02:00
struct id_map * ids ;
2007-08-13 15:27:37 +00:00
DEBUG ( 5 , ( " wb_sid2gid_send called \n " ) ) ;
result = composite_create ( mem_ctx , service - > task - > event_ctx ) ;
if ( ! result ) return NULL ;
state = talloc ( result , struct sid2gid_state ) ;
if ( composite_nomem ( state , result ) ) return result ;
state - > ctx = result ;
result - > private_data = state ;
state - > service = service ;
2009-04-23 16:37:11 +02:00
ids = talloc ( result , struct id_map ) ;
2008-03-06 00:52:37 +01:00
if ( composite_nomem ( ids , result ) ) return result ;
ids - > sid = dom_sid_dup ( result , sid ) ;
if ( composite_nomem ( ids - > sid , result ) ) return result ;
ctx = wb_sids2xids_send ( result , service , 1 , ids ) ;
if ( composite_nomem ( ctx , result ) ) return result ;
2007-08-13 15:27:37 +00:00
2008-03-06 00:52:37 +01:00
composite_continue ( result , ctx , sid2gid_recv_gid , state ) ;
2007-08-13 15:27:37 +00:00
return result ;
}
2008-03-06 00:52:37 +01:00
static void sid2gid_recv_gid ( struct composite_context * ctx )
{
struct sid2gid_state * state = talloc_get_type ( ctx - > async . private_data ,
struct sid2gid_state ) ;
2009-04-23 16:37:11 +02:00
struct id_map * ids = NULL ;
2008-03-06 00:52:37 +01:00
2011-07-26 10:50:22 +10:00
state - > ctx - > status = wb_sids2xids_recv ( ctx , & ids , NULL ) ;
2008-03-06 00:52:37 +01:00
if ( ! composite_is_ok ( state - > ctx ) ) return ;
2009-04-23 16:37:11 +02:00
if ( ids - > status ! = ID_MAPPED ) {
composite_error ( state - > ctx , NT_STATUS_UNSUCCESSFUL ) ;
2008-03-06 00:52:37 +01:00
return ;
}
2010-05-24 10:16:34 +10:00
if ( ids - > xid . type = = ID_TYPE_BOTH | |
ids - > xid . type = = ID_TYPE_GID ) {
state - > gid = ids - > xid . id ;
2008-03-06 00:52:37 +01:00
composite_done ( state - > ctx ) ;
2012-04-23 17:28:39 +10:00
return ;
2008-03-06 00:52:37 +01:00
} else {
composite_error ( state - > ctx , NT_STATUS_INVALID_SID ) ;
2012-04-23 17:28:39 +10:00
return ;
2008-03-06 00:52:37 +01:00
}
}
2007-08-13 15:27:37 +00:00
NTSTATUS wb_sid2gid_recv ( struct composite_context * ctx , gid_t * gid )
{
NTSTATUS status = composite_wait ( ctx ) ;
DEBUG ( 5 , ( " wb_sid2gid_recv called \n " ) ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
struct sid2gid_state * state =
talloc_get_type ( ctx - > private_data ,
struct sid2gid_state ) ;
* gid = state - > gid ;
}
talloc_free ( ctx ) ;
return status ;
}