2003-04-12 03:32:00 +04:00
/*
Unix SMB / CIFS implementation .
FS info functions
Copyright ( C ) Stefan ( metze ) Metzmacher 2003
2007-12-27 04:12:36 +03:00
Copyright ( C ) Jeremy Allison 2007
2011-12-27 03:25:55 +04:00
Copyright ( C ) Andrew Bartlett 2011
2010-02-07 13:05:07 +03:00
2003-04-12 03:32:00 +04: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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-04-12 03:32:00 +04:00
( at your option ) any later version .
2010-02-07 13:05:07 +03:00
2003-04-12 03:32:00 +04:00
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 .
2010-02-07 13:05:07 +03:00
2003-04-12 03:32:00 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-04-12 03:32:00 +04:00
*/
# include "includes.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2011-04-28 19:38:09 +04:00
# include "../lib/util/tevent_ntstatus.h"
2010-08-26 11:58:09 +04:00
# include "async_smb.h"
2011-10-19 15:47:39 +04:00
# include "../libcli/smb/smb_seal.h"
2011-02-25 02:03:01 +03:00
# include "trans2.h"
2011-12-27 03:25:55 +04:00
# include "auth_generic.h"
2011-10-18 14:13:16 +04:00
# include "auth/gensec/gensec.h"
2011-09-22 23:09:00 +04:00
# include "../libcli/smb/smbXcli_base.h"
2012-01-13 13:34:10 +04:00
# include "auth/credentials/credentials.h"
2003-04-12 03:32:00 +04:00
2004-11-13 02:42:12 +03:00
/****************************************************************************
Get UNIX extensions version info .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-07 04:16:33 +03:00
2009-11-13 01:07:21 +03:00
struct cli_unix_extensions_version_state {
2010-04-14 05:41:14 +04:00
struct cli_state * cli ;
2009-11-13 01:07:21 +03:00
uint16_t setup [ 1 ] ;
uint8_t param [ 2 ] ;
uint16_t major , minor ;
uint32_t caplow , caphigh ;
} ;
static void cli_unix_extensions_version_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_unix_extensions_version_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli )
2004-11-13 02:42:12 +03:00
{
2009-11-13 01:07:21 +03:00
struct tevent_req * req , * subreq ;
struct cli_unix_extensions_version_state * state ;
2004-11-13 02:42:12 +03:00
2009-11-13 01:07:21 +03:00
req = tevent_req_create ( mem_ctx , & state ,
struct cli_unix_extensions_version_state ) ;
if ( req = = NULL ) {
return NULL ;
2004-11-13 02:42:12 +03:00
}
2010-04-14 05:41:14 +04:00
state - > cli = cli ;
2009-11-13 01:07:21 +03:00
SSVAL ( state - > setup , 0 , TRANSACT2_QFSINFO ) ;
SSVAL ( state - > param , 0 , SMB_QUERY_CIFS_UNIX_INFO ) ;
2007-12-07 04:16:33 +03:00
2009-11-13 01:07:21 +03:00
subreq = cli_trans_send ( state , ev , cli , SMBtrans2 ,
NULL , 0 , 0 , 0 ,
state - > setup , 1 , 0 ,
state - > param , 2 , 0 ,
NULL , 0 , 560 ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2004-11-13 02:42:12 +03:00
}
2009-11-13 01:07:21 +03:00
tevent_req_set_callback ( subreq , cli_unix_extensions_version_done , req ) ;
return req ;
}
2004-11-13 02:42:12 +03:00
2009-11-13 01:07:21 +03:00
static void cli_unix_extensions_version_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_unix_extensions_version_state * state = tevent_req_data (
req , struct cli_unix_extensions_version_state ) ;
uint8_t * data ;
uint32_t num_data ;
NTSTATUS status ;
2010-08-05 14:48:52 +04:00
status = cli_trans_recv ( subreq , state , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , & data , 12 , & num_data ) ;
2009-11-13 01:07:21 +03:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
2004-11-13 02:42:12 +03:00
2009-11-13 01:07:21 +03:00
state - > major = SVAL ( data , 0 ) ;
state - > minor = SVAL ( data , 2 ) ;
state - > caplow = IVAL ( data , 4 ) ;
state - > caphigh = IVAL ( data , 8 ) ;
TALLOC_FREE ( data ) ;
tevent_req_done ( req ) ;
}
NTSTATUS cli_unix_extensions_version_recv ( struct tevent_req * req ,
uint16_t * pmajor , uint16_t * pminor ,
uint32_t * pcaplow ,
uint32_t * pcaphigh )
{
struct cli_unix_extensions_version_state * state = tevent_req_data (
req , struct cli_unix_extensions_version_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* pmajor = state - > major ;
* pminor = state - > minor ;
* pcaplow = state - > caplow ;
* pcaphigh = state - > caphigh ;
2010-04-14 05:41:14 +04:00
state - > cli - > server_posix_capabilities = * pcaplow ;
2009-11-13 01:07:21 +03:00
return NT_STATUS_OK ;
}
2015-05-10 02:59:45 +03:00
NTSTATUS cli_unix_extensions_version ( struct cli_state * cli , uint16_t * pmajor ,
uint16_t * pminor , uint32_t * pcaplow ,
uint32_t * pcaphigh )
2009-11-13 01:07:21 +03:00
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2013-02-18 12:59:58 +04:00
struct tevent_context * ev ;
2009-11-13 01:07:21 +03:00
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
2012-05-26 13:45:09 +04:00
if ( smbXcli_conn_has_async_calls ( cli - > conn ) ) {
2009-11-13 01:07:21 +03:00
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2004-11-13 02:42:12 +03:00
}
2013-02-18 12:08:19 +04:00
ev = samba_tevent_context_init ( frame ) ;
2009-11-13 01:07:21 +03:00
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2004-11-13 02:42:12 +03:00
2009-11-13 01:07:21 +03:00
req = cli_unix_extensions_version_send ( frame , ev , cli ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2004-11-13 02:42:12 +03:00
2015-04-28 17:00:06 +03:00
if ( ! tevent_req_poll_ntstatus ( req , ev , & status ) ) {
2009-11-13 01:07:21 +03:00
goto fail ;
}
2004-11-13 02:42:12 +03:00
2009-11-13 01:07:21 +03:00
status = cli_unix_extensions_version_recv ( req , pmajor , pminor , pcaplow ,
pcaphigh ) ;
fail :
TALLOC_FREE ( frame ) ;
return status ;
2004-11-13 02:42:12 +03:00
}
2003-04-12 03:32:00 +04:00
2006-07-12 04:21:14 +04:00
/****************************************************************************
Set UNIX extensions capabilities .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-07 04:16:33 +03:00
2009-11-14 02:40:21 +03:00
struct cli_set_unix_extensions_capabilities_state {
2010-04-14 05:41:14 +04:00
struct cli_state * cli ;
2009-11-14 02:40:21 +03:00
uint16_t setup [ 1 ] ;
uint8_t param [ 4 ] ;
uint8_t data [ 12 ] ;
} ;
static void cli_set_unix_extensions_capabilities_done (
struct tevent_req * subreq ) ;
struct tevent_req * cli_set_unix_extensions_capabilities_send (
TALLOC_CTX * mem_ctx , struct tevent_context * ev , struct cli_state * cli ,
uint16_t major , uint16_t minor , uint32_t caplow , uint32_t caphigh )
2006-07-12 04:21:14 +04:00
{
2009-11-14 02:40:21 +03:00
struct tevent_req * req , * subreq ;
struct cli_set_unix_extensions_capabilities_state * state ;
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
req = tevent_req_create (
mem_ctx , & state ,
struct cli_set_unix_extensions_capabilities_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2007-12-07 04:16:33 +03:00
2010-04-14 05:41:14 +04:00
state - > cli = cli ;
2009-11-14 02:40:21 +03:00
SSVAL ( state - > setup + 0 , 0 , TRANSACT2_SETFSINFO ) ;
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
SSVAL ( state - > param , 0 , 0 ) ;
SSVAL ( state - > param , 2 , SMB_SET_CIFS_UNIX_INFO ) ;
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
SSVAL ( state - > data , 0 , major ) ;
SSVAL ( state - > data , 2 , minor ) ;
SIVAL ( state - > data , 4 , caplow ) ;
SIVAL ( state - > data , 8 , caphigh ) ;
2007-12-07 04:16:33 +03:00
2009-11-14 02:40:21 +03:00
subreq = cli_trans_send ( state , ev , cli , SMBtrans2 ,
NULL , 0 , 0 , 0 ,
state - > setup , 1 , 0 ,
state - > param , 4 , 0 ,
state - > data , 12 , 560 ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2006-07-12 04:21:14 +04:00
}
2009-11-14 02:40:21 +03:00
tevent_req_set_callback (
subreq , cli_set_unix_extensions_capabilities_done , req ) ;
return req ;
}
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
static void cli_set_unix_extensions_capabilities_done (
struct tevent_req * subreq )
{
2010-04-14 05:41:14 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_set_unix_extensions_capabilities_state * state = tevent_req_data (
req , struct cli_set_unix_extensions_capabilities_state ) ;
2010-08-05 14:48:52 +04:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , NULL , 0 , NULL ,
2009-11-16 11:59:58 +03:00
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2010-04-14 05:41:14 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
state - > cli - > requested_posix_capabilities = IVAL ( state - > data , 4 ) ;
}
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-11-14 02:40:21 +03:00
}
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
NTSTATUS cli_set_unix_extensions_capabilities_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
2006-07-12 04:21:14 +04:00
2009-11-14 02:40:21 +03:00
NTSTATUS cli_set_unix_extensions_capabilities ( struct cli_state * cli ,
2015-05-14 03:26:01 +03:00
uint16_t major , uint16_t minor ,
uint32_t caplow , uint32_t caphigh )
2009-11-14 02:40:21 +03:00
{
struct tevent_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_NO_MEMORY ;
2012-05-26 13:45:09 +04:00
if ( smbXcli_conn_has_async_calls ( cli - > conn ) ) {
2009-11-14 02:40:21 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2013-02-18 12:08:19 +04:00
ev = samba_tevent_context_init ( talloc_tos ( ) ) ;
2009-11-14 02:40:21 +03:00
if ( ev = = NULL ) {
goto fail ;
}
req = cli_set_unix_extensions_capabilities_send (
ev , ev , cli , major , minor , caplow , caphigh ) ;
if ( req = = NULL ) {
goto fail ;
}
if ( ! tevent_req_poll_ntstatus ( req , ev , & status ) ) {
goto fail ;
}
status = cli_set_unix_extensions_capabilities_recv ( req ) ;
fail :
TALLOC_FREE ( ev ) ;
return status ;
2006-07-12 04:21:14 +04:00
}
2009-11-21 15:46:52 +03:00
struct cli_get_fs_attr_info_state {
uint16_t setup [ 1 ] ;
uint8_t param [ 2 ] ;
uint32_t fs_attr ;
} ;
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
static void cli_get_fs_attr_info_done ( struct tevent_req * subreq ) ;
2007-12-07 04:16:33 +03:00
2009-11-21 15:46:52 +03:00
struct tevent_req * cli_get_fs_attr_info_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli )
{
struct tevent_req * subreq , * req ;
struct cli_get_fs_attr_info_state * state ;
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
req = tevent_req_create ( mem_ctx , & state ,
struct cli_get_fs_attr_info_state ) ;
if ( req = = NULL ) {
return NULL ;
2003-04-12 03:32:00 +04:00
}
2009-11-21 15:46:52 +03:00
SSVAL ( state - > setup + 0 , 0 , TRANSACT2_QFSINFO ) ;
SSVAL ( state - > param + 0 , 0 , SMB_QUERY_FS_ATTRIBUTE_INFO ) ;
2007-12-07 04:16:33 +03:00
2009-11-21 15:46:52 +03:00
subreq = cli_trans_send ( state , ev , cli , SMBtrans2 ,
NULL , 0 , 0 , 0 ,
state - > setup , 1 , 0 ,
state - > param , 2 , 0 ,
NULL , 0 , 560 ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2003-04-12 03:32:00 +04:00
}
2009-11-21 15:46:52 +03:00
tevent_req_set_callback ( subreq , cli_get_fs_attr_info_done , req ) ;
return req ;
}
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
static void cli_get_fs_attr_info_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_get_fs_attr_info_state * state = tevent_req_data (
req , struct cli_get_fs_attr_info_state ) ;
uint8_t * data ;
uint32_t num_data ;
NTSTATUS status ;
2003-04-12 03:32:00 +04:00
2010-08-05 14:48:52 +04:00
status = cli_trans_recv ( subreq , talloc_tos ( ) , NULL , NULL , 0 , NULL ,
2009-11-21 15:46:52 +03:00
NULL , 0 , NULL , & data , 12 , & num_data ) ;
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2003-04-12 03:32:00 +04:00
}
2009-11-21 15:46:52 +03:00
state - > fs_attr = IVAL ( data , 0 ) ;
TALLOC_FREE ( data ) ;
tevent_req_done ( req ) ;
}
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
NTSTATUS cli_get_fs_attr_info_recv ( struct tevent_req * req , uint32_t * fs_attr )
{
struct cli_get_fs_attr_info_state * state = tevent_req_data (
req , struct cli_get_fs_attr_info_state ) ;
NTSTATUS status ;
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* fs_attr = state - > fs_attr ;
return NT_STATUS_OK ;
}
2003-04-12 03:32:00 +04:00
2009-11-21 15:46:52 +03:00
NTSTATUS cli_get_fs_attr_info ( struct cli_state * cli , uint32_t * fs_attr )
{
struct tevent_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_NO_MEMORY ;
2003-04-12 03:32:00 +04:00
2012-05-26 13:45:09 +04:00
if ( smbXcli_conn_has_async_calls ( cli - > conn ) ) {
2009-11-21 15:46:52 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2013-02-18 12:08:19 +04:00
ev = samba_tevent_context_init ( talloc_tos ( ) ) ;
2009-11-21 15:46:52 +03:00
if ( ev = = NULL ) {
goto fail ;
}
req = cli_get_fs_attr_info_send ( ev , ev , cli ) ;
if ( req = = NULL ) {
goto fail ;
}
if ( ! tevent_req_poll_ntstatus ( req , ev , & status ) ) {
goto fail ;
}
status = cli_get_fs_attr_info_recv ( req , fs_attr ) ;
fail :
TALLOC_FREE ( ev ) ;
return status ;
2003-04-12 03:32:00 +04:00
}
2005-03-30 04:47:57 +04:00
2011-07-06 15:57:20 +04:00
NTSTATUS cli_get_fs_volume_info ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx ,
char * * _volume_name ,
uint32_t * pserial_number ,
time_t * pdate )
2005-03-30 04:47:57 +04:00
{
2010-02-07 14:08:39 +03:00
NTSTATUS status ;
2011-07-06 15:57:20 +04:00
uint16_t recv_flags2 ;
uint16_t setup [ 1 ] ;
2010-02-07 14:08:39 +03:00
uint8_t param [ 2 ] ;
uint8_t * rdata ;
uint32_t rdata_count ;
2005-03-30 04:47:57 +04:00
unsigned int nlen ;
2011-07-06 15:57:20 +04:00
char * volume_name = NULL ;
2005-03-30 04:47:57 +04:00
2010-02-07 14:08:39 +03:00
SSVAL ( setup , 0 , TRANSACT2_QFSINFO ) ;
2005-03-30 04:47:57 +04:00
SSVAL ( param , 0 , SMB_QUERY_FS_VOLUME_INFO ) ;
2010-02-07 14:08:39 +03:00
status = cli_trans ( talloc_tos ( ) , cli , SMBtrans2 ,
NULL , 0 , 0 , 0 ,
setup , 1 , 0 ,
param , 2 , 0 ,
NULL , 0 , 560 ,
2011-07-06 15:57:20 +04:00
& recv_flags2 ,
2010-02-07 14:08:39 +03:00
NULL , 0 , NULL ,
NULL , 0 , NULL ,
2011-07-06 15:21:41 +04:00
& rdata , 18 , & rdata_count ) ;
2010-02-07 14:08:39 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2005-03-30 04:47:57 +04:00
}
if ( pdate ) {
2006-08-24 20:44:00 +04:00
struct timespec ts ;
2010-02-07 14:08:39 +03:00
ts = interpret_long_date ( ( char * ) rdata ) ;
2006-08-24 20:44:00 +04:00
* pdate = ts . tv_sec ;
2005-03-30 04:47:57 +04:00
}
if ( pserial_number ) {
* pserial_number = IVAL ( rdata , 8 ) ;
}
nlen = IVAL ( rdata , 12 ) ;
2011-07-06 15:57:20 +04:00
if ( nlen > ( rdata_count - 18 ) ) {
TALLOC_FREE ( rdata ) ;
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
clistr_pull_talloc ( mem_ctx ,
( const char * ) rdata ,
recv_flags2 ,
& volume_name ,
rdata + 18 ,
nlen , STR_UNICODE ) ;
if ( volume_name = = NULL ) {
status = map_nt_error_from_unix ( errno ) ;
TALLOC_FREE ( rdata ) ;
return status ;
}
2005-03-30 04:47:57 +04:00
2007-12-07 04:16:33 +03:00
/* todo: but not yet needed
2005-03-30 04:47:57 +04:00
* return the other stuff
*/
2011-07-06 15:57:20 +04:00
* _volume_name = volume_name ;
2010-02-07 14:08:39 +03:00
TALLOC_FREE ( rdata ) ;
return NT_STATUS_OK ;
2005-03-30 04:47:57 +04:00
}
2007-12-27 04:12:36 +03:00
2010-11-04 21:23:06 +03:00
NTSTATUS cli_get_fs_full_size_info ( struct cli_state * cli ,
uint64_t * total_allocation_units ,
uint64_t * caller_allocation_units ,
uint64_t * actual_allocation_units ,
uint64_t * sectors_per_allocation_unit ,
uint64_t * bytes_per_sector )
2009-02-12 18:39:17 +03:00
{
2015-05-10 02:59:45 +03:00
uint16_t setup [ 1 ] ;
2010-11-04 21:23:06 +03:00
uint8_t param [ 2 ] ;
uint8_t * rdata = NULL ;
uint32_t rdata_count ;
NTSTATUS status ;
2009-02-12 18:39:17 +03:00
2010-11-04 21:23:06 +03:00
SSVAL ( setup , 0 , TRANSACT2_QFSINFO ) ;
SSVAL ( param , 0 , SMB_FS_FULL_SIZE_INFORMATION ) ;
2009-02-12 18:39:17 +03:00
2010-11-04 21:23:06 +03:00
status = cli_trans ( talloc_tos ( ) , cli , SMBtrans2 ,
NULL , 0 , 0 , 0 ,
setup , 1 , 0 , /* setup */
param , 2 , 0 , /* param */
NULL , 0 , 560 , /* data */
NULL ,
NULL , 0 , NULL , /* rsetup */
NULL , 0 , NULL , /* rparam */
& rdata , 32 , & rdata_count ) ; /* rdata */
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto fail ;
2009-02-12 18:39:17 +03:00
}
if ( total_allocation_units ) {
* total_allocation_units = BIG_UINT ( rdata , 0 ) ;
}
if ( caller_allocation_units ) {
* caller_allocation_units = BIG_UINT ( rdata , 8 ) ;
}
if ( actual_allocation_units ) {
* actual_allocation_units = BIG_UINT ( rdata , 16 ) ;
}
if ( sectors_per_allocation_unit ) {
* sectors_per_allocation_unit = IVAL ( rdata , 24 ) ;
}
if ( bytes_per_sector ) {
* bytes_per_sector = IVAL ( rdata , 28 ) ;
}
2010-11-04 21:23:06 +03:00
fail :
TALLOC_FREE ( rdata ) ;
return status ;
2009-02-12 18:39:17 +03:00
}
2010-11-11 18:29:33 +03:00
NTSTATUS cli_get_posix_fs_info ( struct cli_state * cli ,
2015-05-10 02:59:45 +03:00
uint32_t * optimal_transfer_size ,
uint32_t * block_size ,
2010-11-11 18:29:33 +03:00
uint64_t * total_blocks ,
uint64_t * blocks_available ,
uint64_t * user_blocks_available ,
uint64_t * total_file_nodes ,
uint64_t * free_file_nodes ,
uint64_t * fs_identifier )
2009-02-12 18:39:17 +03:00
{
2015-05-10 02:59:45 +03:00
uint16_t setup [ 1 ] ;
2010-11-11 18:29:33 +03:00
uint8_t param [ 2 ] ;
uint8_t * rdata = NULL ;
2011-08-02 03:40:22 +04:00
uint32_t rdata_count ;
2010-11-11 18:29:33 +03:00
NTSTATUS status ;
2009-02-12 18:39:17 +03:00
2010-11-11 18:29:33 +03:00
SSVAL ( setup , 0 , TRANSACT2_QFSINFO ) ;
2009-02-12 18:39:17 +03:00
SSVAL ( param , 0 , SMB_QUERY_POSIX_FS_INFO ) ;
2010-11-11 18:29:33 +03:00
status = cli_trans ( talloc_tos ( ) , cli , SMBtrans2 , NULL , 0 , 0 , 0 ,
setup , 1 , 0 ,
param , 2 , 0 ,
NULL , 0 , 560 ,
NULL ,
NULL , 0 , NULL , /* rsetup */
NULL , 0 , NULL , /* rparam */
2011-08-02 03:40:22 +04:00
& rdata , 56 , & rdata_count ) ;
2010-11-11 18:29:33 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2009-02-12 18:39:17 +03:00
}
if ( optimal_transfer_size ) {
* optimal_transfer_size = IVAL ( rdata , 0 ) ;
}
if ( block_size ) {
* block_size = IVAL ( rdata , 4 ) ;
}
if ( total_blocks ) {
* total_blocks = BIG_UINT ( rdata , 8 ) ;
}
if ( blocks_available ) {
* blocks_available = BIG_UINT ( rdata , 16 ) ;
}
if ( user_blocks_available ) {
* user_blocks_available = BIG_UINT ( rdata , 24 ) ;
}
if ( total_file_nodes ) {
* total_file_nodes = BIG_UINT ( rdata , 32 ) ;
}
if ( free_file_nodes ) {
* free_file_nodes = BIG_UINT ( rdata , 40 ) ;
}
if ( fs_identifier ) {
* fs_identifier = BIG_UINT ( rdata , 48 ) ;
}
2010-11-11 18:29:33 +03:00
return NT_STATUS_OK ;
2009-02-12 18:39:17 +03:00
}
2007-12-27 04:12:36 +03:00
/******************************************************************************
Send / receive the request encryption blob .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS enc_blob_send_receive ( struct cli_state * cli , DATA_BLOB * in , DATA_BLOB * out , DATA_BLOB * param_out )
{
2011-01-09 12:53:04 +03:00
uint16_t setup [ 1 ] ;
uint8_t param [ 4 ] ;
uint8_t * rparam = NULL , * rdata = NULL ;
uint32_t num_rparam , num_rdata ;
NTSTATUS status ;
2007-12-27 04:12:36 +03:00
2011-01-09 12:53:04 +03:00
SSVAL ( setup + 0 , 0 , TRANSACT2_SETFSINFO ) ;
2007-12-27 04:12:36 +03:00
SSVAL ( param , 0 , 0 ) ;
SSVAL ( param , 2 , SMB_REQUEST_TRANSPORT_ENCRYPTION ) ;
2011-01-09 12:53:04 +03:00
status = cli_trans ( talloc_tos ( ) , cli , SMBtrans2 , NULL , 0 , 0 , 0 ,
setup , 1 , 0 ,
param , 4 , 2 ,
( uint8_t * ) in - > data , in - > length , CLI_BUFFER_SIZE ,
NULL , /* recv_flags */
NULL , 0 , NULL , /* rsetup */
& rparam , 0 , & num_rparam ,
& rdata , 0 , & num_rdata ) ;
2007-12-27 04:12:36 +03:00
2011-01-09 12:53:04 +03:00
if ( ! NT_STATUS_IS_OK ( status ) & &
! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
return status ;
2007-12-27 04:12:36 +03:00
}
2011-01-09 12:53:04 +03:00
* out = data_blob ( rdata , num_rdata ) ;
* param_out = data_blob ( rparam , num_rparam ) ;
2007-12-27 04:12:36 +03:00
2011-01-09 12:53:04 +03:00
TALLOC_FREE ( rparam ) ;
TALLOC_FREE ( rdata ) ;
2007-12-27 04:12:36 +03:00
return status ;
}
/******************************************************************************
Start a raw ntlmssp encryption .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS cli_raw_ntlm_smb_encryption_start ( struct cli_state * cli ,
const char * user ,
const char * pass ,
const char * domain )
{
DATA_BLOB blob_in = data_blob_null ;
DATA_BLOB blob_out = data_blob_null ;
DATA_BLOB param_out = data_blob_null ;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2011-12-27 03:25:55 +04:00
struct auth_generic_state * auth_generic_state ;
2012-01-14 08:30:34 +04:00
struct smb_trans_enc_state * es = talloc_zero ( NULL , struct smb_trans_enc_state ) ;
2007-12-27 04:12:36 +03:00
if ( ! es ) {
return NT_STATUS_NO_MEMORY ;
}
2012-01-14 08:30:34 +04:00
status = auth_generic_client_prepare ( es ,
2011-12-27 03:25:55 +04:00
& auth_generic_state ) ;
2007-12-27 04:12:36 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto fail ;
}
2011-12-27 03:25:55 +04:00
gensec_want_feature ( auth_generic_state - > gensec_security , GENSEC_FEATURE_SESSION_KEY ) ;
gensec_want_feature ( auth_generic_state - > gensec_security , GENSEC_FEATURE_SEAL ) ;
2007-12-27 04:12:36 +03:00
2011-12-27 03:25:55 +04:00
if ( ! NT_STATUS_IS_OK ( status = auth_generic_set_username ( auth_generic_state , user ) ) ) {
2007-12-27 04:12:36 +03:00
goto fail ;
}
2011-12-27 03:25:55 +04:00
if ( ! NT_STATUS_IS_OK ( status = auth_generic_set_domain ( auth_generic_state , domain ) ) ) {
2007-12-27 04:12:36 +03:00
goto fail ;
}
2011-12-27 03:25:55 +04:00
if ( ! NT_STATUS_IS_OK ( status = auth_generic_set_password ( auth_generic_state , pass ) ) ) {
2007-12-27 04:12:36 +03:00
goto fail ;
}
2011-12-27 03:25:55 +04:00
if ( ! NT_STATUS_IS_OK ( status = auth_generic_client_start ( auth_generic_state , GENSEC_OID_NTLMSSP ) ) ) {
2011-10-17 13:19:11 +04:00
goto fail ;
}
2007-12-27 04:12:36 +03:00
do {
2011-12-27 03:25:55 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , auth_generic_state ,
2013-12-13 22:56:13 +04:00
blob_in , & blob_out ) ;
2007-12-27 04:12:36 +03:00
data_blob_free ( & blob_in ) ;
data_blob_free ( & param_out ) ;
if ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) | | NT_STATUS_IS_OK ( status ) ) {
NTSTATUS trans_status = enc_blob_send_receive ( cli ,
& blob_out ,
& blob_in ,
& param_out ) ;
if ( ! NT_STATUS_EQUAL ( trans_status ,
NT_STATUS_MORE_PROCESSING_REQUIRED ) & &
! NT_STATUS_IS_OK ( trans_status ) ) {
status = trans_status ;
} else {
if ( param_out . length = = 2 ) {
es - > enc_ctx_num = SVAL ( param_out . data , 0 ) ;
}
}
}
data_blob_free ( & blob_out ) ;
} while ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) ;
data_blob_free ( & blob_in ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2011-09-22 23:09:00 +04:00
es - > enc_on = true ;
2007-12-27 04:12:36 +03:00
/* Replace the old state, if any. */
2011-10-19 08:57:18 +04:00
/* We only need the gensec_security part from here.
* es is a malloc ( ) ed pointer , so we cannot make
* gensec_security a talloc child */
2012-01-14 05:00:53 +04:00
es - > gensec_security = talloc_move ( NULL ,
& auth_generic_state - > gensec_security ) ;
2011-09-22 23:09:00 +04:00
smb1cli_conn_set_encryption ( cli - > conn , es ) ;
2007-12-27 04:12:36 +03:00
es = NULL ;
}
fail :
2012-01-14 08:30:34 +04:00
TALLOC_FREE ( es ) ;
2007-12-27 04:12:36 +03:00
return status ;
}
/******************************************************************************
Start a SPNEGO gssapi encryption context .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS cli_gss_smb_encryption_start ( struct cli_state * cli )
{
DATA_BLOB blob_recv = data_blob_null ;
DATA_BLOB blob_send = data_blob_null ;
DATA_BLOB param_out = data_blob_null ;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2012-01-13 13:34:10 +04:00
struct auth_generic_state * auth_generic_state ;
2012-01-14 08:30:34 +04:00
struct smb_trans_enc_state * es = talloc_zero ( NULL , struct smb_trans_enc_state ) ;
2007-12-27 04:12:36 +03:00
if ( ! es ) {
return NT_STATUS_NO_MEMORY ;
}
2012-01-14 08:30:34 +04:00
status = auth_generic_client_prepare ( es ,
2012-01-13 13:34:10 +04:00
& auth_generic_state ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto fail ;
}
gensec_want_feature ( auth_generic_state - > gensec_security , GENSEC_FEATURE_SESSION_KEY ) ;
gensec_want_feature ( auth_generic_state - > gensec_security , GENSEC_FEATURE_SEAL ) ;
cli_credentials_set_kerberos_state ( auth_generic_state - > credentials ,
CRED_MUST_USE_KERBEROS ) ;
status = gensec_set_target_service ( auth_generic_state - > gensec_security , " cifs " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto fail ;
}
status = gensec_set_target_hostname ( auth_generic_state - > gensec_security ,
2012-05-19 19:31:50 +04:00
smbXcli_conn_remote_name ( cli - > conn ) ) ;
2012-01-13 13:34:10 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto fail ;
}
2012-01-14 05:28:28 +04:00
if ( ! NT_STATUS_IS_OK ( status = auth_generic_client_start ( auth_generic_state , GENSEC_OID_SPNEGO ) ) ) {
2012-01-13 13:34:10 +04:00
goto fail ;
}
2012-01-14 05:28:28 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) ,
2013-12-13 22:56:13 +04:00
blob_recv , & blob_send ) ;
2012-01-14 05:28:28 +04:00
2007-12-27 04:12:36 +03:00
do {
data_blob_free ( & blob_recv ) ;
status = enc_blob_send_receive ( cli , & blob_send , & blob_recv , & param_out ) ;
if ( param_out . length = = 2 ) {
es - > enc_ctx_num = SVAL ( param_out . data , 0 ) ;
}
data_blob_free ( & blob_send ) ;
2012-01-14 05:28:28 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) ,
2013-12-13 22:56:13 +04:00
blob_recv , & blob_send ) ;
2007-12-27 04:12:36 +03:00
} while ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) ;
data_blob_free ( & blob_recv ) ;
2012-01-13 13:34:10 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
if ( ! gensec_have_feature ( auth_generic_state - > gensec_security ,
GENSEC_FEATURE_SIGN ) | |
! gensec_have_feature ( auth_generic_state - > gensec_security ,
GENSEC_FEATURE_SEAL ) ) {
status = NT_STATUS_ACCESS_DENIED ;
}
}
2007-12-27 04:12:36 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2011-09-22 23:09:00 +04:00
es - > enc_on = true ;
2007-12-27 04:12:36 +03:00
/* Replace the old state, if any. */
2012-01-13 13:34:10 +04:00
/* We only need the gensec_security part from here.
* es is a malloc ( ) ed pointer , so we cannot make
* gensec_security a talloc child */
2012-01-14 08:30:34 +04:00
es - > gensec_security = talloc_move ( es ,
2012-01-14 05:00:53 +04:00
& auth_generic_state - > gensec_security ) ;
2011-09-22 23:09:00 +04:00
smb1cli_conn_set_encryption ( cli - > conn , es ) ;
2007-12-27 04:12:36 +03:00
es = NULL ;
}
2012-01-13 13:34:10 +04:00
fail :
2012-01-14 08:30:34 +04:00
TALLOC_FREE ( es ) ;
2007-12-27 04:12:36 +03:00
return status ;
}
2008-01-05 11:23:35 +03:00
/********************************************************************
Ensure a connection is encrypted .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS cli_force_encryption ( struct cli_state * c ,
const char * username ,
const char * password ,
const char * domain )
{
2015-05-10 02:59:45 +03:00
uint16_t major , minor ;
uint32_t caplow , caphigh ;
2009-11-13 01:07:21 +03:00
NTSTATUS status ;
2008-01-05 11:23:35 +03:00
if ( ! SERVER_HAS_UNIX_CIFS ( c ) ) {
return NT_STATUS_NOT_SUPPORTED ;
}
2009-11-13 01:07:21 +03:00
status = cli_unix_extensions_version ( c , & major , & minor , & caplow ,
& caphigh ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " cli_force_encryption: cli_unix_extensions_version "
" returned %s \n " , nt_errstr ( status ) ) ) ;
2008-01-05 11:23:35 +03:00
return NT_STATUS_UNKNOWN_REVISION ;
}
if ( ! ( caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP ) ) {
return NT_STATUS_UNSUPPORTED_COMPRESSION ;
}
if ( c - > use_kerberos ) {
return cli_gss_smb_encryption_start ( c ) ;
}
return cli_raw_ntlm_smb_encryption_start ( c ,
username ,
password ,
domain ) ;
}