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 "../lib/crypto/crypto.h"
24 #include "vfs_smb_traffic_analyzer.h"
25 #include "../libcli/security/dom_sid.h"
27 #include "../librpc/gen_ndr/ndr_netlogon.h"
29 /* abstraction for the send_over_network function */
30 enum sock_type
{INTERNET_SOCKET
= 0, UNIX_DOMAIN_SOCKET
};
32 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
34 static int vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
36 static enum sock_type
smb_traffic_analyzer_connMode(vfs_handle_struct
*handle
)
38 connection_struct
*conn
= handle
->conn
;
40 Mode
=lp_parm_const_string(SNUM(conn
), "smb_traffic_analyzer","mode", \
42 if (strstr(Mode
,"unix_domain_socket")) {
43 return UNIX_DOMAIN_SOCKET
;
45 return INTERNET_SOCKET
;
50 /* Connect to an internet socket */
51 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct
*handle
,
52 const char *name
, uint16_t port
)
54 /* Create a streaming Socket */
56 struct addrinfo hints
;
57 struct addrinfo
*ailist
= NULL
;
58 struct addrinfo
*res
= NULL
;
62 /* By default make sure it supports TCP. */
63 hints
.ai_socktype
= SOCK_STREAM
;
64 hints
.ai_flags
= AI_ADDRCONFIG
;
66 ret
= getaddrinfo(name
,
72 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
73 "getaddrinfo failed for name %s [%s]\n",
79 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
80 "Port: %i\n", name
, port
));
82 for (res
= ailist
; res
; res
= res
->ai_next
) {
83 struct sockaddr_storage ss
;
86 if (!res
->ai_addr
|| res
->ai_addrlen
== 0) {
91 memcpy(&ss
, res
->ai_addr
, res
->ai_addrlen
);
93 status
= open_socket_out(&ss
, port
, 10000, &sockfd
);
94 if (NT_STATUS_IS_OK(status
)) {
100 freeaddrinfo(ailist
);
104 DEBUG(1, ("smb_traffic_analyzer: unable to create "
105 "socket, error is %s",
113 /* Connect to a unix domain socket */
114 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct
*handle
,
117 /* Create the socket to stad */
119 struct sockaddr_un remote
;
121 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
122 "Unix domain socket mode. Using %s\n",
125 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
126 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
127 "Couldn't create socket, "
128 "make sure stad is running!\n"));
131 remote
.sun_family
= AF_UNIX
;
132 strlcpy(remote
.sun_path
, name
,
133 sizeof(remote
.sun_path
));
134 len
=strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
135 if (connect(sock
, (struct sockaddr
*)&remote
, len
) == -1 ) {
136 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
137 "Could not connect to "
138 "socket, make sure\nstad is running!\n"));
145 /* Private data allowing shared connection sockets. */
146 struct refcounted_sock
{
147 struct refcounted_sock
*next
, *prev
;
151 unsigned int ref_count
;
156 * Encryption of a data block with AES
157 * TALLOC_CTX *ctx Talloc context to work on
158 * const char *akey 128bit key for the encryption
159 * const char *str Data buffer to encrypt, \0 terminated
160 * int *len Will be set to the length of the
161 * resulting data block
162 * The caller has to take care for the memory
163 * allocated on the context.
165 static char *smb_traffic_analyzer_encrypt( TALLOC_CTX
*ctx
,
166 const char *akey
, const char *str
, size_t *len
)
170 unsigned char filler
[17]= "................";
172 unsigned char crypted
[18];
173 if (akey
== NULL
) return NULL
;
174 samba_AES_set_encrypt_key((unsigned char *) akey
, 128, &key
);
175 s1
= strlen(str
) / 16;
176 s2
= strlen(str
) % 16;
177 for (h
= 0; h
< s2
; h
++) *(filler
+h
)=*(str
+(s1
*16)+h
);
178 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
179 " as filling block.\n", filler
));
180 output
= talloc_array(ctx
, char, (s1
*16)+17 );
182 for (h
= 0; h
< s1
; h
++) {
183 samba_AES_encrypt((unsigned char *) str
+(16*h
), crypted
, &key
);
184 for (d
= 0; d
<16; d
++) output
[d
+(16*h
)]=crypted
[d
];
186 samba_AES_encrypt( (unsigned char *) str
+(16*h
), filler
, &key
);
187 for (d
= 0;d
< 16; d
++) output
[d
+(16*h
)]=*(filler
+d
);
193 * Create a v2 header.
194 * TALLLOC_CTX *ctx Talloc context to work on
195 * const char *state_flags State flag string
196 * int len length of the data block
198 static char *smb_traffic_analyzer_create_header( TALLOC_CTX
*ctx
,
199 const char *state_flags
, size_t data_len
)
201 char *header
= talloc_asprintf( ctx
, "V2.%s%017u",
202 state_flags
, (unsigned int) data_len
);
203 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
204 dump_data(10, (uint8_t *)header
, strlen(header
));
210 * Actually send header and data over the network
211 * char *header Header data
212 * char *data Data Block
213 * int dlength Length of data block
216 static void smb_traffic_analyzer_write_data( char *header
, char *data
,
217 int dlength
, int _socket
)
219 int len
= strlen(header
);
220 if (write_data( _socket
, header
, len
) != len
) {
221 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
222 "error sending the header"
223 " over the socket!\n"));
225 DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
226 dump_data( 10, (uint8_t *)data
, dlength
);
228 if (write_data( _socket
, data
, dlength
) != dlength
) {
229 DEBUG(1, ("smb_traffic_analyzer_write_data: "
230 "error sending crypted data to socket!\n"));
236 * Anonymize a string if required.
237 * TALLOC_CTX *ctx The talloc context to work on
238 * const char *str The string to anonymize
239 * vfs_handle_struct *handle The handle struct to work on
241 * Returns a newly allocated string, either the anonymized one,
242 * or a copy of const char *str. The caller has to take care for
243 * freeing the allocated memory.
245 static char *smb_traffic_analyzer_anonymize( TALLOC_CTX
*ctx
,
247 vfs_handle_struct
*handle
)
249 const char *total_anonymization
;
250 const char *anon_prefix
;
252 total_anonymization
=lp_parm_const_string(SNUM(handle
->conn
),
253 "smb_traffic_analyzer",
254 "total_anonymization", NULL
);
256 anon_prefix
=lp_parm_const_string(SNUM(handle
->conn
),
257 "smb_traffic_analyzer",
258 "anonymize_prefix", NULL
);
259 if (anon_prefix
!= NULL
) {
260 if (total_anonymization
!= NULL
) {
261 output
= talloc_asprintf(ctx
, "%s",
264 output
= talloc_asprintf(ctx
, "%s%i", anon_prefix
,
268 output
= talloc_asprintf(ctx
, "%s", str
);
276 * The marshalling function for protocol v2.
277 * TALLOC_CTX *ctx Talloc context to work on
278 * struct tm *tm tm struct for the timestamp
279 * int seconds milliseconds of the timestamp
280 * vfs_handle_struct *handle vfs_handle_struct
281 * char *username Name of the user
282 * int vfs_operation VFS operation identifier
283 * int count Number of the common data blocks
284 * [...] variable args data blocks taken from the individual
285 * VFS data structures
287 * Returns the complete data block to send. The caller has to
288 * take care for freeing the allocated buffer.
290 static char *smb_traffic_analyzer_create_string( TALLOC_CTX
*ctx
,
291 struct tm
*tm
, int seconds
, vfs_handle_struct
*handle
, \
292 char *username
, int vfs_operation
, int count
, ... )
298 char *common_data_count_str
= NULL
;
299 char *timestr
= NULL
;
301 char *usersid
= NULL
;
303 char *vfs_operation_str
= NULL
;
304 const char *service_name
= lp_const_servicename(handle
->conn
->params
->service
);
307 * first create the data that is transfered with any VFS op
308 * These are, in the following order:
309 *(0) number of data to come [6 in v2.0]
310 * 1.vfs_operation identifier
319 * number of common data blocks to come,
320 * this is a #define in vfs_smb_traffic_anaylzer.h,
321 * it's length is known at compile time
323 common_data_count_str
= talloc_strdup( ctx
, SMBTA_COMMON_DATA_COUNT
);
324 /* vfs operation identifier */
325 vfs_operation_str
= talloc_asprintf( common_data_count_str
, "%i",
328 * Handle anonymization. In protocol v2, we have to anonymize
329 * both the SID and the username. The name is already
330 * anonymized if needed, by the calling function.
332 usersid
= dom_sid_string( common_data_count_str
,
333 &handle
->conn
->server_info
->ptok
->user_sids
[0]);
335 sidstr
= smb_traffic_analyzer_anonymize(
336 common_data_count_str
,
341 timestr
= talloc_asprintf( common_data_count_str
, \
342 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
350 len
= strlen( timestr
);
352 /* create the string of common data */
353 buf
= talloc_asprintf(ctx
,
354 "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
355 common_data_count_str
,
356 (unsigned int) strlen(vfs_operation_str
),
358 (unsigned int) strlen(username
),
360 (unsigned int) strlen(sidstr
),
362 (unsigned int) strlen(service_name
),
365 strlen(handle
->conn
->server_info
->info3
->base
.domain
.string
),
366 handle
->conn
->server_info
->info3
->base
.domain
.string
,
367 (unsigned int) strlen(timestr
),
370 talloc_free(common_data_count_str
);
372 /* data blocks depending on the VFS function */
373 va_start( ap
, count
);
375 arg
= va_arg( ap
, char * );
377 * protocol v2 sends a four byte string
378 * as a header to each block, including
379 * the numbers of bytes to come in the
383 buf
= talloc_asprintf_append( buf
, "%04u%s", len
, arg
);
389 static void smb_traffic_analyzer_send_data(vfs_handle_struct
*handle
,
391 enum vfs_id vfs_operation
)
393 struct refcounted_sock
*rf_sock
= NULL
;
396 struct tm
*tm
= NULL
;
399 char *username
= NULL
;
401 const char *protocol_version
= NULL
;
408 * The state flags are part of the header
409 * and are descripted in the protocol description
410 * in vfs_smb_traffic_analyzer.h. They begin at byte
413 char state_flags
[9] = "000000\0";
415 SMB_VFS_HANDLE_GET_DATA(handle
, rf_sock
, struct refcounted_sock
, return);
417 if (rf_sock
== NULL
|| rf_sock
->sock
== -1) {
418 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
424 tv_sec
= convert_timespec_to_time_t(convert_timeval_to_timespec(tv
));
425 tm
= localtime(&tv_sec
);
429 seconds
=(float) (tv
.tv_usec
/ 1000);
432 * Check if anonymization is required, and if yes do this only for
433 * the username here, needed vor protocol version 1. In v2 we
434 * additionally anonymize the SID, which is done in it's marshalling
437 username
= smb_traffic_analyzer_anonymize( talloc_tos(),
438 handle
->conn
->server_info
->sanitized_username
,
445 protocol_version
= lp_parm_const_string(SNUM(handle
->conn
),
446 "smb_traffic_analyzer",
447 "protocol_version", NULL
);
450 if ( protocol_version
== NULL
|| strcmp( protocol_version
,"V1") == 0) {
452 struct rw_data
*s_data
= (struct rw_data
*) data
;
455 * in case of protocol v1, ignore any vfs operations
456 * except read,pread,write,pwrite, and set the "Write"
457 * bool accordingly, send data and return.
459 if ( vfs_operation
> vfs_id_pwrite
) return;
461 if ( vfs_operation
<= vfs_id_pread
) Write
=false;
464 str
= talloc_asprintf(talloc_tos(),
465 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
466 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
467 (unsigned int) s_data
->len
,
469 handle
->conn
->server_info
->info3
->base
.domain
.string
,
471 handle
->conn
->connectpath
,
481 if (write_data(rf_sock
->sock
, str
, len
) != len
) {
482 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
483 "error sending V1 protocol data to socket!\n"));
487 } else if ( strcmp( protocol_version
, "V2") == 0) {
489 switch( vfs_operation
) {
491 str
= smb_traffic_analyzer_create_string( talloc_tos(),
492 tm
, seconds
, handle
, username
, vfs_id_open
,
493 3, ((struct open_data
*) data
)->filename
,
494 talloc_asprintf( talloc_tos(), "%u",
495 ((struct open_data
*) data
)->mode
),
496 talloc_asprintf( talloc_tos(), "%u",
497 ((struct open_data
*) data
)->result
));
500 str
= smb_traffic_analyzer_create_string( talloc_tos(),
501 tm
, seconds
, handle
, username
, vfs_id_close
,
502 2, ((struct close_data
*) data
)->filename
,
503 talloc_asprintf( talloc_tos(), "%u",
504 ((struct close_data
*) data
)->result
));
507 str
= smb_traffic_analyzer_create_string( talloc_tos(),
508 tm
, seconds
, handle
, username
, vfs_id_mkdir
, \
509 3, ((struct mkdir_data
*) data
)->path
, \
510 talloc_asprintf( talloc_tos(), "%u", \
511 ((struct mkdir_data
*) data
)->mode
), \
512 talloc_asprintf( talloc_tos(), "%u", \
513 ((struct mkdir_data
*) data
)->result
));
516 str
= smb_traffic_analyzer_create_string( talloc_tos(),
517 tm
, seconds
, handle
, username
, vfs_id_rmdir
,
518 2, ((struct rmdir_data
*) data
)->path
, \
519 talloc_asprintf( talloc_tos(), "%u", \
520 ((struct rmdir_data
*) data
)->result
));
522 case vfs_id_rename
: ;
523 str
= smb_traffic_analyzer_create_string( talloc_tos(),
524 tm
, seconds
, handle
, username
, vfs_id_rename
,
525 3, ((struct rename_data
*) data
)->src
, \
526 ((struct rename_data
*) data
)->dst
,
527 talloc_asprintf(talloc_tos(), "%u", \
528 ((struct rename_data
*) data
)->result
));
531 str
= smb_traffic_analyzer_create_string( talloc_tos(),
532 tm
, seconds
, handle
, username
, vfs_id_chdir
,
533 2, ((struct chdir_data
*) data
)->path
, \
534 talloc_asprintf(talloc_tos(), "%u", \
535 ((struct chdir_data
*) data
)->result
));
542 str
= smb_traffic_analyzer_create_string( talloc_tos(),
543 tm
, seconds
, handle
, username
, vfs_operation
,
544 2, ((struct rw_data
*) data
)->filename
, \
545 talloc_asprintf(talloc_tos(), "%u", \
547 ((struct rw_data
*) data
)->len
));
550 DEBUG(1, ("smb_traffic_analyzer: error! "
551 "wrong VFS operation id detected!\n"));
556 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
557 "error, unkown protocol given!\n"));
562 DEBUG(1, ("smb_traffic_analyzer_send_data: "
563 "unable to create string to send!\n"));
569 * If configured, optain the key and run AES encryption
573 akey
= (char *) secrets_fetch("smb_traffic_analyzer_key", &size
);
575 if ( akey
!= NULL
) {
576 state_flags
[2] = 'E';
577 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
578 " found, encrypting data!\n"));
579 output
= smb_traffic_analyzer_encrypt( talloc_tos(),
581 header
= smb_traffic_analyzer_create_header( talloc_tos(),
584 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
585 " header created for crypted data: %s\n", header
));
586 smb_traffic_analyzer_write_data(header
, output
, len
,
593 header
= smb_traffic_analyzer_create_header( talloc_tos(),
595 smb_traffic_analyzer_write_data(header
, str
, strlen(str
),
600 static struct refcounted_sock
*sock_list
;
602 static void smb_traffic_analyzer_free_data(void **pptr
)
604 struct refcounted_sock
*rf_sock
= *(struct refcounted_sock
**)pptr
;
605 if (rf_sock
== NULL
) {
608 rf_sock
->ref_count
--;
609 if (rf_sock
->ref_count
!= 0) {
612 if (rf_sock
->sock
!= -1) {
613 close(rf_sock
->sock
);
615 DLIST_REMOVE(sock_list
, rf_sock
);
616 TALLOC_FREE(rf_sock
);
619 static int smb_traffic_analyzer_connect(struct vfs_handle_struct
*handle
,
623 connection_struct
*conn
= handle
->conn
;
624 enum sock_type st
= smb_traffic_analyzer_connMode(handle
);
625 struct refcounted_sock
*rf_sock
= NULL
;
626 const char *name
= (st
== UNIX_DOMAIN_SOCKET
) ? LOCAL_PATHNAME
:
627 lp_parm_const_string(SNUM(conn
),
628 "smb_traffic_analyzer",
629 "host", "localhost");
630 uint16_t port
= (st
== UNIX_DOMAIN_SOCKET
) ? 0 :
631 atoi( lp_parm_const_string(SNUM(conn
),
632 "smb_traffic_analyzer", "port", "9430"));
633 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
639 /* Are we already connected ? */
640 for (rf_sock
= sock_list
; rf_sock
; rf_sock
= rf_sock
->next
) {
641 if (port
== rf_sock
->port
&&
642 (strcmp(name
, rf_sock
->name
) == 0)) {
647 /* If we're connected already, just increase the
648 * reference count. */
650 rf_sock
->ref_count
++;
652 /* New connection. */
653 rf_sock
= TALLOC_ZERO_P(NULL
, struct refcounted_sock
);
654 if (rf_sock
== NULL
) {
655 SMB_VFS_NEXT_DISCONNECT(handle
);
659 rf_sock
->name
= talloc_strdup(rf_sock
, name
);
660 if (rf_sock
->name
== NULL
) {
661 SMB_VFS_NEXT_DISCONNECT(handle
);
662 TALLOC_FREE(rf_sock
);
666 rf_sock
->port
= port
;
667 rf_sock
->ref_count
= 1;
669 if (st
== UNIX_DOMAIN_SOCKET
) {
670 rf_sock
->sock
= smb_traffic_analyzer_connect_unix_socket(handle
,
674 rf_sock
->sock
= smb_traffic_analyzer_connect_inet_socket(handle
,
678 if (rf_sock
->sock
== -1) {
679 SMB_VFS_NEXT_DISCONNECT(handle
);
680 TALLOC_FREE(rf_sock
);
683 DLIST_ADD(sock_list
, rf_sock
);
686 /* Store the private data. */
687 SMB_VFS_HANDLE_SET_DATA(handle
, rf_sock
, smb_traffic_analyzer_free_data
,
688 struct refcounted_sock
, return -1);
693 static int smb_traffic_analyzer_chdir(vfs_handle_struct
*handle
, \
696 struct chdir_data s_data
;
697 s_data
.result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
699 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path
));
700 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_chdir
);
701 return s_data
.result
;
704 static int smb_traffic_analyzer_rename(vfs_handle_struct
*handle
, \
705 const struct smb_filename
*smb_fname_src
,
706 const struct smb_filename
*smb_fname_dst
)
708 struct rename_data s_data
;
709 s_data
.result
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, \
711 s_data
.src
= smb_fname_src
->base_name
;
712 s_data
.dst
= smb_fname_dst
->base_name
;
713 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
714 smb_fname_src
->base_name
,
715 smb_fname_dst
->base_name
));
716 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rename
);
717 return s_data
.result
;
720 static int smb_traffic_analyzer_rmdir(vfs_handle_struct
*handle
, \
723 struct rmdir_data s_data
;
724 s_data
.result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
726 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path
));
727 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rmdir
);
728 return s_data
.result
;
731 static int smb_traffic_analyzer_mkdir(vfs_handle_struct
*handle
, \
732 const char *path
, mode_t mode
)
734 struct mkdir_data s_data
;
735 s_data
.result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
738 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path
));
739 smb_traffic_analyzer_send_data(handle
,
742 return s_data
.result
;
745 static ssize_t
smb_traffic_analyzer_read(vfs_handle_struct
*handle
, \
746 files_struct
*fsp
, void *data
, size_t n
)
748 struct rw_data s_data
;
750 s_data
.len
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
751 s_data
.filename
= fsp
->fsp_name
->base_name
;
752 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp
)));
754 smb_traffic_analyzer_send_data(handle
,
761 static ssize_t
smb_traffic_analyzer_pread(vfs_handle_struct
*handle
, \
762 files_struct
*fsp
, void *data
, size_t n
, SMB_OFF_T offset
)
764 struct rw_data s_data
;
766 s_data
.len
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
767 s_data
.filename
= fsp
->fsp_name
->base_name
;
768 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
771 smb_traffic_analyzer_send_data(handle
,
778 static ssize_t
smb_traffic_analyzer_write(vfs_handle_struct
*handle
, \
779 files_struct
*fsp
, const void *data
, size_t n
)
781 struct rw_data s_data
;
783 s_data
.len
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
784 s_data
.filename
= fsp
->fsp_name
->base_name
;
785 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
788 smb_traffic_analyzer_send_data(handle
,
794 static ssize_t
smb_traffic_analyzer_pwrite(vfs_handle_struct
*handle
, \
795 files_struct
*fsp
, const void *data
, size_t n
, SMB_OFF_T offset
)
797 struct rw_data s_data
;
799 s_data
.len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
800 s_data
.filename
= fsp
->fsp_name
->base_name
;
801 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
804 smb_traffic_analyzer_send_data(handle
,
810 static int smb_traffic_analyzer_open(vfs_handle_struct
*handle
, \
811 struct smb_filename
*smb_fname
, files_struct
*fsp
,\
812 int flags
, mode_t mode
)
814 struct open_data s_data
;
816 s_data
.result
= SMB_VFS_NEXT_OPEN( handle
, smb_fname
, fsp
,
818 DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
820 s_data
.filename
= fsp
->fsp_name
->base_name
;
822 smb_traffic_analyzer_send_data(handle
,
825 return s_data
.result
;
828 static int smb_traffic_analyzer_close(vfs_handle_struct
*handle
, \
831 struct close_data s_data
;
832 s_data
.result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
833 DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
835 s_data
.filename
= fsp
->fsp_name
->base_name
;
836 smb_traffic_analyzer_send_data(handle
,
839 return s_data
.result
;
843 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns
= {
844 .connect_fn
= smb_traffic_analyzer_connect
,
845 .vfs_read
= smb_traffic_analyzer_read
,
846 .pread
= smb_traffic_analyzer_pread
,
847 .write
= smb_traffic_analyzer_write
,
848 .pwrite
= smb_traffic_analyzer_pwrite
,
849 .mkdir
= smb_traffic_analyzer_mkdir
,
850 .rename
= smb_traffic_analyzer_rename
,
851 .chdir
= smb_traffic_analyzer_chdir
,
852 .open
= smb_traffic_analyzer_open
,
853 .rmdir
= smb_traffic_analyzer_rmdir
,
854 .close_fn
= smb_traffic_analyzer_close
857 /* Module initialization */
858 NTSTATUS
vfs_smb_traffic_analyzer_init(void)
860 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
861 "smb_traffic_analyzer",
862 &vfs_smb_traffic_analyzer_fns
);
864 if (!NT_STATUS_IS_OK(ret
)) {
868 vfs_smb_traffic_analyzer_debug_level
=
869 debug_add_class("smb_traffic_analyzer");
871 if (vfs_smb_traffic_analyzer_debug_level
== -1) {
872 vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
873 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
874 "debugging class!\n"));
876 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
877 "'smb_traffic_analyzer': %d\n", \
878 vfs_smb_traffic_analyzer_debug_level
));