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 30920 : 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 30920 : if (!handle) {
148 0 : return -1;
149 : }
150 :
151 30920 : clock_gettime_mono(&ts1);
152 30920 : result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
153 30920 : clock_gettime_mono(&ts2);
154 30920 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
155 30920 : if (timediff > audit_timeout) {
156 0 : smb_time_audit_log_msg("connect", timediff, user);
157 : }
158 30920 : return result;
159 : }
160 :
161 30860 : static void smb_time_audit_disconnect(vfs_handle_struct *handle)
162 : {
163 : struct timespec ts1,ts2;
164 : double timediff;
165 :
166 30860 : clock_gettime_mono(&ts1);
167 30860 : SMB_VFS_NEXT_DISCONNECT(handle);
168 30860 : clock_gettime_mono(&ts2);
169 30860 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
170 :
171 30860 : if (timediff > audit_timeout) {
172 0 : smb_time_audit_log("disconnect", timediff);
173 : }
174 30860 : }
175 :
176 849 : 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 849 : clock_gettime_mono(&ts1);
187 849 : result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
188 849 : clock_gettime_mono(&ts2);
189 849 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
190 :
191 : /* Don't have a reasonable notion of failure here */
192 849 : if (timediff > audit_timeout) {
193 0 : smb_time_audit_log_fname("disk_free",
194 : timediff,
195 0 : smb_fname->base_name);
196 : }
197 :
198 849 : return result;
199 : }
200 :
201 1762 : 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 1762 : clock_gettime_mono(&ts1);
212 1762 : result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
213 1762 : clock_gettime_mono(&ts2);
214 1762 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
215 :
216 1762 : if (timediff > audit_timeout) {
217 0 : smb_time_audit_log_fname("get_quota",
218 : timediff,
219 0 : smb_fname->base_name);
220 : }
221 1762 : return result;
222 : }
223 :
224 4 : 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 4 : clock_gettime_mono(&ts1);
233 4 : result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
234 4 : clock_gettime_mono(&ts2);
235 4 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
236 :
237 4 : if (timediff > audit_timeout) {
238 0 : smb_time_audit_log("set_quota", timediff);
239 : }
240 :
241 4 : return result;
242 : }
243 :
244 228 : 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 228 : clock_gettime_mono(&ts1);
254 228 : result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp,
255 : shadow_copy_data, labels);
256 228 : clock_gettime_mono(&ts2);
257 228 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
258 :
259 228 : if (timediff > audit_timeout) {
260 0 : smb_time_audit_log_fsp("get_shadow_copy_data", timediff, fsp);
261 : }
262 :
263 228 : return result;
264 : }
265 :
266 30908 : 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 30908 : clock_gettime_mono(&ts1);
275 30908 : result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
276 30908 : clock_gettime_mono(&ts2);
277 30908 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
278 :
279 30908 : if (timediff > audit_timeout) {
280 0 : smb_time_audit_log_fname("statvfs", timediff,
281 0 : smb_fname->base_name);
282 : }
283 :
284 30908 : return result;
285 : }
286 :
287 30908 : 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 30908 : clock_gettime_mono(&ts1);
295 30908 : result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
296 30908 : clock_gettime_mono(&ts2);
297 30908 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
298 :
299 30908 : if (timediff > audit_timeout) {
300 0 : smb_time_audit_log("fs_capabilities", timediff);
301 : }
302 :
303 30908 : return result;
304 : }
305 :
306 8716 : 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 8716 : clock_gettime_mono(&ts1);
315 8716 : result = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
316 8716 : clock_gettime_mono(&ts2);
317 8716 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
318 :
319 8716 : if (timediff > audit_timeout) {
320 0 : smb_time_audit_log("get_dfs_referrals", timediff);
321 : }
322 :
323 8716 : 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 16674 : 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 16674 : struct smb_filename *full_fname = NULL;
373 :
374 16674 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
375 : dirfsp,
376 : smb_fname);
377 16674 : if (full_fname == NULL) {
378 0 : return NT_STATUS_NO_MEMORY;
379 : }
380 :
381 16674 : clock_gettime_mono(&ts1);
382 16674 : result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
383 : mem_ctx,
384 : dirfsp,
385 : smb_fname,
386 : ppreflist,
387 : preferral_count);
388 16674 : clock_gettime_mono(&ts2);
389 16674 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
390 :
391 16674 : if (timediff > audit_timeout) {
392 0 : smb_time_audit_log_smb_fname("read_dfs_pathat",
393 : timediff,
394 : full_fname);
395 : }
396 :
397 16674 : TALLOC_FREE(full_fname);
398 16674 : 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 146081 : 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 146081 : clock_gettime_mono(&ts1);
479 146081 : result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
480 146081 : clock_gettime_mono(&ts2);
481 146081 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
482 :
483 146081 : if (timediff > audit_timeout) {
484 0 : smb_time_audit_log_fsp("fdopendir", timediff, fsp);
485 : }
486 :
487 146081 : return result;
488 : }
489 :
490 78201567 : 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 78201567 : clock_gettime_mono(&ts1);
500 78201567 : result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
501 78201567 : clock_gettime_mono(&ts2);
502 78201567 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
503 :
504 78201567 : if (timediff > audit_timeout) {
505 0 : smb_time_audit_log("readdir", timediff);
506 : }
507 :
508 78201567 : return result;
509 : }
510 :
511 1314 : 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 1314 : clock_gettime_mono(&ts1);
518 1314 : SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
519 1314 : clock_gettime_mono(&ts2);
520 1314 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
521 :
522 1314 : if (timediff > audit_timeout) {
523 0 : smb_time_audit_log("seekdir", timediff);
524 : }
525 :
526 1314 : }
527 :
528 77767752 : 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 77767752 : clock_gettime_mono(&ts1);
536 77767752 : result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
537 77767752 : clock_gettime_mono(&ts2);
538 77767752 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
539 :
540 77767752 : if (timediff > audit_timeout) {
541 0 : smb_time_audit_log("telldir", timediff);
542 : }
543 :
544 77767752 : return result;
545 : }
546 :
547 56 : static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
548 : DIR *dirp)
549 : {
550 : struct timespec ts1,ts2;
551 : double timediff;
552 :
553 56 : clock_gettime_mono(&ts1);
554 56 : SMB_VFS_NEXT_REWINDDIR(handle, dirp);
555 56 : clock_gettime_mono(&ts2);
556 56 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
557 :
558 56 : if (timediff > audit_timeout) {
559 0 : smb_time_audit_log("rewinddir", timediff);
560 : }
561 :
562 56 : }
563 :
564 5544 : 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 5544 : struct smb_filename *full_fname = NULL;
570 : int result;
571 : struct timespec ts1,ts2;
572 : double timediff;
573 :
574 5544 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
575 : dirfsp,
576 : smb_fname);
577 5544 : if (full_fname == NULL) {
578 0 : errno = ENOMEM;
579 0 : return -1;
580 : }
581 :
582 5544 : clock_gettime_mono(&ts1);
583 5544 : result = SMB_VFS_NEXT_MKDIRAT(handle,
584 : dirfsp,
585 : smb_fname,
586 : mode);
587 5544 : clock_gettime_mono(&ts2);
588 5544 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
589 :
590 5544 : if (timediff > audit_timeout) {
591 0 : smb_time_audit_log_smb_fname("mkdirat",
592 : timediff,
593 : full_fname);
594 : }
595 :
596 5544 : TALLOC_FREE(full_fname);
597 :
598 5544 : return result;
599 : }
600 :
601 146081 : 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 146081 : clock_gettime_mono(&ts1);
609 146081 : result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
610 146081 : clock_gettime_mono(&ts2);
611 146081 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
612 :
613 146081 : if (timediff > audit_timeout) {
614 0 : smb_time_audit_log("closedir", timediff);
615 : }
616 :
617 146081 : return result;
618 : }
619 :
620 5636836 : 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 : int flags,
625 : mode_t mode)
626 : {
627 : int result;
628 : struct timespec ts1,ts2;
629 : double timediff;
630 :
631 5636836 : clock_gettime_mono(&ts1);
632 5636836 : result = SMB_VFS_NEXT_OPENAT(handle,
633 : dirfsp,
634 : smb_fname,
635 : fsp,
636 : flags,
637 : mode);
638 5636836 : clock_gettime_mono(&ts2);
639 5636836 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
640 :
641 5636836 : if (timediff > audit_timeout) {
642 0 : smb_time_audit_log_fsp("openat", timediff, fsp);
643 : }
644 :
645 5636836 : return result;
646 : }
647 :
648 250961 : static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
649 : struct smb_request *req,
650 : struct smb_filename *fname,
651 : uint32_t access_mask,
652 : uint32_t share_access,
653 : uint32_t create_disposition,
654 : uint32_t create_options,
655 : uint32_t file_attributes,
656 : uint32_t oplock_request,
657 : const struct smb2_lease *lease,
658 : uint64_t allocation_size,
659 : uint32_t private_flags,
660 : struct security_descriptor *sd,
661 : struct ea_list *ea_list,
662 : files_struct **result_fsp,
663 : int *pinfo,
664 : const struct smb2_create_blobs *in_context_blobs,
665 : struct smb2_create_blobs *out_context_blobs)
666 : {
667 : NTSTATUS result;
668 : struct timespec ts1,ts2;
669 : double timediff;
670 :
671 250961 : clock_gettime_mono(&ts1);
672 250961 : result = SMB_VFS_NEXT_CREATE_FILE(
673 : handle, /* handle */
674 : req, /* req */
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 250961 : clock_gettime_mono(&ts2);
691 250961 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
692 :
693 250961 : 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 250961 : return result;
703 : }
704 :
705 5490505 : 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 5490505 : clock_gettime_mono(&ts1);
712 5490505 : result = SMB_VFS_NEXT_CLOSE(handle, fsp);
713 5490505 : clock_gettime_mono(&ts2);
714 5490505 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
715 :
716 5490505 : if (timediff > audit_timeout) {
717 0 : smb_time_audit_log_fsp("close", timediff, fsp);
718 : }
719 :
720 5490505 : return result;
721 : }
722 :
723 1836 : 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 1836 : clock_gettime_mono(&ts1);
732 1836 : result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
733 1836 : clock_gettime_mono(&ts2);
734 1836 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
735 :
736 1836 : if (timediff > audit_timeout) {
737 0 : smb_time_audit_log_fsp("pread", timediff, fsp);
738 : }
739 :
740 1836 : 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 8805 : 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 8805 : req = tevent_req_create(mem_ctx, &state,
760 : struct smb_time_audit_pread_state);
761 8805 : if (req == NULL) {
762 0 : return NULL;
763 : }
764 8805 : state->fsp = fsp;
765 :
766 8805 : subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
767 : n, offset);
768 8805 : if (tevent_req_nomem(subreq, req)) {
769 0 : return tevent_req_post(req, ev);
770 : }
771 8805 : tevent_req_set_callback(subreq, smb_time_audit_pread_done, req);
772 8805 : return req;
773 : }
774 :
775 8805 : static void smb_time_audit_pread_done(struct tevent_req *subreq)
776 : {
777 8805 : struct tevent_req *req = tevent_req_callback_data(
778 : subreq, struct tevent_req);
779 8805 : struct smb_time_audit_pread_state *state = tevent_req_data(
780 : req, struct smb_time_audit_pread_state);
781 :
782 8805 : state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
783 8805 : TALLOC_FREE(subreq);
784 8805 : tevent_req_done(req);
785 8805 : }
786 :
787 8805 : static ssize_t smb_time_audit_pread_recv(struct tevent_req *req,
788 : struct vfs_aio_state *vfs_aio_state)
789 : {
790 8805 : struct smb_time_audit_pread_state *state = tevent_req_data(
791 : req, struct smb_time_audit_pread_state);
792 : double timediff;
793 :
794 8805 : timediff = state->vfs_aio_state.duration * 1.0e-9;
795 :
796 8805 : if (timediff > audit_timeout) {
797 0 : smb_time_audit_log_fsp("async pread", timediff, state->fsp);
798 : }
799 :
800 8805 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
801 0 : return -1;
802 : }
803 8805 : *vfs_aio_state = state->vfs_aio_state;
804 8805 : return state->ret;
805 : }
806 :
807 226 : 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 226 : clock_gettime_mono(&ts1);
817 226 : result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
818 226 : clock_gettime_mono(&ts2);
819 226 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
820 :
821 226 : if (timediff > audit_timeout) {
822 0 : smb_time_audit_log_fsp("pwrite", timediff, fsp);
823 : }
824 :
825 226 : 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 99168 : 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 99168 : req = tevent_req_create(mem_ctx, &state,
845 : struct smb_time_audit_pwrite_state);
846 99168 : if (req == NULL) {
847 0 : return NULL;
848 : }
849 99168 : state->fsp = fsp;
850 :
851 99168 : subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
852 : n, offset);
853 99168 : if (tevent_req_nomem(subreq, req)) {
854 0 : return tevent_req_post(req, ev);
855 : }
856 99168 : tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
857 99168 : return req;
858 : }
859 :
860 99168 : static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
861 : {
862 99168 : struct tevent_req *req = tevent_req_callback_data(
863 : subreq, struct tevent_req);
864 99168 : struct smb_time_audit_pwrite_state *state = tevent_req_data(
865 : req, struct smb_time_audit_pwrite_state);
866 :
867 99168 : state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
868 99168 : TALLOC_FREE(subreq);
869 99168 : tevent_req_done(req);
870 99168 : }
871 :
872 99168 : static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req,
873 : struct vfs_aio_state *vfs_aio_state)
874 : {
875 99168 : struct smb_time_audit_pwrite_state *state = tevent_req_data(
876 : req, struct smb_time_audit_pwrite_state);
877 : double timediff;
878 :
879 99168 : timediff = state->vfs_aio_state.duration * 1.0e-9;
880 :
881 99168 : if (timediff > audit_timeout) {
882 0 : smb_time_audit_log_fsp("async pwrite", timediff, state->fsp);
883 : }
884 :
885 99168 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
886 0 : return -1;
887 : }
888 99168 : *vfs_aio_state = state->vfs_aio_state;
889 99168 : return state->ret;
890 : }
891 :
892 222 : 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 222 : clock_gettime_mono(&ts1);
901 222 : result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
902 222 : clock_gettime_mono(&ts2);
903 222 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
904 :
905 222 : if (timediff > audit_timeout) {
906 0 : smb_time_audit_log_fsp("lseek", timediff, fsp);
907 : }
908 :
909 222 : 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 398 : 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 398 : struct smb_filename *new_full_fname = NULL;
964 :
965 398 : new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
966 : dstfsp,
967 : newname);
968 398 : if (new_full_fname == NULL) {
969 0 : errno = ENOMEM;
970 0 : return -1;
971 : }
972 398 : clock_gettime_mono(&ts1);
973 398 : result = SMB_VFS_NEXT_RENAMEAT(handle,
974 : srcfsp,
975 : oldname,
976 : dstfsp,
977 : newname);
978 398 : clock_gettime_mono(&ts2);
979 398 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
980 :
981 398 : if (timediff > audit_timeout) {
982 0 : smb_time_audit_log_smb_fname("renameat",
983 : timediff,
984 : new_full_fname);
985 : }
986 :
987 398 : TALLOC_FREE(new_full_fname);
988 398 : 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 116 : 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 116 : req = tevent_req_create(mem_ctx, &state,
1007 : struct smb_time_audit_fsync_state);
1008 116 : if (req == NULL) {
1009 0 : return NULL;
1010 : }
1011 116 : state->fsp = fsp;
1012 :
1013 116 : subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1014 116 : if (tevent_req_nomem(subreq, req)) {
1015 0 : return tevent_req_post(req, ev);
1016 : }
1017 116 : tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
1018 116 : return req;
1019 : }
1020 :
1021 116 : static void smb_time_audit_fsync_done(struct tevent_req *subreq)
1022 : {
1023 116 : struct tevent_req *req = tevent_req_callback_data(
1024 : subreq, struct tevent_req);
1025 116 : struct smb_time_audit_fsync_state *state = tevent_req_data(
1026 : req, struct smb_time_audit_fsync_state);
1027 :
1028 116 : state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1029 116 : TALLOC_FREE(subreq);
1030 116 : tevent_req_done(req);
1031 116 : }
1032 :
1033 116 : static int smb_time_audit_fsync_recv(struct tevent_req *req,
1034 : struct vfs_aio_state *vfs_aio_state)
1035 : {
1036 116 : struct smb_time_audit_fsync_state *state = tevent_req_data(
1037 : req, struct smb_time_audit_fsync_state);
1038 : double timediff;
1039 :
1040 116 : timediff = state->vfs_aio_state.duration * 1.0e-9;
1041 :
1042 116 : if (timediff > audit_timeout) {
1043 0 : smb_time_audit_log_fsp("async fsync", timediff, state->fsp);
1044 : }
1045 :
1046 116 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1047 0 : return -1;
1048 : }
1049 116 : *vfs_aio_state = state->vfs_aio_state;
1050 116 : return state->ret;
1051 : }
1052 :
1053 16386258 : 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 16386258 : clock_gettime_mono(&ts1);
1061 16386258 : result = SMB_VFS_NEXT_STAT(handle, fname);
1062 16386258 : clock_gettime_mono(&ts2);
1063 16386258 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1064 :
1065 16386258 : if (timediff > audit_timeout) {
1066 0 : smb_time_audit_log_smb_fname("stat", timediff, fname);
1067 : }
1068 :
1069 16386258 : return result;
1070 : }
1071 :
1072 33443204 : 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 33443204 : clock_gettime_mono(&ts1);
1080 33443204 : result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1081 33443204 : clock_gettime_mono(&ts2);
1082 33443204 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1083 :
1084 33443204 : if (timediff > audit_timeout) {
1085 0 : smb_time_audit_log_fsp("fstat", timediff, fsp);
1086 : }
1087 :
1088 33443204 : return result;
1089 : }
1090 :
1091 11412 : 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 11412 : clock_gettime_mono(&ts1);
1099 11412 : result = SMB_VFS_NEXT_LSTAT(handle, path);
1100 11412 : clock_gettime_mono(&ts2);
1101 11412 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1102 :
1103 11412 : if (timediff > audit_timeout) {
1104 0 : smb_time_audit_log_smb_fname("lstat", timediff, path);
1105 : }
1106 :
1107 11412 : return result;
1108 : }
1109 :
1110 588112 : static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
1111 : files_struct *fsp,
1112 : const SMB_STRUCT_STAT *sbuf)
1113 : {
1114 : uint64_t result;
1115 : struct timespec ts1,ts2;
1116 : double timediff;
1117 :
1118 588112 : clock_gettime_mono(&ts1);
1119 588112 : result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1120 588112 : clock_gettime_mono(&ts2);
1121 588112 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1122 :
1123 588112 : if (timediff > audit_timeout) {
1124 0 : smb_time_audit_log_fsp("get_alloc_size", timediff, fsp);
1125 : }
1126 :
1127 588112 : return result;
1128 : }
1129 :
1130 80968 : static int smb_time_audit_unlinkat(vfs_handle_struct *handle,
1131 : struct files_struct *dirfsp,
1132 : const struct smb_filename *path,
1133 : int flags)
1134 : {
1135 80968 : struct smb_filename *full_fname = NULL;
1136 : int result;
1137 : struct timespec ts1,ts2;
1138 : double timediff;
1139 :
1140 80968 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1141 : dirfsp,
1142 : path);
1143 80968 : if (full_fname == NULL) {
1144 0 : return -1;
1145 : }
1146 :
1147 80968 : clock_gettime_mono(&ts1);
1148 80968 : result = SMB_VFS_NEXT_UNLINKAT(handle,
1149 : dirfsp,
1150 : path,
1151 : flags);
1152 80968 : clock_gettime_mono(&ts2);
1153 80968 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1154 :
1155 80968 : if (timediff > audit_timeout) {
1156 0 : smb_time_audit_log_smb_fname("unlinkat", timediff, full_fname);
1157 : }
1158 :
1159 80968 : TALLOC_FREE(full_fname);
1160 80968 : return result;
1161 : }
1162 :
1163 12 : static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1164 : mode_t mode)
1165 : {
1166 : int result;
1167 : struct timespec ts1,ts2;
1168 : double timediff;
1169 :
1170 12 : clock_gettime_mono(&ts1);
1171 12 : result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1172 12 : clock_gettime_mono(&ts2);
1173 12 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1174 :
1175 12 : if (timediff > audit_timeout) {
1176 0 : smb_time_audit_log_fsp("fchmod", timediff, fsp);
1177 : }
1178 :
1179 12 : return result;
1180 : }
1181 :
1182 0 : static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1183 : uid_t uid, gid_t gid)
1184 : {
1185 : int result;
1186 : struct timespec ts1,ts2;
1187 : double timediff;
1188 :
1189 0 : clock_gettime_mono(&ts1);
1190 0 : result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1191 0 : clock_gettime_mono(&ts2);
1192 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1193 :
1194 0 : if (timediff > audit_timeout) {
1195 0 : smb_time_audit_log_fsp("fchown", timediff, fsp);
1196 : }
1197 :
1198 0 : return result;
1199 : }
1200 :
1201 0 : static int smb_time_audit_lchown(vfs_handle_struct *handle,
1202 : const struct smb_filename *smb_fname,
1203 : uid_t uid,
1204 : gid_t gid)
1205 : {
1206 : int result;
1207 : struct timespec ts1,ts2;
1208 : double timediff;
1209 :
1210 0 : clock_gettime_mono(&ts1);
1211 0 : result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1212 0 : clock_gettime_mono(&ts2);
1213 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1214 :
1215 0 : if (timediff > audit_timeout) {
1216 0 : smb_time_audit_log_fname("lchown",
1217 : timediff,
1218 0 : smb_fname->base_name);
1219 : }
1220 :
1221 0 : return result;
1222 : }
1223 :
1224 4094108 : static int smb_time_audit_chdir(vfs_handle_struct *handle,
1225 : const struct smb_filename *smb_fname)
1226 : {
1227 : int result;
1228 : struct timespec ts1,ts2;
1229 : double timediff;
1230 :
1231 4094108 : clock_gettime_mono(&ts1);
1232 4094108 : result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1233 4094108 : clock_gettime_mono(&ts2);
1234 4094108 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1235 :
1236 4094108 : if (timediff > audit_timeout) {
1237 0 : smb_time_audit_log_fname("chdir",
1238 : timediff,
1239 0 : smb_fname->base_name);
1240 : }
1241 :
1242 4094108 : return result;
1243 : }
1244 :
1245 75918 : static struct smb_filename *smb_time_audit_getwd(vfs_handle_struct *handle,
1246 : TALLOC_CTX *mem_ctx)
1247 : {
1248 : struct smb_filename *result;
1249 : struct timespec ts1,ts2;
1250 : double timediff;
1251 :
1252 75918 : clock_gettime_mono(&ts1);
1253 75918 : result = SMB_VFS_NEXT_GETWD(handle, mem_ctx);
1254 75918 : clock_gettime_mono(&ts2);
1255 75918 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1256 :
1257 75918 : if (timediff > audit_timeout) {
1258 0 : smb_time_audit_log("getwd", timediff);
1259 : }
1260 :
1261 75918 : return result;
1262 : }
1263 :
1264 6708 : static int smb_time_audit_fntimes(vfs_handle_struct *handle,
1265 : files_struct *fsp,
1266 : struct smb_file_time *ft)
1267 : {
1268 : int result;
1269 : struct timespec ts1,ts2;
1270 : double timediff;
1271 :
1272 6708 : clock_gettime_mono(&ts1);
1273 6708 : result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1274 6708 : clock_gettime_mono(&ts2);
1275 6708 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
1276 :
1277 6708 : if (timediff > audit_timeout) {
1278 0 : smb_time_audit_log_fsp("fntimes", timediff, fsp);
1279 : }
1280 :
1281 6708 : return result;
1282 : }
1283 :
1284 479 : static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
1285 : files_struct *fsp,
1286 : off_t len)
1287 : {
1288 : int result;
1289 : struct timespec ts1,ts2;
1290 : double timediff;
1291 :
1292 479 : clock_gettime_mono(&ts1);
1293 479 : result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1294 479 : clock_gettime_mono(&ts2);
1295 479 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1296 :
1297 479 : if (timediff > audit_timeout) {
1298 0 : smb_time_audit_log_fsp("ftruncate", timediff, fsp);
1299 : }
1300 :
1301 479 : return result;
1302 : }
1303 :
1304 94 : static int smb_time_audit_fallocate(vfs_handle_struct *handle,
1305 : files_struct *fsp,
1306 : uint32_t mode,
1307 : off_t offset,
1308 : off_t len)
1309 : {
1310 : int result;
1311 94 : int saved_errno = 0;
1312 : struct timespec ts1,ts2;
1313 : double timediff;
1314 :
1315 94 : clock_gettime_mono(&ts1);
1316 94 : result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1317 94 : if (result == -1) {
1318 0 : saved_errno = errno;
1319 : }
1320 94 : clock_gettime_mono(&ts2);
1321 94 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1322 :
1323 94 : if (timediff > audit_timeout) {
1324 0 : smb_time_audit_log_fsp("fallocate", timediff, fsp);
1325 : }
1326 94 : if (result == -1) {
1327 0 : errno = saved_errno;
1328 : }
1329 94 : return result;
1330 : }
1331 :
1332 4066 : static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1333 : int op, off_t offset, off_t count,
1334 : int type)
1335 : {
1336 : bool result;
1337 : struct timespec ts1,ts2;
1338 : double timediff;
1339 :
1340 4066 : clock_gettime_mono(&ts1);
1341 4066 : result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1342 4066 : clock_gettime_mono(&ts2);
1343 4066 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1344 :
1345 4066 : if (timediff > audit_timeout) {
1346 0 : smb_time_audit_log_fsp("lock", timediff, fsp);
1347 : }
1348 :
1349 4066 : return result;
1350 : }
1351 :
1352 0 : static int smb_time_audit_filesystem_sharemode(struct vfs_handle_struct *handle,
1353 : struct files_struct *fsp,
1354 : uint32_t share_access,
1355 : uint32_t access_mask)
1356 : {
1357 : int result;
1358 : struct timespec ts1,ts2;
1359 : double timediff;
1360 :
1361 0 : clock_gettime_mono(&ts1);
1362 0 : result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1363 : fsp,
1364 : share_access,
1365 : access_mask);
1366 0 : clock_gettime_mono(&ts2);
1367 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1368 :
1369 0 : if (timediff > audit_timeout) {
1370 0 : smb_time_audit_log_fsp("filesystem_sharemode", timediff, fsp);
1371 : }
1372 :
1373 0 : return result;
1374 : }
1375 :
1376 183714 : static int smb_time_audit_fcntl(struct vfs_handle_struct *handle,
1377 : struct files_struct *fsp,
1378 : int cmd, va_list cmd_arg)
1379 : {
1380 : void *arg;
1381 : va_list dup_cmd_arg;
1382 : int result;
1383 : struct timespec ts1,ts2;
1384 : double timediff;
1385 :
1386 183714 : va_copy(dup_cmd_arg, cmd_arg);
1387 183714 : arg = va_arg(dup_cmd_arg, void *);
1388 183714 : clock_gettime_mono(&ts1);
1389 183714 : result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1390 183714 : clock_gettime_mono(&ts2);
1391 183714 : va_end(dup_cmd_arg);
1392 :
1393 183714 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1394 183714 : if (timediff > audit_timeout) {
1395 0 : smb_time_audit_log_fsp("fcntl", timediff, fsp);
1396 : }
1397 :
1398 183714 : return result;
1399 : }
1400 :
1401 0 : static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
1402 : files_struct *fsp,
1403 : int leasetype)
1404 : {
1405 : int result;
1406 : struct timespec ts1,ts2;
1407 : double timediff;
1408 :
1409 0 : clock_gettime_mono(&ts1);
1410 0 : result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1411 0 : clock_gettime_mono(&ts2);
1412 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1413 :
1414 0 : if (timediff > audit_timeout) {
1415 0 : smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
1416 : }
1417 :
1418 0 : return result;
1419 : }
1420 :
1421 108287 : static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1422 : files_struct *fsp,
1423 : off_t *poffset, off_t *pcount,
1424 : int *ptype, pid_t *ppid)
1425 : {
1426 : bool result;
1427 : struct timespec ts1,ts2;
1428 : double timediff;
1429 :
1430 108287 : clock_gettime_mono(&ts1);
1431 108287 : result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1432 : ppid);
1433 108287 : clock_gettime_mono(&ts2);
1434 108287 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1435 :
1436 108287 : if (timediff > audit_timeout) {
1437 0 : smb_time_audit_log_fsp("getlock", timediff, fsp);
1438 : }
1439 :
1440 108287 : return result;
1441 : }
1442 :
1443 6 : static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
1444 : const struct smb_filename *link_contents,
1445 : struct files_struct *dirfsp,
1446 : const struct smb_filename *new_smb_fname)
1447 : {
1448 6 : struct smb_filename *full_fname = NULL;
1449 : int result;
1450 : struct timespec ts1,ts2;
1451 : double timediff;
1452 :
1453 6 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1454 : dirfsp,
1455 : new_smb_fname);
1456 6 : if (full_fname == NULL) {
1457 0 : errno = ENOMEM;
1458 0 : return -1;
1459 : }
1460 :
1461 6 : clock_gettime_mono(&ts1);
1462 6 : result = SMB_VFS_NEXT_SYMLINKAT(handle,
1463 : link_contents,
1464 : dirfsp,
1465 : new_smb_fname);
1466 6 : clock_gettime_mono(&ts2);
1467 6 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1468 :
1469 6 : if (timediff > audit_timeout) {
1470 0 : smb_time_audit_log_fname("symlinkat", timediff,
1471 0 : full_fname->base_name);
1472 : }
1473 :
1474 6 : TALLOC_FREE(full_fname);
1475 6 : return result;
1476 : }
1477 :
1478 132 : static int smb_time_audit_readlinkat(vfs_handle_struct *handle,
1479 : const struct files_struct *dirfsp,
1480 : const struct smb_filename *smb_fname,
1481 : char *buf,
1482 : size_t bufsiz)
1483 : {
1484 132 : struct smb_filename *full_fname = NULL;
1485 : int result;
1486 : struct timespec ts1,ts2;
1487 : double timediff;
1488 :
1489 132 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1490 : dirfsp,
1491 : smb_fname);
1492 132 : if (full_fname == NULL) {
1493 0 : errno = ENOMEM;
1494 0 : return -1;
1495 : }
1496 :
1497 132 : clock_gettime_mono(&ts1);
1498 132 : result = SMB_VFS_NEXT_READLINKAT(handle,
1499 : dirfsp,
1500 : smb_fname,
1501 : buf,
1502 : bufsiz);
1503 132 : clock_gettime_mono(&ts2);
1504 132 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1505 :
1506 132 : if (timediff > audit_timeout) {
1507 0 : smb_time_audit_log_fname("readlinkat", timediff,
1508 0 : full_fname->base_name);
1509 : }
1510 :
1511 132 : TALLOC_FREE(full_fname);
1512 132 : return result;
1513 : }
1514 :
1515 10 : static int smb_time_audit_linkat(vfs_handle_struct *handle,
1516 : files_struct *srcfsp,
1517 : const struct smb_filename *old_smb_fname,
1518 : files_struct *dstfsp,
1519 : const struct smb_filename *new_smb_fname,
1520 : int flags)
1521 : {
1522 10 : struct smb_filename *new_full_fname = NULL;
1523 : int result;
1524 : struct timespec ts1,ts2;
1525 : double timediff;
1526 :
1527 10 : new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1528 : dstfsp,
1529 : new_smb_fname);
1530 10 : if (new_full_fname == NULL) {
1531 0 : errno = ENOMEM;
1532 0 : return -1;
1533 : }
1534 :
1535 10 : clock_gettime_mono(&ts1);
1536 10 : result = SMB_VFS_NEXT_LINKAT(handle,
1537 : srcfsp,
1538 : old_smb_fname,
1539 : dstfsp,
1540 : new_smb_fname,
1541 : flags);
1542 10 : clock_gettime_mono(&ts2);
1543 10 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1544 :
1545 10 : if (timediff > audit_timeout) {
1546 0 : smb_time_audit_log_fname("linkat", timediff,
1547 0 : new_full_fname->base_name);
1548 : }
1549 :
1550 10 : TALLOC_FREE(new_full_fname);
1551 10 : return result;
1552 : }
1553 :
1554 0 : static int smb_time_audit_mknodat(vfs_handle_struct *handle,
1555 : files_struct *dirfsp,
1556 : const struct smb_filename *smb_fname,
1557 : mode_t mode,
1558 : SMB_DEV_T dev)
1559 : {
1560 0 : struct smb_filename *full_fname = NULL;
1561 : int result;
1562 : struct timespec ts1,ts2;
1563 : double timediff;
1564 :
1565 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1566 : dirfsp,
1567 : smb_fname);
1568 0 : if (full_fname == NULL) {
1569 0 : errno = ENOMEM;
1570 0 : return -1;
1571 : }
1572 :
1573 0 : clock_gettime_mono(&ts1);
1574 0 : result = SMB_VFS_NEXT_MKNODAT(handle,
1575 : dirfsp,
1576 : smb_fname,
1577 : mode,
1578 : dev);
1579 0 : clock_gettime_mono(&ts2);
1580 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1581 :
1582 0 : if (timediff > audit_timeout) {
1583 0 : smb_time_audit_log_smb_fname("mknodat", timediff, full_fname);
1584 : }
1585 :
1586 0 : TALLOC_FREE(full_fname);
1587 0 : return result;
1588 : }
1589 :
1590 6002829 : static struct smb_filename *smb_time_audit_realpath(vfs_handle_struct *handle,
1591 : TALLOC_CTX *ctx,
1592 : const struct smb_filename *smb_fname)
1593 : {
1594 : struct smb_filename *result_fname;
1595 : struct timespec ts1,ts2;
1596 : double timediff;
1597 :
1598 6002829 : clock_gettime_mono(&ts1);
1599 6002829 : result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1600 6002829 : clock_gettime_mono(&ts2);
1601 6002829 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1602 :
1603 6002829 : if (timediff > audit_timeout) {
1604 0 : smb_time_audit_log_fname("realpath", timediff,
1605 0 : smb_fname->base_name);
1606 : }
1607 :
1608 6002829 : return result_fname;
1609 : }
1610 :
1611 0 : static int smb_time_audit_fchflags(vfs_handle_struct *handle,
1612 : struct files_struct *fsp,
1613 : unsigned int flags)
1614 : {
1615 : int result;
1616 : struct timespec ts1,ts2;
1617 : double timediff;
1618 :
1619 0 : clock_gettime_mono(&ts1);
1620 0 : result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
1621 0 : clock_gettime_mono(&ts2);
1622 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1623 :
1624 0 : if (timediff > audit_timeout) {
1625 0 : smb_time_audit_log_smb_fname("chflags",
1626 : timediff,
1627 0 : fsp->fsp_name);
1628 : }
1629 :
1630 0 : return result;
1631 : }
1632 :
1633 40258263 : static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1634 : const SMB_STRUCT_STAT *sbuf)
1635 : {
1636 : struct file_id id_zero;
1637 : struct file_id result;
1638 : struct timespec ts1,ts2;
1639 : double timediff;
1640 :
1641 40258263 : ZERO_STRUCT(id_zero);
1642 :
1643 40258263 : clock_gettime_mono(&ts1);
1644 40258263 : result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1645 40258263 : clock_gettime_mono(&ts2);
1646 40258263 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1647 :
1648 40258263 : if (timediff > audit_timeout) {
1649 0 : smb_time_audit_log("file_id_create", timediff);
1650 : }
1651 :
1652 40258263 : return result;
1653 : }
1654 :
1655 211847 : static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct *handle,
1656 : const SMB_STRUCT_STAT *sbuf)
1657 : {
1658 : uint64_t result;
1659 : struct timespec ts1,ts2;
1660 : double timediff;
1661 :
1662 211847 : clock_gettime_mono(&ts1);
1663 211847 : result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1664 211847 : clock_gettime_mono(&ts2);
1665 211847 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1666 :
1667 211847 : if (timediff > audit_timeout) {
1668 0 : smb_time_audit_log("fs_file_id", timediff);
1669 : }
1670 :
1671 211847 : return result;
1672 : }
1673 :
1674 168822 : static NTSTATUS smb_time_audit_fstreaminfo(vfs_handle_struct *handle,
1675 : struct files_struct *fsp,
1676 : TALLOC_CTX *mem_ctx,
1677 : unsigned int *pnum_streams,
1678 : struct stream_struct **pstreams)
1679 : {
1680 : NTSTATUS result;
1681 : struct timespec ts1,ts2;
1682 : double timediff;
1683 :
1684 168822 : clock_gettime_mono(&ts1);
1685 168822 : result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
1686 : pnum_streams, pstreams);
1687 168822 : clock_gettime_mono(&ts2);
1688 168822 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1689 :
1690 168822 : if (timediff > audit_timeout) {
1691 0 : smb_time_audit_log_fsp("fstreaminfo", timediff, fsp);
1692 : }
1693 :
1694 168822 : return result;
1695 : }
1696 :
1697 130699 : static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
1698 : const struct smb_filename *path,
1699 : const char *name,
1700 : TALLOC_CTX *mem_ctx,
1701 : char **found_name)
1702 : {
1703 : int result;
1704 : struct timespec ts1,ts2;
1705 : double timediff;
1706 :
1707 130699 : clock_gettime_mono(&ts1);
1708 130699 : result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1709 : found_name);
1710 130699 : clock_gettime_mono(&ts2);
1711 130699 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1712 :
1713 130699 : if (timediff > audit_timeout) {
1714 0 : smb_time_audit_log_fname("get_real_filename",
1715 0 : timediff, path->base_name);
1716 : }
1717 :
1718 130699 : return result;
1719 : }
1720 :
1721 5729767 : static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
1722 : const struct smb_filename *smb_fname)
1723 : {
1724 : const char *result;
1725 : struct timespec ts1,ts2;
1726 : double timediff;
1727 :
1728 5729767 : clock_gettime_mono(&ts1);
1729 5729767 : result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1730 5729767 : clock_gettime_mono(&ts2);
1731 5729767 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1732 :
1733 5729767 : if (timediff > audit_timeout) {
1734 0 : smb_time_audit_log_fname("connectpath", timediff,
1735 0 : smb_fname->base_name);
1736 : }
1737 :
1738 5729767 : return result;
1739 : }
1740 :
1741 5629 : static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1742 : struct byte_range_lock *br_lck,
1743 : struct lock_struct *plock)
1744 : {
1745 : NTSTATUS result;
1746 : struct timespec ts1,ts2;
1747 : double timediff;
1748 :
1749 5629 : clock_gettime_mono(&ts1);
1750 5629 : result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1751 5629 : clock_gettime_mono(&ts2);
1752 5629 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1753 :
1754 5629 : if (timediff > audit_timeout) {
1755 0 : smb_time_audit_log_fsp("brl_lock_windows", timediff,
1756 0 : brl_fsp(br_lck));
1757 : }
1758 :
1759 5629 : return result;
1760 : }
1761 :
1762 2769 : static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1763 : struct byte_range_lock *br_lck,
1764 : const struct lock_struct *plock)
1765 : {
1766 : bool result;
1767 : struct timespec ts1,ts2;
1768 : double timediff;
1769 :
1770 2769 : clock_gettime_mono(&ts1);
1771 2769 : result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1772 2769 : clock_gettime_mono(&ts2);
1773 2769 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1774 :
1775 2769 : if (timediff > audit_timeout) {
1776 0 : smb_time_audit_log_fsp("brl_unlock_windows", timediff,
1777 0 : brl_fsp(br_lck));
1778 : }
1779 :
1780 2769 : return result;
1781 : }
1782 :
1783 108831 : static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct *handle,
1784 : struct files_struct *fsp,
1785 : struct lock_struct *plock)
1786 : {
1787 : bool result;
1788 : struct timespec ts1,ts2;
1789 : double timediff;
1790 :
1791 108831 : clock_gettime_mono(&ts1);
1792 108831 : result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1793 108831 : clock_gettime_mono(&ts2);
1794 108831 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1795 :
1796 108831 : if (timediff > audit_timeout) {
1797 0 : smb_time_audit_log_fsp("strict_lock_check", timediff, fsp);
1798 : }
1799 :
1800 108831 : return result;
1801 : }
1802 :
1803 78057824 : static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1804 : const char *name,
1805 : enum vfs_translate_direction direction,
1806 : TALLOC_CTX *mem_ctx,
1807 : char **mapped_name)
1808 : {
1809 : NTSTATUS result;
1810 : struct timespec ts1,ts2;
1811 : double timediff;
1812 :
1813 78057824 : clock_gettime_mono(&ts1);
1814 78057824 : result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1815 : mapped_name);
1816 78057824 : clock_gettime_mono(&ts2);
1817 78057824 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1818 :
1819 78057824 : if (timediff > audit_timeout) {
1820 0 : smb_time_audit_log_fname("translate_name", timediff, name);
1821 : }
1822 :
1823 78057824 : return result;
1824 : }
1825 :
1826 896924 : static NTSTATUS smb_time_audit_parent_pathname(struct vfs_handle_struct *handle,
1827 : TALLOC_CTX *mem_ctx,
1828 : const struct smb_filename *smb_fname_in,
1829 : struct smb_filename **parent_dir_out,
1830 : struct smb_filename **atname_out)
1831 : {
1832 : NTSTATUS result;
1833 : struct timespec ts1,ts2;
1834 : double timediff;
1835 :
1836 896924 : clock_gettime_mono(&ts1);
1837 896924 : result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
1838 : mem_ctx,
1839 : smb_fname_in,
1840 : parent_dir_out,
1841 : atname_out);
1842 896924 : clock_gettime_mono(&ts2);
1843 896924 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1844 :
1845 896924 : if (timediff > audit_timeout) {
1846 0 : smb_time_audit_log_fname("parent_pathname",
1847 : timediff,
1848 0 : smb_fname_in->base_name);
1849 : }
1850 :
1851 896924 : return result;
1852 : }
1853 :
1854 426 : static NTSTATUS smb_time_audit_fsctl(struct vfs_handle_struct *handle,
1855 : struct files_struct *fsp,
1856 : TALLOC_CTX *ctx,
1857 : uint32_t function,
1858 : uint16_t req_flags,
1859 : const uint8_t *_in_data,
1860 : uint32_t in_len,
1861 : uint8_t **_out_data,
1862 : uint32_t max_out_len,
1863 : uint32_t *out_len)
1864 : {
1865 : NTSTATUS result;
1866 : struct timespec ts1,ts2;
1867 : double timediff;
1868 :
1869 426 : clock_gettime_mono(&ts1);
1870 426 : result = SMB_VFS_NEXT_FSCTL(handle,
1871 : fsp,
1872 : ctx,
1873 : function,
1874 : req_flags,
1875 : _in_data,
1876 : in_len,
1877 : _out_data,
1878 : max_out_len,
1879 : out_len);
1880 426 : clock_gettime_mono(&ts2);
1881 426 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1882 :
1883 426 : if (timediff > audit_timeout) {
1884 0 : smb_time_audit_log_fsp("fsctl", timediff, fsp);
1885 : }
1886 :
1887 426 : return result;
1888 : }
1889 :
1890 : struct smb_time_audit_get_dos_attributes_state {
1891 : struct vfs_aio_state aio_state;
1892 : files_struct *dir_fsp;
1893 : const struct smb_filename *smb_fname;
1894 : uint32_t dosmode;
1895 : };
1896 :
1897 : static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq);
1898 :
1899 0 : static struct tevent_req *smb_time_audit_get_dos_attributes_send(
1900 : TALLOC_CTX *mem_ctx,
1901 : struct tevent_context *ev,
1902 : struct vfs_handle_struct *handle,
1903 : files_struct *dir_fsp,
1904 : struct smb_filename *smb_fname)
1905 : {
1906 0 : struct tevent_req *req = NULL;
1907 0 : struct smb_time_audit_get_dos_attributes_state *state = NULL;
1908 0 : struct tevent_req *subreq = NULL;
1909 :
1910 0 : req = tevent_req_create(mem_ctx, &state,
1911 : struct smb_time_audit_get_dos_attributes_state);
1912 0 : if (req == NULL) {
1913 0 : return NULL;
1914 : }
1915 0 : *state = (struct smb_time_audit_get_dos_attributes_state) {
1916 : .dir_fsp = dir_fsp,
1917 : .smb_fname = smb_fname,
1918 : };
1919 :
1920 0 : subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
1921 : ev,
1922 : handle,
1923 : dir_fsp,
1924 : smb_fname);
1925 0 : if (tevent_req_nomem(subreq, req)) {
1926 0 : return tevent_req_post(req, ev);
1927 : }
1928 0 : tevent_req_set_callback(subreq,
1929 : smb_time_audit_get_dos_attributes_done,
1930 : req);
1931 :
1932 0 : return req;
1933 : }
1934 :
1935 0 : static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq)
1936 : {
1937 0 : struct tevent_req *req =
1938 0 : tevent_req_callback_data(subreq,
1939 : struct tevent_req);
1940 0 : struct smb_time_audit_get_dos_attributes_state *state =
1941 0 : tevent_req_data(req,
1942 : struct smb_time_audit_get_dos_attributes_state);
1943 : NTSTATUS status;
1944 :
1945 0 : status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
1946 : &state->aio_state,
1947 : &state->dosmode);
1948 0 : TALLOC_FREE(subreq);
1949 0 : if (tevent_req_nterror(req, status)) {
1950 0 : return;
1951 : }
1952 :
1953 0 : tevent_req_done(req);
1954 0 : return;
1955 : }
1956 :
1957 0 : static NTSTATUS smb_time_audit_get_dos_attributes_recv(struct tevent_req *req,
1958 : struct vfs_aio_state *aio_state,
1959 : uint32_t *dosmode)
1960 : {
1961 0 : struct smb_time_audit_get_dos_attributes_state *state =
1962 0 : tevent_req_data(req,
1963 : struct smb_time_audit_get_dos_attributes_state);
1964 : NTSTATUS status;
1965 : double timediff;
1966 :
1967 0 : timediff = state->aio_state.duration * 1.0e-9;
1968 :
1969 0 : if (timediff > audit_timeout) {
1970 0 : smb_time_audit_log_at("async get_dos_attributes",
1971 : timediff,
1972 0 : state->dir_fsp,
1973 : state->smb_fname);
1974 : }
1975 :
1976 0 : if (tevent_req_is_nterror(req, &status)) {
1977 0 : tevent_req_received(req);
1978 0 : return status;
1979 : }
1980 :
1981 0 : *aio_state = state->aio_state;
1982 0 : *dosmode = state->dosmode;
1983 0 : tevent_req_received(req);
1984 0 : return NT_STATUS_OK;
1985 : }
1986 :
1987 597711 : static NTSTATUS smb_time_fget_dos_attributes(struct vfs_handle_struct *handle,
1988 : struct files_struct *fsp,
1989 : uint32_t *dosmode)
1990 : {
1991 : NTSTATUS result;
1992 : struct timespec ts1,ts2;
1993 : double timediff;
1994 :
1995 597711 : clock_gettime_mono(&ts1);
1996 597711 : result = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
1997 : fsp,
1998 : dosmode);
1999 597711 : clock_gettime_mono(&ts2);
2000 597711 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2001 :
2002 597711 : if (timediff > audit_timeout) {
2003 0 : smb_time_audit_log_fsp("fget_dos_attributes", timediff, fsp);
2004 : }
2005 :
2006 597711 : return result;
2007 : }
2008 :
2009 83359 : static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
2010 : struct files_struct *fsp,
2011 : uint32_t dosmode)
2012 : {
2013 : NTSTATUS result;
2014 : struct timespec ts1,ts2;
2015 : double timediff;
2016 :
2017 83359 : clock_gettime_mono(&ts1);
2018 83359 : result = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2019 : fsp,
2020 : dosmode);
2021 83359 : clock_gettime_mono(&ts2);
2022 83359 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2023 :
2024 83359 : if (timediff > audit_timeout) {
2025 0 : smb_time_audit_log_fsp("fset_dos_attributes", timediff, fsp);
2026 : }
2027 :
2028 83359 : return result;
2029 : }
2030 :
2031 : struct time_audit_offload_read_state {
2032 : struct vfs_handle_struct *handle;
2033 : struct timespec ts_send;
2034 : DATA_BLOB token_blob;
2035 : };
2036 :
2037 : static void smb_time_audit_offload_read_done(struct tevent_req *subreq);
2038 :
2039 120 : static struct tevent_req *smb_time_audit_offload_read_send(
2040 : TALLOC_CTX *mem_ctx,
2041 : struct tevent_context *ev,
2042 : struct vfs_handle_struct *handle,
2043 : struct files_struct *fsp,
2044 : uint32_t fsctl,
2045 : uint32_t ttl,
2046 : off_t offset,
2047 : size_t to_copy)
2048 : {
2049 120 : struct tevent_req *req = NULL;
2050 120 : struct tevent_req *subreq = NULL;
2051 120 : struct time_audit_offload_read_state *state = NULL;
2052 :
2053 120 : req = tevent_req_create(mem_ctx, &state,
2054 : struct time_audit_offload_read_state);
2055 120 : if (req == NULL) {
2056 0 : return NULL;
2057 : }
2058 120 : state->handle = handle;
2059 120 : clock_gettime_mono(&state->ts_send);
2060 :
2061 120 : subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev,
2062 : handle, fsp,
2063 : fsctl, ttl,
2064 : offset, to_copy);
2065 120 : if (tevent_req_nomem(subreq, req)) {
2066 0 : return tevent_req_post(req, ev);
2067 : }
2068 :
2069 120 : tevent_req_set_callback(subreq, smb_time_audit_offload_read_done, req);
2070 120 : return req;
2071 : }
2072 :
2073 120 : static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
2074 : {
2075 120 : struct tevent_req *req = tevent_req_callback_data(
2076 : subreq, struct tevent_req);
2077 120 : struct time_audit_offload_read_state *state = tevent_req_data(
2078 : req, struct time_audit_offload_read_state);
2079 : NTSTATUS status;
2080 :
2081 120 : status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
2082 : state->handle,
2083 : state,
2084 : &state->token_blob);
2085 120 : TALLOC_FREE(subreq);
2086 120 : if (tevent_req_nterror(req, status)) {
2087 0 : return;
2088 : }
2089 120 : tevent_req_done(req);
2090 : }
2091 :
2092 120 : static NTSTATUS smb_time_audit_offload_read_recv(
2093 : struct tevent_req *req,
2094 : struct vfs_handle_struct *handle,
2095 : TALLOC_CTX *mem_ctx,
2096 : DATA_BLOB *token_blob)
2097 : {
2098 120 : struct time_audit_offload_read_state *state = tevent_req_data(
2099 : req, struct time_audit_offload_read_state);
2100 : struct timespec ts_recv;
2101 : double timediff;
2102 : NTSTATUS status;
2103 :
2104 120 : clock_gettime_mono(&ts_recv);
2105 120 : timediff = nsec_time_diff(&ts_recv, &state->ts_send) * 1.0e-9;
2106 120 : if (timediff > audit_timeout) {
2107 0 : smb_time_audit_log("offload_read", timediff);
2108 : }
2109 :
2110 120 : if (tevent_req_is_nterror(req, &status)) {
2111 0 : tevent_req_received(req);
2112 0 : return status;
2113 : }
2114 :
2115 120 : token_blob->length = state->token_blob.length;
2116 120 : token_blob->data = talloc_move(mem_ctx, &state->token_blob.data);
2117 :
2118 120 : tevent_req_received(req);
2119 120 : return NT_STATUS_OK;
2120 : }
2121 :
2122 : struct time_audit_offload_write_state {
2123 : struct timespec ts_send;
2124 : struct vfs_handle_struct *handle;
2125 : off_t copied;
2126 : };
2127 : static void smb_time_audit_offload_write_done(struct tevent_req *subreq);
2128 :
2129 136 : static struct tevent_req *smb_time_audit_offload_write_send(struct vfs_handle_struct *handle,
2130 : TALLOC_CTX *mem_ctx,
2131 : struct tevent_context *ev,
2132 : uint32_t fsctl,
2133 : DATA_BLOB *token,
2134 : off_t transfer_offset,
2135 : struct files_struct *dest_fsp,
2136 : off_t dest_off,
2137 : off_t num)
2138 : {
2139 : struct tevent_req *req;
2140 : struct tevent_req *subreq;
2141 : struct time_audit_offload_write_state *state;
2142 :
2143 136 : req = tevent_req_create(mem_ctx, &state,
2144 : struct time_audit_offload_write_state);
2145 136 : if (req == NULL) {
2146 0 : return NULL;
2147 : }
2148 :
2149 136 : state->handle = handle;
2150 136 : clock_gettime_mono(&state->ts_send);
2151 136 : subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
2152 : fsctl, token, transfer_offset,
2153 : dest_fsp, dest_off, num);
2154 136 : if (tevent_req_nomem(subreq, req)) {
2155 0 : return tevent_req_post(req, ev);
2156 : }
2157 :
2158 136 : tevent_req_set_callback(subreq, smb_time_audit_offload_write_done, req);
2159 136 : return req;
2160 : }
2161 :
2162 136 : static void smb_time_audit_offload_write_done(struct tevent_req *subreq)
2163 : {
2164 136 : struct tevent_req *req = tevent_req_callback_data(
2165 : subreq, struct tevent_req);
2166 136 : struct time_audit_offload_write_state *state = tevent_req_data(
2167 : req, struct time_audit_offload_write_state);
2168 : NTSTATUS status;
2169 :
2170 136 : status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
2171 : subreq,
2172 : &state->copied);
2173 136 : TALLOC_FREE(subreq);
2174 136 : if (tevent_req_nterror(req, status)) {
2175 36 : return;
2176 : }
2177 100 : tevent_req_done(req);
2178 : }
2179 :
2180 136 : static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *handle,
2181 : struct tevent_req *req,
2182 : off_t *copied)
2183 : {
2184 136 : struct time_audit_offload_write_state *state = tevent_req_data(
2185 : req, struct time_audit_offload_write_state);
2186 : struct timespec ts_recv;
2187 : double timediff;
2188 : NTSTATUS status;
2189 :
2190 136 : clock_gettime_mono(&ts_recv);
2191 136 : timediff = nsec_time_diff(&ts_recv, &state->ts_send)*1.0e-9;
2192 136 : if (timediff > audit_timeout) {
2193 0 : smb_time_audit_log("offload_write", timediff);
2194 : }
2195 :
2196 136 : *copied = state->copied;
2197 136 : if (tevent_req_is_nterror(req, &status)) {
2198 36 : tevent_req_received(req);
2199 36 : return status;
2200 : }
2201 :
2202 100 : tevent_req_received(req);
2203 100 : return NT_STATUS_OK;
2204 : }
2205 :
2206 0 : static NTSTATUS smb_time_audit_fget_compression(vfs_handle_struct *handle,
2207 : TALLOC_CTX *mem_ctx,
2208 : struct files_struct *fsp,
2209 : uint16_t *_compression_fmt)
2210 : {
2211 : NTSTATUS result;
2212 : struct timespec ts1,ts2;
2213 : double timediff;
2214 :
2215 0 : clock_gettime_mono(&ts1);
2216 0 : result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2217 : _compression_fmt);
2218 0 : clock_gettime_mono(&ts2);
2219 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2220 :
2221 0 : if (timediff > audit_timeout) {
2222 0 : smb_time_audit_log_fsp("get_compression",
2223 : timediff, fsp);
2224 : }
2225 :
2226 0 : return result;
2227 : }
2228 :
2229 0 : static NTSTATUS smb_time_audit_set_compression(vfs_handle_struct *handle,
2230 : TALLOC_CTX *mem_ctx,
2231 : struct files_struct *fsp,
2232 : uint16_t compression_fmt)
2233 : {
2234 : NTSTATUS result;
2235 : struct timespec ts1,ts2;
2236 : double timediff;
2237 :
2238 0 : clock_gettime_mono(&ts1);
2239 0 : result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2240 : compression_fmt);
2241 0 : clock_gettime_mono(&ts2);
2242 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2243 :
2244 0 : if (timediff > audit_timeout) {
2245 0 : smb_time_audit_log_fsp("set_compression", timediff, fsp);
2246 : }
2247 :
2248 0 : return result;
2249 : }
2250 :
2251 202565 : static NTSTATUS smb_time_audit_freaddir_attr(struct vfs_handle_struct *handle,
2252 : struct files_struct *fsp,
2253 : TALLOC_CTX *mem_ctx,
2254 : struct readdir_attr_data **pattr_data)
2255 : {
2256 : NTSTATUS status;
2257 : struct timespec ts1, ts2;
2258 : double timediff;
2259 :
2260 202565 : clock_gettime_mono(&ts1);
2261 202565 : status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2262 202565 : clock_gettime_mono(&ts2);
2263 202565 : timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
2264 :
2265 202565 : if (timediff > audit_timeout) {
2266 0 : smb_time_audit_log_fsp("freaddir_attr", timediff, fsp);
2267 : }
2268 :
2269 202565 : return status;
2270 : }
2271 :
2272 193693 : static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
2273 : files_struct *fsp,
2274 : uint32_t security_info,
2275 : TALLOC_CTX *mem_ctx,
2276 : struct security_descriptor **ppdesc)
2277 : {
2278 : NTSTATUS result;
2279 : struct timespec ts1,ts2;
2280 : double timediff;
2281 :
2282 193693 : clock_gettime_mono(&ts1);
2283 193693 : result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2284 : mem_ctx, ppdesc);
2285 193693 : clock_gettime_mono(&ts2);
2286 193693 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2287 :
2288 193693 : if (timediff > audit_timeout) {
2289 0 : smb_time_audit_log_fsp("fget_nt_acl", timediff, fsp);
2290 : }
2291 :
2292 193693 : return result;
2293 : }
2294 :
2295 85561 : static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
2296 : files_struct *fsp,
2297 : uint32_t security_info_sent,
2298 : const struct security_descriptor *psd)
2299 : {
2300 : NTSTATUS result;
2301 : struct timespec ts1,ts2;
2302 : double timediff;
2303 :
2304 85561 : clock_gettime_mono(&ts1);
2305 85561 : result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
2306 : psd);
2307 85561 : clock_gettime_mono(&ts2);
2308 85561 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2309 :
2310 85561 : if (timediff > audit_timeout) {
2311 0 : smb_time_audit_log_fsp("fset_nt_acl", timediff, fsp);
2312 : }
2313 :
2314 85561 : return result;
2315 : }
2316 :
2317 0 : static NTSTATUS smb_time_audit_audit_file(struct vfs_handle_struct *handle,
2318 : struct smb_filename *smb_fname,
2319 : struct security_acl *sacl,
2320 : uint32_t access_requested,
2321 : uint32_t access_denied)
2322 : {
2323 : NTSTATUS result;
2324 : struct timespec ts1,ts2;
2325 : double timediff;
2326 :
2327 0 : clock_gettime_mono(&ts1);
2328 0 : result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2329 : smb_fname,
2330 : sacl,
2331 : access_requested,
2332 : access_denied);
2333 0 : clock_gettime_mono(&ts2);
2334 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2335 :
2336 0 : if (timediff > audit_timeout) {
2337 0 : smb_time_audit_log_fname("audit_file",
2338 : timediff,
2339 0 : smb_fname->base_name);
2340 : }
2341 :
2342 0 : return result;
2343 : }
2344 :
2345 0 : static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2346 : files_struct *fsp,
2347 : SMB_ACL_TYPE_T type,
2348 : TALLOC_CTX *mem_ctx)
2349 : {
2350 : SMB_ACL_T result;
2351 : struct timespec ts1,ts2;
2352 : double timediff;
2353 :
2354 0 : clock_gettime_mono(&ts1);
2355 0 : result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
2356 0 : clock_gettime_mono(&ts2);
2357 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2358 :
2359 0 : if (timediff > audit_timeout) {
2360 0 : smb_time_audit_log_fsp("sys_acl_get_fd", timediff, fsp);
2361 : }
2362 :
2363 0 : return result;
2364 : }
2365 :
2366 0 : static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2367 : files_struct *fsp,
2368 : TALLOC_CTX *mem_ctx,
2369 : char **blob_description,
2370 : DATA_BLOB *blob)
2371 : {
2372 : int result;
2373 : struct timespec ts1,ts2;
2374 : double timediff;
2375 :
2376 0 : clock_gettime_mono(&ts1);
2377 0 : result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2378 0 : clock_gettime_mono(&ts2);
2379 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2380 :
2381 0 : if (timediff > audit_timeout) {
2382 0 : smb_time_audit_log("sys_acl_blob_get_fd", timediff);
2383 : }
2384 :
2385 0 : return result;
2386 : }
2387 :
2388 0 : static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2389 : files_struct *fsp,
2390 : SMB_ACL_TYPE_T type,
2391 : SMB_ACL_T theacl)
2392 : {
2393 : int result;
2394 : struct timespec ts1,ts2;
2395 : double timediff;
2396 :
2397 0 : clock_gettime_mono(&ts1);
2398 0 : result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2399 0 : clock_gettime_mono(&ts2);
2400 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2401 :
2402 0 : if (timediff > audit_timeout) {
2403 0 : smb_time_audit_log_fsp("sys_acl_set_fd", timediff, fsp);
2404 : }
2405 :
2406 0 : return result;
2407 : }
2408 :
2409 0 : static int smb_time_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2410 : files_struct *fsp)
2411 : {
2412 : int result;
2413 : struct timespec ts1,ts2;
2414 : double timediff;
2415 :
2416 0 : clock_gettime_mono(&ts1);
2417 0 : result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2418 0 : clock_gettime_mono(&ts2);
2419 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2420 :
2421 0 : if (timediff > audit_timeout) {
2422 0 : smb_time_audit_log_fsp("sys_acl_delete_def_fd", timediff, fsp);
2423 : }
2424 :
2425 0 : return result;
2426 : }
2427 :
2428 : struct smb_time_audit_getxattrat_state {
2429 : struct vfs_aio_state aio_state;
2430 : files_struct *dir_fsp;
2431 : const struct smb_filename *smb_fname;
2432 : const char *xattr_name;
2433 : ssize_t xattr_size;
2434 : uint8_t *xattr_value;
2435 : };
2436 :
2437 : static void smb_time_audit_getxattrat_done(struct tevent_req *subreq);
2438 :
2439 0 : static struct tevent_req *smb_time_audit_getxattrat_send(
2440 : TALLOC_CTX *mem_ctx,
2441 : struct tevent_context *ev,
2442 : struct vfs_handle_struct *handle,
2443 : files_struct *dir_fsp,
2444 : const struct smb_filename *smb_fname,
2445 : const char *xattr_name,
2446 : size_t alloc_hint)
2447 : {
2448 0 : struct tevent_req *req = NULL;
2449 0 : struct tevent_req *subreq = NULL;
2450 0 : struct smb_time_audit_getxattrat_state *state = NULL;
2451 :
2452 0 : req = tevent_req_create(mem_ctx, &state,
2453 : struct smb_time_audit_getxattrat_state);
2454 0 : if (req == NULL) {
2455 0 : return NULL;
2456 : }
2457 0 : *state = (struct smb_time_audit_getxattrat_state) {
2458 : .dir_fsp = dir_fsp,
2459 : .smb_fname = smb_fname,
2460 : .xattr_name = xattr_name,
2461 : };
2462 :
2463 0 : subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2464 : ev,
2465 : handle,
2466 : dir_fsp,
2467 : smb_fname,
2468 : xattr_name,
2469 : alloc_hint);
2470 0 : if (tevent_req_nomem(subreq, req)) {
2471 0 : return tevent_req_post(req, ev);
2472 : }
2473 0 : tevent_req_set_callback(subreq, smb_time_audit_getxattrat_done, req);
2474 :
2475 0 : return req;
2476 : }
2477 :
2478 0 : static void smb_time_audit_getxattrat_done(struct tevent_req *subreq)
2479 : {
2480 0 : struct tevent_req *req = tevent_req_callback_data(
2481 : subreq, struct tevent_req);
2482 0 : struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2483 : req, struct smb_time_audit_getxattrat_state);
2484 :
2485 0 : state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2486 : &state->aio_state,
2487 : state,
2488 : &state->xattr_value);
2489 0 : TALLOC_FREE(subreq);
2490 0 : if (state->xattr_size == -1) {
2491 0 : tevent_req_error(req, state->aio_state.error);
2492 0 : return;
2493 : }
2494 :
2495 0 : tevent_req_done(req);
2496 : }
2497 :
2498 0 : static ssize_t smb_time_audit_getxattrat_recv(struct tevent_req *req,
2499 : struct vfs_aio_state *aio_state,
2500 : TALLOC_CTX *mem_ctx,
2501 : uint8_t **xattr_value)
2502 : {
2503 0 : struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2504 : req, struct smb_time_audit_getxattrat_state);
2505 : ssize_t xattr_size;
2506 : double timediff;
2507 :
2508 0 : timediff = state->aio_state.duration * 1.0e-9;
2509 :
2510 0 : if (timediff > audit_timeout) {
2511 0 : smb_time_audit_log_at("async getxattrat",
2512 : timediff,
2513 0 : state->dir_fsp,
2514 : state->smb_fname);
2515 : }
2516 :
2517 0 : if (tevent_req_is_unix_error(req, &aio_state->error)) {
2518 0 : tevent_req_received(req);
2519 0 : return -1;
2520 : }
2521 :
2522 0 : *aio_state = state->aio_state;
2523 0 : xattr_size = state->xattr_size;
2524 0 : if (xattr_value != NULL) {
2525 0 : *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2526 : }
2527 :
2528 0 : tevent_req_received(req);
2529 0 : return xattr_size;
2530 : }
2531 :
2532 0 : static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
2533 : struct files_struct *fsp,
2534 : const char *name, void *value,
2535 : size_t size)
2536 : {
2537 : ssize_t result;
2538 : struct timespec ts1,ts2;
2539 : double timediff;
2540 :
2541 0 : clock_gettime_mono(&ts1);
2542 0 : result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2543 0 : clock_gettime_mono(&ts2);
2544 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2545 :
2546 0 : if (timediff > audit_timeout) {
2547 0 : smb_time_audit_log_fsp("fgetxattr", timediff, fsp);
2548 : }
2549 :
2550 0 : return result;
2551 : }
2552 :
2553 0 : static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2554 : struct files_struct *fsp, char *list,
2555 : size_t size)
2556 : {
2557 : ssize_t result;
2558 : struct timespec ts1,ts2;
2559 : double timediff;
2560 :
2561 0 : clock_gettime_mono(&ts1);
2562 0 : result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2563 0 : clock_gettime_mono(&ts2);
2564 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2565 :
2566 0 : if (timediff > audit_timeout) {
2567 0 : smb_time_audit_log_fsp("flistxattr", timediff, fsp);
2568 : }
2569 :
2570 0 : return result;
2571 : }
2572 :
2573 0 : static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2574 : struct files_struct *fsp,
2575 : const char *name)
2576 : {
2577 : int result;
2578 : struct timespec ts1,ts2;
2579 : double timediff;
2580 :
2581 0 : clock_gettime_mono(&ts1);
2582 0 : result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2583 0 : clock_gettime_mono(&ts2);
2584 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2585 :
2586 0 : if (timediff > audit_timeout) {
2587 0 : smb_time_audit_log_fsp("fremovexattr", timediff, fsp);
2588 : }
2589 :
2590 0 : return result;
2591 : }
2592 :
2593 0 : static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2594 : struct files_struct *fsp, const char *name,
2595 : const void *value, size_t size, int flags)
2596 : {
2597 : int result;
2598 : struct timespec ts1,ts2;
2599 : double timediff;
2600 :
2601 0 : clock_gettime_mono(&ts1);
2602 0 : result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2603 0 : clock_gettime_mono(&ts2);
2604 0 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2605 :
2606 0 : if (timediff > audit_timeout) {
2607 0 : smb_time_audit_log_fsp("fsetxattr", timediff, fsp);
2608 : }
2609 :
2610 0 : return result;
2611 : }
2612 :
2613 46 : static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2614 : struct files_struct *fsp)
2615 : {
2616 : bool result;
2617 : struct timespec ts1,ts2;
2618 : double timediff;
2619 :
2620 46 : clock_gettime_mono(&ts1);
2621 46 : result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2622 46 : clock_gettime_mono(&ts2);
2623 46 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2624 :
2625 46 : if (timediff > audit_timeout) {
2626 0 : smb_time_audit_log_fsp("aio_force", timediff, fsp);
2627 : }
2628 :
2629 46 : return result;
2630 : }
2631 :
2632 380 : static NTSTATUS smb_time_audit_durable_cookie(struct vfs_handle_struct *handle,
2633 : struct files_struct *fsp,
2634 : TALLOC_CTX *mem_ctx,
2635 : DATA_BLOB *cookie)
2636 : {
2637 : NTSTATUS result;
2638 : struct timespec ts1,ts2;
2639 : double timediff;
2640 :
2641 380 : clock_gettime_mono(&ts1);
2642 380 : result = SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie);
2643 380 : clock_gettime_mono(&ts2);
2644 380 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2645 :
2646 380 : if (timediff > audit_timeout) {
2647 0 : smb_time_audit_log_fsp("durable_cookie", timediff, fsp);
2648 : }
2649 :
2650 380 : return result;
2651 : }
2652 :
2653 110 : static NTSTATUS smb_time_audit_durable_disconnect(struct vfs_handle_struct *handle,
2654 : struct files_struct *fsp,
2655 : const DATA_BLOB old_cookie,
2656 : TALLOC_CTX *mem_ctx,
2657 : DATA_BLOB *new_cookie)
2658 : {
2659 : NTSTATUS result;
2660 : struct timespec ts1,ts2;
2661 : double timediff;
2662 :
2663 110 : clock_gettime_mono(&ts1);
2664 110 : result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie,
2665 : mem_ctx, new_cookie);
2666 110 : clock_gettime_mono(&ts2);
2667 110 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2668 :
2669 110 : if (timediff > audit_timeout) {
2670 0 : smb_time_audit_log_fsp("durable_disconnect", timediff, fsp);
2671 : }
2672 :
2673 110 : return result;
2674 : }
2675 :
2676 108 : static NTSTATUS smb_time_audit_durable_reconnect(struct vfs_handle_struct *handle,
2677 : struct smb_request *smb1req,
2678 : struct smbXsrv_open *op,
2679 : const DATA_BLOB old_cookie,
2680 : TALLOC_CTX *mem_ctx,
2681 : struct files_struct **fsp,
2682 : DATA_BLOB *new_cookie)
2683 : {
2684 : NTSTATUS result;
2685 : struct timespec ts1,ts2;
2686 : double timediff;
2687 :
2688 108 : clock_gettime_mono(&ts1);
2689 108 : result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie,
2690 : mem_ctx, fsp, new_cookie);
2691 108 : clock_gettime_mono(&ts2);
2692 108 : timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2693 :
2694 108 : if (timediff > audit_timeout) {
2695 0 : smb_time_audit_log("durable_reconnect", timediff);
2696 : }
2697 :
2698 108 : return result;
2699 : }
2700 :
2701 : /* VFS operations */
2702 :
2703 : static struct vfs_fn_pointers vfs_time_audit_fns = {
2704 : .connect_fn = smb_time_audit_connect,
2705 : .disconnect_fn = smb_time_audit_disconnect,
2706 : .disk_free_fn = smb_time_audit_disk_free,
2707 : .get_quota_fn = smb_time_audit_get_quota,
2708 : .set_quota_fn = smb_time_audit_set_quota,
2709 : .get_shadow_copy_data_fn = smb_time_audit_get_shadow_copy_data,
2710 : .statvfs_fn = smb_time_audit_statvfs,
2711 : .fs_capabilities_fn = smb_time_audit_fs_capabilities,
2712 : .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
2713 : .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat,
2714 : .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat,
2715 : .fdopendir_fn = smb_time_audit_fdopendir,
2716 : .readdir_fn = smb_time_audit_readdir,
2717 : .seekdir_fn = smb_time_audit_seekdir,
2718 : .telldir_fn = smb_time_audit_telldir,
2719 : .rewind_dir_fn = smb_time_audit_rewinddir,
2720 : .mkdirat_fn = smb_time_audit_mkdirat,
2721 : .closedir_fn = smb_time_audit_closedir,
2722 : .openat_fn = smb_time_audit_openat,
2723 : .create_file_fn = smb_time_audit_create_file,
2724 : .close_fn = smb_time_audit_close,
2725 : .pread_fn = smb_time_audit_pread,
2726 : .pread_send_fn = smb_time_audit_pread_send,
2727 : .pread_recv_fn = smb_time_audit_pread_recv,
2728 : .pwrite_fn = smb_time_audit_pwrite,
2729 : .pwrite_send_fn = smb_time_audit_pwrite_send,
2730 : .pwrite_recv_fn = smb_time_audit_pwrite_recv,
2731 : .lseek_fn = smb_time_audit_lseek,
2732 : .sendfile_fn = smb_time_audit_sendfile,
2733 : .recvfile_fn = smb_time_audit_recvfile,
2734 : .renameat_fn = smb_time_audit_renameat,
2735 : .fsync_send_fn = smb_time_audit_fsync_send,
2736 : .fsync_recv_fn = smb_time_audit_fsync_recv,
2737 : .stat_fn = smb_time_audit_stat,
2738 : .fstat_fn = smb_time_audit_fstat,
2739 : .lstat_fn = smb_time_audit_lstat,
2740 : .get_alloc_size_fn = smb_time_audit_get_alloc_size,
2741 : .unlinkat_fn = smb_time_audit_unlinkat,
2742 : .fchmod_fn = smb_time_audit_fchmod,
2743 : .fchown_fn = smb_time_audit_fchown,
2744 : .lchown_fn = smb_time_audit_lchown,
2745 : .chdir_fn = smb_time_audit_chdir,
2746 : .getwd_fn = smb_time_audit_getwd,
2747 : .fntimes_fn = smb_time_audit_fntimes,
2748 : .ftruncate_fn = smb_time_audit_ftruncate,
2749 : .fallocate_fn = smb_time_audit_fallocate,
2750 : .lock_fn = smb_time_audit_lock,
2751 : .filesystem_sharemode_fn = smb_time_audit_filesystem_sharemode,
2752 : .fcntl_fn = smb_time_audit_fcntl,
2753 : .linux_setlease_fn = smb_time_audit_linux_setlease,
2754 : .getlock_fn = smb_time_audit_getlock,
2755 : .symlinkat_fn = smb_time_audit_symlinkat,
2756 : .readlinkat_fn = smb_time_audit_readlinkat,
2757 : .linkat_fn = smb_time_audit_linkat,
2758 : .mknodat_fn = smb_time_audit_mknodat,
2759 : .realpath_fn = smb_time_audit_realpath,
2760 : .fchflags_fn = smb_time_audit_fchflags,
2761 : .file_id_create_fn = smb_time_audit_file_id_create,
2762 : .fs_file_id_fn = smb_time_audit_fs_file_id,
2763 : .offload_read_send_fn = smb_time_audit_offload_read_send,
2764 : .offload_read_recv_fn = smb_time_audit_offload_read_recv,
2765 : .offload_write_send_fn = smb_time_audit_offload_write_send,
2766 : .offload_write_recv_fn = smb_time_audit_offload_write_recv,
2767 : .fget_compression_fn = smb_time_audit_fget_compression,
2768 : .set_compression_fn = smb_time_audit_set_compression,
2769 : .snap_check_path_fn = smb_time_audit_snap_check_path,
2770 : .snap_create_fn = smb_time_audit_snap_create,
2771 : .snap_delete_fn = smb_time_audit_snap_delete,
2772 : .fstreaminfo_fn = smb_time_audit_fstreaminfo,
2773 : .get_real_filename_fn = smb_time_audit_get_real_filename,
2774 : .connectpath_fn = smb_time_audit_connectpath,
2775 : .brl_lock_windows_fn = smb_time_audit_brl_lock_windows,
2776 : .brl_unlock_windows_fn = smb_time_audit_brl_unlock_windows,
2777 : .strict_lock_check_fn = smb_time_audit_strict_lock_check,
2778 : .translate_name_fn = smb_time_audit_translate_name,
2779 : .parent_pathname_fn = smb_time_audit_parent_pathname,
2780 : .fsctl_fn = smb_time_audit_fsctl,
2781 : .get_dos_attributes_send_fn = smb_time_audit_get_dos_attributes_send,
2782 : .get_dos_attributes_recv_fn = smb_time_audit_get_dos_attributes_recv,
2783 : .fget_dos_attributes_fn = smb_time_fget_dos_attributes,
2784 : .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
2785 : .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
2786 : .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
2787 : .audit_file_fn = smb_time_audit_audit_file,
2788 : .sys_acl_get_fd_fn = smb_time_audit_sys_acl_get_fd,
2789 : .sys_acl_blob_get_fd_fn = smb_time_audit_sys_acl_blob_get_fd,
2790 : .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
2791 : .sys_acl_delete_def_fd_fn = smb_time_audit_sys_acl_delete_def_fd,
2792 : .getxattrat_send_fn = smb_time_audit_getxattrat_send,
2793 : .getxattrat_recv_fn = smb_time_audit_getxattrat_recv,
2794 : .fgetxattr_fn = smb_time_audit_fgetxattr,
2795 : .flistxattr_fn = smb_time_audit_flistxattr,
2796 : .fremovexattr_fn = smb_time_audit_fremovexattr,
2797 : .fsetxattr_fn = smb_time_audit_fsetxattr,
2798 : .aio_force_fn = smb_time_audit_aio_force,
2799 : .durable_cookie_fn = smb_time_audit_durable_cookie,
2800 : .durable_disconnect_fn = smb_time_audit_durable_disconnect,
2801 : .durable_reconnect_fn = smb_time_audit_durable_reconnect,
2802 : .freaddir_attr_fn = smb_time_audit_freaddir_attr,
2803 : };
2804 :
2805 :
2806 : static_decl_vfs;
2807 16310 : NTSTATUS vfs_time_audit_init(TALLOC_CTX *ctx)
2808 : {
2809 16310 : smb_vfs_assert_all_fns(&vfs_time_audit_fns, "time_audit");
2810 :
2811 32151 : audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2812 16310 : 10000) / 1000.0;
2813 16310 : return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2814 : &vfs_time_audit_fns);
2815 : }
|