s3: Add vfs_linux_xfs_sgid
[Samba/ekacnet.git] / source3 / modules / vfs_smb_traffic_analyzer.c
bloba73d9d0755bd25c8b882b76d86b41ffa7bf861a3
1 /*
2 * traffic-analyzer VFS module. Measure the smb traffic users create
3 * on the net.
5 * Copyright (C) Holger Hetterich, 2008-2010
6 * Copyright (C) Jeremy Allison, 2008
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "../lib/crypto/crypto.h"
24 #include "vfs_smb_traffic_analyzer.h"
26 /* abstraction for the send_over_network function */
27 enum sock_type {INTERNET_SOCKET = 0, UNIX_DOMAIN_SOCKET};
29 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
31 static int vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
33 static enum sock_type smb_traffic_analyzer_connMode(vfs_handle_struct *handle)
35 connection_struct *conn = handle->conn;
36 const char *Mode;
37 Mode=lp_parm_const_string(SNUM(conn), "smb_traffic_analyzer","mode", \
38 "internet_socket");
39 if (strstr(Mode,"unix_domain_socket")) {
40 return UNIX_DOMAIN_SOCKET;
41 } else {
42 return INTERNET_SOCKET;
47 /* Connect to an internet socket */
48 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct *handle,
49 const char *name, uint16_t port)
51 /* Create a streaming Socket */
52 int sockfd = -1;
53 struct addrinfo hints;
54 struct addrinfo *ailist = NULL;
55 struct addrinfo *res = NULL;
56 int ret;
58 ZERO_STRUCT(hints);
59 /* By default make sure it supports TCP. */
60 hints.ai_socktype = SOCK_STREAM;
61 hints.ai_flags = AI_ADDRCONFIG;
63 ret = getaddrinfo(name,
64 NULL,
65 &hints,
66 &ailist);
68 if (ret) {
69 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
70 "getaddrinfo failed for name %s [%s]\n",
71 name,
72 gai_strerror(ret) ));
73 return -1;
76 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
77 "Port: %i\n", name, port));
79 for (res = ailist; res; res = res->ai_next) {
80 struct sockaddr_storage ss;
81 NTSTATUS status;
83 if (!res->ai_addr || res->ai_addrlen == 0) {
84 continue;
87 ZERO_STRUCT(ss);
88 memcpy(&ss, res->ai_addr, res->ai_addrlen);
90 status = open_socket_out(&ss, port, 10000, &sockfd);
91 if (NT_STATUS_IS_OK(status)) {
92 break;
96 if (ailist) {
97 freeaddrinfo(ailist);
100 if (sockfd == -1) {
101 DEBUG(1, ("smb_traffic_analyzer: unable to create "
102 "socket, error is %s",
103 strerror(errno)));
104 return -1;
107 return sockfd;
110 /* Connect to a unix domain socket */
111 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct *handle,
112 const char *name)
114 /* Create the socket to stad */
115 int len, sock;
116 struct sockaddr_un remote;
118 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
119 "Unix domain socket mode. Using %s\n",
120 name ));
122 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
123 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
124 "Couldn't create socket, "
125 "make sure stad is running!\n"));
126 return -1;
128 remote.sun_family = AF_UNIX;
129 strlcpy(remote.sun_path, name,
130 sizeof(remote.sun_path));
131 len=strlen(remote.sun_path) + sizeof(remote.sun_family);
132 if (connect(sock, (struct sockaddr *)&remote, len) == -1 ) {
133 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
134 "Could not connect to "
135 "socket, make sure\nstad is running!\n"));
136 close(sock);
137 return -1;
139 return sock;
142 /* Private data allowing shared connection sockets. */
143 struct refcounted_sock {
144 struct refcounted_sock *next, *prev;
145 char *name;
146 uint16_t port;
147 int sock;
148 unsigned int ref_count;
153 * Encryption of a data block with AES
154 * TALLOC_CTX *ctx Talloc context to work on
155 * const char *akey 128bit key for the encryption
156 * const char *str Data buffer to encrypt, \0 terminated
157 * int *len Will be set to the length of the
158 * resulting data block
159 * The caller has to take care for the memory
160 * allocated on the context.
162 static char *smb_traffic_analyzer_encrypt( TALLOC_CTX *ctx,
163 const char *akey, const char *str, size_t *len)
165 int s1,s2,h,d;
166 AES_KEY key;
167 unsigned char filler[17]= "................";
168 char *output;
169 unsigned char crypted[18];
170 if (akey == NULL) return NULL;
171 samba_AES_set_encrypt_key((unsigned char *) akey, 128, &key);
172 s1 = strlen(str) / 16;
173 s2 = strlen(str) % 16;
174 for (h = 0; h < s2; h++) *(filler+h)=*(str+(s1*16)+h);
175 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
176 " as filling block.\n", filler));
177 output = talloc_array(ctx, char, (s1*16)+17 );
178 d=0;
179 for (h = 0; h < s1; h++) {
180 samba_AES_encrypt((unsigned char *) str+(16*h), crypted, &key);
181 for (d = 0; d<16; d++) output[d+(16*h)]=crypted[d];
183 samba_AES_encrypt( (unsigned char *) str+(16*h), filler, &key );
184 for (d = 0;d < 16; d++) output[d+(16*h)]=*(filler+d);
185 *len = (s1*16)+16;
186 return output;
190 * Create a v2 header.
191 * TALLLOC_CTX *ctx Talloc context to work on
192 * const char *state_flags State flag string
193 * int len length of the data block
195 static char *smb_traffic_analyzer_create_header( TALLOC_CTX *ctx,
196 const char *state_flags, size_t data_len)
198 char *header = talloc_asprintf( ctx, "V2.%s%017u",
199 state_flags, (unsigned int) data_len);
200 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
201 dump_data(10, (uint8_t *)header, strlen(header));
202 return header;
207 * Actually send header and data over the network
208 * char *header Header data
209 * char *data Data Block
210 * int dlength Length of data block
211 * int socket
213 static void smb_traffic_analyzer_write_data( char *header, char *data,
214 int dlength, int _socket)
216 int len = strlen(header);
217 if (write_data( _socket, header, len) != len) {
218 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
219 "error sending the header"
220 " over the socket!\n"));
222 DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
223 dump_data( 10, (uint8_t *)data, dlength);
225 if (write_data( _socket, data, dlength) != dlength) {
226 DEBUG(1, ("smb_traffic_analyzer_write_data: "
227 "error sending crypted data to socket!\n"));
233 * Anonymize a string if required.
234 * TALLOC_CTX *ctx The talloc context to work on
235 * const char *str The string to anonymize
236 * vfs_handle_struct *handle The handle struct to work on
238 * Returns a newly allocated string, either the anonymized one,
239 * or a copy of const char *str. The caller has to take care for
240 * freeing the allocated memory.
242 static char *smb_traffic_analyzer_anonymize( TALLOC_CTX *ctx,
243 const char *str,
244 vfs_handle_struct *handle )
246 const char *total_anonymization;
247 const char *anon_prefix;
248 char *output;
249 total_anonymization=lp_parm_const_string(SNUM(handle->conn),
250 "smb_traffic_analyzer",
251 "total_anonymization", NULL);
253 anon_prefix=lp_parm_const_string(SNUM(handle->conn),
254 "smb_traffic_analyzer",
255 "anonymize_prefix", NULL );
256 if (anon_prefix != NULL) {
257 if (total_anonymization != NULL) {
258 output = talloc_asprintf(ctx, "%s",
259 anon_prefix);
260 } else {
261 output = talloc_asprintf(ctx, "%s%i", anon_prefix,
262 str_checksum(str));
264 } else {
265 output = talloc_asprintf(ctx, "%s", str);
268 return output;
273 * The marshalling function for protocol v2.
274 * TALLOC_CTX *ctx Talloc context to work on
275 * struct tm *tm tm struct for the timestamp
276 * int seconds milliseconds of the timestamp
277 * vfs_handle_struct *handle vfs_handle_struct
278 * char *username Name of the user
279 * int vfs_operation VFS operation identifier
280 * int count Number of the common data blocks
281 * [...] variable args data blocks taken from the individual
282 * VFS data structures
284 * Returns the complete data block to send. The caller has to
285 * take care for freeing the allocated buffer.
287 static char *smb_traffic_analyzer_create_string( TALLOC_CTX *ctx,
288 struct tm *tm, int seconds, vfs_handle_struct *handle, \
289 char *username, int vfs_operation, int count, ... )
292 va_list ap;
293 char *arg = NULL;
294 int len;
295 char *common_data_count_str = NULL;
296 char *timestr = NULL;
297 char *sidstr = NULL;
298 char *usersid = NULL;
299 char *buf = NULL;
300 char *vfs_operation_str = NULL;
301 const char *service_name = lp_const_servicename(handle->conn->params->service);
304 * first create the data that is transfered with any VFS op
305 * These are, in the following order:
306 *(0) number of data to come [6 in v2.0]
307 * 1.vfs_operation identifier
308 * 2.username
309 * 3.user-SID
310 * 4.affected share
311 * 5.domain
312 * 6.timestamp
316 * number of common data blocks to come,
317 * this is a #define in vfs_smb_traffic_anaylzer.h,
318 * it's length is known at compile time
320 common_data_count_str = talloc_strdup( ctx, SMBTA_COMMON_DATA_COUNT);
321 /* vfs operation identifier */
322 vfs_operation_str = talloc_asprintf( common_data_count_str, "%i",
323 vfs_operation);
325 * Handle anonymization. In protocol v2, we have to anonymize
326 * both the SID and the username. The name is already
327 * anonymized if needed, by the calling function.
329 usersid = dom_sid_string( common_data_count_str,
330 &handle->conn->server_info->ptok->user_sids[0]);
332 sidstr = smb_traffic_analyzer_anonymize(
333 common_data_count_str,
334 usersid,
335 handle);
337 /* time stamp */
338 timestr = talloc_asprintf( common_data_count_str, \
339 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
340 tm->tm_year+1900, \
341 tm->tm_mon+1, \
342 tm->tm_mday, \
343 tm->tm_hour, \
344 tm->tm_min, \
345 tm->tm_sec, \
346 (int)seconds);
347 len = strlen( timestr );
349 /* create the string of common data */
350 buf = talloc_asprintf(ctx,
351 "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
352 common_data_count_str,
353 (unsigned int) strlen(vfs_operation_str),
354 vfs_operation_str,
355 (unsigned int) strlen(username),
356 username,
357 (unsigned int) strlen(sidstr),
358 sidstr,
359 (unsigned int) strlen(service_name),
360 service_name,
361 (unsigned int)
362 strlen(handle->conn->server_info->info3->base.domain.string),
363 handle->conn->server_info->info3->base.domain.string,
364 (unsigned int) strlen(timestr),
365 timestr);
367 talloc_free(common_data_count_str);
369 /* data blocks depending on the VFS function */
370 va_start( ap, count );
371 while ( count-- ) {
372 arg = va_arg( ap, char * );
374 * protocol v2 sends a four byte string
375 * as a header to each block, including
376 * the numbers of bytes to come in the
377 * next string.
379 len = strlen( arg );
380 buf = talloc_asprintf_append( buf, "%04u%s", len, arg);
382 va_end( ap );
383 return buf;
386 static void smb_traffic_analyzer_send_data(vfs_handle_struct *handle,
387 void *data,
388 enum vfs_id vfs_operation )
390 struct refcounted_sock *rf_sock = NULL;
391 struct timeval tv;
392 time_t tv_sec;
393 struct tm *tm = NULL;
394 int seconds;
395 char *str = NULL;
396 char *username = NULL;
397 char *header = NULL;
398 const char *protocol_version = NULL;
399 bool Write = false;
400 size_t len;
401 size_t size;
402 char *akey, *output;
405 * The state flags are part of the header
406 * and are descripted in the protocol description
407 * in vfs_smb_traffic_analyzer.h. They begin at byte
408 * 03 of the header.
410 char state_flags[9] = "000000\0";
412 SMB_VFS_HANDLE_GET_DATA(handle, rf_sock, struct refcounted_sock, return);
414 if (rf_sock == NULL || rf_sock->sock == -1) {
415 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
416 "closed\n"));
417 return;
420 GetTimeOfDay(&tv);
421 tv_sec = convert_timespec_to_time_t(convert_timeval_to_timespec(tv));
422 tm = localtime(&tv_sec);
423 if (!tm) {
424 return;
426 seconds=(float) (tv.tv_usec / 1000);
429 * Check if anonymization is required, and if yes do this only for
430 * the username here, needed vor protocol version 1. In v2 we
431 * additionally anonymize the SID, which is done in it's marshalling
432 * function.
434 username = smb_traffic_analyzer_anonymize( talloc_tos(),
435 handle->conn->server_info->sanitized_username,
436 handle);
438 if (!username) {
439 return;
442 protocol_version = lp_parm_const_string(SNUM(handle->conn),
443 "smb_traffic_analyzer",
444 "protocol_version", NULL );
447 if ( protocol_version == NULL || strcmp( protocol_version,"V1") == 0) {
449 struct rw_data *s_data = (struct rw_data *) data;
452 * in case of protocol v1, ignore any vfs operations
453 * except read,pread,write,pwrite, and set the "Write"
454 * bool accordingly, send data and return.
456 if ( vfs_operation > vfs_id_pwrite ) return;
458 if ( vfs_operation <= vfs_id_pread ) Write=false;
459 else Write=true;
461 str = talloc_asprintf(talloc_tos(),
462 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
463 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
464 (unsigned int) s_data->len,
465 username,
466 handle->conn->server_info->info3->base.domain.string,
467 Write ? 'W' : 'R',
468 handle->conn->connectpath,
469 s_data->filename,
470 tm->tm_year+1900,
471 tm->tm_mon+1,
472 tm->tm_mday,
473 tm->tm_hour,
474 tm->tm_min,
475 tm->tm_sec,
476 (int)seconds);
477 len = strlen(str);
478 if (write_data(rf_sock->sock, str, len) != len) {
479 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
480 "error sending V1 protocol data to socket!\n"));
481 return;
484 } else if ( strcmp( protocol_version, "V2") == 0) {
486 switch( vfs_operation ) {
487 case vfs_id_open: ;
488 str = smb_traffic_analyzer_create_string( talloc_tos(),
489 tm, seconds, handle, username, vfs_id_open,
490 3, ((struct open_data *) data)->filename,
491 talloc_asprintf( talloc_tos(), "%u",
492 ((struct open_data *) data)->mode),
493 talloc_asprintf( talloc_tos(), "%u",
494 ((struct open_data *) data)->result));
495 break;
496 case vfs_id_close: ;
497 str = smb_traffic_analyzer_create_string( talloc_tos(),
498 tm, seconds, handle, username, vfs_id_close,
499 2, ((struct close_data *) data)->filename,
500 talloc_asprintf( talloc_tos(), "%u",
501 ((struct close_data *) data)->result));
502 break;
503 case vfs_id_mkdir: ;
504 str = smb_traffic_analyzer_create_string( talloc_tos(),
505 tm, seconds, handle, username, vfs_id_mkdir, \
506 3, ((struct mkdir_data *) data)->path, \
507 talloc_asprintf( talloc_tos(), "%u", \
508 ((struct mkdir_data *) data)->mode), \
509 talloc_asprintf( talloc_tos(), "%u", \
510 ((struct mkdir_data *) data)->result ));
511 break;
512 case vfs_id_rmdir: ;
513 str = smb_traffic_analyzer_create_string( talloc_tos(),
514 tm, seconds, handle, username, vfs_id_rmdir,
515 2, ((struct rmdir_data *) data)->path, \
516 talloc_asprintf( talloc_tos(), "%u", \
517 ((struct rmdir_data *) data)->result ));
518 break;
519 case vfs_id_rename: ;
520 str = smb_traffic_analyzer_create_string( talloc_tos(),
521 tm, seconds, handle, username, vfs_id_rename,
522 3, ((struct rename_data *) data)->src, \
523 ((struct rename_data *) data)->dst,
524 talloc_asprintf(talloc_tos(), "%u", \
525 ((struct rename_data *) data)->result));
526 break;
527 case vfs_id_chdir: ;
528 str = smb_traffic_analyzer_create_string( talloc_tos(),
529 tm, seconds, handle, username, vfs_id_chdir,
530 2, ((struct chdir_data *) data)->path, \
531 talloc_asprintf(talloc_tos(), "%u", \
532 ((struct chdir_data *) data)->result));
533 break;
535 case vfs_id_write:
536 case vfs_id_pwrite:
537 case vfs_id_read:
538 case vfs_id_pread: ;
539 str = smb_traffic_analyzer_create_string( talloc_tos(),
540 tm, seconds, handle, username, vfs_operation,
541 2, ((struct rw_data *) data)->filename, \
542 talloc_asprintf(talloc_tos(), "%u", \
543 (unsigned int)
544 ((struct rw_data *) data)->len));
545 break;
546 default:
547 DEBUG(1, ("smb_traffic_analyzer: error! "
548 "wrong VFS operation id detected!\n"));
549 return;
552 } else {
553 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
554 "error, unkown protocol given!\n"));
555 return;
558 if (!str) {
559 DEBUG(1, ("smb_traffic_analyzer_send_data: "
560 "unable to create string to send!\n"));
561 return;
566 * If configured, optain the key and run AES encryption
567 * over the data.
569 become_root();
570 akey = (char *) secrets_fetch("smb_traffic_analyzer_key", &size);
571 unbecome_root();
572 if ( akey != NULL ) {
573 state_flags[2] = 'E';
574 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
575 " found, encrypting data!\n"));
576 output = smb_traffic_analyzer_encrypt( talloc_tos(),
577 akey, str, &len);
578 header = smb_traffic_analyzer_create_header( talloc_tos(),
579 state_flags, len);
581 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
582 " header created for crypted data: %s\n", header));
583 smb_traffic_analyzer_write_data(header, output, len,
584 rf_sock->sock);
585 return;
589 len = strlen(str);
590 header = smb_traffic_analyzer_create_header( talloc_tos(),
591 state_flags, len);
592 smb_traffic_analyzer_write_data(header, str, strlen(str),
593 rf_sock->sock);
597 static struct refcounted_sock *sock_list;
599 static void smb_traffic_analyzer_free_data(void **pptr)
601 struct refcounted_sock *rf_sock = *(struct refcounted_sock **)pptr;
602 if (rf_sock == NULL) {
603 return;
605 rf_sock->ref_count--;
606 if (rf_sock->ref_count != 0) {
607 return;
609 if (rf_sock->sock != -1) {
610 close(rf_sock->sock);
612 DLIST_REMOVE(sock_list, rf_sock);
613 TALLOC_FREE(rf_sock);
616 static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
617 const char *service,
618 const char *user)
620 connection_struct *conn = handle->conn;
621 enum sock_type st = smb_traffic_analyzer_connMode(handle);
622 struct refcounted_sock *rf_sock = NULL;
623 const char *name = (st == UNIX_DOMAIN_SOCKET) ? LOCAL_PATHNAME :
624 lp_parm_const_string(SNUM(conn),
625 "smb_traffic_analyzer",
626 "host", "localhost");
627 uint16_t port = (st == UNIX_DOMAIN_SOCKET) ? 0 :
628 atoi( lp_parm_const_string(SNUM(conn),
629 "smb_traffic_analyzer", "port", "9430"));
630 int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
632 if (ret < 0) {
633 return ret;
636 /* Are we already connected ? */
637 for (rf_sock = sock_list; rf_sock; rf_sock = rf_sock->next) {
638 if (port == rf_sock->port &&
639 (strcmp(name, rf_sock->name) == 0)) {
640 break;
644 /* If we're connected already, just increase the
645 * reference count. */
646 if (rf_sock) {
647 rf_sock->ref_count++;
648 } else {
649 /* New connection. */
650 rf_sock = TALLOC_ZERO_P(NULL, struct refcounted_sock);
651 if (rf_sock == NULL) {
652 SMB_VFS_NEXT_DISCONNECT(handle);
653 errno = ENOMEM;
654 return -1;
656 rf_sock->name = talloc_strdup(rf_sock, name);
657 if (rf_sock->name == NULL) {
658 SMB_VFS_NEXT_DISCONNECT(handle);
659 TALLOC_FREE(rf_sock);
660 errno = ENOMEM;
661 return -1;
663 rf_sock->port = port;
664 rf_sock->ref_count = 1;
666 if (st == UNIX_DOMAIN_SOCKET) {
667 rf_sock->sock = smb_traffic_analyzer_connect_unix_socket(handle,
668 name);
669 } else {
671 rf_sock->sock = smb_traffic_analyzer_connect_inet_socket(handle,
672 name,
673 port);
675 if (rf_sock->sock == -1) {
676 SMB_VFS_NEXT_DISCONNECT(handle);
677 TALLOC_FREE(rf_sock);
678 return -1;
680 DLIST_ADD(sock_list, rf_sock);
683 /* Store the private data. */
684 SMB_VFS_HANDLE_SET_DATA(handle, rf_sock, smb_traffic_analyzer_free_data,
685 struct refcounted_sock, return -1);
686 return 0;
689 /* VFS Functions */
690 static int smb_traffic_analyzer_chdir(vfs_handle_struct *handle, \
691 const char *path)
693 struct chdir_data s_data;
694 s_data.result = SMB_VFS_NEXT_CHDIR(handle, path);
695 s_data.path = path;
696 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path));
697 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_chdir);
698 return s_data.result;
701 static int smb_traffic_analyzer_rename(vfs_handle_struct *handle, \
702 const struct smb_filename *smb_fname_src,
703 const struct smb_filename *smb_fname_dst)
705 struct rename_data s_data;
706 s_data.result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, \
707 smb_fname_dst);
708 s_data.src = smb_fname_src->base_name;
709 s_data.dst = smb_fname_dst->base_name;
710 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
711 smb_fname_src->base_name,
712 smb_fname_dst->base_name));
713 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rename);
714 return s_data.result;
717 static int smb_traffic_analyzer_rmdir(vfs_handle_struct *handle, \
718 const char *path)
720 struct rmdir_data s_data;
721 s_data.result = SMB_VFS_NEXT_RMDIR(handle, path);
722 s_data.path = path;
723 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path));
724 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rmdir);
725 return s_data.result;
728 static int smb_traffic_analyzer_mkdir(vfs_handle_struct *handle, \
729 const char *path, mode_t mode)
731 struct mkdir_data s_data;
732 s_data.result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
733 s_data.path = path;
734 s_data.mode = mode;
735 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path));
736 smb_traffic_analyzer_send_data(handle,
737 &s_data,
738 vfs_id_mkdir);
739 return s_data.result;
742 static ssize_t smb_traffic_analyzer_read(vfs_handle_struct *handle, \
743 files_struct *fsp, void *data, size_t n)
745 struct rw_data s_data;
747 s_data.len = SMB_VFS_NEXT_READ(handle, fsp, data, n);
748 s_data.filename = fsp->fsp_name->base_name;
749 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp)));
751 smb_traffic_analyzer_send_data(handle,
752 &s_data,
753 vfs_id_read);
754 return s_data.len;
758 static ssize_t smb_traffic_analyzer_pread(vfs_handle_struct *handle, \
759 files_struct *fsp, void *data, size_t n, SMB_OFF_T offset)
761 struct rw_data s_data;
763 s_data.len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
764 s_data.filename = fsp->fsp_name->base_name;
765 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
766 fsp_str_dbg(fsp)));
768 smb_traffic_analyzer_send_data(handle,
769 &s_data,
770 vfs_id_pread);
772 return s_data.len;
775 static ssize_t smb_traffic_analyzer_write(vfs_handle_struct *handle, \
776 files_struct *fsp, const void *data, size_t n)
778 struct rw_data s_data;
780 s_data.len = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
781 s_data.filename = fsp->fsp_name->base_name;
782 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
783 fsp_str_dbg(fsp)));
785 smb_traffic_analyzer_send_data(handle,
786 &s_data,
787 vfs_id_write);
788 return s_data.len;
791 static ssize_t smb_traffic_analyzer_pwrite(vfs_handle_struct *handle, \
792 files_struct *fsp, const void *data, size_t n, SMB_OFF_T offset)
794 struct rw_data s_data;
796 s_data.len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
797 s_data.filename = fsp->fsp_name->base_name;
798 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
799 fsp_str_dbg(fsp)));
801 smb_traffic_analyzer_send_data(handle,
802 &s_data,
803 vfs_id_pwrite);
804 return s_data.len;
807 static int smb_traffic_analyzer_open(vfs_handle_struct *handle, \
808 struct smb_filename *smb_fname, files_struct *fsp,\
809 int flags, mode_t mode)
811 struct open_data s_data;
813 s_data.result = SMB_VFS_NEXT_OPEN( handle, smb_fname, fsp,
814 flags, mode);
815 DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
816 fsp_str_dbg(fsp)));
817 s_data.filename = fsp->fsp_name->base_name;
818 s_data.mode = mode;
819 smb_traffic_analyzer_send_data(handle,
820 &s_data,
821 vfs_id_open);
822 return s_data.result;
825 static int smb_traffic_analyzer_close(vfs_handle_struct *handle, \
826 files_struct *fsp)
828 struct close_data s_data;
829 s_data.result = SMB_VFS_NEXT_CLOSE(handle, fsp);
830 DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
831 fsp_str_dbg(fsp)));
832 s_data.filename = fsp->fsp_name->base_name;
833 smb_traffic_analyzer_send_data(handle,
834 &s_data,
835 vfs_id_close);
836 return s_data.result;
840 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
841 .connect_fn = smb_traffic_analyzer_connect,
842 .vfs_read = smb_traffic_analyzer_read,
843 .pread = smb_traffic_analyzer_pread,
844 .write = smb_traffic_analyzer_write,
845 .pwrite = smb_traffic_analyzer_pwrite,
846 .mkdir = smb_traffic_analyzer_mkdir,
847 .rename = smb_traffic_analyzer_rename,
848 .chdir = smb_traffic_analyzer_chdir,
849 .open = smb_traffic_analyzer_open,
850 .rmdir = smb_traffic_analyzer_rmdir,
851 .close_fn = smb_traffic_analyzer_close
854 /* Module initialization */
855 NTSTATUS vfs_smb_traffic_analyzer_init(void)
857 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
858 "smb_traffic_analyzer",
859 &vfs_smb_traffic_analyzer_fns);
861 if (!NT_STATUS_IS_OK(ret)) {
862 return ret;
865 vfs_smb_traffic_analyzer_debug_level =
866 debug_add_class("smb_traffic_analyzer");
868 if (vfs_smb_traffic_analyzer_debug_level == -1) {
869 vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
870 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
871 "debugging class!\n"));
872 } else {
873 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
874 "'smb_traffic_analyzer': %d\n", \
875 vfs_smb_traffic_analyzer_debug_level));
878 return ret;