2 * traffic-analyzer VFS module. Measure the smb traffic users create
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/>.
23 #include "smbd/smbd.h"
24 #include "../smbd/globals.h"
25 #include "../lib/crypto/crypto.h"
26 #include "vfs_smb_traffic_analyzer.h"
27 #include "../libcli/security/security.h"
29 #include "../librpc/gen_ndr/ndr_netlogon.h"
31 #include "../lib/tsocket/tsocket.h"
33 /* abstraction for the send_over_network function */
34 enum sock_type
{INTERNET_SOCKET
= 0, UNIX_DOMAIN_SOCKET
};
36 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
38 static int vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
40 static enum sock_type
smb_traffic_analyzer_connMode(vfs_handle_struct
*handle
)
42 connection_struct
*conn
= handle
->conn
;
44 Mode
=lp_parm_const_string(SNUM(conn
), "smb_traffic_analyzer","mode", \
46 if (strstr(Mode
,"unix_domain_socket")) {
47 return UNIX_DOMAIN_SOCKET
;
49 return INTERNET_SOCKET
;
54 /* Connect to an internet socket */
55 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct
*handle
,
56 const char *name
, uint16_t port
)
58 /* Create a streaming Socket */
60 struct addrinfo hints
;
61 struct addrinfo
*ailist
= NULL
;
62 struct addrinfo
*res
= NULL
;
66 /* By default make sure it supports TCP. */
67 hints
.ai_socktype
= SOCK_STREAM
;
68 hints
.ai_flags
= AI_ADDRCONFIG
;
70 ret
= getaddrinfo(name
,
76 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
77 "getaddrinfo failed for name %s [%s]\n",
83 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
84 "Port: %i\n", name
, port
));
86 for (res
= ailist
; res
; res
= res
->ai_next
) {
87 struct sockaddr_storage ss
;
90 if (!res
->ai_addr
|| res
->ai_addrlen
== 0) {
95 memcpy(&ss
, res
->ai_addr
, res
->ai_addrlen
);
97 status
= open_socket_out(&ss
, port
, 10000, &sockfd
);
98 if (NT_STATUS_IS_OK(status
)) {
104 freeaddrinfo(ailist
);
108 DEBUG(1, ("smb_traffic_analyzer: unable to create "
109 "socket, error is %s",
117 /* Connect to a unix domain socket */
118 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct
*handle
,
121 /* Create the socket to stad */
123 struct sockaddr_un remote
;
125 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
126 "Unix domain socket mode. Using %s\n",
129 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
130 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
131 "Couldn't create socket, "
132 "make sure stad is running!\n"));
135 remote
.sun_family
= AF_UNIX
;
136 strlcpy(remote
.sun_path
, name
,
137 sizeof(remote
.sun_path
));
138 len
=strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
139 if (connect(sock
, (struct sockaddr
*)&remote
, len
) == -1 ) {
140 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
141 "Could not connect to "
142 "socket, make sure\nstad is running!\n"));
149 /* Private data allowing shared connection sockets. */
150 struct refcounted_sock
{
151 struct refcounted_sock
*next
, *prev
;
155 unsigned int ref_count
;
160 * Encryption of a data block with AES
161 * TALLOC_CTX *ctx Talloc context to work on
162 * const char *akey 128bit key for the encryption
163 * const char *str Data buffer to encrypt, \0 terminated
164 * int *len Will be set to the length of the
165 * resulting data block
166 * The caller has to take care for the memory
167 * allocated on the context.
169 static char *smb_traffic_analyzer_encrypt( TALLOC_CTX
*ctx
,
170 const char *akey
, const char *str
, size_t *len
)
174 unsigned char filler
[17]= "................";
176 unsigned char crypted
[18];
177 if (akey
== NULL
) return NULL
;
178 samba_AES_set_encrypt_key((const unsigned char *) akey
, 128, &key
);
179 s1
= strlen(str
) / 16;
180 s2
= strlen(str
) % 16;
181 for (h
= 0; h
< s2
; h
++) *(filler
+h
)=*(str
+(s1
*16)+h
);
182 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
183 " as filling block.\n", filler
));
184 output
= talloc_array(ctx
, char, (s1
*16)+17 );
186 for (h
= 0; h
< s1
; h
++) {
187 samba_AES_encrypt((const unsigned char *) str
+(16*h
), crypted
, &key
);
188 for (d
= 0; d
<16; d
++) output
[d
+(16*h
)]=crypted
[d
];
190 samba_AES_encrypt( (const unsigned char *) str
+(16*h
), filler
, &key
);
191 for (d
= 0;d
< 16; d
++) output
[d
+(16*h
)]=*(filler
+d
);
197 * Create a v2 header.
198 * TALLLOC_CTX *ctx Talloc context to work on
199 * const char *state_flags State flag string
200 * int len length of the data block
202 static char *smb_traffic_analyzer_create_header( TALLOC_CTX
*ctx
,
203 const char *state_flags
, size_t data_len
)
205 char *header
= talloc_asprintf( ctx
, "V2.%s%017u",
206 state_flags
, (unsigned int) data_len
);
207 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
208 dump_data(10, (uint8_t *)header
, strlen(header
));
214 * Actually send header and data over the network
215 * char *header Header data
216 * char *data Data Block
217 * int dlength Length of data block
220 static void smb_traffic_analyzer_write_data( char *header
, char *data
,
221 int dlength
, int _socket
)
223 int len
= strlen(header
);
224 if (write_data( _socket
, header
, len
) != len
) {
225 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
226 "error sending the header"
227 " over the socket!\n"));
229 DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
230 dump_data( 10, (uint8_t *)data
, dlength
);
232 if (write_data( _socket
, data
, dlength
) != dlength
) {
233 DEBUG(1, ("smb_traffic_analyzer_write_data: "
234 "error sending crypted data to socket!\n"));
240 * Anonymize a string if required.
241 * TALLOC_CTX *ctx The talloc context to work on
242 * const char *str The string to anonymize
243 * vfs_handle_struct *handle The handle struct to work on
245 * Returns a newly allocated string, either the anonymized one,
246 * or a copy of const char *str. The caller has to take care for
247 * freeing the allocated memory.
249 static char *smb_traffic_analyzer_anonymize( TALLOC_CTX
*ctx
,
251 vfs_handle_struct
*handle
)
253 const char *total_anonymization
;
254 const char *anon_prefix
;
256 total_anonymization
=lp_parm_const_string(SNUM(handle
->conn
),
257 "smb_traffic_analyzer",
258 "total_anonymization", NULL
);
260 anon_prefix
=lp_parm_const_string(SNUM(handle
->conn
),
261 "smb_traffic_analyzer",
262 "anonymize_prefix", NULL
);
263 if (anon_prefix
!= NULL
) {
264 if (total_anonymization
!= NULL
) {
265 output
= talloc_asprintf(ctx
, "%s",
268 output
= talloc_asprintf(ctx
, "%s%i", anon_prefix
,
272 output
= talloc_asprintf(ctx
, "%s", str
);
280 * The marshalling function for protocol v2.
281 * TALLOC_CTX *ctx Talloc context to work on
282 * struct tm *tm tm struct for the timestamp
283 * int seconds milliseconds of the timestamp
284 * vfs_handle_struct *handle vfs_handle_struct
285 * char *username Name of the user
286 * int vfs_operation VFS operation identifier
287 * int count Number of the common data blocks
288 * [...] variable args data blocks taken from the individual
289 * VFS data structures
291 * Returns the complete data block to send. The caller has to
292 * take care for freeing the allocated buffer.
294 static char *smb_traffic_analyzer_create_string( TALLOC_CTX
*ctx
,
295 struct tm
*tm
, int seconds
, vfs_handle_struct
*handle
, \
296 char *username
, int vfs_operation
, int count
, ... )
302 char *common_data_count_str
= NULL
;
303 char *timestr
= NULL
;
305 char *usersid
= NULL
;
308 char *vfs_operation_str
= NULL
;
309 const char *service_name
= lp_const_servicename(handle
->conn
->params
->service
);
312 * first create the data that is transfered with any VFS op
313 * These are, in the following order:
314 *(0) number of data to come [6 in v2.0]
315 * 1.vfs_operation identifier
321 * 7.IP Addresss of client
325 * number of common data blocks to come,
326 * this is a #define in vfs_smb_traffic_anaylzer.h,
327 * it's length is known at compile time
329 common_data_count_str
= talloc_strdup( ctx
, SMBTA_COMMON_DATA_COUNT
);
330 /* vfs operation identifier */
331 vfs_operation_str
= talloc_asprintf( common_data_count_str
, "%i",
334 * Handle anonymization. In protocol v2, we have to anonymize
335 * both the SID and the username. The name is already
336 * anonymized if needed, by the calling function.
338 usersid
= dom_sid_string( common_data_count_str
,
339 &handle
->conn
->session_info
->security_token
->sids
[0]);
341 sidstr
= smb_traffic_analyzer_anonymize(
342 common_data_count_str
,
346 raddr
= tsocket_address_inet_addr_string(handle
->conn
->sconn
->remote_address
,
353 timestr
= talloc_asprintf( common_data_count_str
, \
354 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
362 len
= strlen( timestr
);
363 /* create the string of common data */
364 buf
= talloc_asprintf(ctx
,
365 "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
366 common_data_count_str
,
367 (unsigned int) strlen(vfs_operation_str
),
369 (unsigned int) strlen(username
),
371 (unsigned int) strlen(sidstr
),
373 (unsigned int) strlen(service_name
),
376 strlen(handle
->conn
->session_info
->info
->domain_name
),
377 handle
->conn
->session_info
->info
->domain_name
,
378 (unsigned int) strlen(timestr
),
380 (unsigned int) strlen(raddr
),
383 talloc_free(common_data_count_str
);
385 /* data blocks depending on the VFS function */
386 va_start( ap
, count
);
388 arg
= va_arg( ap
, char * );
390 * protocol v2 sends a four byte string
391 * as a header to each block, including
392 * the numbers of bytes to come in the
396 buf
= talloc_asprintf_append( buf
, "%04u%s", len
, arg
);
402 static void smb_traffic_analyzer_send_data(vfs_handle_struct
*handle
,
404 enum vfs_id vfs_operation
)
406 struct refcounted_sock
*rf_sock
= NULL
;
409 struct tm
*tm
= NULL
;
412 char *username
= NULL
;
414 const char *protocol_version
= NULL
;
421 * The state flags are part of the header
422 * and are descripted in the protocol description
423 * in vfs_smb_traffic_analyzer.h. They begin at byte
426 char state_flags
[9] = "000000\0";
429 * The first byte of the state flag string represents
430 * the modules protocol subversion number, defined
431 * in smb_traffic_analyzer.h. smbtatools/smbtad are designed
432 * to handle not yet implemented protocol enhancements
433 * by ignoring them. By recognizing the SMBTA_SUBRELEASE
434 * smbtatools can tell the user to update the client
437 state_flags
[0] = SMBTA_SUBRELEASE
;
439 SMB_VFS_HANDLE_GET_DATA(handle
, rf_sock
, struct refcounted_sock
, return);
441 if (rf_sock
== NULL
|| rf_sock
->sock
== -1) {
442 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
449 tm
= localtime(&tv_sec
);
453 seconds
=(float) (tv
.tv_usec
/ 1000);
456 * Check if anonymization is required, and if yes do this only for
457 * the username here, needed vor protocol version 1. In v2 we
458 * additionally anonymize the SID, which is done in it's marshalling
461 username
= smb_traffic_analyzer_anonymize( talloc_tos(),
462 handle
->conn
->session_info
->unix_info
->sanitized_username
,
469 protocol_version
= lp_parm_const_string(SNUM(handle
->conn
),
470 "smb_traffic_analyzer",
471 "protocol_version", NULL
);
474 if (protocol_version
!= NULL
&& strcmp(protocol_version
,"V1") == 0) {
476 struct rw_data
*s_data
= (struct rw_data
*) data
;
479 * in case of protocol v1, ignore any vfs operations
480 * except read,pread,write,pwrite, and set the "Write"
481 * bool accordingly, send data and return.
483 if ( vfs_operation
> vfs_id_pwrite
) return;
485 if ( vfs_operation
<= vfs_id_pread
) Write
=false;
488 str
= talloc_asprintf(talloc_tos(),
489 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
490 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
491 (unsigned int) s_data
->len
,
493 handle
->conn
->session_info
->info
->domain_name
,
495 handle
->conn
->connectpath
,
505 if (write_data(rf_sock
->sock
, str
, len
) != len
) {
506 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
507 "error sending V1 protocol data to socket!\n"));
513 * Protocol 2 is used by default.
516 switch( vfs_operation
) {
518 str
= smb_traffic_analyzer_create_string( talloc_tos(),
519 tm
, seconds
, handle
, username
, vfs_id_open
,
520 3, ((struct open_data
*) data
)->filename
,
521 talloc_asprintf( talloc_tos(), "%u",
522 ((struct open_data
*) data
)->mode
),
523 talloc_asprintf( talloc_tos(), "%u",
524 ((struct open_data
*) data
)->result
));
527 str
= smb_traffic_analyzer_create_string( talloc_tos(),
528 tm
, seconds
, handle
, username
, vfs_id_close
,
529 2, ((struct close_data
*) data
)->filename
,
530 talloc_asprintf( talloc_tos(), "%u",
531 ((struct close_data
*) data
)->result
));
534 str
= smb_traffic_analyzer_create_string( talloc_tos(),
535 tm
, seconds
, handle
, username
, vfs_id_mkdir
, \
536 3, ((struct mkdir_data
*) data
)->path
, \
537 talloc_asprintf( talloc_tos(), "%u", \
538 ((struct mkdir_data
*) data
)->mode
), \
539 talloc_asprintf( talloc_tos(), "%u", \
540 ((struct mkdir_data
*) data
)->result
));
543 str
= smb_traffic_analyzer_create_string( talloc_tos(),
544 tm
, seconds
, handle
, username
, vfs_id_rmdir
,
545 2, ((struct rmdir_data
*) data
)->path
, \
546 talloc_asprintf( talloc_tos(), "%u", \
547 ((struct rmdir_data
*) data
)->result
));
549 case vfs_id_rename
: ;
550 str
= smb_traffic_analyzer_create_string( talloc_tos(),
551 tm
, seconds
, handle
, username
, vfs_id_rename
,
552 3, ((struct rename_data
*) data
)->src
, \
553 ((struct rename_data
*) data
)->dst
,
554 talloc_asprintf(talloc_tos(), "%u", \
555 ((struct rename_data
*) data
)->result
));
558 str
= smb_traffic_analyzer_create_string( talloc_tos(),
559 tm
, seconds
, handle
, username
, vfs_id_chdir
,
560 2, ((struct chdir_data
*) data
)->path
, \
561 talloc_asprintf(talloc_tos(), "%u", \
562 ((struct chdir_data
*) data
)->result
));
569 str
= smb_traffic_analyzer_create_string( talloc_tos(),
570 tm
, seconds
, handle
, username
, vfs_operation
,
571 2, ((struct rw_data
*) data
)->filename
, \
572 talloc_asprintf(talloc_tos(), "%u", \
574 ((struct rw_data
*) data
)->len
));
577 DEBUG(1, ("smb_traffic_analyzer: error! "
578 "wrong VFS operation id detected!\n"));
585 DEBUG(1, ("smb_traffic_analyzer_send_data: "
586 "unable to create string to send!\n"));
592 * If configured, optain the key and run AES encryption
596 akey
= (char *) secrets_fetch("smb_traffic_analyzer_key", &size
);
598 if ( akey
!= NULL
) {
599 state_flags
[2] = 'E';
600 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
601 " found, encrypting data!\n"));
602 output
= smb_traffic_analyzer_encrypt( talloc_tos(),
605 header
= smb_traffic_analyzer_create_header( talloc_tos(),
608 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
609 " header created for crypted data: %s\n", header
));
610 smb_traffic_analyzer_write_data(header
, output
, len
,
617 header
= smb_traffic_analyzer_create_header( talloc_tos(),
619 smb_traffic_analyzer_write_data(header
, str
, strlen(str
),
624 static struct refcounted_sock
*sock_list
;
626 static void smb_traffic_analyzer_free_data(void **pptr
)
628 struct refcounted_sock
*rf_sock
= *(struct refcounted_sock
**)pptr
;
629 if (rf_sock
== NULL
) {
632 rf_sock
->ref_count
--;
633 if (rf_sock
->ref_count
!= 0) {
636 if (rf_sock
->sock
!= -1) {
637 close(rf_sock
->sock
);
639 DLIST_REMOVE(sock_list
, rf_sock
);
640 TALLOC_FREE(rf_sock
);
643 static int smb_traffic_analyzer_connect(struct vfs_handle_struct
*handle
,
647 connection_struct
*conn
= handle
->conn
;
648 enum sock_type st
= smb_traffic_analyzer_connMode(handle
);
649 struct refcounted_sock
*rf_sock
= NULL
;
650 const char *name
= (st
== UNIX_DOMAIN_SOCKET
) ? LOCAL_PATHNAME
:
651 lp_parm_const_string(SNUM(conn
),
652 "smb_traffic_analyzer",
653 "host", "localhost");
654 uint16_t port
= (st
== UNIX_DOMAIN_SOCKET
) ? 0 :
655 atoi( lp_parm_const_string(SNUM(conn
),
656 "smb_traffic_analyzer", "port", "9430"));
657 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
663 /* Are we already connected ? */
664 for (rf_sock
= sock_list
; rf_sock
; rf_sock
= rf_sock
->next
) {
665 if (port
== rf_sock
->port
&&
666 (strcmp(name
, rf_sock
->name
) == 0)) {
671 /* If we're connected already, just increase the
672 * reference count. */
674 rf_sock
->ref_count
++;
676 /* New connection. */
677 rf_sock
= talloc_zero(NULL
, struct refcounted_sock
);
678 if (rf_sock
== NULL
) {
679 SMB_VFS_NEXT_DISCONNECT(handle
);
683 rf_sock
->name
= talloc_strdup(rf_sock
, name
);
684 if (rf_sock
->name
== NULL
) {
685 SMB_VFS_NEXT_DISCONNECT(handle
);
686 TALLOC_FREE(rf_sock
);
690 rf_sock
->port
= port
;
691 rf_sock
->ref_count
= 1;
693 if (st
== UNIX_DOMAIN_SOCKET
) {
694 rf_sock
->sock
= smb_traffic_analyzer_connect_unix_socket(handle
,
698 rf_sock
->sock
= smb_traffic_analyzer_connect_inet_socket(handle
,
702 if (rf_sock
->sock
== -1) {
703 SMB_VFS_NEXT_DISCONNECT(handle
);
704 TALLOC_FREE(rf_sock
);
707 DLIST_ADD(sock_list
, rf_sock
);
710 /* Store the private data. */
711 SMB_VFS_HANDLE_SET_DATA(handle
, rf_sock
, smb_traffic_analyzer_free_data
,
712 struct refcounted_sock
, return -1);
717 static int smb_traffic_analyzer_chdir(vfs_handle_struct
*handle
, \
720 struct chdir_data s_data
;
721 s_data
.result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
723 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path
));
724 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_chdir
);
725 return s_data
.result
;
728 static int smb_traffic_analyzer_rename(vfs_handle_struct
*handle
, \
729 const struct smb_filename
*smb_fname_src
,
730 const struct smb_filename
*smb_fname_dst
)
732 struct rename_data s_data
;
733 s_data
.result
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, \
735 s_data
.src
= smb_fname_src
->base_name
;
736 s_data
.dst
= smb_fname_dst
->base_name
;
737 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
738 smb_fname_src
->base_name
,
739 smb_fname_dst
->base_name
));
740 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rename
);
741 return s_data
.result
;
744 static int smb_traffic_analyzer_rmdir(vfs_handle_struct
*handle
, \
747 struct rmdir_data s_data
;
748 s_data
.result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
750 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path
));
751 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rmdir
);
752 return s_data
.result
;
755 static int smb_traffic_analyzer_mkdir(vfs_handle_struct
*handle
, \
756 const char *path
, mode_t mode
)
758 struct mkdir_data s_data
;
759 s_data
.result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
762 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path
));
763 smb_traffic_analyzer_send_data(handle
,
766 return s_data
.result
;
769 static ssize_t
smb_traffic_analyzer_sendfile(vfs_handle_struct
*handle
,
771 files_struct
*fromfsp
,
772 const DATA_BLOB
*hdr
,
776 struct rw_data s_data
;
777 s_data
.len
= SMB_VFS_NEXT_SENDFILE(handle
,
778 tofd
, fromfsp
, hdr
, offset
, n
);
779 s_data
.filename
= fromfsp
->fsp_name
->base_name
;
780 DEBUG(10, ("smb_traffic_analyzer_sendfile: sendfile(r): %s\n",
781 fsp_str_dbg(fromfsp
)));
782 smb_traffic_analyzer_send_data(handle
,
788 static ssize_t
smb_traffic_analyzer_recvfile(vfs_handle_struct
*handle
,
794 struct rw_data s_data
;
795 s_data
.len
= SMB_VFS_NEXT_RECVFILE(handle
,
796 fromfd
, tofsp
, offset
, n
);
797 s_data
.filename
= tofsp
->fsp_name
->base_name
;
798 DEBUG(10, ("smb_traffic_analyzer_recvfile: recvfile(w): %s\n",
799 fsp_str_dbg(tofsp
)));
800 smb_traffic_analyzer_send_data(handle
,
807 static ssize_t
smb_traffic_analyzer_read(vfs_handle_struct
*handle
, \
808 files_struct
*fsp
, void *data
, size_t n
)
810 struct rw_data s_data
;
812 s_data
.len
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
813 s_data
.filename
= fsp
->fsp_name
->base_name
;
814 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp
)));
816 smb_traffic_analyzer_send_data(handle
,
823 static ssize_t
smb_traffic_analyzer_pread(vfs_handle_struct
*handle
, \
824 files_struct
*fsp
, void *data
, size_t n
, SMB_OFF_T offset
)
826 struct rw_data s_data
;
828 s_data
.len
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
829 s_data
.filename
= fsp
->fsp_name
->base_name
;
830 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
833 smb_traffic_analyzer_send_data(handle
,
840 static ssize_t
smb_traffic_analyzer_write(vfs_handle_struct
*handle
, \
841 files_struct
*fsp
, const void *data
, size_t n
)
843 struct rw_data s_data
;
845 s_data
.len
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
846 s_data
.filename
= fsp
->fsp_name
->base_name
;
847 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
850 smb_traffic_analyzer_send_data(handle
,
856 static ssize_t
smb_traffic_analyzer_pwrite(vfs_handle_struct
*handle
, \
857 files_struct
*fsp
, const void *data
, size_t n
, SMB_OFF_T offset
)
859 struct rw_data s_data
;
861 s_data
.len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
862 s_data
.filename
= fsp
->fsp_name
->base_name
;
863 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
866 smb_traffic_analyzer_send_data(handle
,
872 static int smb_traffic_analyzer_open(vfs_handle_struct
*handle
, \
873 struct smb_filename
*smb_fname
, files_struct
*fsp
,\
874 int flags
, mode_t mode
)
876 struct open_data s_data
;
878 s_data
.result
= SMB_VFS_NEXT_OPEN( handle
, smb_fname
, fsp
,
880 DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
882 s_data
.filename
= fsp
->fsp_name
->base_name
;
884 smb_traffic_analyzer_send_data(handle
,
887 return s_data
.result
;
890 static int smb_traffic_analyzer_close(vfs_handle_struct
*handle
, \
893 struct close_data s_data
;
894 s_data
.result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
895 DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
897 s_data
.filename
= fsp
->fsp_name
->base_name
;
898 smb_traffic_analyzer_send_data(handle
,
901 return s_data
.result
;
905 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns
= {
906 .connect_fn
= smb_traffic_analyzer_connect
,
907 .vfs_read
= smb_traffic_analyzer_read
,
908 .pread
= smb_traffic_analyzer_pread
,
909 .write
= smb_traffic_analyzer_write
,
910 .pwrite
= smb_traffic_analyzer_pwrite
,
911 .mkdir
= smb_traffic_analyzer_mkdir
,
912 .rename
= smb_traffic_analyzer_rename
,
913 .chdir
= smb_traffic_analyzer_chdir
,
914 .open_fn
= smb_traffic_analyzer_open
,
915 .rmdir
= smb_traffic_analyzer_rmdir
,
916 .close_fn
= smb_traffic_analyzer_close
,
917 .sendfile
= smb_traffic_analyzer_sendfile
,
918 .recvfile
= smb_traffic_analyzer_recvfile
921 /* Module initialization */
922 NTSTATUS
vfs_smb_traffic_analyzer_init(void)
924 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
925 "smb_traffic_analyzer",
926 &vfs_smb_traffic_analyzer_fns
);
928 if (!NT_STATUS_IS_OK(ret
)) {
932 vfs_smb_traffic_analyzer_debug_level
=
933 debug_add_class("smb_traffic_analyzer");
935 if (vfs_smb_traffic_analyzer_debug_level
== -1) {
936 vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
937 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
938 "debugging class!\n"));
940 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
941 "'smb_traffic_analyzer': %d\n", \
942 vfs_smb_traffic_analyzer_debug_level
));