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 "libsmb/smb2cli.h"
24 #include "libcli/security/security.h"
26 extern fstring host
, workgroup
, share
, password
, username
, myname
;
28 bool run_smb2_basic(int dummy
)
30 struct cli_state
*cli
;
32 uint64_t fid_persistent
, fid_volatile
;
33 const char *hello
= "Hello, world\n";
37 uint32_t dir_data_length
;
39 printf("Starting SMB2-BASIC\n");
41 if (!torture_init_connection(&cli
)) {
44 cli
->smb2
.pid
= 0xFEFF;
46 status
= smb2cli_negprot(cli
);
47 if (!NT_STATUS_IS_OK(status
)) {
48 printf("smb2cli_negprot returned %s\n", nt_errstr(status
));
52 status
= smb2cli_sesssetup_ntlmssp(cli
, username
, workgroup
, password
);
53 if (!NT_STATUS_IS_OK(status
)) {
54 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
58 status
= smb2cli_tcon(cli
, share
);
59 if (!NT_STATUS_IS_OK(status
)) {
60 printf("smb2cli_tcon returned %s\n", nt_errstr(status
));
64 status
= smb2cli_create(cli
, "smb2-basic.txt",
65 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
66 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
67 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
68 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
69 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
70 FILE_CREATE
, /* create_disposition, */
71 FILE_DELETE_ON_CLOSE
, /* create_options, */
72 NULL
, /* smb2_create_blobs *blobs */
75 if (!NT_STATUS_IS_OK(status
)) {
76 printf("smb2cli_create returned %s\n", nt_errstr(status
));
80 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
81 fid_volatile
, 0, 0, (const uint8_t *)hello
);
82 if (!NT_STATUS_IS_OK(status
)) {
83 printf("smb2cli_write returned %s\n", nt_errstr(status
));
87 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
93 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
95 talloc_tos(), &result
, &nread
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 printf("smb2cli_read returned %s\n", nt_errstr(status
));
101 if (nread
!= strlen(hello
)) {
102 printf("smb2cli_read returned %d bytes, expected %d\n",
103 (int)nread
, (int)strlen(hello
));
107 if (memcmp(hello
, result
, nread
) != 0) {
108 printf("smb2cli_read returned '%s', expected '%s'\n",
113 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
114 if (!NT_STATUS_IS_OK(status
)) {
115 printf("smb2cli_close returned %s\n", nt_errstr(status
));
119 status
= smb2cli_create(cli
, "",
120 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
121 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
124 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
125 0, /* file_attributes, */
126 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
127 FILE_OPEN
, /* create_disposition, */
128 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
129 NULL
, /* smb2_create_blobs *blobs */
132 if (!NT_STATUS_IS_OK(status
)) {
133 printf("smb2cli_create returned %s\n", nt_errstr(status
));
137 status
= smb2cli_query_directory(
138 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
139 talloc_tos(), &dir_data
, &dir_data_length
);
141 if (!NT_STATUS_IS_OK(status
)) {
142 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
146 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
147 if (!NT_STATUS_IS_OK(status
)) {
148 printf("smb2cli_close returned %s\n", nt_errstr(status
));