2003-10-30 08:32:26 +00:00
/*
Unix SMB / CIFS implementation .
ACL get / set operations
2004-11-18 01:02:27 +00:00
Copyright ( C ) Andrew Tridgell 2003 - 2004
2003-10-30 08:32:26 +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 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"
2004-11-17 14:35:29 +00:00
# include "librpc/gen_ndr/ndr_security.h"
2003-10-30 08:32:26 +00:00
/****************************************************************************
fetch file ACL ( async send )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
struct smbcli_request * smb_raw_query_secdesc_send ( struct smbcli_tree * tree ,
2004-11-18 01:41:43 +00:00
union smb_fileinfo * io )
2003-10-30 08:32:26 +00:00
{
struct smb_nttrans nt ;
2004-05-25 17:50:17 +00:00
uint8_t params [ 8 ] ;
2003-10-30 08:32:26 +00:00
nt . in . max_setup = 0 ;
nt . in . max_param = 4 ;
2004-12-21 11:47:08 +00:00
nt . in . max_data = 0xFFFF ;
2003-10-30 08:32:26 +00:00
nt . in . setup_count = 0 ;
nt . in . function = NT_TRANSACT_QUERY_SECURITY_DESC ;
nt . in . setup = NULL ;
2004-11-18 01:41:43 +00:00
SSVAL ( params , 0 , io - > query_secdesc . in . fnum ) ;
2003-10-30 08:32:26 +00:00
SSVAL ( params , 2 , 0 ) ; /* padding */
2005-04-14 13:19:40 +00:00
SIVAL ( params , 4 , io - > query_secdesc . secinfo_flags ) ;
2003-10-30 08:32:26 +00:00
nt . in . params . data = params ;
nt . in . params . length = 8 ;
nt . in . data = data_blob ( NULL , 0 ) ;
return smb_raw_nttrans_send ( tree , & nt ) ;
}
/****************************************************************************
fetch file ACL ( async recv )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
NTSTATUS smb_raw_query_secdesc_recv ( struct smbcli_request * req ,
2003-10-30 08:32:26 +00:00
TALLOC_CTX * mem_ctx ,
2004-11-18 01:41:43 +00:00
union smb_fileinfo * io )
2003-10-30 08:32:26 +00:00
{
NTSTATUS status ;
struct smb_nttrans nt ;
2003-11-03 06:22:45 +00:00
struct ndr_pull * ndr ;
2003-10-30 08:32:26 +00:00
status = smb_raw_nttrans_recv ( req , mem_ctx , & nt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
/* check that the basics are valid */
if ( nt . out . params . length ! = 4 | |
IVAL ( nt . out . params . data , 0 ) > nt . out . data . length ) {
return NT_STATUS_INVALID_PARAMETER ;
}
nt . out . data . length = IVAL ( nt . out . params . data , 0 ) ;
2003-11-03 06:22:45 +00:00
ndr = ndr_pull_init_blob ( & nt . out . data , mem_ctx ) ;
if ( ! ndr ) {
2003-10-30 08:32:26 +00:00
return NT_STATUS_INVALID_PARAMETER ;
}
2005-01-27 07:08:20 +00:00
io - > query_secdesc . out . sd = talloc ( mem_ctx , struct security_descriptor ) ;
2004-11-18 01:41:43 +00:00
if ( ! io - > query_secdesc . out . sd ) {
2003-11-08 11:21:57 +00:00
return NT_STATUS_NO_MEMORY ;
}
2004-11-18 01:41:43 +00:00
status = ndr_pull_security_descriptor ( ndr , NDR_SCALARS | NDR_BUFFERS ,
io - > query_secdesc . out . sd ) ;
2003-10-30 08:32:26 +00:00
2004-08-18 13:43:53 +00:00
return status ;
2003-10-30 08:32:26 +00:00
}
/****************************************************************************
fetch file ACL ( sync interface )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
NTSTATUS smb_raw_query_secdesc ( struct smbcli_tree * tree ,
2003-10-30 08:32:26 +00:00
TALLOC_CTX * mem_ctx ,
2004-11-18 01:41:43 +00:00
union smb_fileinfo * io )
2003-10-30 08:32:26 +00:00
{
2004-11-18 01:41:43 +00:00
struct smbcli_request * req = smb_raw_query_secdesc_send ( tree , io ) ;
return smb_raw_query_secdesc_recv ( req , mem_ctx , io ) ;
2003-10-30 08:32:26 +00:00
}
2003-11-03 06:22:45 +00:00
/****************************************************************************
set file ACL ( async send )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
struct smbcli_request * smb_raw_set_secdesc_send ( struct smbcli_tree * tree ,
2004-11-18 01:41:43 +00:00
union smb_setfileinfo * io )
2003-11-03 06:22:45 +00:00
{
struct smb_nttrans nt ;
2004-05-25 17:50:17 +00:00
uint8_t params [ 8 ] ;
2003-11-03 06:22:45 +00:00
struct ndr_push * ndr ;
2004-08-04 13:23:35 +00:00
struct smbcli_request * req ;
2003-11-03 06:22:45 +00:00
NTSTATUS status ;
nt . in . max_setup = 0 ;
nt . in . max_param = 0 ;
nt . in . max_data = 0 ;
nt . in . setup_count = 0 ;
nt . in . function = NT_TRANSACT_SET_SECURITY_DESC ;
nt . in . setup = NULL ;
2004-11-18 01:41:43 +00:00
SSVAL ( params , 0 , io - > set_secdesc . file . fnum ) ;
2003-11-03 06:22:45 +00:00
SSVAL ( params , 2 , 0 ) ; /* padding */
2004-11-18 01:41:43 +00:00
SIVAL ( params , 4 , io - > set_secdesc . in . secinfo_flags ) ;
2003-11-03 06:22:45 +00:00
nt . in . params . data = params ;
nt . in . params . length = 8 ;
ndr = ndr_push_init ( ) ;
if ( ! ndr ) return NULL ;
2004-11-18 01:41:43 +00:00
status = ndr_push_security_descriptor ( ndr , NDR_SCALARS | NDR_BUFFERS , io - > set_secdesc . in . sd ) ;
2003-11-03 06:22:45 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
ndr_push_free ( ndr ) ;
return NULL ;
}
2004-08-18 13:43:53 +00:00
2003-11-03 06:22:45 +00:00
nt . in . data = ndr_push_blob ( ndr ) ;
req = smb_raw_nttrans_send ( tree , & nt ) ;
ndr_push_free ( ndr ) ;
return req ;
}
2004-11-18 01:02:27 +00:00
/****************************************************************************
set file ACL ( sync interface )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS smb_raw_set_secdesc ( struct smbcli_tree * tree ,
2004-11-18 01:41:43 +00:00
union smb_setfileinfo * io )
2004-11-18 01:02:27 +00:00
{
2004-11-18 01:41:43 +00:00
struct smbcli_request * req = smb_raw_set_secdesc_send ( tree , io ) ;
2004-11-18 01:02:27 +00:00
return smbcli_request_simple_recv ( req ) ;
}