2 * Unix SMB/CIFS implementation.
3 * Test "hide new files timeout"
4 * Copyright (C) Volker Lendecke 2018
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"
22 #include "libsmb/libsmb.h"
23 #include "libcli/security/security.h"
25 static NTSTATUS
servertime(
26 struct cli_state
*cli
, const char *fname
, struct timeval
*tv
)
28 struct smb_create_returns cr
;
32 status
= cli_ntcreate(
36 FILE_GENERIC_WRITE
|DELETE_ACCESS
,
37 FILE_ATTRIBUTE_NORMAL
,
44 if (!NT_STATUS_IS_OK(status
)) {
45 d_printf("cli_ntcreate failed: %s\n", nt_errstr(status
));
49 status
= cli_close(cli
, fnum
);
50 if (!NT_STATUS_IS_OK(status
)) {
51 d_printf("cli_close failed: %s\n", nt_errstr(status
));
55 nttime_to_timeval(tv
, cr
.creation_time
);
60 struct have_file_state
{
65 static NTSTATUS
have_file_fn(struct file_info
*f
,
69 struct have_file_state
*state
= private_data
;
70 state
->found
|= strequal(f
->name
, state
->fname
);
74 static bool have_file(struct cli_state
*cli
, const char *fname
)
76 struct have_file_state state
= { .fname
= fname
};
82 FILE_ATTRIBUTE_DIRECTORY
|
83 FILE_ATTRIBUTE_SYSTEM
|
84 FILE_ATTRIBUTE_HIDDEN
,
87 if (!NT_STATUS_IS_OK(status
)) {
88 d_printf("cli_list failed: %s\n", nt_errstr(status
));
95 bool run_hidenewfiles(int dummy
)
97 const char *tsname
= "timestamp.txt";
98 const char *fname
= "new_hidden.txt";
99 struct cli_state
*cli
;
100 struct smb_create_returns cr
;
101 struct timeval create_time
;
108 /* what is configured in smb.conf */
109 unsigned hideunreadable_seconds
= 5;
111 ok
= torture_open_connection_flags(&cli
, 0, 0);
116 cli_unlink(cli
, tsname
, FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
);
117 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
);
119 status
= cli_ntcreate(
123 FILE_GENERIC_WRITE
|DELETE_ACCESS
,
124 FILE_ATTRIBUTE_NORMAL
,
131 if (!NT_STATUS_IS_OK(status
)) {
132 d_printf("cli_ntcreate failed: %s\n", nt_errstr(status
));
135 nttime_to_timeval(&create_time
, cr
.last_write_time
);
141 gotit
= have_file(cli
, fname
);
143 status
= servertime(cli
, tsname
, &now
);
144 if (!NT_STATUS_IS_OK(status
)) {
145 d_printf("servertime failed: %s\n",
149 age
= timeval_elapsed2(&create_time
, &now
);
151 if ((age
< hideunreadable_seconds
) && gotit
) {
152 d_printf("Found file at age of %f\n", age
);
155 if ((age
> (hideunreadable_seconds
*10)) && !gotit
) {
156 d_printf("Did not find file after %f seconds\n", age
);
168 cli_nt_delete_on_close(cli
, fnum
, true);
169 cli_close(cli
, fnum
);
174 bool run_hidenewfiles_showdirs(int dummy
)
176 const char *dname
= "dir";
177 const char *fname
= "dir/x.txt";
178 struct cli_state
*cli
;
179 struct smb_create_returns cr
;
180 struct timeval create_time
;
181 uint16_t fnum
= UINT16_MAX
;
187 ok
= torture_open_connection_flags(&cli
, 0, 0);
192 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
);
193 cli_rmdir(cli
, dname
);
195 status
= cli_mkdir(cli
, dname
);
196 if (!NT_STATUS_IS_OK(status
)) {
197 d_printf("mkdir(%s) failed: %s\n", dname
, nt_errstr(status
));
201 status
= cli_ntcreate(
205 FILE_GENERIC_WRITE
|DELETE_ACCESS
,
206 FILE_ATTRIBUTE_NORMAL
,
213 if (!NT_STATUS_IS_OK(status
)) {
214 d_printf("cli_ntcreate failed: %s\n", nt_errstr(status
));
217 nttime_to_timeval(&create_time
, cr
.last_write_time
);
219 gotit
= have_file(cli
, dname
);
221 d_printf("%s was hidden\n", dname
);
227 if (fnum
!= UINT16_MAX
) {
228 cli_nt_delete_on_close(cli
, fnum
, true);
229 cli_close(cli
, fnum
);
231 cli_rmdir(cli
, dname
);