s3-libsmb/clidfs.c: remove cli_nt_error()
[Samba/gebeck_regimport.git] / source3 / torture / test_smb2.c
blob1bd0271a678bba6148088bbf1e98a87ba94f6a4e
1 /*
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/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "client.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;
31 NTSTATUS status;
32 uint64_t fid_persistent, fid_volatile;
33 const char *hello = "Hello, world\n";
34 uint8_t *result;
35 uint32_t nread;
36 uint8_t *dir_data;
37 uint32_t dir_data_length;
39 printf("Starting SMB2-BASIC\n");
41 if (!torture_init_connection(&cli)) {
42 return false;
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));
49 return false;
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));
55 return false;
58 status = smb2cli_tcon(cli, share);
59 if (!NT_STATUS_IS_OK(status)) {
60 printf("smb2cli_tcon returned %s\n", nt_errstr(status));
61 return false;
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 */
73 &fid_persistent,
74 &fid_volatile);
75 if (!NT_STATUS_IS_OK(status)) {
76 printf("smb2cli_create returned %s\n", nt_errstr(status));
77 return false;
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));
84 return false;
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));
90 return false;
93 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
94 fid_volatile, 2, 0,
95 talloc_tos(), &result, &nread);
96 if (!NT_STATUS_IS_OK(status)) {
97 printf("smb2cli_read returned %s\n", nt_errstr(status));
98 return false;
101 if (nread != strlen(hello)) {
102 printf("smb2cli_read returned %d bytes, expected %d\n",
103 (int)nread, (int)strlen(hello));
104 return false;
107 if (memcmp(hello, result, nread) != 0) {
108 printf("smb2cli_read returned '%s', expected '%s'\n",
109 result, hello);
110 return false;
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));
116 return false;
119 status = smb2cli_create(cli, "",
120 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
121 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
122 SEC_STD_SYNCHRONIZE|
123 SEC_DIR_LIST|
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 */
130 &fid_persistent,
131 &fid_volatile);
132 if (!NT_STATUS_IS_OK(status)) {
133 printf("smb2cli_create returned %s\n", nt_errstr(status));
134 return false;
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));
143 return false;
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));
149 return false;
152 return true;