mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
started adding SMB2 composite functions that emulate common SMB calls
(such as unlink) (This used to be commit 433038f3fea60087bdca07dcc856d0be4a4753f3)
This commit is contained in:
parent
9b177f8d58
commit
de99db1084
122
source4/libcli/smb_composite/smb2.c
Normal file
122
source4/libcli/smb_composite/smb2.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Copyright (C) Andrew Tridgell 2008
|
||||
|
||||
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/>.
|
||||
*/
|
||||
/*
|
||||
a composite API for making SMB-like calls using SMB2. This is useful
|
||||
as SMB2 often requires more than one requests where a single SMB
|
||||
request would do. In converting code that uses SMB to use SMB2,
|
||||
these routines make life a lot easier
|
||||
*/
|
||||
|
||||
|
||||
#include "includes.h"
|
||||
#include "libcli/raw/libcliraw.h"
|
||||
#include "libcli/raw/raw_proto.h"
|
||||
#include "libcli/composite/composite.h"
|
||||
#include "libcli/smb_composite/smb_composite.h"
|
||||
#include "param/param.h"
|
||||
#include "libcli/smb2/smb2_calls.h"
|
||||
|
||||
/*
|
||||
continue after a SMB2 close
|
||||
*/
|
||||
static void continue_close(struct smb2_request *req)
|
||||
{
|
||||
struct composite_context *ctx = talloc_get_type(req->async.private_data,
|
||||
struct composite_context);
|
||||
NTSTATUS status;
|
||||
struct smb2_close close_parm;
|
||||
|
||||
status = smb2_close_recv(req, &close_parm);
|
||||
composite_error(ctx, status);
|
||||
}
|
||||
|
||||
/*
|
||||
continue after the create in a composite unlink
|
||||
*/
|
||||
static void continue_unlink(struct smb2_request *req)
|
||||
{
|
||||
struct composite_context *ctx = talloc_get_type(req->async.private_data,
|
||||
struct composite_context);
|
||||
struct smb2_tree *tree = req->tree;
|
||||
struct smb2_create create_parm;
|
||||
struct smb2_close close_parm;
|
||||
NTSTATUS status;
|
||||
|
||||
status = smb2_create_recv(req, ctx, &create_parm);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
composite_error(ctx, status);
|
||||
return;
|
||||
}
|
||||
|
||||
ZERO_STRUCT(close_parm);
|
||||
close_parm.in.file.handle = create_parm.out.file.handle;
|
||||
|
||||
req = smb2_close_send(tree, &close_parm);
|
||||
composite_continue_smb2(ctx, req, continue_close, ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
composite SMB2 unlink call
|
||||
*/
|
||||
struct composite_context *smb2_composite_unlink_send(struct smb2_tree *tree,
|
||||
union smb_unlink *io)
|
||||
{
|
||||
struct composite_context *ctx;
|
||||
struct smb2_create create_parm;
|
||||
struct smb2_request *req;
|
||||
|
||||
ctx = composite_create(tree, tree->session->transport->socket->event.ctx);
|
||||
if (ctx == NULL) return NULL;
|
||||
|
||||
/* check for wildcards - we could support these with a
|
||||
search, but for now they aren't necessary */
|
||||
if (strpbrk(io->unlink.in.pattern, "*?<>") != NULL) {
|
||||
composite_error(ctx, NT_STATUS_NOT_SUPPORTED);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ZERO_STRUCT(create_parm);
|
||||
create_parm.in.desired_access = SEC_STD_DELETE;
|
||||
create_parm.in.create_disposition = NTCREATEX_DISP_OPEN;
|
||||
create_parm.in.share_access =
|
||||
NTCREATEX_SHARE_ACCESS_DELETE|
|
||||
NTCREATEX_SHARE_ACCESS_READ|
|
||||
NTCREATEX_SHARE_ACCESS_WRITE;
|
||||
create_parm.in.create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
|
||||
create_parm.in.fname = io->unlink.in.pattern;
|
||||
if (create_parm.in.fname[0] == '\\') {
|
||||
create_parm.in.fname++;
|
||||
}
|
||||
|
||||
req = smb2_create_send(tree, &create_parm);
|
||||
|
||||
composite_continue_smb2(ctx, req, continue_unlink, ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
composite unlink call - sync interface
|
||||
*/
|
||||
NTSTATUS smb2_composite_unlink(struct smb2_tree *tree, union smb_unlink *io)
|
||||
{
|
||||
struct composite_context *c = smb2_composite_unlink_send(tree, io);
|
||||
return composite_wait_free(c);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user