Added an exact description of the V2 protocol.
[Samba/ekacnet.git] / source3 / modules / vfs_smb_traffic_analyzer.c
blob226611ca64e4b6e299fa0991d44aabf85141bff4
1 /*
2 * traffic-analyzer VFS module. Measure the smb traffic users create
3 * on the net.
5 * Copyright (C) Holger Hetterich, 2008
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"
25 /* abstraction for the send_over_network function */
26 enum sock_type {INTERNET_SOCKET = 0, UNIX_DOMAIN_SOCKET};
28 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
32 * Protocol version 2.0 description
34 * The following table shows the exact assembly of the 2.0 protocol.
36 * -->Header<--
37 * The protocol header is always send first, and contains various
38 * information about the data block to come.
39 * The header is always of fixed length, and will be send unencrypted.
41 * Byte Number/Bytes Description
42 * 00-02 Contains always the string "V2."
43 * 03 This byte contains a possible subrelease number of the
44 * protocol. This enables the receiver to make a version
45 * check to ensure the compatibility and allows us to
46 * release 2.x versions of the protocol with bugfixes or
47 * enhancements.
48 * 04 Usually, this byte contains the character '0'. If the
49 * VFS module is configured for anonymization, this is
50 * set to 'A'. This information can be useful for the
51 * receiver.
52 * 05 Usually, this byte contains the character '0'. If the
53 * VFS module is configured for encryption of the data,
54 * this byte is set to 'E'.
55 * 06-09 These bytes contain the character '0' by default, and
56 * are reserved for possible future extensions. They have
57 * no function in 2.0.
58 * 10-27 17 bytes containing a string representation of the
59 * number of bytes to come in the following data block.
60 * It is right aligned and filled from the left with '0'.
62 * -->Data Block<--
63 * The data block is send immediately after the header was send. It's length
64 * is exactly what was given in bytes 11-28 from in the header.
66 * The data block may be send encrypted.
68 * To make the data block easy for the receiver to read, it is divided into
69 * several sub-blocks, each with it's own header of four byte length. In each
70 * of the sub-headers, a string representation of the length of this block is
71 * to be found.
73 * Thus the formal structure is very simple:
75 * [HEADER]data[HEADER]data[HEADER]data[END]
77 * whereas [END] is exactly at the position given in bytes 11-28 of the
78 * header.
80 * Some data the VFS module is capturing is of use for any VFS operation.
81 * Therefore, there is a "common set" of data, that will be send with any
82 * data block. The following provides a list of this data.
83 * - the VFS function identifier (see VFS function ifentifier table below).
84 * - a timestamp to the millisecond.
85 * - the username (as text) who runs the VFS operation.
86 * - the SID of the user who run the VFS operation.
87 * - the domain under which the VFS operation has happened.
92 /* VFS Functions identifier table. In protocol version 2, every vfs */
93 /* function is given a unique id. */
94 enum vfs_id {
95 /* care for the order here, required for compatibility */
96 /* with protocol version 1. */
97 vfs_id_read,
98 vfs_id_pread,
99 vfs_id_write,
100 vfs_id_pwrite,
101 /* end of protocol version 1 identifiers. */
102 vfs_id_mkdir,
103 vfs_id_rmdir,
104 vfs_id_rename,
105 vfs_id_chdir
108 /* Specific data sets for the VFS functions. */
110 struct mkdir_data {
111 const char *path;
112 mode_t mode;
113 int result;
116 struct rmdir_data {
117 const char *path;
118 int result;
121 struct rename_data {
122 const char *src;
123 const char *dst;
124 int result;
127 struct chdir_data {
128 const char *path;
129 int result;
132 /* rw_data used for read/write/pread/pwrite */
133 struct rw_data {
134 char *filename;
135 size_t len;
138 static int vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
140 static enum sock_type smb_traffic_analyzer_connMode(vfs_handle_struct *handle)
142 connection_struct *conn = handle->conn;
143 const char *Mode;
144 Mode=lp_parm_const_string(SNUM(conn), "smb_traffic_analyzer","mode", \
145 "internet_socket");
146 if (strstr(Mode,"unix_domain_socket")) {
147 return UNIX_DOMAIN_SOCKET;
148 } else {
149 return INTERNET_SOCKET;
154 /* Connect to an internet socket */
156 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct *handle,
157 const char *name, uint16_t port)
159 /* Create a streaming Socket */
160 int sockfd = -1;
161 struct addrinfo hints;
162 struct addrinfo *ailist = NULL;
163 struct addrinfo *res = NULL;
164 int ret;
166 ZERO_STRUCT(hints);
167 /* By default make sure it supports TCP. */
168 hints.ai_socktype = SOCK_STREAM;
169 hints.ai_flags = AI_ADDRCONFIG;
171 ret = getaddrinfo(name,
172 NULL,
173 &hints,
174 &ailist);
176 if (ret) {
177 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
178 "getaddrinfo failed for name %s [%s]\n",
179 name,
180 gai_strerror(ret) ));
181 return -1;
184 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
185 "Port: %i\n", name, port));
187 for (res = ailist; res; res = res->ai_next) {
188 struct sockaddr_storage ss;
189 NTSTATUS status;
191 if (!res->ai_addr || res->ai_addrlen == 0) {
192 continue;
195 ZERO_STRUCT(ss);
196 memcpy(&ss, res->ai_addr, res->ai_addrlen);
198 status = open_socket_out(&ss, port, 10000, &sockfd);
199 if (NT_STATUS_IS_OK(status)) {
200 break;
204 if (ailist) {
205 freeaddrinfo(ailist);
208 if (sockfd == -1) {
209 DEBUG(1, ("smb_traffic_analyzer: unable to create "
210 "socket, error is %s",
211 strerror(errno)));
212 return -1;
215 return sockfd;
218 /* Connect to a unix domain socket */
220 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct *handle,
221 const char *name)
223 /* Create the socket to stad */
224 int len, sock;
225 struct sockaddr_un remote;
227 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
228 "Unix domain socket mode. Using %s\n",
229 name ));
231 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
232 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
233 "Couldn't create socket, "
234 "make sure stad is running!\n"));
235 return -1;
237 remote.sun_family = AF_UNIX;
238 strlcpy(remote.sun_path, name,
239 sizeof(remote.sun_path));
240 len=strlen(remote.sun_path) + sizeof(remote.sun_family);
241 if (connect(sock, (struct sockaddr *)&remote, len) == -1 ) {
242 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
243 "Could not connect to "
244 "socket, make sure\nstad is running!\n"));
245 close(sock);
246 return -1;
248 return sock;
251 /* Private data allowing shared connection sockets. */
253 struct refcounted_sock {
254 struct refcounted_sock *next, *prev;
255 char *name;
256 uint16_t port;
257 int sock;
258 unsigned int ref_count;
262 /* The marshaller for the protocol version 2. */
263 static char *smb_traffic_analyzer_create_string( struct tm *tm, \
264 int seconds, vfs_handle_struct *handle, \
265 char *username, int vfs_operation, int count, ... )
268 va_list ap;
269 char *arg = NULL;
270 int len;
271 char *header = NULL;
272 char *buf = NULL;
273 char *timestr = NULL;
274 char *opstr = NULL;
275 char *userSID = NULL;
277 /* first create the data that is transfered with any VFS op */
278 opstr = talloc_asprintf(talloc_tos(), "%i", vfs_operation);
279 len = strlen(opstr);
280 buf = talloc_asprintf(talloc_tos(), "%04u%s", len, opstr);
281 len = strlen( username );
282 buf = talloc_asprintf_append(buf, "%04u%s", len, username);
283 userSID = dom_sid_string( talloc_tos(),
284 &handle->conn->server_info->ptok->user_sids[0]);
285 len = strlen( userSID );
286 buf = talloc_asprintf_append(buf, "%04u%s", len, userSID);
287 len = strlen( handle->conn->connectpath );
288 buf = talloc_asprintf_append( buf, "%04u%s", len, \
289 handle->conn->connectpath );
290 len = strlen( pdb_get_domain(handle->conn->server_info->sam_account) );
291 buf = talloc_asprintf_append( buf, "%04u%s", len, \
292 pdb_get_domain(handle->conn->server_info->sam_account) );
293 timestr = talloc_asprintf(talloc_tos(), \
294 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
295 tm->tm_year+1900, \
296 tm->tm_mon+1, \
297 tm->tm_mday, \
298 tm->tm_hour, \
299 tm->tm_min, \
300 tm->tm_sec, \
301 (int)seconds);
302 len = strlen( timestr );
303 buf = talloc_asprintf_append( buf, "%04u%s", len, timestr);
305 va_start( ap, count );
306 while ( count-- ) {
307 arg = va_arg( ap, char * );
308 /* protocol v2 sends a four byte string */
309 /* as a header to each block, including */
310 /* the numbers of bytes to come in the */
311 /* next string. */
312 len = strlen( arg );
313 buf = talloc_asprintf_append( buf, "%04u%s", len, arg);
315 va_end( ap );
316 return buf;
319 static void smb_traffic_analyzer_send_data(vfs_handle_struct *handle,
320 void *data,
321 enum vfs_id vfs_operation )
323 struct refcounted_sock *rf_sock = NULL;
324 struct timeval tv;
325 time_t tv_sec;
326 struct tm *tm = NULL;
327 int seconds;
328 char *str = NULL;
329 char *username = NULL;
330 char *header = NULL;
331 const char *anon_prefix = NULL;
332 const char *total_anonymization = NULL;
333 const char *protocol_version = NULL;
334 bool Write = false;
335 size_t len;
336 char state_flags[9] = "000000\0";
338 SMB_VFS_HANDLE_GET_DATA(handle, rf_sock, struct refcounted_sock, return);
340 if (rf_sock == NULL || rf_sock->sock == -1) {
341 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
342 "closed\n"));
343 return;
346 GetTimeOfDay(&tv);
347 tv_sec = convert_timespec_to_time_t(convert_timeval_to_timespec(tv));
348 tm = localtime(&tv_sec);
349 if (!tm) {
350 return;
352 seconds=(float) (tv.tv_usec / 1000);
354 /* check if anonymization is required */
356 total_anonymization=lp_parm_const_string(SNUM(handle->conn),"smb_traffic_analyzer",
357 "total_anonymization", NULL);
359 anon_prefix=lp_parm_const_string(SNUM(handle->conn),"smb_traffic_analyzer",\
360 "anonymize_prefix", NULL );
361 if (anon_prefix!=NULL) {
362 state_flags[1] = 'A';
363 if (total_anonymization!=NULL) {
364 username = talloc_asprintf(talloc_tos(),
365 "%s",
366 anon_prefix);
367 } else {
368 username = talloc_asprintf(talloc_tos(),
369 "%s%i",
370 anon_prefix,
371 str_checksum(
372 handle->conn->server_info->sanitized_username ) );
375 } else {
376 username = handle->conn->server_info->sanitized_username;
379 if (!username) {
380 return;
382 protocol_version = lp_parm_const_string(SNUM(handle->conn),
383 "smb_traffic_analyzer",
384 "protocol_version", NULL );
386 if ( protocol_version == NULL || strcmp( protocol_version,"V1") == 0) {
388 struct rw_data *s_data = (struct rw_data *) data;
390 /* in case of protocol v1, ignore any vfs operations */
391 /* except read,pread,write,pwrite, and set the "Write" */
392 /* bool accordingly, send data and return. */
394 if ( vfs_operation > vfs_id_pwrite ) return;
396 if ( vfs_operation <= vfs_id_pread ) Write=false;
397 else Write=true;
399 str = talloc_asprintf(talloc_tos(),
400 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
401 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
402 (unsigned int) s_data->len,
403 username,
404 pdb_get_domain(handle->conn->server_info->sam_account),
405 Write ? 'W' : 'R',
406 handle->conn->connectpath,
407 s_data->filename,
408 tm->tm_year+1900,
409 tm->tm_mon+1,
410 tm->tm_mday,
411 tm->tm_hour,
412 tm->tm_min,
413 tm->tm_sec,
414 (int)seconds);
415 if (write_data(rf_sock->sock, str, len) != len) {
416 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
417 "error sending V1 protocol data to socket!\n"));
418 return;
421 } else if ( strcmp( protocol_version, "V2") == 0) {
423 switch( vfs_operation ) {
424 case vfs_id_mkdir: ;
425 str = smb_traffic_analyzer_create_string( tm, \
426 seconds, handle, username, vfs_id_mkdir, 3,\
427 ((struct mkdir_data *) data)->path, \
428 talloc_asprintf( talloc_tos(), "%u", \
429 ((struct mkdir_data *) data)->mode), \
430 talloc_asprintf( talloc_tos(), "%u", \
431 ((struct mkdir_data *) data)->result ));
432 break;
433 case vfs_id_rmdir: ;
434 str = smb_traffic_analyzer_create_string( tm, \
435 seconds, handle, username, vfs_id_rmdir, 2,\
436 ((struct rmdir_data *) data)->path, \
437 talloc_asprintf( talloc_tos(), "%u", \
438 ((struct rmdir_data *) data)->result ));
439 break;
440 case vfs_id_rename: ;
441 str = smb_traffic_analyzer_create_string( tm, \
442 seconds, handle, username, vfs_id_rename, 3,\
443 ((struct rename_data *) data)->src, \
444 ((struct rename_data *) data)->dst,
445 talloc_asprintf(talloc_tos(), "%u", \
446 ((struct rename_data *) data)->result));
447 break;
448 case vfs_id_chdir: ;
449 str = smb_traffic_analyzer_create_string( tm, \
450 seconds, handle, username, vfs_id_chdir, 2,\
451 ((struct chdir_data *) data)->path, \
452 talloc_asprintf(talloc_tos(), "%u", \
453 ((struct chdir_data *) data)->result));
454 break;
456 case vfs_id_write:
457 case vfs_id_pwrite:
458 case vfs_id_read:
459 case vfs_id_pread: ;
460 str = smb_traffic_analyzer_create_string( tm, \
461 seconds, handle, username, vfs_operation, 2,\
462 ((struct rw_data *) data)->filename, \
463 talloc_asprintf(talloc_tos(), "%u", \
464 ((struct rw_data *) data)->len));
465 break;
466 default:
467 DEBUG(1, ("smb_traffic_analyzer: error! "
468 "wrong VFS operation id detected!\n"));
469 return;
472 } else {
473 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
474 "error, unkown protocol given!\n"));
475 return;
478 if (!str) {
479 DEBUG(1, ("smb_traffic_analyzer_send_data: "
480 "unable to create string to send!\n"));
481 return;
485 /* If configured, optain the key and run AES encryption */
486 /* over the data. */
487 size_t size;
488 char *akey = secrets_fetch("smb_traffic_analyzer_key", &size);
489 if ( akey != NULL ) {
490 char *crypted;
491 state_flags[2] = 'E';
492 DEBUG(10, ("smb_traffic_analyzer: a key was found, encrypting "
493 "data!"));
494 AES_KEY *key;
495 samba_AES_set_encrypt_key(akey, 128, key);
496 samba_AES_encrypt( str, crypted, key );
497 len = strlen( crypted );
498 header = talloc_asprintf( talloc_tos(), "V2.%s%017u",
499 state_flags, len);
501 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
502 " header created for crypted data: %s", header));
503 len = strlen(header);
504 if (write_data(rf_sock->sock, header, len) != len) {
505 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
506 "error sending the header"
507 " over the socket!\n"));
509 len = strlen(crypted);
510 if (write_data(rf_sock->sock, crypted, len) != len) {
511 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
512 "error sending crypted data to socket!\n"));
513 free( crypted );
514 return ;
518 len = strlen(str);
519 header = talloc_asprintf(talloc_tos(), "V2.%s%017u", state_flags, len);
520 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: header created:"
521 "%s\n", header));
522 len = strlen(header);
523 if (write_data(rf_sock->sock, header, len) != len) {
524 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: error "
525 "sending the header over the socket!\n"));
527 len = strlen(str);
528 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: going to send "
529 "data block: %s\n",str));
530 if (write_data(rf_sock->sock, str, len) != len) {
531 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
532 "error sending data to socket!\n"));
533 return ;
537 static struct refcounted_sock *sock_list;
539 static void smb_traffic_analyzer_free_data(void **pptr)
541 struct refcounted_sock *rf_sock = *(struct refcounted_sock **)pptr;
542 if (rf_sock == NULL) {
543 return;
545 rf_sock->ref_count--;
546 if (rf_sock->ref_count != 0) {
547 return;
549 if (rf_sock->sock != -1) {
550 close(rf_sock->sock);
552 DLIST_REMOVE(sock_list, rf_sock);
553 TALLOC_FREE(rf_sock);
556 static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
557 const char *service,
558 const char *user)
560 connection_struct *conn = handle->conn;
561 enum sock_type st = smb_traffic_analyzer_connMode(handle);
562 struct refcounted_sock *rf_sock = NULL;
563 const char *name = (st == UNIX_DOMAIN_SOCKET) ? LOCAL_PATHNAME :
564 lp_parm_const_string(SNUM(conn),
565 "smb_traffic_analyzer",
566 "host", "localhost");
567 uint16_t port = (st == UNIX_DOMAIN_SOCKET) ? 0 :
568 atoi( lp_parm_const_string(SNUM(conn),
569 "smb_traffic_analyzer", "port", "9430"));
570 int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
572 if (ret < 0) {
573 return ret;
576 /* Are we already connected ? */
577 for (rf_sock = sock_list; rf_sock; rf_sock = rf_sock->next) {
578 if (port == rf_sock->port &&
579 (strcmp(name, rf_sock->name) == 0)) {
580 break;
584 /* If we're connected already, just increase the
585 * reference count. */
586 if (rf_sock) {
587 rf_sock->ref_count++;
588 } else {
589 /* New connection. */
590 rf_sock = TALLOC_ZERO_P(NULL, struct refcounted_sock);
591 if (rf_sock == NULL) {
592 SMB_VFS_NEXT_DISCONNECT(handle);
593 errno = ENOMEM;
594 return -1;
596 rf_sock->name = talloc_strdup(rf_sock, name);
597 if (rf_sock->name == NULL) {
598 SMB_VFS_NEXT_DISCONNECT(handle);
599 TALLOC_FREE(rf_sock);
600 errno = ENOMEM;
601 return -1;
603 rf_sock->port = port;
604 rf_sock->ref_count = 1;
606 if (st == UNIX_DOMAIN_SOCKET) {
607 rf_sock->sock = smb_traffic_analyzer_connect_unix_socket(handle,
608 name);
609 } else {
611 rf_sock->sock = smb_traffic_analyzer_connect_inet_socket(handle,
612 name,
613 port);
615 if (rf_sock->sock == -1) {
616 SMB_VFS_NEXT_DISCONNECT(handle);
617 TALLOC_FREE(rf_sock);
618 return -1;
620 DLIST_ADD(sock_list, rf_sock);
623 /* Store the private data. */
624 SMB_VFS_HANDLE_SET_DATA(handle, rf_sock, smb_traffic_analyzer_free_data,
625 struct refcounted_sock, return -1);
626 return 0;
629 /* VFS Functions */
630 static int smb_traffic_analyzer_chdir(vfs_handle_struct *handle, \
631 const char *path)
633 struct chdir_data s_data;
634 s_data.result = SMB_VFS_NEXT_CHDIR(handle, path);
635 s_data.path = path;
636 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path));
637 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_chdir);
638 return s_data.result;
641 static int smb_traffic_analyzer_rename(vfs_handle_struct *handle, \
642 const struct smb_filename *smb_fname_src,
643 const struct smb_filename *smb_fname_dst)
645 struct rename_data s_data;
646 s_data.result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, \
647 smb_fname_dst);
648 s_data.src = smb_fname_src->base_name;
649 s_data.dst = smb_fname_dst->base_name;
650 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
651 smb_fname_src->base_name,
652 smb_fname_dst->base_name));
653 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rename);
654 return s_data.result;
657 static int smb_traffic_analyzer_rmdir(vfs_handle_struct *handle, \
658 const char *path)
660 struct rmdir_data s_data;
661 s_data.result = SMB_VFS_NEXT_RMDIR(handle, path);
662 s_data.path = path;
663 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path));
664 smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rmdir);
665 return s_data.result;
668 static int smb_traffic_analyzer_mkdir(vfs_handle_struct *handle, \
669 const char *path, mode_t mode)
671 struct mkdir_data s_data;
672 s_data.result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
673 s_data.path = path;
674 s_data.mode = mode;
675 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path));
676 smb_traffic_analyzer_send_data(handle,
677 &s_data,
678 vfs_id_mkdir);
679 return s_data.result;
682 static ssize_t smb_traffic_analyzer_read(vfs_handle_struct *handle, \
683 files_struct *fsp, void *data, size_t n)
685 struct rw_data s_data;
687 s_data.len = SMB_VFS_NEXT_READ(handle, fsp, data, n);
688 s_data.filename = fsp->fsp_name->base_name;
689 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp)));
691 smb_traffic_analyzer_send_data(handle,
692 &s_data,
693 vfs_id_read);
694 return s_data.len;
698 static ssize_t smb_traffic_analyzer_pread(vfs_handle_struct *handle, \
699 files_struct *fsp, void *data, size_t n, SMB_OFF_T offset)
701 struct rw_data s_data;
703 s_data.len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
704 s_data.filename = fsp->fsp_name->base_name;
705 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
706 fsp_str_dbg(fsp)));
708 smb_traffic_analyzer_send_data(handle,
709 &s_data,
710 vfs_id_pread);
712 return s_data.len;
715 static ssize_t smb_traffic_analyzer_write(vfs_handle_struct *handle, \
716 files_struct *fsp, const void *data, size_t n)
718 struct rw_data s_data;
720 s_data.len = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
721 s_data.filename = fsp->fsp_name->base_name;
722 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
723 fsp_str_dbg(fsp)));
725 smb_traffic_analyzer_send_data(handle,
726 &s_data,
727 vfs_id_write);
728 return s_data.len;
731 static ssize_t smb_traffic_analyzer_pwrite(vfs_handle_struct *handle, \
732 files_struct *fsp, const void *data, size_t n, SMB_OFF_T offset)
734 struct rw_data s_data;
736 s_data.len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
737 s_data.filename = fsp->fsp_name->base_name;
738 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
739 fsp_str_dbg(fsp)));
741 smb_traffic_analyzer_send_data(handle,
742 &s_data,
743 vfs_id_pwrite);
744 return s_data.len;
747 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
748 .connect_fn = smb_traffic_analyzer_connect,
749 .vfs_read = smb_traffic_analyzer_read,
750 .pread = smb_traffic_analyzer_pread,
751 .write = smb_traffic_analyzer_write,
752 .pwrite = smb_traffic_analyzer_pwrite,
753 .mkdir = smb_traffic_analyzer_mkdir,
754 .rename = smb_traffic_analyzer_rename,
755 .chdir = smb_traffic_analyzer_chdir
758 /* Module initialization */
760 NTSTATUS vfs_smb_traffic_analyzer_init(void)
762 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
763 "smb_traffic_analyzer",
764 &vfs_smb_traffic_analyzer_fns);
766 if (!NT_STATUS_IS_OK(ret)) {
767 return ret;
770 vfs_smb_traffic_analyzer_debug_level =
771 debug_add_class("smb_traffic_analyzer");
773 if (vfs_smb_traffic_analyzer_debug_level == -1) {
774 vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
775 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
776 "debugging class!\n"));
777 } else {
778 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
779 "'smb_traffic_analyzer': %d\n", \
780 vfs_smb_traffic_analyzer_debug_level));
783 return ret;