2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
23 #include "../libcli/smb/smbXcli_base.h"
24 #include "libsmb/smb2cli.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
28 extern fstring host
, workgroup
, share
, password
, username
, myname
;
30 bool run_smb2_basic(int dummy
)
32 struct cli_state
*cli
;
34 uint64_t fid_persistent
, fid_volatile
;
35 const char *hello
= "Hello, world\n";
39 uint32_t dir_data_length
;
41 printf("Starting SMB2-BASIC\n");
43 if (!torture_init_connection(&cli
)) {
46 cli
->smb2
.pid
= 0xFEFF;
48 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
49 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
50 if (!NT_STATUS_IS_OK(status
)) {
51 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
55 status
= cli_session_setup(cli
, username
,
56 password
, strlen(password
),
57 password
, strlen(password
),
59 if (!NT_STATUS_IS_OK(status
)) {
60 printf("cli_session_setup returned %s\n", nt_errstr(status
));
64 status
= smb2cli_tcon(cli
, share
);
65 if (!NT_STATUS_IS_OK(status
)) {
66 printf("smb2cli_tcon returned %s\n", nt_errstr(status
));
70 status
= smb2cli_create(cli
, "smb2-basic.txt",
71 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
72 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
73 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
74 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
75 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
76 FILE_CREATE
, /* create_disposition, */
77 FILE_DELETE_ON_CLOSE
, /* create_options, */
78 NULL
, /* smb2_create_blobs *blobs */
81 if (!NT_STATUS_IS_OK(status
)) {
82 printf("smb2cli_create returned %s\n", nt_errstr(status
));
86 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
87 fid_volatile
, 0, 0, (const uint8_t *)hello
);
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("smb2cli_write returned %s\n", nt_errstr(status
));
93 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
94 if (!NT_STATUS_IS_OK(status
)) {
95 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
99 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
101 talloc_tos(), &result
, &nread
);
102 if (!NT_STATUS_IS_OK(status
)) {
103 printf("smb2cli_read returned %s\n", nt_errstr(status
));
107 if (nread
!= strlen(hello
)) {
108 printf("smb2cli_read returned %d bytes, expected %d\n",
109 (int)nread
, (int)strlen(hello
));
113 if (memcmp(hello
, result
, nread
) != 0) {
114 printf("smb2cli_read returned '%s', expected '%s'\n",
119 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
120 if (!NT_STATUS_IS_OK(status
)) {
121 printf("smb2cli_close returned %s\n", nt_errstr(status
));
125 status
= smb2cli_create(cli
, "",
126 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
127 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
130 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
131 0, /* file_attributes, */
132 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
133 FILE_OPEN
, /* create_disposition, */
134 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
135 NULL
, /* smb2_create_blobs *blobs */
138 if (!NT_STATUS_IS_OK(status
)) {
139 printf("smb2cli_create returned %s\n", nt_errstr(status
));
143 status
= smb2cli_query_directory(
144 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
145 talloc_tos(), &dir_data
, &dir_data_length
);
147 if (!NT_STATUS_IS_OK(status
)) {
148 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
152 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
153 if (!NT_STATUS_IS_OK(status
)) {
154 printf("smb2cli_close returned %s\n", nt_errstr(status
));
161 bool run_smb2_negprot(int dummy
)
163 struct cli_state
*cli
;
165 enum protocol_types protocol
;
166 const char *name
= NULL
;
168 printf("Starting SMB2-NEGPROT\n");
170 if (!torture_init_connection(&cli
)) {
173 cli
->smb2
.pid
= 0xFEFF;
175 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
176 PROTOCOL_CORE
, PROTOCOL_SMB2_22
);
177 if (!NT_STATUS_IS_OK(status
)) {
178 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
182 protocol
= smbXcli_conn_protocol(cli
->conn
);
185 case PROTOCOL_SMB2_02
:
188 case PROTOCOL_SMB2_10
:
191 case PROTOCOL_SMB2_22
:
199 printf("Server supports %s\n", name
);
201 printf("Server DOES NOT support SMB2\n");
205 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
207 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
208 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
209 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
210 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
215 if (smbXcli_conn_is_connected(cli
->conn
)) {
216 printf("2nd smbXcli_negprot should disconnect "
217 "- still connected\n");