s3: Slightly simplify is_stat_open
[Samba/gebeck_regimport.git] / source4 / libcli / smb2 / tcon.c
blobb13b5c1c51c3f235b31b673d7996bbb768fb1667
1 /*
2 Unix SMB/CIFS implementation.
4 SMB2 client tree handling
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "../libcli/smb/smbXcli_base.h"
28 initialise a smb2_session structure
30 struct smb2_tree *smb2_tree_init(struct smb2_session *session,
31 TALLOC_CTX *parent_ctx, bool primary)
33 struct smb2_tree *tree;
35 tree = talloc_zero(parent_ctx, struct smb2_tree);
36 if (!session) {
37 return NULL;
39 if (primary) {
40 tree->session = talloc_steal(tree, session);
41 } else {
42 tree->session = talloc_reference(tree, session);
45 tree->smbXcli = smbXcli_tcon_create(tree);
46 if (tree->smbXcli == NULL) {
47 talloc_free(tree);
48 return NULL;
51 return tree;
55 send a tree connect
57 struct smb2_request *smb2_tree_connect_send(struct smb2_session *session,
58 struct smb2_tree_connect *io)
60 struct smb2_request *req;
61 NTSTATUS status;
63 req = smb2_request_init(session->transport, SMB2_OP_TCON,
64 0x08, true, 0);
65 if (req == NULL) return NULL;
67 req->session = session;
69 SSVAL(req->out.body, 0x02, io->in.reserved);
70 status = smb2_push_o16s16_string(&req->out, 0x04, io->in.path);
71 if (!NT_STATUS_IS_OK(status)) {
72 talloc_free(req);
73 return NULL;
76 smb2_transport_send(req);
78 return req;
83 recv a tree connect reply
85 NTSTATUS smb2_tree_connect_recv(struct smb2_request *req, struct smb2_tree_connect *io)
87 if (!smb2_request_receive(req) ||
88 smb2_request_is_error(req)) {
89 return smb2_request_destroy(req);
92 SMB2_CHECK_PACKET_RECV(req, 0x10, false);
94 io->out.tid = IVAL(req->in.hdr, SMB2_HDR_TID);
96 io->out.share_type = CVAL(req->in.body, 0x02);
97 io->out.reserved = CVAL(req->in.body, 0x03);
98 io->out.flags = IVAL(req->in.body, 0x04);
99 io->out.capabilities= IVAL(req->in.body, 0x08);
100 io->out.access_mask = IVAL(req->in.body, 0x0C);
102 if (io->out.capabilities & ~SMB2_CAP_ALL) {
103 DEBUG(0,("Unknown capabilities mask 0x%x\n", io->out.capabilities));
105 if (io->out.flags & ~SMB2_SHAREFLAG_ALL) {
106 DEBUG(0,("Unknown tcon shareflag 0x%x\n", io->out.flags));
109 return smb2_request_destroy(req);
113 sync tree connect request
115 NTSTATUS smb2_tree_connect(struct smb2_session *session, struct smb2_tree_connect *io)
117 struct smb2_request *req = smb2_tree_connect_send(session, io);
118 return smb2_tree_connect_recv(req, io);