2 * Unix SMB/CIFS implementation.
3 * Test pthreadpool_tevent
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(const char *mntpoint
,
70 struct have_file_state
*state
= private_data
;
71 state
->found
|= strequal(f
->name
, state
->fname
);
75 static bool have_file(struct cli_state
*cli
, const char *fname
)
77 struct have_file_state state
= { .fname
= fname
};
83 FILE_ATTRIBUTE_DIRECTORY
|
84 FILE_ATTRIBUTE_SYSTEM
|
85 FILE_ATTRIBUTE_HIDDEN
,
88 if (!NT_STATUS_IS_OK(status
)) {
89 d_printf("cli_list failed: %s\n", nt_errstr(status
));
96 bool run_hidenewfiles(int dummy
)
98 const char *tsname
= "timestamp.txt";
99 const char *fname
= "new_hidden.txt";
100 struct cli_state
*cli
;
101 struct smb_create_returns cr
;
102 struct timeval create_time
;
109 /* what is configure in smb.conf */
110 unsigned hideunreadable_seconds
= 5;
112 ok
= torture_open_connection(&cli
, 0);
117 cli_unlink(cli
, tsname
, FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
);
118 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
);
120 status
= cli_ntcreate(
124 FILE_GENERIC_WRITE
|DELETE_ACCESS
,
125 FILE_ATTRIBUTE_NORMAL
,
132 if (!NT_STATUS_IS_OK(status
)) {
133 d_printf("cli_ntcreate failed: %s\n", nt_errstr(status
));
136 nttime_to_timeval(&create_time
, cr
.last_write_time
);
142 gotit
= have_file(cli
, fname
);
144 status
= servertime(cli
, tsname
, &now
);
145 if (!NT_STATUS_IS_OK(status
)) {
146 d_printf("servertime failed: %s\n",
150 age
= timeval_elapsed2(&create_time
, &now
);
152 if ((age
< hideunreadable_seconds
) && gotit
) {
153 d_printf("Found file at age of %f\n", age
);
156 if ((age
> (hideunreadable_seconds
*10)) && !gotit
) {
157 d_printf("Did not find file after %f seconds\n", age
);
169 cli_nt_delete_on_close(cli
, fnum
, true);
170 cli_close(cli
, fnum
);