Line data Source code
1 : /*
2 : * Time auditing VFS module for samba. Log time taken for VFS call to syslog
3 : * facility.
4 : *
5 : * Copyright (C) Abhidnya Chirmule <achirmul@in.ibm.com> 2009
6 : *
7 : * This program is free software; you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License as published by
9 : * the Free Software Foundation; either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * This program is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU General Public License
18 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : /*
22 : * This module implements logging for time taken for all Samba VFS operations.
23 : *
24 : * vfs objects = time_audit
25 : */
26 :
27 :
28 : #include "includes.h"
29 : #include "smbd/smbd.h"
30 : #include "ntioctl.h"
31 : #include "lib/util/tevent_unix.h"
32 : #include "lib/util/tevent_ntstatus.h"
33 :
34 : #undef DBGC_CLASS
35 : #define DBGC_CLASS DBGC_VFS
36 :
37 : static double audit_timeout;
38 :
39 0 : static void smb_time_audit_log_msg(const char *syscallname, double elapsed,
40 : const char *msg)
41 : {
42 0 : DEBUG(0, ("WARNING: VFS call \"%s\" took unexpectedly long "
43 : "(%.2f seconds) %s%s-- Validate that file and storage "
44 : "subsystems are operating normally\n", syscallname,
45 : elapsed, (msg != NULL) ? msg : "",
46 : (msg != NULL) ? " " : ""));
47 0 : }
48 :
49 0 : static void smb_time_audit_log(const char *syscallname, double elapsed)
50 : {
51 0 : smb_time_audit_log_msg(syscallname, elapsed, NULL);
52 0 : }
53 :
54 0 : static void smb_time_audit_log_fsp(const char *syscallname, double elapsed,
55 : const struct files_struct *fsp)
56 : {
57 0 : char *base_name = NULL;
58 0 : char *connectpath = NULL;
59 0 : char *msg = NULL;
60 :
61 0 : if (fsp == NULL) {
62 0 : smb_time_audit_log(syscallname, elapsed);
63 0 : return;
64 : }
65 0 : if (fsp->conn)
66 0 : connectpath = fsp->conn->connectpath;
67 0 : if (fsp->fsp_name)
68 0 : base_name = fsp->fsp_name->base_name;
69 :
70 0 : if (connectpath != NULL && base_name != NULL) {
71 0 : msg = talloc_asprintf(talloc_tos(), "filename = \"%s/%s\"",
72 : connectpath, base_name);
73 0 : } else if (connectpath != NULL && base_name == NULL) {
74 0 : msg = talloc_asprintf(talloc_tos(), "connectpath = \"%s\", "
75 : "base_name = <NULL>",
76 : connectpath);
77 0 : } else if (connectpath == NULL && base_name != NULL) {
78 0 : msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
79 : "base_name = \"%s\"",
80 : base_name);
81 : } else { /* connectpath == NULL && base_name == NULL */
82 0 : msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
83 : "base_name = <NULL>");
84 : }
85 0 : smb_time_audit_log_msg(syscallname, elapsed, msg);
86 0 : TALLOC_FREE(msg);
87 : }
88 :
89 0 : static void smb_time_audit_log_at(const char *syscallname,
90 : double elapsed,
91 : const struct files_struct *dir_fsp,
92 : const struct smb_filename *smb_fname)
93 : {
94 0 : char *msg = NULL;
95 :
96 0 : msg = talloc_asprintf(talloc_tos(),
97 : "filename = \"%s/%s/%s\"",
98 0 : dir_fsp->conn->connectpath,
99 0 : dir_fsp->fsp_name->base_name,
100 0 : smb_fname->base_name);
101 :
102 0 : smb_time_audit_log_msg(syscallname, elapsed, msg);
103 0 : TALLOC_FREE(msg);
104 0 : }
105 :
106 0 : static void smb_time_audit_log_fname(const char *syscallname, double elapsed,
107 : const char *fname)
108 : {
109 : char cwd[PATH_MAX];
110 0 : char *msg = NULL;
111 :
112 0 : if (getcwd(cwd, sizeof(cwd)) == NULL) {
113 0 : snprintf(cwd, sizeof(cwd), "<getcwd() error %d>", errno);
114 : }
115 0 : if (fname != NULL) {
116 0 : msg = talloc_asprintf(talloc_tos(),
117 : "cwd = \"%s\", filename = \"%s\"",
118 : cwd, fname);
119 : } else {
120 0 : msg = talloc_asprintf(talloc_tos(),
121 : "cwd = \"%s\", filename = <NULL>",
122 : cwd);
123 : }
124 0 : smb_time_audit_log_msg(syscallname, elapsed, msg);
125 0 : TALLOC_FREE(msg);
126 0 : }
127 :
128 0 : static void smb_time_audit_log_smb_fname(const char *syscallname, double elapsed,
129 : const struct smb_filename *smb_fname)
130 : {
131 0 : if (smb_fname != NULL) {
132 0 : smb_time_audit_log_fname(syscallname, elapsed,
133 0 : smb_fname->base_name);
134 : } else {
135 0 : smb_time_audit_log_fname(syscallname, elapsed,
136 : "smb_fname = <NULL>");
137 : }
138 0 : }
139 :
140 2579 : static int smb_time_audit_connect(vfs_handle_struct *handle,
141 : const char *svc, const char *user)
142 : {
143 : int result;
144 : struct timespec ts1,ts2;
145 : double timediff;
146 :
147 2579 : if (!handle) {
148 0 : return -1;
149 : }
150 :
151 2579 : clock_gettime_mono(&ts1);
152 2579 : result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
153 2579 : clock_gettime_mono(&ts2);
154 2579 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
155 2579 : if (timediff > audit_timeout) {
156 0 : smb_time_audit_log_msg("connect", timediff, user);
157 : }
158 2579 : return result;
159 : }
160 :
161 2579 : static void smb_time_audit_disconnect(vfs_handle_struct *handle)
162 : {
163 : struct timespec ts1,ts2;
164 : double timediff;
165 :
166 2579 : clock_gettime_mono(&ts1);
167 2579 : SMB_VFS_NEXT_DISCONNECT(handle);
168 2579 : clock_gettime_mono(&ts2);
169 2579 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
170 :
171 2579 : if (timediff > audit_timeout) {
172 0 : smb_time_audit_log("disconnect", timediff);
173 : }
174 2579 : }
175 :
176 183 : static uint64_t smb_time_audit_disk_free(vfs_handle_struct *handle,
177 : const struct smb_filename *smb_fname,
178 : uint64_t *bsize,
179 : uint64_t *dfree,
180 : uint64_t *dsize)
181 : {
182 : uint64_t result;
183 : struct timespec ts1,ts2;
184 : double timediff;
185 :
186 183 : clock_gettime_mono(&ts1);
187 183 : result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
188 183 : clock_gettime_mono(&ts2);
189 183 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
190 :
191 : /* Don't have a reasonable notion of failure here */
192 183 : if (timediff > audit_timeout) {
193 0 : smb_time_audit_log_fname("disk_free",
194 : timediff,
195 0 : smb_fname->base_name);
196 : }
197 :
198 183 : return result;
199 : }
200 :
201 366 : static int smb_time_audit_get_quota(struct vfs_handle_struct *handle,
202 : const struct smb_filename *smb_fname,
203 : enum SMB_QUOTA_TYPE qtype,
204 : unid_t id,
205 : SMB_DISK_QUOTA *qt)
206 : {
207 : int result;
208 : struct timespec ts1,ts2;
209 : double timediff;
210 :
211 366 : clock_gettime_mono(&ts1);
212 366 : result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
213 366 : clock_gettime_mono(&ts2);
214 366 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
215 :
216 366 : if (timediff > audit_timeout) {
217 0 : smb_time_audit_log_fname("get_quota",
218 : timediff,
219 0 : smb_fname->base_name);
220 : }
221 366 : return result;
222 : }
223 :
224 0 : static int smb_time_audit_set_quota(struct vfs_handle_struct *handle,
225 : enum SMB_QUOTA_TYPE qtype, unid_t id,
226 : SMB_DISK_QUOTA *qt)
227 : {
228 : int result;
229 : struct timespec ts1,ts2;
230 : double timediff;
231 :
232 0 : clock_gettime_mono(&ts1);
233 0 : result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
234 0 : clock_gettime_mono(&ts2);
235 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
236 :
237 0 : if (timediff > audit_timeout) {
238 0 : smb_time_audit_log("set_quota", timediff);
239 : }
240 :
241 0 : return result;
242 : }
243 :
244 44 : static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
245 : struct files_struct *fsp,
246 : struct shadow_copy_data *shadow_copy_data,
247 : bool labels)
248 : {
249 : int result;
250 : struct timespec ts1,ts2;
251 : double timediff;
252 :
253 44 : clock_gettime_mono(&ts1);
254 44 : result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp,
255 : shadow_copy_data, labels);
256 44 : clock_gettime_mono(&ts2);
257 44 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
258 :
259 44 : if (timediff > audit_timeout) {
260 0 : smb_time_audit_log_fsp("get_shadow_copy_data", timediff, fsp);
261 : }
262 :
263 44 : return result;
264 : }
265 :
266 1745 : static int smb_time_audit_statvfs(struct vfs_handle_struct *handle,
267 : const struct smb_filename *smb_fname,
268 : struct vfs_statvfs_struct *statbuf)
269 : {
270 : int result;
271 : struct timespec ts1,ts2;
272 : double timediff;
273 :
274 1745 : clock_gettime_mono(&ts1);
275 1745 : result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
276 1745 : clock_gettime_mono(&ts2);
277 1745 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
278 :
279 1745 : if (timediff > audit_timeout) {
280 0 : smb_time_audit_log_fname("statvfs", timediff,
281 0 : smb_fname->base_name);
282 : }
283 :
284 1745 : return result;
285 : }
286 :
287 1745 : static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct *handle,
288 : enum timestamp_set_resolution *p_ts_res)
289 : {
290 : uint32_t result;
291 : struct timespec ts1,ts2;
292 : double timediff;
293 :
294 1745 : clock_gettime_mono(&ts1);
295 1745 : result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
296 1745 : clock_gettime_mono(&ts2);
297 1745 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
298 :
299 1745 : if (timediff > audit_timeout) {
300 0 : smb_time_audit_log("fs_capabilities", timediff);
301 : }
302 :
303 1745 : return result;
304 : }
305 :
306 1463 : static NTSTATUS smb_time_audit_get_dfs_referrals(
307 : struct vfs_handle_struct *handle,
308 : struct dfs_GetDFSReferral *r)
309 : {
310 : NTSTATUS result;
311 : struct timespec ts1,ts2;
312 : double timediff;
313 :
314 1463 : clock_gettime_mono(&ts1);
315 1463 : result = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
316 1463 : clock_gettime_mono(&ts2);
317 1463 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
318 :
319 1463 : if (timediff > audit_timeout) {
320 0 : smb_time_audit_log("get_dfs_referrals", timediff);
321 : }
322 :
323 1463 : return result;
324 : }
325 :
326 0 : static NTSTATUS smb_time_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
327 : struct files_struct *dirfsp,
328 : const struct smb_filename *smb_fname,
329 : const struct referral *reflist,
330 : size_t referral_count)
331 : {
332 : NTSTATUS result;
333 : struct timespec ts1,ts2;
334 : double timediff;
335 0 : struct smb_filename *full_fname = NULL;
336 :
337 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
338 : dirfsp,
339 : smb_fname);
340 0 : if (full_fname == NULL) {
341 0 : return NT_STATUS_NO_MEMORY;
342 : }
343 :
344 0 : clock_gettime_mono(&ts1);
345 0 : result = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
346 : dirfsp,
347 : smb_fname,
348 : reflist,
349 : referral_count);
350 0 : clock_gettime_mono(&ts2);
351 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
352 :
353 0 : if (timediff > audit_timeout) {
354 0 : smb_time_audit_log_smb_fname("create_dfs_pathat",
355 : timediff,
356 : full_fname);
357 : }
358 0 : TALLOC_FREE(full_fname);
359 0 : return result;
360 : }
361 :
362 11234 : static NTSTATUS smb_time_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
363 : TALLOC_CTX *mem_ctx,
364 : struct files_struct *dirfsp,
365 : struct smb_filename *smb_fname,
366 : struct referral **ppreflist,
367 : size_t *preferral_count)
368 : {
369 : NTSTATUS result;
370 : struct timespec ts1,ts2;
371 : double timediff;
372 11234 : struct smb_filename *full_fname = NULL;
373 :
374 11234 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
375 : dirfsp,
376 : smb_fname);
377 11234 : if (full_fname == NULL) {
378 0 : return NT_STATUS_NO_MEMORY;
379 : }
380 :
381 11234 : clock_gettime_mono(&ts1);
382 11234 : result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
383 : mem_ctx,
384 : dirfsp,
385 : smb_fname,
386 : ppreflist,
387 : preferral_count);
388 11234 : clock_gettime_mono(&ts2);
389 11234 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
390 :
391 11234 : if (timediff > audit_timeout) {
392 0 : smb_time_audit_log_smb_fname("read_dfs_pathat",
393 : timediff,
394 : full_fname);
395 : }
396 :
397 11234 : TALLOC_FREE(full_fname);
398 11234 : return result;
399 : }
400 :
401 0 : static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle,
402 : TALLOC_CTX *mem_ctx,
403 : const char *service_path,
404 : char **base_volume)
405 : {
406 : NTSTATUS status;
407 : struct timespec ts1,ts2;
408 : double timediff;
409 :
410 0 : clock_gettime_mono(&ts1);
411 0 : status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
412 : base_volume);
413 0 : clock_gettime_mono(&ts2);
414 0 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
415 :
416 0 : if (timediff > audit_timeout) {
417 0 : smb_time_audit_log("snap_check_path", timediff);
418 : }
419 :
420 0 : return status;
421 : }
422 :
423 0 : static NTSTATUS smb_time_audit_snap_create(struct vfs_handle_struct *handle,
424 : TALLOC_CTX *mem_ctx,
425 : const char *base_volume,
426 : time_t *tstamp,
427 : bool rw,
428 : char **base_path,
429 : char **snap_path)
430 : {
431 : NTSTATUS status;
432 : struct timespec ts1,ts2;
433 : double timediff;
434 :
435 0 : clock_gettime_mono(&ts1);
436 0 : status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
437 : rw, base_path, snap_path);
438 0 : clock_gettime_mono(&ts2);
439 0 : timediff = nsec_time_diff(&ts2 ,&ts1) * 1.0e-9;
440 :
441 0 : if (timediff > audit_timeout) {
442 0 : smb_time_audit_log("snap_create", timediff);
443 : }
444 :
445 0 : return status;
446 : }
447 :
448 0 : static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
449 : TALLOC_CTX *mem_ctx,
450 : char *base_path,
451 : char *snap_path)
452 : {
453 : NTSTATUS status;
454 : struct timespec ts1,ts2;
455 : double timediff;
456 :
457 0 : clock_gettime_mono(&ts1);
458 0 : status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
459 : snap_path);
460 0 : clock_gettime_mono(&ts2);
461 0 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
462 :
463 0 : if (timediff > audit_timeout) {
464 0 : smb_time_audit_log("snap_delete", timediff);
465 : }
466 :
467 0 : return status;
468 : }
469 :
470 2302 : static DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
471 : files_struct *fsp,
472 : const char *mask, uint32_t attr)
473 : {
474 : DIR *result;
475 : struct timespec ts1,ts2;
476 : double timediff;
477 :
478 2302 : clock_gettime_mono(&ts1);
479 2302 : result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
480 2302 : clock_gettime_mono(&ts2);
481 2302 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
482 :
483 2302 : if (timediff > audit_timeout) {
484 0 : smb_time_audit_log_fsp("fdopendir", timediff, fsp);
485 : }
486 :
487 2302 : return result;
488 : }
489 :
490 19120 : static struct dirent *smb_time_audit_readdir(vfs_handle_struct *handle,
491 : struct files_struct *dirfsp,
492 : DIR *dirp,
493 : SMB_STRUCT_STAT *sbuf)
494 : {
495 : struct dirent *result;
496 : struct timespec ts1,ts2;
497 : double timediff;
498 :
499 19120 : clock_gettime_mono(&ts1);
500 19120 : result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
501 19120 : clock_gettime_mono(&ts2);
502 19120 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
503 :
504 19120 : if (timediff > audit_timeout) {
505 0 : smb_time_audit_log("readdir", timediff);
506 : }
507 :
508 19120 : return result;
509 : }
510 :
511 0 : static void smb_time_audit_seekdir(vfs_handle_struct *handle,
512 : DIR *dirp, long offset)
513 : {
514 : struct timespec ts1,ts2;
515 : double timediff;
516 :
517 0 : clock_gettime_mono(&ts1);
518 0 : SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
519 0 : clock_gettime_mono(&ts2);
520 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
521 :
522 0 : if (timediff > audit_timeout) {
523 0 : smb_time_audit_log("seekdir", timediff);
524 : }
525 :
526 0 : }
527 :
528 15061 : static long smb_time_audit_telldir(vfs_handle_struct *handle,
529 : DIR *dirp)
530 : {
531 : long result;
532 : struct timespec ts1,ts2;
533 : double timediff;
534 :
535 15061 : clock_gettime_mono(&ts1);
536 15061 : result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
537 15061 : clock_gettime_mono(&ts2);
538 15061 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
539 :
540 15061 : if (timediff > audit_timeout) {
541 0 : smb_time_audit_log("telldir", timediff);
542 : }
543 :
544 15061 : return result;
545 : }
546 :
547 0 : static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
548 : DIR *dirp)
549 : {
550 : struct timespec ts1,ts2;
551 : double timediff;
552 :
553 0 : clock_gettime_mono(&ts1);
554 0 : SMB_VFS_NEXT_REWINDDIR(handle, dirp);
555 0 : clock_gettime_mono(&ts2);
556 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
557 :
558 0 : if (timediff > audit_timeout) {
559 0 : smb_time_audit_log("rewinddir", timediff);
560 : }
561 :
562 0 : }
563 :
564 176 : static int smb_time_audit_mkdirat(vfs_handle_struct *handle,
565 : struct files_struct *dirfsp,
566 : const struct smb_filename *smb_fname,
567 : mode_t mode)
568 : {
569 176 : struct smb_filename *full_fname = NULL;
570 : int result;
571 : struct timespec ts1,ts2;
572 : double timediff;
573 :
574 176 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
575 : dirfsp,
576 : smb_fname);
577 176 : if (full_fname == NULL) {
578 0 : errno = ENOMEM;
579 0 : return -1;
580 : }
581 :
582 176 : clock_gettime_mono(&ts1);
583 176 : result = SMB_VFS_NEXT_MKDIRAT(handle,
584 : dirfsp,
585 : smb_fname,
586 : mode);
587 176 : clock_gettime_mono(&ts2);
588 176 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
589 :
590 176 : if (timediff > audit_timeout) {
591 0 : smb_time_audit_log_smb_fname("mkdirat",
592 : timediff,
593 : full_fname);
594 : }
595 :
596 176 : TALLOC_FREE(full_fname);
597 :
598 176 : return result;
599 : }
600 :
601 2302 : static int smb_time_audit_closedir(vfs_handle_struct *handle,
602 : DIR *dirp)
603 : {
604 : int result;
605 : struct timespec ts1,ts2;
606 : double timediff;
607 :
608 2302 : clock_gettime_mono(&ts1);
609 2302 : result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
610 2302 : clock_gettime_mono(&ts2);
611 2302 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
612 :
613 2302 : if (timediff > audit_timeout) {
614 0 : smb_time_audit_log("closedir", timediff);
615 : }
616 :
617 2302 : return result;
618 : }
619 :
620 73127 : static int smb_time_audit_openat(vfs_handle_struct *handle,
621 : const struct files_struct *dirfsp,
622 : const struct smb_filename *smb_fname,
623 : struct files_struct *fsp,
624 : const struct vfs_open_how *how)
625 : {
626 : int result;
627 : struct timespec ts1,ts2;
628 : double timediff;
629 :
630 73127 : clock_gettime_mono(&ts1);
631 73127 : result = SMB_VFS_NEXT_OPENAT(handle,
632 : dirfsp,
633 : smb_fname,
634 : fsp,
635 : how);
636 73127 : clock_gettime_mono(&ts2);
637 73127 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
638 :
639 73127 : if (timediff > audit_timeout) {
640 0 : smb_time_audit_log_fsp("openat", timediff, fsp);
641 : }
642 :
643 73127 : return result;
644 : }
645 :
646 7397 : static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
647 : struct smb_request *req,
648 : struct files_struct *dirfsp,
649 : struct smb_filename *fname,
650 : uint32_t access_mask,
651 : uint32_t share_access,
652 : uint32_t create_disposition,
653 : uint32_t create_options,
654 : uint32_t file_attributes,
655 : uint32_t oplock_request,
656 : const struct smb2_lease *lease,
657 : uint64_t allocation_size,
658 : uint32_t private_flags,
659 : struct security_descriptor *sd,
660 : struct ea_list *ea_list,
661 : files_struct **result_fsp,
662 : int *pinfo,
663 : const struct smb2_create_blobs *in_context_blobs,
664 : struct smb2_create_blobs *out_context_blobs)
665 : {
666 : NTSTATUS result;
667 : struct timespec ts1,ts2;
668 : double timediff;
669 :
670 7397 : clock_gettime_mono(&ts1);
671 7397 : result = SMB_VFS_NEXT_CREATE_FILE(
672 : handle, /* handle */
673 : req, /* req */
674 : dirfsp, /* dirfsp */
675 : fname, /* fname */
676 : access_mask, /* access_mask */
677 : share_access, /* share_access */
678 : create_disposition, /* create_disposition*/
679 : create_options, /* create_options */
680 : file_attributes, /* file_attributes */
681 : oplock_request, /* oplock_request */
682 : lease, /* lease */
683 : allocation_size, /* allocation_size */
684 : private_flags,
685 : sd, /* sd */
686 : ea_list, /* ea_list */
687 : result_fsp, /* result */
688 : pinfo,
689 : in_context_blobs, out_context_blobs); /* create context */
690 7397 : clock_gettime_mono(&ts2);
691 7397 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
692 :
693 7397 : if (timediff > audit_timeout) {
694 : /*
695 : * can't use result_fsp this time, may have
696 : * invalid content causing smbd crash
697 : */
698 0 : smb_time_audit_log_smb_fname("create_file", timediff,
699 : fname);
700 : }
701 :
702 7397 : return result;
703 : }
704 :
705 37787 : static int smb_time_audit_close(vfs_handle_struct *handle, files_struct *fsp)
706 : {
707 : int result;
708 : struct timespec ts1,ts2;
709 : double timediff;
710 :
711 37787 : clock_gettime_mono(&ts1);
712 37787 : result = SMB_VFS_NEXT_CLOSE(handle, fsp);
713 37787 : clock_gettime_mono(&ts2);
714 37787 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
715 :
716 37787 : if (timediff > audit_timeout) {
717 0 : smb_time_audit_log_fsp("close", timediff, fsp);
718 : }
719 :
720 37787 : return result;
721 : }
722 :
723 0 : static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
724 : files_struct *fsp,
725 : void *data, size_t n, off_t offset)
726 : {
727 : ssize_t result;
728 : struct timespec ts1,ts2;
729 : double timediff;
730 :
731 0 : clock_gettime_mono(&ts1);
732 0 : result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
733 0 : clock_gettime_mono(&ts2);
734 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
735 :
736 0 : if (timediff > audit_timeout) {
737 0 : smb_time_audit_log_fsp("pread", timediff, fsp);
738 : }
739 :
740 0 : return result;
741 : }
742 :
743 : struct smb_time_audit_pread_state {
744 : struct files_struct *fsp;
745 : ssize_t ret;
746 : struct vfs_aio_state vfs_aio_state;
747 : };
748 :
749 : static void smb_time_audit_pread_done(struct tevent_req *subreq);
750 :
751 19 : static struct tevent_req *smb_time_audit_pread_send(
752 : struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
753 : struct tevent_context *ev, struct files_struct *fsp,
754 : void *data, size_t n, off_t offset)
755 : {
756 : struct tevent_req *req, *subreq;
757 : struct smb_time_audit_pread_state *state;
758 :
759 19 : req = tevent_req_create(mem_ctx, &state,
760 : struct smb_time_audit_pread_state);
761 19 : if (req == NULL) {
762 0 : return NULL;
763 : }
764 19 : state->fsp = fsp;
765 :
766 19 : subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
767 : n, offset);
768 19 : if (tevent_req_nomem(subreq, req)) {
769 0 : return tevent_req_post(req, ev);
770 : }
771 19 : tevent_req_set_callback(subreq, smb_time_audit_pread_done, req);
772 19 : return req;
773 : }
774 :
775 19 : static void smb_time_audit_pread_done(struct tevent_req *subreq)
776 : {
777 19 : struct tevent_req *req = tevent_req_callback_data(
778 : subreq, struct tevent_req);
779 19 : struct smb_time_audit_pread_state *state = tevent_req_data(
780 : req, struct smb_time_audit_pread_state);
781 :
782 19 : state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
783 19 : TALLOC_FREE(subreq);
784 19 : tevent_req_done(req);
785 19 : }
786 :
787 19 : static ssize_t smb_time_audit_pread_recv(struct tevent_req *req,
788 : struct vfs_aio_state *vfs_aio_state)
789 : {
790 19 : struct smb_time_audit_pread_state *state = tevent_req_data(
791 : req, struct smb_time_audit_pread_state);
792 : double timediff;
793 :
794 19 : timediff = state->vfs_aio_state.duration * 1.0e-9;
795 :
796 19 : if (timediff > audit_timeout) {
797 0 : smb_time_audit_log_fsp("async pread", timediff, state->fsp);
798 : }
799 :
800 19 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
801 0 : return -1;
802 : }
803 19 : *vfs_aio_state = state->vfs_aio_state;
804 19 : return state->ret;
805 : }
806 :
807 20 : static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
808 : files_struct *fsp,
809 : const void *data, size_t n,
810 : off_t offset)
811 : {
812 : ssize_t result;
813 : struct timespec ts1,ts2;
814 : double timediff;
815 :
816 20 : clock_gettime_mono(&ts1);
817 20 : result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
818 20 : clock_gettime_mono(&ts2);
819 20 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
820 :
821 20 : if (timediff > audit_timeout) {
822 0 : smb_time_audit_log_fsp("pwrite", timediff, fsp);
823 : }
824 :
825 20 : return result;
826 : }
827 :
828 : struct smb_time_audit_pwrite_state {
829 : struct files_struct *fsp;
830 : ssize_t ret;
831 : struct vfs_aio_state vfs_aio_state;
832 : };
833 :
834 : static void smb_time_audit_pwrite_done(struct tevent_req *subreq);
835 :
836 49 : static struct tevent_req *smb_time_audit_pwrite_send(
837 : struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
838 : struct tevent_context *ev, struct files_struct *fsp,
839 : const void *data, size_t n, off_t offset)
840 : {
841 : struct tevent_req *req, *subreq;
842 : struct smb_time_audit_pwrite_state *state;
843 :
844 49 : req = tevent_req_create(mem_ctx, &state,
845 : struct smb_time_audit_pwrite_state);
846 49 : if (req == NULL) {
847 0 : return NULL;
848 : }
849 49 : state->fsp = fsp;
850 :
851 49 : subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
852 : n, offset);
853 49 : if (tevent_req_nomem(subreq, req)) {
854 0 : return tevent_req_post(req, ev);
855 : }
856 49 : tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
857 49 : return req;
858 : }
859 :
860 49 : static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
861 : {
862 49 : struct tevent_req *req = tevent_req_callback_data(
863 : subreq, struct tevent_req);
864 49 : struct smb_time_audit_pwrite_state *state = tevent_req_data(
865 : req, struct smb_time_audit_pwrite_state);
866 :
867 49 : state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
868 49 : TALLOC_FREE(subreq);
869 49 : tevent_req_done(req);
870 49 : }
871 :
872 49 : static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req,
873 : struct vfs_aio_state *vfs_aio_state)
874 : {
875 49 : struct smb_time_audit_pwrite_state *state = tevent_req_data(
876 : req, struct smb_time_audit_pwrite_state);
877 : double timediff;
878 :
879 49 : timediff = state->vfs_aio_state.duration * 1.0e-9;
880 :
881 49 : if (timediff > audit_timeout) {
882 0 : smb_time_audit_log_fsp("async pwrite", timediff, state->fsp);
883 : }
884 :
885 49 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
886 0 : return -1;
887 : }
888 49 : *vfs_aio_state = state->vfs_aio_state;
889 49 : return state->ret;
890 : }
891 :
892 0 : static off_t smb_time_audit_lseek(vfs_handle_struct *handle,
893 : files_struct *fsp,
894 : off_t offset, int whence)
895 : {
896 : off_t result;
897 : struct timespec ts1,ts2;
898 : double timediff;
899 :
900 0 : clock_gettime_mono(&ts1);
901 0 : result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
902 0 : clock_gettime_mono(&ts2);
903 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
904 :
905 0 : if (timediff > audit_timeout) {
906 0 : smb_time_audit_log_fsp("lseek", timediff, fsp);
907 : }
908 :
909 0 : return result;
910 : }
911 :
912 0 : static ssize_t smb_time_audit_sendfile(vfs_handle_struct *handle, int tofd,
913 : files_struct *fromfsp,
914 : const DATA_BLOB *hdr, off_t offset,
915 : size_t n)
916 : {
917 : ssize_t result;
918 : struct timespec ts1,ts2;
919 : double timediff;
920 :
921 0 : clock_gettime_mono(&ts1);
922 0 : result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
923 0 : clock_gettime_mono(&ts2);
924 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
925 :
926 0 : if (timediff > audit_timeout) {
927 0 : smb_time_audit_log_fsp("sendfile", timediff, fromfsp);
928 : }
929 :
930 0 : return result;
931 : }
932 :
933 0 : static ssize_t smb_time_audit_recvfile(vfs_handle_struct *handle, int fromfd,
934 : files_struct *tofsp,
935 : off_t offset,
936 : size_t n)
937 : {
938 : ssize_t result;
939 : struct timespec ts1,ts2;
940 : double timediff;
941 :
942 0 : clock_gettime_mono(&ts1);
943 0 : result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
944 0 : clock_gettime_mono(&ts2);
945 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
946 :
947 0 : if (timediff > audit_timeout) {
948 0 : smb_time_audit_log_fsp("recvfile", timediff, tofsp);
949 : }
950 :
951 0 : return result;
952 : }
953 :
954 20 : static int smb_time_audit_renameat(vfs_handle_struct *handle,
955 : files_struct *srcfsp,
956 : const struct smb_filename *oldname,
957 : files_struct *dstfsp,
958 : const struct smb_filename *newname)
959 : {
960 : int result;
961 : struct timespec ts1,ts2;
962 : double timediff;
963 20 : struct smb_filename *new_full_fname = NULL;
964 :
965 20 : new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
966 : dstfsp,
967 : newname);
968 20 : if (new_full_fname == NULL) {
969 0 : errno = ENOMEM;
970 0 : return -1;
971 : }
972 20 : clock_gettime_mono(&ts1);
973 20 : result = SMB_VFS_NEXT_RENAMEAT(handle,
974 : srcfsp,
975 : oldname,
976 : dstfsp,
977 : newname);
978 20 : clock_gettime_mono(&ts2);
979 20 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
980 :
981 20 : if (timediff > audit_timeout) {
982 0 : smb_time_audit_log_smb_fname("renameat",
983 : timediff,
984 : new_full_fname);
985 : }
986 :
987 20 : TALLOC_FREE(new_full_fname);
988 20 : return result;
989 : }
990 :
991 : struct smb_time_audit_fsync_state {
992 : struct files_struct *fsp;
993 : int ret;
994 : struct vfs_aio_state vfs_aio_state;
995 : };
996 :
997 : static void smb_time_audit_fsync_done(struct tevent_req *subreq);
998 :
999 0 : static struct tevent_req *smb_time_audit_fsync_send(
1000 : struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1001 : struct tevent_context *ev, struct files_struct *fsp)
1002 : {
1003 : struct tevent_req *req, *subreq;
1004 : struct smb_time_audit_fsync_state *state;
1005 :
1006 0 : req = tevent_req_create(mem_ctx, &state,
1007 : struct smb_time_audit_fsync_state);
1008 0 : if (req == NULL) {
1009 0 : return NULL;
1010 : }
1011 0 : state->fsp = fsp;
1012 :
1013 0 : subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1014 0 : if (tevent_req_nomem(subreq, req)) {
1015 0 : return tevent_req_post(req, ev);
1016 : }
1017 0 : tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
1018 0 : return req;
1019 : }
1020 :
1021 0 : static void smb_time_audit_fsync_done(struct tevent_req *subreq)
1022 : {
1023 0 : struct tevent_req *req = tevent_req_callback_data(
1024 : subreq, struct tevent_req);
1025 0 : struct smb_time_audit_fsync_state *state = tevent_req_data(
1026 : req, struct smb_time_audit_fsync_state);
1027 :
1028 0 : state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1029 0 : TALLOC_FREE(subreq);
1030 0 : tevent_req_done(req);
1031 0 : }
1032 :
1033 0 : static int smb_time_audit_fsync_recv(struct tevent_req *req,
1034 : struct vfs_aio_state *vfs_aio_state)
1035 : {
1036 0 : struct smb_time_audit_fsync_state *state = tevent_req_data(
1037 : req, struct smb_time_audit_fsync_state);
1038 : double timediff;
1039 :
1040 0 : timediff = state->vfs_aio_state.duration * 1.0e-9;
1041 :
1042 0 : if (timediff > audit_timeout) {
1043 0 : smb_time_audit_log_fsp("async fsync", timediff, state->fsp);
1044 : }
1045 :
1046 0 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1047 0 : return -1;
1048 : }
1049 0 : *vfs_aio_state = state->vfs_aio_state;
1050 0 : return state->ret;
1051 : }
1052 :
1053 48668 : static int smb_time_audit_stat(vfs_handle_struct *handle,
1054 : struct smb_filename *fname)
1055 : {
1056 : int result;
1057 : struct timespec ts1,ts2;
1058 : double timediff;
1059 :
1060 48668 : clock_gettime_mono(&ts1);
1061 48668 : result = SMB_VFS_NEXT_STAT(handle, fname);
1062 48668 : clock_gettime_mono(&ts2);
1063 48668 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1064 :
1065 48668 : if (timediff > audit_timeout) {
1066 0 : smb_time_audit_log_smb_fname("stat", timediff, fname);
1067 : }
1068 :
1069 48668 : return result;
1070 : }
1071 :
1072 205783 : static int smb_time_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1073 : SMB_STRUCT_STAT *sbuf)
1074 : {
1075 : int result;
1076 : struct timespec ts1,ts2;
1077 : double timediff;
1078 :
1079 205783 : clock_gettime_mono(&ts1);
1080 205783 : result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1081 205783 : clock_gettime_mono(&ts2);
1082 205783 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1083 :
1084 205783 : if (timediff > audit_timeout) {
1085 0 : smb_time_audit_log_fsp("fstat", timediff, fsp);
1086 : }
1087 :
1088 205783 : return result;
1089 : }
1090 :
1091 103 : static int smb_time_audit_lstat(vfs_handle_struct *handle,
1092 : struct smb_filename *path)
1093 : {
1094 : int result;
1095 : struct timespec ts1,ts2;
1096 : double timediff;
1097 :
1098 103 : clock_gettime_mono(&ts1);
1099 103 : result = SMB_VFS_NEXT_LSTAT(handle, path);
1100 103 : clock_gettime_mono(&ts2);
1101 103 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1102 :
1103 103 : if (timediff > audit_timeout) {
1104 0 : smb_time_audit_log_smb_fname("lstat", timediff, path);
1105 : }
1106 :
1107 103 : return result;
1108 : }
1109 :
1110 120 : static int smb_time_audit_fstatat(
1111 : struct vfs_handle_struct *handle,
1112 : const struct files_struct *dirfsp,
1113 : const struct smb_filename *smb_fname,
1114 : SMB_STRUCT_STAT *sbuf,
1115 : int flags)
1116 : {
1117 : int result;
1118 : struct timespec ts1,ts2;
1119 : double timediff;
1120 :
1121 120 : clock_gettime_mono(&ts1);
1122 120 : result = SMB_VFS_NEXT_FSTATAT(handle, dirfsp, smb_fname, sbuf, flags);
1123 120 : clock_gettime_mono(&ts2);
1124 120 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1125 :
1126 120 : if (timediff > audit_timeout) {
1127 0 : smb_time_audit_log_smb_fname("fstatat", timediff, smb_fname);
1128 : }
1129 :
1130 120 : return result;
1131 : }
1132 :
1133 13487 : static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
1134 : files_struct *fsp,
1135 : const SMB_STRUCT_STAT *sbuf)
1136 : {
1137 : uint64_t result;
1138 : struct timespec ts1,ts2;
1139 : double timediff;
1140 :
1141 13487 : clock_gettime_mono(&ts1);
1142 13487 : result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1143 13487 : clock_gettime_mono(&ts2);
1144 13487 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1145 :
1146 13487 : if (timediff > audit_timeout) {
1147 0 : smb_time_audit_log_fsp("get_alloc_size", timediff, fsp);
1148 : }
1149 :
1150 13487 : return result;
1151 : }
1152 :
1153 333 : static int smb_time_audit_unlinkat(vfs_handle_struct *handle,
1154 : struct files_struct *dirfsp,
1155 : const struct smb_filename *path,
1156 : int flags)
1157 : {
1158 333 : struct smb_filename *full_fname = NULL;
1159 : int result;
1160 : struct timespec ts1,ts2;
1161 : double timediff;
1162 :
1163 333 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1164 : dirfsp,
1165 : path);
1166 333 : if (full_fname == NULL) {
1167 0 : return -1;
1168 : }
1169 :
1170 333 : clock_gettime_mono(&ts1);
1171 333 : result = SMB_VFS_NEXT_UNLINKAT(handle,
1172 : dirfsp,
1173 : path,
1174 : flags);
1175 333 : clock_gettime_mono(&ts2);
1176 333 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1177 :
1178 333 : if (timediff > audit_timeout) {
1179 0 : smb_time_audit_log_smb_fname("unlinkat", timediff, full_fname);
1180 : }
1181 :
1182 333 : TALLOC_FREE(full_fname);
1183 333 : return result;
1184 : }
1185 :
1186 0 : static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1187 : mode_t mode)
1188 : {
1189 : int result;
1190 : struct timespec ts1,ts2;
1191 : double timediff;
1192 :
1193 0 : clock_gettime_mono(&ts1);
1194 0 : result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1195 0 : clock_gettime_mono(&ts2);
1196 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1197 :
1198 0 : if (timediff > audit_timeout) {
1199 0 : smb_time_audit_log_fsp("fchmod", timediff, fsp);
1200 : }
1201 :
1202 0 : return result;
1203 : }
1204 :
1205 0 : static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1206 : uid_t uid, gid_t gid)
1207 : {
1208 : int result;
1209 : struct timespec ts1,ts2;
1210 : double timediff;
1211 :
1212 0 : clock_gettime_mono(&ts1);
1213 0 : result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1214 0 : clock_gettime_mono(&ts2);
1215 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1216 :
1217 0 : if (timediff > audit_timeout) {
1218 0 : smb_time_audit_log_fsp("fchown", timediff, fsp);
1219 : }
1220 :
1221 0 : return result;
1222 : }
1223 :
1224 0 : static int smb_time_audit_lchown(vfs_handle_struct *handle,
1225 : const struct smb_filename *smb_fname,
1226 : uid_t uid,
1227 : gid_t gid)
1228 : {
1229 : int result;
1230 : struct timespec ts1,ts2;
1231 : double timediff;
1232 :
1233 0 : clock_gettime_mono(&ts1);
1234 0 : result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1235 0 : clock_gettime_mono(&ts2);
1236 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1237 :
1238 0 : if (timediff > audit_timeout) {
1239 0 : smb_time_audit_log_fname("lchown",
1240 : timediff,
1241 0 : smb_fname->base_name);
1242 : }
1243 :
1244 0 : return result;
1245 : }
1246 :
1247 17538 : static int smb_time_audit_chdir(vfs_handle_struct *handle,
1248 : const struct smb_filename *smb_fname)
1249 : {
1250 : int result;
1251 : struct timespec ts1,ts2;
1252 : double timediff;
1253 :
1254 17538 : clock_gettime_mono(&ts1);
1255 17538 : result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1256 17538 : clock_gettime_mono(&ts2);
1257 17538 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1258 :
1259 17538 : if (timediff > audit_timeout) {
1260 0 : smb_time_audit_log_fname("chdir",
1261 : timediff,
1262 0 : smb_fname->base_name);
1263 : }
1264 :
1265 17538 : return result;
1266 : }
1267 :
1268 3267 : static struct smb_filename *smb_time_audit_getwd(vfs_handle_struct *handle,
1269 : TALLOC_CTX *mem_ctx)
1270 : {
1271 : struct smb_filename *result;
1272 : struct timespec ts1,ts2;
1273 : double timediff;
1274 :
1275 3267 : clock_gettime_mono(&ts1);
1276 3267 : result = SMB_VFS_NEXT_GETWD(handle, mem_ctx);
1277 3267 : clock_gettime_mono(&ts2);
1278 3267 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1279 :
1280 3267 : if (timediff > audit_timeout) {
1281 0 : smb_time_audit_log("getwd", timediff);
1282 : }
1283 :
1284 3267 : return result;
1285 : }
1286 :
1287 113 : static int smb_time_audit_fntimes(vfs_handle_struct *handle,
1288 : files_struct *fsp,
1289 : struct smb_file_time *ft)
1290 : {
1291 : int result;
1292 : struct timespec ts1,ts2;
1293 : double timediff;
1294 :
1295 113 : clock_gettime_mono(&ts1);
1296 113 : result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1297 113 : clock_gettime_mono(&ts2);
1298 113 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
1299 :
1300 113 : if (timediff > audit_timeout) {
1301 0 : smb_time_audit_log_fsp("fntimes", timediff, fsp);
1302 : }
1303 :
1304 113 : return result;
1305 : }
1306 :
1307 14 : static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
1308 : files_struct *fsp,
1309 : off_t len)
1310 : {
1311 : int result;
1312 : struct timespec ts1,ts2;
1313 : double timediff;
1314 :
1315 14 : clock_gettime_mono(&ts1);
1316 14 : result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1317 14 : clock_gettime_mono(&ts2);
1318 14 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1319 :
1320 14 : if (timediff > audit_timeout) {
1321 0 : smb_time_audit_log_fsp("ftruncate", timediff, fsp);
1322 : }
1323 :
1324 14 : return result;
1325 : }
1326 :
1327 0 : static int smb_time_audit_fallocate(vfs_handle_struct *handle,
1328 : files_struct *fsp,
1329 : uint32_t mode,
1330 : off_t offset,
1331 : off_t len)
1332 : {
1333 : int result;
1334 0 : int saved_errno = 0;
1335 : struct timespec ts1,ts2;
1336 : double timediff;
1337 :
1338 0 : clock_gettime_mono(&ts1);
1339 0 : result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1340 0 : if (result == -1) {
1341 0 : saved_errno = errno;
1342 : }
1343 0 : clock_gettime_mono(&ts2);
1344 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1345 :
1346 0 : if (timediff > audit_timeout) {
1347 0 : smb_time_audit_log_fsp("fallocate", timediff, fsp);
1348 : }
1349 0 : if (result == -1) {
1350 0 : errno = saved_errno;
1351 : }
1352 0 : return result;
1353 : }
1354 :
1355 10 : static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1356 : int op, off_t offset, off_t count,
1357 : int type)
1358 : {
1359 : bool result;
1360 : struct timespec ts1,ts2;
1361 : double timediff;
1362 :
1363 10 : clock_gettime_mono(&ts1);
1364 10 : result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1365 10 : clock_gettime_mono(&ts2);
1366 10 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1367 :
1368 10 : if (timediff > audit_timeout) {
1369 0 : smb_time_audit_log_fsp("lock", timediff, fsp);
1370 : }
1371 :
1372 10 : return result;
1373 : }
1374 :
1375 0 : static int smb_time_audit_filesystem_sharemode(struct vfs_handle_struct *handle,
1376 : struct files_struct *fsp,
1377 : uint32_t share_access,
1378 : uint32_t access_mask)
1379 : {
1380 : int result;
1381 : struct timespec ts1,ts2;
1382 : double timediff;
1383 :
1384 0 : clock_gettime_mono(&ts1);
1385 0 : result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1386 : fsp,
1387 : share_access,
1388 : access_mask);
1389 0 : clock_gettime_mono(&ts2);
1390 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1391 :
1392 0 : if (timediff > audit_timeout) {
1393 0 : smb_time_audit_log_fsp("filesystem_sharemode", timediff, fsp);
1394 : }
1395 :
1396 0 : return result;
1397 : }
1398 :
1399 620 : static int smb_time_audit_fcntl(struct vfs_handle_struct *handle,
1400 : struct files_struct *fsp,
1401 : int cmd, va_list cmd_arg)
1402 : {
1403 : void *arg;
1404 : va_list dup_cmd_arg;
1405 : int result;
1406 : struct timespec ts1,ts2;
1407 : double timediff;
1408 :
1409 620 : va_copy(dup_cmd_arg, cmd_arg);
1410 620 : arg = va_arg(dup_cmd_arg, void *);
1411 620 : clock_gettime_mono(&ts1);
1412 620 : result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1413 620 : clock_gettime_mono(&ts2);
1414 620 : va_end(dup_cmd_arg);
1415 :
1416 620 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1417 620 : if (timediff > audit_timeout) {
1418 0 : smb_time_audit_log_fsp("fcntl", timediff, fsp);
1419 : }
1420 :
1421 620 : return result;
1422 : }
1423 :
1424 0 : static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
1425 : files_struct *fsp,
1426 : int leasetype)
1427 : {
1428 : int result;
1429 : struct timespec ts1,ts2;
1430 : double timediff;
1431 :
1432 0 : clock_gettime_mono(&ts1);
1433 0 : result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1434 0 : clock_gettime_mono(&ts2);
1435 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1436 :
1437 0 : if (timediff > audit_timeout) {
1438 0 : smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
1439 : }
1440 :
1441 0 : return result;
1442 : }
1443 :
1444 88 : static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1445 : files_struct *fsp,
1446 : off_t *poffset, off_t *pcount,
1447 : int *ptype, pid_t *ppid)
1448 : {
1449 : bool result;
1450 : struct timespec ts1,ts2;
1451 : double timediff;
1452 :
1453 88 : clock_gettime_mono(&ts1);
1454 88 : result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1455 : ppid);
1456 88 : clock_gettime_mono(&ts2);
1457 88 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1458 :
1459 88 : if (timediff > audit_timeout) {
1460 0 : smb_time_audit_log_fsp("getlock", timediff, fsp);
1461 : }
1462 :
1463 88 : return result;
1464 : }
1465 :
1466 0 : static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
1467 : const struct smb_filename *link_contents,
1468 : struct files_struct *dirfsp,
1469 : const struct smb_filename *new_smb_fname)
1470 : {
1471 0 : struct smb_filename *full_fname = NULL;
1472 : int result;
1473 : struct timespec ts1,ts2;
1474 : double timediff;
1475 :
1476 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1477 : dirfsp,
1478 : new_smb_fname);
1479 0 : if (full_fname == NULL) {
1480 0 : errno = ENOMEM;
1481 0 : return -1;
1482 : }
1483 :
1484 0 : clock_gettime_mono(&ts1);
1485 0 : result = SMB_VFS_NEXT_SYMLINKAT(handle,
1486 : link_contents,
1487 : dirfsp,
1488 : new_smb_fname);
1489 0 : clock_gettime_mono(&ts2);
1490 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1491 :
1492 0 : if (timediff > audit_timeout) {
1493 0 : smb_time_audit_log_fname("symlinkat", timediff,
1494 0 : full_fname->base_name);
1495 : }
1496 :
1497 0 : TALLOC_FREE(full_fname);
1498 0 : return result;
1499 : }
1500 :
1501 14786 : static int smb_time_audit_readlinkat(vfs_handle_struct *handle,
1502 : const struct files_struct *dirfsp,
1503 : const struct smb_filename *smb_fname,
1504 : char *buf,
1505 : size_t bufsiz)
1506 : {
1507 14786 : struct smb_filename *full_fname = NULL;
1508 : int result;
1509 : struct timespec ts1,ts2;
1510 : double timediff;
1511 :
1512 14786 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1513 : dirfsp,
1514 : smb_fname);
1515 14786 : if (full_fname == NULL) {
1516 0 : errno = ENOMEM;
1517 0 : return -1;
1518 : }
1519 :
1520 14786 : clock_gettime_mono(&ts1);
1521 14786 : result = SMB_VFS_NEXT_READLINKAT(handle,
1522 : dirfsp,
1523 : smb_fname,
1524 : buf,
1525 : bufsiz);
1526 14786 : clock_gettime_mono(&ts2);
1527 14786 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1528 :
1529 14786 : if (timediff > audit_timeout) {
1530 0 : smb_time_audit_log_fname("readlinkat", timediff,
1531 0 : full_fname->base_name);
1532 : }
1533 :
1534 14786 : TALLOC_FREE(full_fname);
1535 14786 : return result;
1536 : }
1537 :
1538 4 : static int smb_time_audit_linkat(vfs_handle_struct *handle,
1539 : files_struct *srcfsp,
1540 : const struct smb_filename *old_smb_fname,
1541 : files_struct *dstfsp,
1542 : const struct smb_filename *new_smb_fname,
1543 : int flags)
1544 : {
1545 4 : struct smb_filename *new_full_fname = NULL;
1546 : int result;
1547 : struct timespec ts1,ts2;
1548 : double timediff;
1549 :
1550 4 : new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1551 : dstfsp,
1552 : new_smb_fname);
1553 4 : if (new_full_fname == NULL) {
1554 0 : errno = ENOMEM;
1555 0 : return -1;
1556 : }
1557 :
1558 4 : clock_gettime_mono(&ts1);
1559 4 : result = SMB_VFS_NEXT_LINKAT(handle,
1560 : srcfsp,
1561 : old_smb_fname,
1562 : dstfsp,
1563 : new_smb_fname,
1564 : flags);
1565 4 : clock_gettime_mono(&ts2);
1566 4 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1567 :
1568 4 : if (timediff > audit_timeout) {
1569 0 : smb_time_audit_log_fname("linkat", timediff,
1570 0 : new_full_fname->base_name);
1571 : }
1572 :
1573 4 : TALLOC_FREE(new_full_fname);
1574 4 : return result;
1575 : }
1576 :
1577 0 : static int smb_time_audit_mknodat(vfs_handle_struct *handle,
1578 : files_struct *dirfsp,
1579 : const struct smb_filename *smb_fname,
1580 : mode_t mode,
1581 : SMB_DEV_T dev)
1582 : {
1583 0 : struct smb_filename *full_fname = NULL;
1584 : int result;
1585 : struct timespec ts1,ts2;
1586 : double timediff;
1587 :
1588 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1589 : dirfsp,
1590 : smb_fname);
1591 0 : if (full_fname == NULL) {
1592 0 : errno = ENOMEM;
1593 0 : return -1;
1594 : }
1595 :
1596 0 : clock_gettime_mono(&ts1);
1597 0 : result = SMB_VFS_NEXT_MKNODAT(handle,
1598 : dirfsp,
1599 : smb_fname,
1600 : mode,
1601 : dev);
1602 0 : clock_gettime_mono(&ts2);
1603 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1604 :
1605 0 : if (timediff > audit_timeout) {
1606 0 : smb_time_audit_log_smb_fname("mknodat", timediff, full_fname);
1607 : }
1608 :
1609 0 : TALLOC_FREE(full_fname);
1610 0 : return result;
1611 : }
1612 :
1613 39081 : static struct smb_filename *smb_time_audit_realpath(vfs_handle_struct *handle,
1614 : TALLOC_CTX *ctx,
1615 : const struct smb_filename *smb_fname)
1616 : {
1617 : struct smb_filename *result_fname;
1618 : struct timespec ts1,ts2;
1619 : double timediff;
1620 :
1621 39081 : clock_gettime_mono(&ts1);
1622 39081 : result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1623 39081 : clock_gettime_mono(&ts2);
1624 39081 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1625 :
1626 39081 : if (timediff > audit_timeout) {
1627 0 : smb_time_audit_log_fname("realpath", timediff,
1628 0 : smb_fname->base_name);
1629 : }
1630 :
1631 39081 : return result_fname;
1632 : }
1633 :
1634 0 : static int smb_time_audit_fchflags(vfs_handle_struct *handle,
1635 : struct files_struct *fsp,
1636 : unsigned int flags)
1637 : {
1638 : int result;
1639 : struct timespec ts1,ts2;
1640 : double timediff;
1641 :
1642 0 : clock_gettime_mono(&ts1);
1643 0 : result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
1644 0 : clock_gettime_mono(&ts2);
1645 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1646 :
1647 0 : if (timediff > audit_timeout) {
1648 0 : smb_time_audit_log_smb_fname("chflags",
1649 : timediff,
1650 0 : fsp->fsp_name);
1651 : }
1652 :
1653 0 : return result;
1654 : }
1655 :
1656 235151 : static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1657 : const SMB_STRUCT_STAT *sbuf)
1658 : {
1659 : struct file_id id_zero;
1660 : struct file_id result;
1661 : struct timespec ts1,ts2;
1662 : double timediff;
1663 :
1664 235151 : ZERO_STRUCT(id_zero);
1665 :
1666 235151 : clock_gettime_mono(&ts1);
1667 235151 : result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1668 235151 : clock_gettime_mono(&ts2);
1669 235151 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1670 :
1671 235151 : if (timediff > audit_timeout) {
1672 0 : smb_time_audit_log("file_id_create", timediff);
1673 : }
1674 :
1675 235151 : return result;
1676 : }
1677 :
1678 5775 : static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct *handle,
1679 : const SMB_STRUCT_STAT *sbuf)
1680 : {
1681 : uint64_t result;
1682 : struct timespec ts1,ts2;
1683 : double timediff;
1684 :
1685 5775 : clock_gettime_mono(&ts1);
1686 5775 : result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1687 5775 : clock_gettime_mono(&ts2);
1688 5775 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1689 :
1690 5775 : if (timediff > audit_timeout) {
1691 0 : smb_time_audit_log("fs_file_id", timediff);
1692 : }
1693 :
1694 5775 : return result;
1695 : }
1696 :
1697 635 : static NTSTATUS smb_time_audit_fstreaminfo(vfs_handle_struct *handle,
1698 : struct files_struct *fsp,
1699 : TALLOC_CTX *mem_ctx,
1700 : unsigned int *pnum_streams,
1701 : struct stream_struct **pstreams)
1702 : {
1703 : NTSTATUS result;
1704 : struct timespec ts1,ts2;
1705 : double timediff;
1706 :
1707 635 : clock_gettime_mono(&ts1);
1708 635 : result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
1709 : pnum_streams, pstreams);
1710 635 : clock_gettime_mono(&ts2);
1711 635 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1712 :
1713 635 : if (timediff > audit_timeout) {
1714 0 : smb_time_audit_log_fsp("fstreaminfo", timediff, fsp);
1715 : }
1716 :
1717 635 : return result;
1718 : }
1719 :
1720 1438 : static NTSTATUS smb_time_audit_get_real_filename_at(
1721 : struct vfs_handle_struct *handle,
1722 : struct files_struct *dirfsp,
1723 : const char *name,
1724 : TALLOC_CTX *mem_ctx,
1725 : char **found_name)
1726 : {
1727 : NTSTATUS result;
1728 : struct timespec ts1,ts2;
1729 : double timediff;
1730 :
1731 1438 : clock_gettime_mono(&ts1);
1732 1438 : result = SMB_VFS_NEXT_GET_REAL_FILENAME_AT(
1733 : handle, dirfsp, name, mem_ctx, found_name);
1734 1438 : clock_gettime_mono(&ts2);
1735 1438 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1736 :
1737 1438 : if (timediff > audit_timeout) {
1738 0 : smb_time_audit_log_fname("get_real_filename_at",
1739 : timediff,
1740 : fsp_str_dbg(dirfsp));
1741 : }
1742 :
1743 1438 : return result;
1744 : }
1745 :
1746 49711 : static const char *smb_time_audit_connectpath(
1747 : vfs_handle_struct *handle,
1748 : const struct files_struct *dirfsp,
1749 : const struct smb_filename *smb_fname)
1750 : {
1751 : const char *result;
1752 : struct timespec ts1,ts2;
1753 : double timediff;
1754 :
1755 49711 : clock_gettime_mono(&ts1);
1756 49711 : result = SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname);
1757 49711 : clock_gettime_mono(&ts2);
1758 49711 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1759 :
1760 49711 : if (timediff > audit_timeout) {
1761 0 : smb_time_audit_log_fname("connectpath", timediff,
1762 0 : smb_fname->base_name);
1763 : }
1764 :
1765 49711 : return result;
1766 : }
1767 :
1768 5 : static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1769 : struct byte_range_lock *br_lck,
1770 : struct lock_struct *plock)
1771 : {
1772 : NTSTATUS result;
1773 : struct timespec ts1,ts2;
1774 : double timediff;
1775 :
1776 5 : clock_gettime_mono(&ts1);
1777 5 : result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1778 5 : clock_gettime_mono(&ts2);
1779 5 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1780 :
1781 5 : if (timediff > audit_timeout) {
1782 0 : smb_time_audit_log_fsp("brl_lock_windows", timediff,
1783 0 : brl_fsp(br_lck));
1784 : }
1785 :
1786 5 : return result;
1787 : }
1788 :
1789 9 : static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1790 : struct byte_range_lock *br_lck,
1791 : const struct lock_struct *plock)
1792 : {
1793 : bool result;
1794 : struct timespec ts1,ts2;
1795 : double timediff;
1796 :
1797 9 : clock_gettime_mono(&ts1);
1798 9 : result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1799 9 : clock_gettime_mono(&ts2);
1800 9 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1801 :
1802 9 : if (timediff > audit_timeout) {
1803 0 : smb_time_audit_log_fsp("brl_unlock_windows", timediff,
1804 0 : brl_fsp(br_lck));
1805 : }
1806 :
1807 9 : return result;
1808 : }
1809 :
1810 88 : static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct *handle,
1811 : struct files_struct *fsp,
1812 : struct lock_struct *plock)
1813 : {
1814 : bool result;
1815 : struct timespec ts1,ts2;
1816 : double timediff;
1817 :
1818 88 : clock_gettime_mono(&ts1);
1819 88 : result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1820 88 : clock_gettime_mono(&ts2);
1821 88 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1822 :
1823 88 : if (timediff > audit_timeout) {
1824 0 : smb_time_audit_log_fsp("strict_lock_check", timediff, fsp);
1825 : }
1826 :
1827 88 : return result;
1828 : }
1829 :
1830 17775 : static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1831 : const char *name,
1832 : enum vfs_translate_direction direction,
1833 : TALLOC_CTX *mem_ctx,
1834 : char **mapped_name)
1835 : {
1836 : NTSTATUS result;
1837 : struct timespec ts1,ts2;
1838 : double timediff;
1839 :
1840 17775 : clock_gettime_mono(&ts1);
1841 17775 : result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1842 : mapped_name);
1843 17775 : clock_gettime_mono(&ts2);
1844 17775 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1845 :
1846 17775 : if (timediff > audit_timeout) {
1847 0 : smb_time_audit_log_fname("translate_name", timediff, name);
1848 : }
1849 :
1850 17775 : return result;
1851 : }
1852 :
1853 43211 : static NTSTATUS smb_time_audit_parent_pathname(struct vfs_handle_struct *handle,
1854 : TALLOC_CTX *mem_ctx,
1855 : const struct smb_filename *smb_fname_in,
1856 : struct smb_filename **parent_dir_out,
1857 : struct smb_filename **atname_out)
1858 : {
1859 : NTSTATUS result;
1860 : struct timespec ts1,ts2;
1861 : double timediff;
1862 :
1863 43211 : clock_gettime_mono(&ts1);
1864 43211 : result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
1865 : mem_ctx,
1866 : smb_fname_in,
1867 : parent_dir_out,
1868 : atname_out);
1869 43211 : clock_gettime_mono(&ts2);
1870 43211 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1871 :
1872 43211 : if (timediff > audit_timeout) {
1873 0 : smb_time_audit_log_fname("parent_pathname",
1874 : timediff,
1875 0 : smb_fname_in->base_name);
1876 : }
1877 :
1878 43211 : return result;
1879 : }
1880 :
1881 48 : static NTSTATUS smb_time_audit_fsctl(struct vfs_handle_struct *handle,
1882 : struct files_struct *fsp,
1883 : TALLOC_CTX *ctx,
1884 : uint32_t function,
1885 : uint16_t req_flags,
1886 : const uint8_t *_in_data,
1887 : uint32_t in_len,
1888 : uint8_t **_out_data,
1889 : uint32_t max_out_len,
1890 : uint32_t *out_len)
1891 : {
1892 : NTSTATUS result;
1893 : struct timespec ts1,ts2;
1894 : double timediff;
1895 :
1896 48 : clock_gettime_mono(&ts1);
1897 48 : result = SMB_VFS_NEXT_FSCTL(handle,
1898 : fsp,
1899 : ctx,
1900 : function,
1901 : req_flags,
1902 : _in_data,
1903 : in_len,
1904 : _out_data,
1905 : max_out_len,
1906 : out_len);
1907 48 : clock_gettime_mono(&ts2);
1908 48 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1909 :
1910 48 : if (timediff > audit_timeout) {
1911 0 : smb_time_audit_log_fsp("fsctl", timediff, fsp);
1912 : }
1913 :
1914 48 : return result;
1915 : }
1916 :
1917 : struct smb_time_audit_get_dos_attributes_state {
1918 : struct vfs_aio_state aio_state;
1919 : files_struct *dir_fsp;
1920 : const struct smb_filename *smb_fname;
1921 : uint32_t dosmode;
1922 : };
1923 :
1924 : static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq);
1925 :
1926 0 : static struct tevent_req *smb_time_audit_get_dos_attributes_send(
1927 : TALLOC_CTX *mem_ctx,
1928 : struct tevent_context *ev,
1929 : struct vfs_handle_struct *handle,
1930 : files_struct *dir_fsp,
1931 : struct smb_filename *smb_fname)
1932 : {
1933 0 : struct tevent_req *req = NULL;
1934 0 : struct smb_time_audit_get_dos_attributes_state *state = NULL;
1935 0 : struct tevent_req *subreq = NULL;
1936 :
1937 0 : req = tevent_req_create(mem_ctx, &state,
1938 : struct smb_time_audit_get_dos_attributes_state);
1939 0 : if (req == NULL) {
1940 0 : return NULL;
1941 : }
1942 0 : *state = (struct smb_time_audit_get_dos_attributes_state) {
1943 : .dir_fsp = dir_fsp,
1944 : .smb_fname = smb_fname,
1945 : };
1946 :
1947 0 : subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
1948 : ev,
1949 : handle,
1950 : dir_fsp,
1951 : smb_fname);
1952 0 : if (tevent_req_nomem(subreq, req)) {
1953 0 : return tevent_req_post(req, ev);
1954 : }
1955 0 : tevent_req_set_callback(subreq,
1956 : smb_time_audit_get_dos_attributes_done,
1957 : req);
1958 :
1959 0 : return req;
1960 : }
1961 :
1962 0 : static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq)
1963 : {
1964 : struct tevent_req *req =
1965 0 : tevent_req_callback_data(subreq,
1966 : struct tevent_req);
1967 : struct smb_time_audit_get_dos_attributes_state *state =
1968 0 : tevent_req_data(req,
1969 : struct smb_time_audit_get_dos_attributes_state);
1970 : NTSTATUS status;
1971 :
1972 0 : status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
1973 : &state->aio_state,
1974 : &state->dosmode);
1975 0 : TALLOC_FREE(subreq);
1976 0 : if (tevent_req_nterror(req, status)) {
1977 0 : return;
1978 : }
1979 :
1980 0 : tevent_req_done(req);
1981 0 : return;
1982 : }
1983 :
1984 0 : static NTSTATUS smb_time_audit_get_dos_attributes_recv(struct tevent_req *req,
1985 : struct vfs_aio_state *aio_state,
1986 : uint32_t *dosmode)
1987 : {
1988 : struct smb_time_audit_get_dos_attributes_state *state =
1989 0 : tevent_req_data(req,
1990 : struct smb_time_audit_get_dos_attributes_state);
1991 : NTSTATUS status;
1992 : double timediff;
1993 :
1994 0 : timediff = state->aio_state.duration * 1.0e-9;
1995 :
1996 0 : if (timediff > audit_timeout) {
1997 0 : smb_time_audit_log_at("async get_dos_attributes",
1998 : timediff,
1999 0 : state->dir_fsp,
2000 : state->smb_fname);
2001 : }
2002 :
2003 0 : if (tevent_req_is_nterror(req, &status)) {
2004 0 : tevent_req_received(req);
2005 0 : return status;
2006 : }
2007 :
2008 0 : *aio_state = state->aio_state;
2009 0 : *dosmode = state->dosmode;
2010 0 : tevent_req_received(req);
2011 0 : return NT_STATUS_OK;
2012 : }
2013 :
2014 18473 : static NTSTATUS smb_time_fget_dos_attributes(struct vfs_handle_struct *handle,
2015 : struct files_struct *fsp,
2016 : uint32_t *dosmode)
2017 : {
2018 : NTSTATUS result;
2019 : struct timespec ts1,ts2;
2020 : double timediff;
2021 :
2022 18473 : clock_gettime_mono(&ts1);
2023 18473 : result = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2024 : fsp,
2025 : dosmode);
2026 18473 : clock_gettime_mono(&ts2);
2027 18473 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2028 :
2029 18473 : if (timediff > audit_timeout) {
2030 0 : smb_time_audit_log_fsp("fget_dos_attributes", timediff, fsp);
2031 : }
2032 :
2033 18473 : return result;
2034 : }
2035 :
2036 417 : static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
2037 : struct files_struct *fsp,
2038 : uint32_t dosmode)
2039 : {
2040 : NTSTATUS result;
2041 : struct timespec ts1,ts2;
2042 : double timediff;
2043 :
2044 417 : clock_gettime_mono(&ts1);
2045 417 : result = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2046 : fsp,
2047 : dosmode);
2048 417 : clock_gettime_mono(&ts2);
2049 417 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2050 :
2051 417 : if (timediff > audit_timeout) {
2052 0 : smb_time_audit_log_fsp("fset_dos_attributes", timediff, fsp);
2053 : }
2054 :
2055 417 : return result;
2056 : }
2057 :
2058 : struct time_audit_offload_read_state {
2059 : struct vfs_handle_struct *handle;
2060 : struct timespec ts_send;
2061 : uint32_t flags;
2062 : uint64_t xferlen;
2063 : DATA_BLOB token_blob;
2064 : };
2065 :
2066 : static void smb_time_audit_offload_read_done(struct tevent_req *subreq);
2067 :
2068 0 : static struct tevent_req *smb_time_audit_offload_read_send(
2069 : TALLOC_CTX *mem_ctx,
2070 : struct tevent_context *ev,
2071 : struct vfs_handle_struct *handle,
2072 : struct files_struct *fsp,
2073 : uint32_t fsctl,
2074 : uint32_t ttl,
2075 : off_t offset,
2076 : size_t to_copy)
2077 : {
2078 0 : struct tevent_req *req = NULL;
2079 0 : struct tevent_req *subreq = NULL;
2080 0 : struct time_audit_offload_read_state *state = NULL;
2081 :
2082 0 : req = tevent_req_create(mem_ctx, &state,
2083 : struct time_audit_offload_read_state);
2084 0 : if (req == NULL) {
2085 0 : return NULL;
2086 : }
2087 0 : state->handle = handle;
2088 0 : clock_gettime_mono(&state->ts_send);
2089 :
2090 0 : subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev,
2091 : handle, fsp,
2092 : fsctl, ttl,
2093 : offset, to_copy);
2094 0 : if (tevent_req_nomem(subreq, req)) {
2095 0 : return tevent_req_post(req, ev);
2096 : }
2097 :
2098 0 : tevent_req_set_callback(subreq, smb_time_audit_offload_read_done, req);
2099 0 : return req;
2100 : }
2101 :
2102 0 : static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
2103 : {
2104 0 : struct tevent_req *req = tevent_req_callback_data(
2105 : subreq, struct tevent_req);
2106 0 : struct time_audit_offload_read_state *state = tevent_req_data(
2107 : req, struct time_audit_offload_read_state);
2108 : NTSTATUS status;
2109 :
2110 0 : status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
2111 : state->handle,
2112 : state,
2113 : &state->flags,
2114 : &state->xferlen,
2115 : &state->token_blob);
2116 0 : TALLOC_FREE(subreq);
2117 0 : if (tevent_req_nterror(req, status)) {
2118 0 : return;
2119 : }
2120 0 : tevent_req_done(req);
2121 : }
2122 :
2123 0 : static NTSTATUS smb_time_audit_offload_read_recv(
2124 : struct tevent_req *req,
2125 : struct vfs_handle_struct *handle,
2126 : TALLOC_CTX *mem_ctx,
2127 : uint32_t *flags,
2128 : uint64_t *xferlen,
2129 : DATA_BLOB *token_blob)
2130 : {
2131 0 : struct time_audit_offload_read_state *state = tevent_req_data(
2132 : req, struct time_audit_offload_read_state);
2133 : struct timespec ts_recv;
2134 : double timediff;
2135 : NTSTATUS status;
2136 :
2137 0 : clock_gettime_mono(&ts_recv);
2138 0 : timediff = nsec_time_diff(&ts_recv, &state->ts_send) * 1.0e-9;
2139 0 : if (timediff > audit_timeout) {
2140 0 : smb_time_audit_log("offload_read", timediff);
2141 : }
2142 :
2143 0 : if (tevent_req_is_nterror(req, &status)) {
2144 0 : tevent_req_received(req);
2145 0 : return status;
2146 : }
2147 :
2148 0 : *flags = state->flags;
2149 0 : *xferlen = state->xferlen;
2150 0 : token_blob->length = state->token_blob.length;
2151 0 : token_blob->data = talloc_move(mem_ctx, &state->token_blob.data);
2152 :
2153 0 : tevent_req_received(req);
2154 0 : return NT_STATUS_OK;
2155 : }
2156 :
2157 : struct time_audit_offload_write_state {
2158 : struct timespec ts_send;
2159 : struct vfs_handle_struct *handle;
2160 : off_t copied;
2161 : };
2162 : static void smb_time_audit_offload_write_done(struct tevent_req *subreq);
2163 :
2164 0 : static struct tevent_req *smb_time_audit_offload_write_send(struct vfs_handle_struct *handle,
2165 : TALLOC_CTX *mem_ctx,
2166 : struct tevent_context *ev,
2167 : uint32_t fsctl,
2168 : DATA_BLOB *token,
2169 : off_t transfer_offset,
2170 : struct files_struct *dest_fsp,
2171 : off_t dest_off,
2172 : off_t num)
2173 : {
2174 : struct tevent_req *req;
2175 : struct tevent_req *subreq;
2176 : struct time_audit_offload_write_state *state;
2177 :
2178 0 : req = tevent_req_create(mem_ctx, &state,
2179 : struct time_audit_offload_write_state);
2180 0 : if (req == NULL) {
2181 0 : return NULL;
2182 : }
2183 :
2184 0 : state->handle = handle;
2185 0 : clock_gettime_mono(&state->ts_send);
2186 0 : subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
2187 : fsctl, token, transfer_offset,
2188 : dest_fsp, dest_off, num);
2189 0 : if (tevent_req_nomem(subreq, req)) {
2190 0 : return tevent_req_post(req, ev);
2191 : }
2192 :
2193 0 : tevent_req_set_callback(subreq, smb_time_audit_offload_write_done, req);
2194 0 : return req;
2195 : }
2196 :
2197 0 : static void smb_time_audit_offload_write_done(struct tevent_req *subreq)
2198 : {
2199 0 : struct tevent_req *req = tevent_req_callback_data(
2200 : subreq, struct tevent_req);
2201 0 : struct time_audit_offload_write_state *state = tevent_req_data(
2202 : req, struct time_audit_offload_write_state);
2203 : NTSTATUS status;
2204 :
2205 0 : status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
2206 : subreq,
2207 : &state->copied);
2208 0 : TALLOC_FREE(subreq);
2209 0 : if (tevent_req_nterror(req, status)) {
2210 0 : return;
2211 : }
2212 0 : tevent_req_done(req);
2213 : }
2214 :
2215 0 : static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *handle,
2216 : struct tevent_req *req,
2217 : off_t *copied)
2218 : {
2219 0 : struct time_audit_offload_write_state *state = tevent_req_data(
2220 : req, struct time_audit_offload_write_state);
2221 : struct timespec ts_recv;
2222 : double timediff;
2223 : NTSTATUS status;
2224 :
2225 0 : clock_gettime_mono(&ts_recv);
2226 0 : timediff = nsec_time_diff(&ts_recv, &state->ts_send)*1.0e-9;
2227 0 : if (timediff > audit_timeout) {
2228 0 : smb_time_audit_log("offload_write", timediff);
2229 : }
2230 :
2231 0 : *copied = state->copied;
2232 0 : if (tevent_req_is_nterror(req, &status)) {
2233 0 : tevent_req_received(req);
2234 0 : return status;
2235 : }
2236 :
2237 0 : tevent_req_received(req);
2238 0 : return NT_STATUS_OK;
2239 : }
2240 :
2241 0 : static NTSTATUS smb_time_audit_fget_compression(vfs_handle_struct *handle,
2242 : TALLOC_CTX *mem_ctx,
2243 : struct files_struct *fsp,
2244 : uint16_t *_compression_fmt)
2245 : {
2246 : NTSTATUS result;
2247 : struct timespec ts1,ts2;
2248 : double timediff;
2249 :
2250 0 : clock_gettime_mono(&ts1);
2251 0 : result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2252 : _compression_fmt);
2253 0 : clock_gettime_mono(&ts2);
2254 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2255 :
2256 0 : if (timediff > audit_timeout) {
2257 0 : smb_time_audit_log_fsp("get_compression",
2258 : timediff, fsp);
2259 : }
2260 :
2261 0 : return result;
2262 : }
2263 :
2264 0 : static NTSTATUS smb_time_audit_set_compression(vfs_handle_struct *handle,
2265 : TALLOC_CTX *mem_ctx,
2266 : struct files_struct *fsp,
2267 : uint16_t compression_fmt)
2268 : {
2269 : NTSTATUS result;
2270 : struct timespec ts1,ts2;
2271 : double timediff;
2272 :
2273 0 : clock_gettime_mono(&ts1);
2274 0 : result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2275 : compression_fmt);
2276 0 : clock_gettime_mono(&ts2);
2277 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2278 :
2279 0 : if (timediff > audit_timeout) {
2280 0 : smb_time_audit_log_fsp("set_compression", timediff, fsp);
2281 : }
2282 :
2283 0 : return result;
2284 : }
2285 :
2286 5017 : static NTSTATUS smb_time_audit_freaddir_attr(struct vfs_handle_struct *handle,
2287 : struct files_struct *fsp,
2288 : TALLOC_CTX *mem_ctx,
2289 : struct readdir_attr_data **pattr_data)
2290 : {
2291 : NTSTATUS status;
2292 : struct timespec ts1, ts2;
2293 : double timediff;
2294 :
2295 5017 : clock_gettime_mono(&ts1);
2296 5017 : status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2297 5017 : clock_gettime_mono(&ts2);
2298 5017 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
2299 :
2300 5017 : if (timediff > audit_timeout) {
2301 0 : smb_time_audit_log_fsp("freaddir_attr", timediff, fsp);
2302 : }
2303 :
2304 5017 : return status;
2305 : }
2306 :
2307 2186 : static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
2308 : files_struct *fsp,
2309 : uint32_t security_info,
2310 : TALLOC_CTX *mem_ctx,
2311 : struct security_descriptor **ppdesc)
2312 : {
2313 : NTSTATUS result;
2314 : struct timespec ts1,ts2;
2315 : double timediff;
2316 :
2317 2186 : clock_gettime_mono(&ts1);
2318 2186 : result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2319 : mem_ctx, ppdesc);
2320 2186 : clock_gettime_mono(&ts2);
2321 2186 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2322 :
2323 2186 : if (timediff > audit_timeout) {
2324 0 : smb_time_audit_log_fsp("fget_nt_acl", timediff, fsp);
2325 : }
2326 :
2327 2186 : return result;
2328 : }
2329 :
2330 350 : static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
2331 : files_struct *fsp,
2332 : uint32_t security_info_sent,
2333 : const struct security_descriptor *psd)
2334 : {
2335 : NTSTATUS result;
2336 : struct timespec ts1,ts2;
2337 : double timediff;
2338 :
2339 350 : clock_gettime_mono(&ts1);
2340 350 : result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
2341 : psd);
2342 350 : clock_gettime_mono(&ts2);
2343 350 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2344 :
2345 350 : if (timediff > audit_timeout) {
2346 0 : smb_time_audit_log_fsp("fset_nt_acl", timediff, fsp);
2347 : }
2348 :
2349 350 : return result;
2350 : }
2351 :
2352 0 : static NTSTATUS smb_time_audit_audit_file(struct vfs_handle_struct *handle,
2353 : struct smb_filename *smb_fname,
2354 : struct security_acl *sacl,
2355 : uint32_t access_requested,
2356 : uint32_t access_denied)
2357 : {
2358 : NTSTATUS result;
2359 : struct timespec ts1,ts2;
2360 : double timediff;
2361 :
2362 0 : clock_gettime_mono(&ts1);
2363 0 : result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2364 : smb_fname,
2365 : sacl,
2366 : access_requested,
2367 : access_denied);
2368 0 : clock_gettime_mono(&ts2);
2369 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2370 :
2371 0 : if (timediff > audit_timeout) {
2372 0 : smb_time_audit_log_fname("audit_file",
2373 : timediff,
2374 0 : smb_fname->base_name);
2375 : }
2376 :
2377 0 : return result;
2378 : }
2379 :
2380 0 : static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2381 : files_struct *fsp,
2382 : SMB_ACL_TYPE_T type,
2383 : TALLOC_CTX *mem_ctx)
2384 : {
2385 : SMB_ACL_T result;
2386 : struct timespec ts1,ts2;
2387 : double timediff;
2388 :
2389 0 : clock_gettime_mono(&ts1);
2390 0 : result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
2391 0 : clock_gettime_mono(&ts2);
2392 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2393 :
2394 0 : if (timediff > audit_timeout) {
2395 0 : smb_time_audit_log_fsp("sys_acl_get_fd", timediff, fsp);
2396 : }
2397 :
2398 0 : return result;
2399 : }
2400 :
2401 0 : static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2402 : files_struct *fsp,
2403 : TALLOC_CTX *mem_ctx,
2404 : char **blob_description,
2405 : DATA_BLOB *blob)
2406 : {
2407 : int result;
2408 : struct timespec ts1,ts2;
2409 : double timediff;
2410 :
2411 0 : clock_gettime_mono(&ts1);
2412 0 : result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2413 0 : clock_gettime_mono(&ts2);
2414 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2415 :
2416 0 : if (timediff > audit_timeout) {
2417 0 : smb_time_audit_log("sys_acl_blob_get_fd", timediff);
2418 : }
2419 :
2420 0 : return result;
2421 : }
2422 :
2423 0 : static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2424 : files_struct *fsp,
2425 : SMB_ACL_TYPE_T type,
2426 : SMB_ACL_T theacl)
2427 : {
2428 : int result;
2429 : struct timespec ts1,ts2;
2430 : double timediff;
2431 :
2432 0 : clock_gettime_mono(&ts1);
2433 0 : result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2434 0 : clock_gettime_mono(&ts2);
2435 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2436 :
2437 0 : if (timediff > audit_timeout) {
2438 0 : smb_time_audit_log_fsp("sys_acl_set_fd", timediff, fsp);
2439 : }
2440 :
2441 0 : return result;
2442 : }
2443 :
2444 0 : static int smb_time_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2445 : files_struct *fsp)
2446 : {
2447 : int result;
2448 : struct timespec ts1,ts2;
2449 : double timediff;
2450 :
2451 0 : clock_gettime_mono(&ts1);
2452 0 : result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2453 0 : clock_gettime_mono(&ts2);
2454 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2455 :
2456 0 : if (timediff > audit_timeout) {
2457 0 : smb_time_audit_log_fsp("sys_acl_delete_def_fd", timediff, fsp);
2458 : }
2459 :
2460 0 : return result;
2461 : }
2462 :
2463 : struct smb_time_audit_getxattrat_state {
2464 : struct vfs_aio_state aio_state;
2465 : files_struct *dir_fsp;
2466 : const struct smb_filename *smb_fname;
2467 : const char *xattr_name;
2468 : ssize_t xattr_size;
2469 : uint8_t *xattr_value;
2470 : };
2471 :
2472 : static void smb_time_audit_getxattrat_done(struct tevent_req *subreq);
2473 :
2474 0 : static struct tevent_req *smb_time_audit_getxattrat_send(
2475 : TALLOC_CTX *mem_ctx,
2476 : struct tevent_context *ev,
2477 : struct vfs_handle_struct *handle,
2478 : files_struct *dir_fsp,
2479 : const struct smb_filename *smb_fname,
2480 : const char *xattr_name,
2481 : size_t alloc_hint)
2482 : {
2483 0 : struct tevent_req *req = NULL;
2484 0 : struct tevent_req *subreq = NULL;
2485 0 : struct smb_time_audit_getxattrat_state *state = NULL;
2486 :
2487 0 : req = tevent_req_create(mem_ctx, &state,
2488 : struct smb_time_audit_getxattrat_state);
2489 0 : if (req == NULL) {
2490 0 : return NULL;
2491 : }
2492 0 : *state = (struct smb_time_audit_getxattrat_state) {
2493 : .dir_fsp = dir_fsp,
2494 : .smb_fname = smb_fname,
2495 : .xattr_name = xattr_name,
2496 : };
2497 :
2498 0 : subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2499 : ev,
2500 : handle,
2501 : dir_fsp,
2502 : smb_fname,
2503 : xattr_name,
2504 : alloc_hint);
2505 0 : if (tevent_req_nomem(subreq, req)) {
2506 0 : return tevent_req_post(req, ev);
2507 : }
2508 0 : tevent_req_set_callback(subreq, smb_time_audit_getxattrat_done, req);
2509 :
2510 0 : return req;
2511 : }
2512 :
2513 0 : static void smb_time_audit_getxattrat_done(struct tevent_req *subreq)
2514 : {
2515 0 : struct tevent_req *req = tevent_req_callback_data(
2516 : subreq, struct tevent_req);
2517 0 : struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2518 : req, struct smb_time_audit_getxattrat_state);
2519 :
2520 0 : state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2521 : &state->aio_state,
2522 : state,
2523 : &state->xattr_value);
2524 0 : TALLOC_FREE(subreq);
2525 0 : if (state->xattr_size == -1) {
2526 0 : tevent_req_error(req, state->aio_state.error);
2527 0 : return;
2528 : }
2529 :
2530 0 : tevent_req_done(req);
2531 : }
2532 :
2533 0 : static ssize_t smb_time_audit_getxattrat_recv(struct tevent_req *req,
2534 : struct vfs_aio_state *aio_state,
2535 : TALLOC_CTX *mem_ctx,
2536 : uint8_t **xattr_value)
2537 : {
2538 0 : struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2539 : req, struct smb_time_audit_getxattrat_state);
2540 : ssize_t xattr_size;
2541 : double timediff;
2542 :
2543 0 : timediff = state->aio_state.duration * 1.0e-9;
2544 :
2545 0 : if (timediff > audit_timeout) {
2546 0 : smb_time_audit_log_at("async getxattrat",
2547 : timediff,
2548 0 : state->dir_fsp,
2549 : state->smb_fname);
2550 : }
2551 :
2552 0 : if (tevent_req_is_unix_error(req, &aio_state->error)) {
2553 0 : tevent_req_received(req);
2554 0 : return -1;
2555 : }
2556 :
2557 0 : *aio_state = state->aio_state;
2558 0 : xattr_size = state->xattr_size;
2559 0 : if (xattr_value != NULL) {
2560 0 : *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2561 : }
2562 :
2563 0 : tevent_req_received(req);
2564 0 : return xattr_size;
2565 : }
2566 :
2567 0 : static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
2568 : struct files_struct *fsp,
2569 : const char *name, void *value,
2570 : size_t size)
2571 : {
2572 : ssize_t result;
2573 : struct timespec ts1,ts2;
2574 : double timediff;
2575 :
2576 0 : clock_gettime_mono(&ts1);
2577 0 : result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2578 0 : clock_gettime_mono(&ts2);
2579 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2580 :
2581 0 : if (timediff > audit_timeout) {
2582 0 : smb_time_audit_log_fsp("fgetxattr", timediff, fsp);
2583 : }
2584 :
2585 0 : return result;
2586 : }
2587 :
2588 0 : static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2589 : struct files_struct *fsp, char *list,
2590 : size_t size)
2591 : {
2592 : ssize_t result;
2593 : struct timespec ts1,ts2;
2594 : double timediff;
2595 :
2596 0 : clock_gettime_mono(&ts1);
2597 0 : result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2598 0 : clock_gettime_mono(&ts2);
2599 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2600 :
2601 0 : if (timediff > audit_timeout) {
2602 0 : smb_time_audit_log_fsp("flistxattr", timediff, fsp);
2603 : }
2604 :
2605 0 : return result;
2606 : }
2607 :
2608 0 : static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2609 : struct files_struct *fsp,
2610 : const char *name)
2611 : {
2612 : int result;
2613 : struct timespec ts1,ts2;
2614 : double timediff;
2615 :
2616 0 : clock_gettime_mono(&ts1);
2617 0 : result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2618 0 : clock_gettime_mono(&ts2);
2619 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2620 :
2621 0 : if (timediff > audit_timeout) {
2622 0 : smb_time_audit_log_fsp("fremovexattr", timediff, fsp);
2623 : }
2624 :
2625 0 : return result;
2626 : }
2627 :
2628 0 : static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2629 : struct files_struct *fsp, const char *name,
2630 : const void *value, size_t size, int flags)
2631 : {
2632 : int result;
2633 : struct timespec ts1,ts2;
2634 : double timediff;
2635 :
2636 0 : clock_gettime_mono(&ts1);
2637 0 : result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2638 0 : clock_gettime_mono(&ts2);
2639 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2640 :
2641 0 : if (timediff > audit_timeout) {
2642 0 : smb_time_audit_log_fsp("fsetxattr", timediff, fsp);
2643 : }
2644 :
2645 0 : return result;
2646 : }
2647 :
2648 0 : static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2649 : struct files_struct *fsp)
2650 : {
2651 : bool result;
2652 : struct timespec ts1,ts2;
2653 : double timediff;
2654 :
2655 0 : clock_gettime_mono(&ts1);
2656 0 : result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2657 0 : clock_gettime_mono(&ts2);
2658 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2659 :
2660 0 : if (timediff > audit_timeout) {
2661 0 : smb_time_audit_log_fsp("aio_force", timediff, fsp);
2662 : }
2663 :
2664 0 : return result;
2665 : }
2666 :
2667 0 : static NTSTATUS smb_time_audit_durable_cookie(struct vfs_handle_struct *handle,
2668 : struct files_struct *fsp,
2669 : TALLOC_CTX *mem_ctx,
2670 : DATA_BLOB *cookie)
2671 : {
2672 : NTSTATUS result;
2673 : struct timespec ts1,ts2;
2674 : double timediff;
2675 :
2676 0 : clock_gettime_mono(&ts1);
2677 0 : result = SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie);
2678 0 : clock_gettime_mono(&ts2);
2679 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2680 :
2681 0 : if (timediff > audit_timeout) {
2682 0 : smb_time_audit_log_fsp("durable_cookie", timediff, fsp);
2683 : }
2684 :
2685 0 : return result;
2686 : }
2687 :
2688 0 : static NTSTATUS smb_time_audit_durable_disconnect(struct vfs_handle_struct *handle,
2689 : struct files_struct *fsp,
2690 : const DATA_BLOB old_cookie,
2691 : TALLOC_CTX *mem_ctx,
2692 : DATA_BLOB *new_cookie)
2693 : {
2694 : NTSTATUS result;
2695 : struct timespec ts1,ts2;
2696 : double timediff;
2697 :
2698 0 : clock_gettime_mono(&ts1);
2699 0 : result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie,
2700 : mem_ctx, new_cookie);
2701 0 : clock_gettime_mono(&ts2);
2702 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2703 :
2704 0 : if (timediff > audit_timeout) {
2705 0 : smb_time_audit_log_fsp("durable_disconnect", timediff, fsp);
2706 : }
2707 :
2708 0 : return result;
2709 : }
2710 :
2711 0 : static NTSTATUS smb_time_audit_durable_reconnect(struct vfs_handle_struct *handle,
2712 : struct smb_request *smb1req,
2713 : struct smbXsrv_open *op,
2714 : const DATA_BLOB old_cookie,
2715 : TALLOC_CTX *mem_ctx,
2716 : struct files_struct **fsp,
2717 : DATA_BLOB *new_cookie)
2718 : {
2719 : NTSTATUS result;
2720 : struct timespec ts1,ts2;
2721 : double timediff;
2722 :
2723 0 : clock_gettime_mono(&ts1);
2724 0 : result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie,
2725 : mem_ctx, fsp, new_cookie);
2726 0 : clock_gettime_mono(&ts2);
2727 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2728 :
2729 0 : if (timediff > audit_timeout) {
2730 0 : smb_time_audit_log("durable_reconnect", timediff);
2731 : }
2732 :
2733 0 : return result;
2734 : }
2735 :
2736 : /* VFS operations */
2737 :
2738 : static struct vfs_fn_pointers vfs_time_audit_fns = {
2739 : .connect_fn = smb_time_audit_connect,
2740 : .disconnect_fn = smb_time_audit_disconnect,
2741 : .disk_free_fn = smb_time_audit_disk_free,
2742 : .get_quota_fn = smb_time_audit_get_quota,
2743 : .set_quota_fn = smb_time_audit_set_quota,
2744 : .get_shadow_copy_data_fn = smb_time_audit_get_shadow_copy_data,
2745 : .statvfs_fn = smb_time_audit_statvfs,
2746 : .fs_capabilities_fn = smb_time_audit_fs_capabilities,
2747 : .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
2748 : .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat,
2749 : .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat,
2750 : .fdopendir_fn = smb_time_audit_fdopendir,
2751 : .readdir_fn = smb_time_audit_readdir,
2752 : .seekdir_fn = smb_time_audit_seekdir,
2753 : .telldir_fn = smb_time_audit_telldir,
2754 : .rewind_dir_fn = smb_time_audit_rewinddir,
2755 : .mkdirat_fn = smb_time_audit_mkdirat,
2756 : .closedir_fn = smb_time_audit_closedir,
2757 : .openat_fn = smb_time_audit_openat,
2758 : .create_file_fn = smb_time_audit_create_file,
2759 : .close_fn = smb_time_audit_close,
2760 : .pread_fn = smb_time_audit_pread,
2761 : .pread_send_fn = smb_time_audit_pread_send,
2762 : .pread_recv_fn = smb_time_audit_pread_recv,
2763 : .pwrite_fn = smb_time_audit_pwrite,
2764 : .pwrite_send_fn = smb_time_audit_pwrite_send,
2765 : .pwrite_recv_fn = smb_time_audit_pwrite_recv,
2766 : .lseek_fn = smb_time_audit_lseek,
2767 : .sendfile_fn = smb_time_audit_sendfile,
2768 : .recvfile_fn = smb_time_audit_recvfile,
2769 : .renameat_fn = smb_time_audit_renameat,
2770 : .fsync_send_fn = smb_time_audit_fsync_send,
2771 : .fsync_recv_fn = smb_time_audit_fsync_recv,
2772 : .stat_fn = smb_time_audit_stat,
2773 : .fstat_fn = smb_time_audit_fstat,
2774 : .lstat_fn = smb_time_audit_lstat,
2775 : .fstatat_fn = smb_time_audit_fstatat,
2776 : .get_alloc_size_fn = smb_time_audit_get_alloc_size,
2777 : .unlinkat_fn = smb_time_audit_unlinkat,
2778 : .fchmod_fn = smb_time_audit_fchmod,
2779 : .fchown_fn = smb_time_audit_fchown,
2780 : .lchown_fn = smb_time_audit_lchown,
2781 : .chdir_fn = smb_time_audit_chdir,
2782 : .getwd_fn = smb_time_audit_getwd,
2783 : .fntimes_fn = smb_time_audit_fntimes,
2784 : .ftruncate_fn = smb_time_audit_ftruncate,
2785 : .fallocate_fn = smb_time_audit_fallocate,
2786 : .lock_fn = smb_time_audit_lock,
2787 : .filesystem_sharemode_fn = smb_time_audit_filesystem_sharemode,
2788 : .fcntl_fn = smb_time_audit_fcntl,
2789 : .linux_setlease_fn = smb_time_audit_linux_setlease,
2790 : .getlock_fn = smb_time_audit_getlock,
2791 : .symlinkat_fn = smb_time_audit_symlinkat,
2792 : .readlinkat_fn = smb_time_audit_readlinkat,
2793 : .linkat_fn = smb_time_audit_linkat,
2794 : .mknodat_fn = smb_time_audit_mknodat,
2795 : .realpath_fn = smb_time_audit_realpath,
2796 : .fchflags_fn = smb_time_audit_fchflags,
2797 : .file_id_create_fn = smb_time_audit_file_id_create,
2798 : .fs_file_id_fn = smb_time_audit_fs_file_id,
2799 : .offload_read_send_fn = smb_time_audit_offload_read_send,
2800 : .offload_read_recv_fn = smb_time_audit_offload_read_recv,
2801 : .offload_write_send_fn = smb_time_audit_offload_write_send,
2802 : .offload_write_recv_fn = smb_time_audit_offload_write_recv,
2803 : .fget_compression_fn = smb_time_audit_fget_compression,
2804 : .set_compression_fn = smb_time_audit_set_compression,
2805 : .snap_check_path_fn = smb_time_audit_snap_check_path,
2806 : .snap_create_fn = smb_time_audit_snap_create,
2807 : .snap_delete_fn = smb_time_audit_snap_delete,
2808 : .fstreaminfo_fn = smb_time_audit_fstreaminfo,
2809 : .get_real_filename_at_fn = smb_time_audit_get_real_filename_at,
2810 : .connectpath_fn = smb_time_audit_connectpath,
2811 : .brl_lock_windows_fn = smb_time_audit_brl_lock_windows,
2812 : .brl_unlock_windows_fn = smb_time_audit_brl_unlock_windows,
2813 : .strict_lock_check_fn = smb_time_audit_strict_lock_check,
2814 : .translate_name_fn = smb_time_audit_translate_name,
2815 : .parent_pathname_fn = smb_time_audit_parent_pathname,
2816 : .fsctl_fn = smb_time_audit_fsctl,
2817 : .get_dos_attributes_send_fn = smb_time_audit_get_dos_attributes_send,
2818 : .get_dos_attributes_recv_fn = smb_time_audit_get_dos_attributes_recv,
2819 : .fget_dos_attributes_fn = smb_time_fget_dos_attributes,
2820 : .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
2821 : .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
2822 : .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
2823 : .audit_file_fn = smb_time_audit_audit_file,
2824 : .sys_acl_get_fd_fn = smb_time_audit_sys_acl_get_fd,
2825 : .sys_acl_blob_get_fd_fn = smb_time_audit_sys_acl_blob_get_fd,
2826 : .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
2827 : .sys_acl_delete_def_fd_fn = smb_time_audit_sys_acl_delete_def_fd,
2828 : .getxattrat_send_fn = smb_time_audit_getxattrat_send,
2829 : .getxattrat_recv_fn = smb_time_audit_getxattrat_recv,
2830 : .fgetxattr_fn = smb_time_audit_fgetxattr,
2831 : .flistxattr_fn = smb_time_audit_flistxattr,
2832 : .fremovexattr_fn = smb_time_audit_fremovexattr,
2833 : .fsetxattr_fn = smb_time_audit_fsetxattr,
2834 : .aio_force_fn = smb_time_audit_aio_force,
2835 : .durable_cookie_fn = smb_time_audit_durable_cookie,
2836 : .durable_disconnect_fn = smb_time_audit_durable_disconnect,
2837 : .durable_reconnect_fn = smb_time_audit_durable_reconnect,
2838 : .freaddir_attr_fn = smb_time_audit_freaddir_attr,
2839 : };
2840 :
2841 :
2842 : static_decl_vfs;
2843 1122 : NTSTATUS vfs_time_audit_init(TALLOC_CTX *ctx)
2844 : {
2845 1122 : smb_vfs_assert_all_fns(&vfs_time_audit_fns, "time_audit");
2846 :
2847 1122 : audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2848 1122 : 10000) / 1000.0;
2849 1122 : return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2850 : &vfs_time_audit_fns);
2851 : }
|