2023-10-31 15:48:09 +01:00
/*
2003-08-13 01:53:07 +00:00
Unix SMB / CIFS implementation .
client change notify operations
Copyright ( C ) Andrew Tridgell 2003
2023-10-31 15:48:09 +01:00
2003-08-13 01:53:07 +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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00:00
( at your option ) any later version .
2023-10-31 15:48:09 +01:00
2003-08-13 01:53:07 +00: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 .
2023-10-31 15:48:09 +01:00
2003-08-13 01:53:07 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2011-09-23 08:35:17 +02:00
# include <tevent.h>
2004-11-01 01:03:22 +00:00
# include "libcli/raw/libcliraw.h"
2008-04-02 04:53:27 +02:00
# include "libcli/raw/raw_proto.h"
2003-08-13 01:53:07 +00:00
/****************************************************************************
change notify ( async send )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 04:53:27 +02:00
_PUBLIC_ struct smbcli_request * smb_raw_changenotify_send ( struct smbcli_tree * tree , union smb_notify * parms )
2003-08-13 01:53:07 +00:00
{
struct smb_nttrans nt ;
2007-02-07 00:21:29 +00:00
uint8_t setup [ 8 ] ;
2003-08-13 01:53:07 +00:00
2006-07-12 14:25:50 +00:00
if ( parms - > nttrans . level ! = RAW_NOTIFY_NTTRANS ) {
return NULL ;
}
2003-08-13 01:53:07 +00:00
nt . in . max_setup = 0 ;
2006-07-12 14:25:50 +00:00
nt . in . max_param = parms - > nttrans . in . buffer_size ;
2003-08-13 01:53:07 +00:00
nt . in . max_data = 0 ;
nt . in . setup_count = 4 ;
nt . in . setup = setup ;
2006-07-12 14:25:50 +00:00
SIVAL ( setup , 0 , parms - > nttrans . in . completion_filter ) ;
SSVAL ( setup , 4 , parms - > nttrans . in . file . fnum ) ;
2023-10-31 15:48:09 +01:00
SSVAL ( setup , 6 , parms - > nttrans . in . recursive ) ;
2003-08-13 01:53:07 +00:00
nt . in . function = NT_TRANSACT_NOTIFY_CHANGE ;
nt . in . params = data_blob ( NULL , 0 ) ;
nt . in . data = data_blob ( NULL , 0 ) ;
return smb_raw_nttrans_send ( tree , & nt ) ;
}
/****************************************************************************
change notify ( async recv )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-10-31 15:48:09 +01:00
_PUBLIC_ NTSTATUS smb_raw_changenotify_recv ( struct smbcli_request * req ,
2006-07-12 14:25:50 +00:00
TALLOC_CTX * mem_ctx , union smb_notify * parms )
2003-08-13 01:53:07 +00:00
{
struct smb_nttrans nt ;
NTSTATUS status ;
2004-05-25 16:24:13 +00:00
uint32_t ofs , i ;
2004-08-04 13:23:35 +00:00
struct smbcli_session * session = req ? req - > session : NULL ;
2003-08-13 01:53:07 +00:00
2006-07-12 14:25:50 +00:00
if ( parms - > nttrans . level ! = RAW_NOTIFY_NTTRANS ) {
return NT_STATUS_INVALID_LEVEL ;
}
2003-08-13 01:53:07 +00:00
status = smb_raw_nttrans_recv ( req , mem_ctx , & nt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2006-07-12 14:25:50 +00:00
parms - > nttrans . out . changes = NULL ;
parms - > nttrans . out . num_changes = 0 ;
2010-06-28 16:06:33 -07:00
2003-08-13 01:53:07 +00:00
/* count them */
for ( ofs = 0 ; nt . out . params . length - ofs > 12 ; ) {
2004-05-25 16:24:13 +00:00
uint32_t next = IVAL ( nt . out . params . data , ofs ) ;
2010-06-28 16:06:33 -07:00
if ( next % 4 ! = 0 )
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
2006-07-12 14:25:50 +00:00
parms - > nttrans . out . num_changes + + ;
2003-08-13 01:53:07 +00:00
if ( next = = 0 | |
ofs + next > = nt . out . params . length ) break ;
ofs + = next ;
}
/* allocate array */
2006-07-12 14:25:50 +00:00
parms - > nttrans . out . changes = talloc_array ( mem_ctx , struct notify_changes , parms - > nttrans . out . num_changes ) ;
if ( ! parms - > nttrans . out . changes ) {
2003-08-13 01:53:07 +00:00
return NT_STATUS_NO_MEMORY ;
}
2006-07-12 14:25:50 +00:00
for ( i = ofs = 0 ; i < parms - > nttrans . out . num_changes ; i + + ) {
parms - > nttrans . out . changes [ i ] . action = IVAL ( nt . out . params . data , ofs + 4 ) ;
2023-10-31 15:48:09 +01:00
smbcli_blob_pull_string ( session , mem_ctx , & nt . out . params ,
& parms - > nttrans . out . changes [ i ] . name ,
2006-07-12 14:25:50 +00:00
ofs + 8 , ofs + 12 , STR_UNICODE ) ;
2003-08-13 01:53:07 +00:00
ofs + = IVAL ( nt . out . params . data , ofs ) ;
}
return NT_STATUS_OK ;
}
/****************************************************************************
Send a NT Cancel request - used to hurry along a pending request . Usually
used to cancel a pending change notify request
note that this request does not expect a response !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
NTSTATUS smb_raw_ntcancel ( struct smbcli_request * oldreq )
2003-08-13 01:53:07 +00:00
{
2011-09-23 08:35:17 +02:00
bool ok ;
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
if ( oldreq - > subreqs [ 0 ] = = NULL ) {
return NT_STATUS_OK ;
}
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
ok = tevent_req_cancel ( oldreq - > subreqs [ 0 ] ) ;
if ( ! ok ) {
return NT_STATUS_INTERNAL_ERROR ;
}
2005-11-10 16:09:44 +00:00
2004-08-03 06:52:06 +00:00
return NT_STATUS_OK ;
2003-08-13 01:53:07 +00:00
}