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)); \
37 static BOOL check_ea(struct smbcli_state *cli,
38 const char *fname, const char *eaname, const char *value)
40 NTSTATUS status = torture_check_ea(cli, fname, eaname, value);
41 return NT_STATUS_IS_OK(status);
44 static BOOL test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
47 union smb_setfileinfo setfile;
49 const char *fname = BASEDIR "\\ea.txt";
53 printf("TESTING SETFILEINFO EA_SET\n");
55 io.generic.level = RAW_OPEN_NTCREATEX;
56 io.ntcreatex.in.root_fid = 0;
57 io.ntcreatex.in.flags = 0;
58 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
59 io.ntcreatex.in.create_options = 0;
60 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
61 io.ntcreatex.in.share_access =
62 NTCREATEX_SHARE_ACCESS_READ |
63 NTCREATEX_SHARE_ACCESS_WRITE;
64 io.ntcreatex.in.alloc_size = 0;
65 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
66 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
67 io.ntcreatex.in.security_flags = 0;
68 io.ntcreatex.in.fname = fname;
69 status = smb_raw_open(cli->tree, mem_ctx, &io);
70 CHECK_STATUS(status, NT_STATUS_OK);
71 fnum = io.ntcreatex.out.fnum;
73 ret &= check_ea(cli, fname, "EAONE", NULL);
75 printf("Adding first two EAs\n");
76 setfile.generic.level = RAW_SFILEINFO_EA_SET;
77 setfile.generic.file.fnum = fnum;
78 setfile.ea_set.in.num_eas = 2;
79 setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
80 setfile.ea_set.in.eas[0].flags = 0;
81 setfile.ea_set.in.eas[0].name.s = "EAONE";
82 setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE1");
83 setfile.ea_set.in.eas[1].flags = 0;
84 setfile.ea_set.in.eas[1].name.s = "SECONDEA";
85 setfile.ea_set.in.eas[1].value = data_blob_string_const("ValueTwo");
87 status = smb_raw_setfileinfo(cli->tree, &setfile);
88 CHECK_STATUS(status, NT_STATUS_OK);
90 ret &= check_ea(cli, fname, "EAONE", "VALUE1");
91 ret &= check_ea(cli, fname, "SECONDEA", "ValueTwo");
93 printf("Modifying 2nd EA\n");
94 setfile.ea_set.in.num_eas = 1;
95 setfile.ea_set.in.eas[0].name.s = "SECONDEA";
96 setfile.ea_set.in.eas[0].value = data_blob_string_const(" Changed Value");
97 status = smb_raw_setfileinfo(cli->tree, &setfile);
98 CHECK_STATUS(status, NT_STATUS_OK);
100 ret &= check_ea(cli, fname, "EAONE", "VALUE1");
101 ret &= check_ea(cli, fname, "SECONDEA", " Changed Value");
103 printf("Setting a NULL EA\n");
104 setfile.ea_set.in.eas[0].value = data_blob(NULL, 0);
105 setfile.ea_set.in.eas[0].name.s = "NULLEA";
106 status = smb_raw_setfileinfo(cli->tree, &setfile);
107 CHECK_STATUS(status, NT_STATUS_OK);
109 ret &= check_ea(cli, fname, "EAONE", "VALUE1");
110 ret &= check_ea(cli, fname, "SECONDEA", " Changed Value");
111 ret &= check_ea(cli, fname, "NULLEA", NULL);
113 printf("Deleting first EA\n");
114 setfile.ea_set.in.eas[0].flags = 0;
115 setfile.ea_set.in.eas[0].name.s = "EAONE";
116 setfile.ea_set.in.eas[0].value = data_blob(NULL, 0);
117 status = smb_raw_setfileinfo(cli->tree, &setfile);
118 CHECK_STATUS(status, NT_STATUS_OK);
120 ret &= check_ea(cli, fname, "EAONE", NULL);
121 ret &= check_ea(cli, fname, "SECONDEA", " Changed Value");
123 printf("Deleting second EA\n");
124 setfile.ea_set.in.eas[0].flags = 0;
125 setfile.ea_set.in.eas[0].name.s = "SECONDEA";
126 setfile.ea_set.in.eas[0].value = data_blob(NULL, 0);
127 status = smb_raw_setfileinfo(cli->tree, &setfile);
128 CHECK_STATUS(status, NT_STATUS_OK);
130 ret &= check_ea(cli, fname, "EAONE", NULL);
131 ret &= check_ea(cli, fname, "SECONDEA", NULL);
134 smbcli_close(cli->tree, fnum);
140 test using NTTRANS CREATE to create a file with an initial EA set
142 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
146 const char *fname = BASEDIR "\\ea2.txt";
149 struct ea_struct eas[3];
150 struct smb_ea_list ea_list;
152 printf("TESTING NTTRANS CREATE WITH EAS\n");
154 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
155 io.ntcreatex.in.root_fid = 0;
156 io.ntcreatex.in.flags = 0;
157 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
158 io.ntcreatex.in.create_options = 0;
159 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
160 io.ntcreatex.in.share_access =
161 NTCREATEX_SHARE_ACCESS_READ |
162 NTCREATEX_SHARE_ACCESS_WRITE;
163 io.ntcreatex.in.alloc_size = 0;
164 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
165 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
166 io.ntcreatex.in.security_flags = 0;
167 io.ntcreatex.in.fname = fname;
173 eas[0].name.s = "1st EA";
174 eas[0].value = data_blob_string_const("Value One");
177 eas[1].name.s = "2nd EA";
178 eas[1].value = data_blob_string_const("Second Value");
181 eas[2].name.s = "and 3rd";
182 eas[2].value = data_blob_string_const("final value");
184 io.ntcreatex.in.ea_list = &ea_list;
185 io.ntcreatex.in.sec_desc = NULL;
187 status = smb_raw_open(cli->tree, mem_ctx, &io);
188 CHECK_STATUS(status, NT_STATUS_OK);
189 fnum = io.ntcreatex.out.fnum;
191 ret &= check_ea(cli, fname, "EAONE", NULL);
192 ret &= check_ea(cli, fname, "1st EA", "Value One");
193 ret &= check_ea(cli, fname, "2nd EA", "Second Value");
194 ret &= check_ea(cli, fname, "and 3rd", "final value");
196 smbcli_close(cli->tree, fnum);
198 printf("Trying to add EAs on non-create\n");
199 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
200 io.ntcreatex.in.fname = fname;
204 eas[0].name.s = "Fourth EA";
205 eas[0].value = data_blob_string_const("Value Four");
207 status = smb_raw_open(cli->tree, mem_ctx, &io);
208 CHECK_STATUS(status, NT_STATUS_OK);
209 fnum = io.ntcreatex.out.fnum;
211 ret &= check_ea(cli, fname, "1st EA", "Value One");
212 ret &= check_ea(cli, fname, "2nd EA", "Second Value");
213 ret &= check_ea(cli, fname, "and 3rd", "final value");
214 ret &= check_ea(cli, fname, "Fourth EA", NULL);
217 smbcli_close(cli->tree, fnum);
222 basic testing of EA calls
224 BOOL torture_raw_eas(void)
226 struct smbcli_state *cli;
230 if (!torture_open_connection(&cli)) {
234 mem_ctx = talloc_init("torture_raw_eas");
236 if (!torture_setup_dir(cli, BASEDIR)) {
240 ret &= test_eas(cli, mem_ctx);
241 ret &= test_nttrans_create(cli, mem_ctx);
243 smb_raw_exit(cli->session);
244 smbcli_deltree(cli->tree, BASEDIR);
246 torture_close_connection(cli);
247 talloc_free(mem_ctx);