2 Unix SMB/CIFS implementation.
4 test DOS extended attributes
6 Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/raw/libcliraw.h"
25 #include "librpc/gen_ndr/ndr_security.h"
27 #define BASEDIR "\\testeas"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 printf("(%s) Incorrect status %s - should be %s\n", \
32 __location__, nt_errstr(status), nt_errstr(correct)); \
38 check that an EA has the right value
40 static BOOL check_ea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx,
41 const char *fname, const char *eaname, const char *value)
43 union smb_fileinfo info;
48 info.all_eas.level = RAW_FILEINFO_ALL_EAS;
49 info.all_eas.in.fname = fname;
51 status = smb_raw_pathinfo(cli->tree, mem_ctx, &info);
52 CHECK_STATUS(status, NT_STATUS_OK);
54 for (i=0;i<info.all_eas.out.num_eas;i++) {
55 if (StrCaseCmp(eaname, info.all_eas.out.eas[i].name.s) == 0) {
57 printf("attr '%s' should not be present\n", eaname);
60 if (strlen(value) == info.all_eas.out.eas[i].value.length &&
62 info.all_eas.out.eas[i].value.data,
63 info.all_eas.out.eas[i].value.length) == 0) {
66 printf("attr '%s' has wrong value '%*.*s'\n",
68 info.all_eas.out.eas[i].value.length,
69 info.all_eas.out.eas[i].value.length,
70 info.all_eas.out.eas[i].value.data);
78 printf("attr '%s' not found\n", eaname);
86 static DATA_BLOB data_blob_string_const(const char *str)
89 blob.data = discard_const(str);
90 blob.length = strlen(str);
95 static BOOL test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
98 union smb_setfileinfo setfile;
100 const char *fname = BASEDIR "\\ea.txt";
104 printf("TESTING SETFILEINFO EA_SET\n");
106 io.generic.level = RAW_OPEN_NTCREATEX;
107 io.ntcreatex.in.root_fid = 0;
108 io.ntcreatex.in.flags = 0;
109 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
110 io.ntcreatex.in.create_options = 0;
111 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
112 io.ntcreatex.in.share_access =
113 NTCREATEX_SHARE_ACCESS_READ |
114 NTCREATEX_SHARE_ACCESS_WRITE;
115 io.ntcreatex.in.alloc_size = 0;
116 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
117 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
118 io.ntcreatex.in.security_flags = 0;
119 io.ntcreatex.in.fname = fname;
120 status = smb_raw_open(cli->tree, mem_ctx, &io);
121 CHECK_STATUS(status, NT_STATUS_OK);
122 fnum = io.ntcreatex.out.fnum;
124 ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL);
126 printf("Adding first EA\n");
127 setfile.generic.level = RAW_SFILEINFO_EA_SET;
128 setfile.generic.file.fnum = fnum;
129 setfile.ea_set.in.ea.flags = 0;
130 setfile.ea_set.in.ea.name.s = "EAONE";
131 setfile.ea_set.in.ea.value = data_blob_string_const("VALUE1");
133 status = smb_raw_setfileinfo(cli->tree, &setfile);
134 CHECK_STATUS(status, NT_STATUS_OK);
136 ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1");
138 setfile.ea_set.in.ea.name.s = "SECONDEA";
139 setfile.ea_set.in.ea.value = data_blob_string_const("ValueTwo");
141 printf("Adding second EA\n");
142 status = smb_raw_setfileinfo(cli->tree, &setfile);
143 CHECK_STATUS(status, NT_STATUS_OK);
145 ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1");
146 ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", "ValueTwo");
148 printf("Modifying 2nd EA\n");
149 setfile.ea_set.in.ea.value = data_blob_string_const(" Changed Value");
150 status = smb_raw_setfileinfo(cli->tree, &setfile);
151 CHECK_STATUS(status, NT_STATUS_OK);
153 ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1");
154 ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value");
156 printf("Setting a NULL EA\n");
157 setfile.ea_set.in.ea.value = data_blob(NULL, 0);
158 setfile.ea_set.in.ea.name.s = "NULLEA";
159 status = smb_raw_setfileinfo(cli->tree, &setfile);
160 CHECK_STATUS(status, NT_STATUS_OK);
162 ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1");
163 ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value");
164 ret &= check_ea(cli, mem_ctx, fname, "NULLEA", NULL);
166 printf("Deleting first EA\n");
167 setfile.ea_set.in.ea.flags = 0;
168 setfile.ea_set.in.ea.name.s = "EAONE";
169 setfile.ea_set.in.ea.value = data_blob(NULL, 0);
170 status = smb_raw_setfileinfo(cli->tree, &setfile);
171 CHECK_STATUS(status, NT_STATUS_OK);
173 ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL);
174 ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value");
176 printf("Deleting second EA\n");
177 setfile.ea_set.in.ea.flags = 0;
178 setfile.ea_set.in.ea.name.s = "SECONDEA";
179 setfile.ea_set.in.ea.value = data_blob(NULL, 0);
180 status = smb_raw_setfileinfo(cli->tree, &setfile);
181 CHECK_STATUS(status, NT_STATUS_OK);
183 ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL);
184 ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", NULL);
187 smbcli_close(cli->tree, fnum);
193 test using NTTRANS CREATE to create a file with an initial EA set
195 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
199 const char *fname = BASEDIR "\\ea2.txt";
202 struct ea_struct eas[3];
203 struct smb_ea_list ea_list;
205 printf("TESTING NTTRANS CREATE WITH EAS\n");
207 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
208 io.ntcreatex.in.root_fid = 0;
209 io.ntcreatex.in.flags = 0;
210 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
211 io.ntcreatex.in.create_options = 0;
212 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
213 io.ntcreatex.in.share_access =
214 NTCREATEX_SHARE_ACCESS_READ |
215 NTCREATEX_SHARE_ACCESS_WRITE;
216 io.ntcreatex.in.alloc_size = 0;
217 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
218 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
219 io.ntcreatex.in.security_flags = 0;
220 io.ntcreatex.in.fname = fname;
226 eas[0].name.s = "1st EA";
227 eas[0].value = data_blob_string_const("Value One");
230 eas[1].name.s = "2nd EA";
231 eas[1].value = data_blob_string_const("Second Value");
234 eas[2].name.s = "and 3rd";
235 eas[2].value = data_blob_string_const("final value");
237 io.ntcreatex.in.ea_list = &ea_list;
238 io.ntcreatex.in.sec_desc = NULL;
240 status = smb_raw_open(cli->tree, mem_ctx, &io);
241 CHECK_STATUS(status, NT_STATUS_OK);
242 fnum = io.ntcreatex.out.fnum;
244 ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL);
245 ret &= check_ea(cli, mem_ctx, fname, "1st EA", "Value One");
246 ret &= check_ea(cli, mem_ctx, fname, "2nd EA", "Second Value");
247 ret &= check_ea(cli, mem_ctx, fname, "and 3rd", "final value");
249 smbcli_close(cli->tree, fnum);
251 printf("Trying to add EAs on non-create\n");
252 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
253 io.ntcreatex.in.fname = fname;
257 eas[0].name.s = "Fourth EA";
258 eas[0].value = data_blob_string_const("Value Four");
260 status = smb_raw_open(cli->tree, mem_ctx, &io);
261 CHECK_STATUS(status, NT_STATUS_OK);
262 fnum = io.ntcreatex.out.fnum;
264 ret &= check_ea(cli, mem_ctx, fname, "1st EA", "Value One");
265 ret &= check_ea(cli, mem_ctx, fname, "2nd EA", "Second Value");
266 ret &= check_ea(cli, mem_ctx, fname, "and 3rd", "final value");
267 ret &= check_ea(cli, mem_ctx, fname, "Fourth EA", NULL);
270 smbcli_close(cli->tree, fnum);
275 basic testing of EA calls
277 BOOL torture_raw_eas(void)
279 struct smbcli_state *cli;
283 if (!torture_open_connection(&cli)) {
287 mem_ctx = talloc_init("torture_raw_eas");
289 if (!torture_setup_dir(cli, BASEDIR)) {
293 ret &= test_eas(cli, mem_ctx);
294 ret &= test_nttrans_create(cli, mem_ctx);
296 smb_raw_exit(cli->session);
297 smbcli_deltree(cli->tree, BASEDIR);
299 torture_close_connection(cli);
300 talloc_destroy(mem_ctx);