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/globals.h"
24 #include "../lib/crypto/crypto.h"
25 #include "vfs_smb_traffic_analyzer.h"
26 #include "../libcli/security/security.h"
28 #include "../librpc/gen_ndr/ndr_netlogon.h"
30 /* abstraction for the send_over_network function */
31 enum sock_type
{INTERNET_SOCKET
= 0, UNIX_DOMAIN_SOCKET
};
33 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
35 static int vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
37 static enum sock_type
smb_traffic_analyzer_connMode(vfs_handle_struct
*handle
)
39 connection_struct
*conn
= handle
->conn
;
41 Mode
=lp_parm_const_string(SNUM(conn
), "smb_traffic_analyzer","mode", \
43 if (strstr(Mode
,"unix_domain_socket")) {
44 return UNIX_DOMAIN_SOCKET
;
46 return INTERNET_SOCKET
;
51 /* Connect to an internet socket */
52 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct
*handle
,
53 const char *name
, uint16_t port
)
55 /* Create a streaming Socket */
57 struct addrinfo hints
;
58 struct addrinfo
*ailist
= NULL
;
59 struct addrinfo
*res
= NULL
;
63 /* By default make sure it supports TCP. */
64 hints
.ai_socktype
= SOCK_STREAM
;
65 hints
.ai_flags
= AI_ADDRCONFIG
;
67 ret
= getaddrinfo(name
,
73 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
74 "getaddrinfo failed for name %s [%s]\n",
80 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
81 "Port: %i\n", name
, port
));
83 for (res
= ailist
; res
; res
= res
->ai_next
) {
84 struct sockaddr_storage ss
;
87 if (!res
->ai_addr
|| res
->ai_addrlen
== 0) {
92 memcpy(&ss
, res
->ai_addr
, res
->ai_addrlen
);
94 status
= open_socket_out(&ss
, port
, 10000, &sockfd
);
95 if (NT_STATUS_IS_OK(status
)) {
101 freeaddrinfo(ailist
);
105 DEBUG(1, ("smb_traffic_analyzer: unable to create "
106 "socket, error is %s",
114 /* Connect to a unix domain socket */
115 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct
*handle
,
118 /* Create the socket to stad */
120 struct sockaddr_un remote
;
122 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
123 "Unix domain socket mode. Using %s\n",
126 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
127 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
128 "Couldn't create socket, "
129 "make sure stad is running!\n"));
132 remote
.sun_family
= AF_UNIX
;
133 strlcpy(remote
.sun_path
, name
,
134 sizeof(remote
.sun_path
));
135 len
=strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
136 if (connect(sock
, (struct sockaddr
*)&remote
, len
) == -1 ) {
137 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
138 "Could not connect to "
139 "socket, make sure\nstad is running!\n"));
146 /* Private data allowing shared connection sockets. */
147 struct refcounted_sock
{
148 struct refcounted_sock
*next
, *prev
;
152 unsigned int ref_count
;
157 * Encryption of a data block with AES
158 * TALLOC_CTX *ctx Talloc context to work on
159 * const char *akey 128bit key for the encryption
160 * const char *str Data buffer to encrypt, \0 terminated
161 * int *len Will be set to the length of the
162 * resulting data block
163 * The caller has to take care for the memory
164 * allocated on the context.
166 static char *smb_traffic_analyzer_encrypt( TALLOC_CTX
*ctx
,
167 const char *akey
, const char *str
, size_t *len
)
171 unsigned char filler
[17]= "................";
173 unsigned char crypted
[18];
174 if (akey
== NULL
) return NULL
;
175 samba_AES_set_encrypt_key((unsigned char *) akey
, 128, &key
);
176 s1
= strlen(str
) / 16;
177 s2
= strlen(str
) % 16;
178 for (h
= 0; h
< s2
; h
++) *(filler
+h
)=*(str
+(s1
*16)+h
);
179 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
180 " as filling block.\n", filler
));
181 output
= talloc_array(ctx
, char, (s1
*16)+17 );
183 for (h
= 0; h
< s1
; h
++) {
184 samba_AES_encrypt((unsigned char *) str
+(16*h
), crypted
, &key
);
185 for (d
= 0; d
<16; d
++) output
[d
+(16*h
)]=crypted
[d
];
187 samba_AES_encrypt( (unsigned char *) str
+(16*h
), filler
, &key
);
188 for (d
= 0;d
< 16; d
++) output
[d
+(16*h
)]=*(filler
+d
);
194 * Create a v2 header.
195 * TALLLOC_CTX *ctx Talloc context to work on
196 * const char *state_flags State flag string
197 * int len length of the data block
199 static char *smb_traffic_analyzer_create_header( TALLOC_CTX
*ctx
,
200 const char *state_flags
, size_t data_len
)
202 char *header
= talloc_asprintf( ctx
, "V2.%s%017u",
203 state_flags
, (unsigned int) data_len
);
204 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
205 dump_data(10, (uint8_t *)header
, strlen(header
));
211 * Actually send header and data over the network
212 * char *header Header data
213 * char *data Data Block
214 * int dlength Length of data block
217 static void smb_traffic_analyzer_write_data( char *header
, char *data
,
218 int dlength
, int _socket
)
220 int len
= strlen(header
);
221 if (write_data( _socket
, header
, len
) != len
) {
222 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
223 "error sending the header"
224 " over the socket!\n"));
226 DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
227 dump_data( 10, (uint8_t *)data
, dlength
);
229 if (write_data( _socket
, data
, dlength
) != dlength
) {
230 DEBUG(1, ("smb_traffic_analyzer_write_data: "
231 "error sending crypted data to socket!\n"));
237 * Anonymize a string if required.
238 * TALLOC_CTX *ctx The talloc context to work on
239 * const char *str The string to anonymize
240 * vfs_handle_struct *handle The handle struct to work on
242 * Returns a newly allocated string, either the anonymized one,
243 * or a copy of const char *str. The caller has to take care for
244 * freeing the allocated memory.
246 static char *smb_traffic_analyzer_anonymize( TALLOC_CTX
*ctx
,
248 vfs_handle_struct
*handle
)
250 const char *total_anonymization
;
251 const char *anon_prefix
;
253 total_anonymization
=lp_parm_const_string(SNUM(handle
->conn
),
254 "smb_traffic_analyzer",
255 "total_anonymization", NULL
);
257 anon_prefix
=lp_parm_const_string(SNUM(handle
->conn
),
258 "smb_traffic_analyzer",
259 "anonymize_prefix", NULL
);
260 if (anon_prefix
!= NULL
) {
261 if (total_anonymization
!= NULL
) {
262 output
= talloc_asprintf(ctx
, "%s",
265 output
= talloc_asprintf(ctx
, "%s%i", anon_prefix
,
269 output
= talloc_asprintf(ctx
, "%s", str
);
277 * The marshalling function for protocol v2.
278 * TALLOC_CTX *ctx Talloc context to work on
279 * struct tm *tm tm struct for the timestamp
280 * int seconds milliseconds of the timestamp
281 * vfs_handle_struct *handle vfs_handle_struct
282 * char *username Name of the user
283 * int vfs_operation VFS operation identifier
284 * int count Number of the common data blocks
285 * [...] variable args data blocks taken from the individual
286 * VFS data structures
288 * Returns the complete data block to send. The caller has to
289 * take care for freeing the allocated buffer.
291 static char *smb_traffic_analyzer_create_string( TALLOC_CTX
*ctx
,
292 struct tm
*tm
, int seconds
, vfs_handle_struct
*handle
, \
293 char *username
, int vfs_operation
, int count
, ... )
299 char *common_data_count_str
= NULL
;
300 char *timestr
= NULL
;
302 char *usersid
= NULL
;
304 char *vfs_operation_str
= NULL
;
305 const char *service_name
= lp_const_servicename(handle
->conn
->params
->service
);
308 * first create the data that is transfered with any VFS op
309 * These are, in the following order:
310 *(0) number of data to come [6 in v2.0]
311 * 1.vfs_operation identifier
317 * 7.IP Addresss of client
321 * number of common data blocks to come,
322 * this is a #define in vfs_smb_traffic_anaylzer.h,
323 * it's length is known at compile time
325 common_data_count_str
= talloc_strdup( ctx
, SMBTA_COMMON_DATA_COUNT
);
326 /* vfs operation identifier */
327 vfs_operation_str
= talloc_asprintf( common_data_count_str
, "%i",
330 * Handle anonymization. In protocol v2, we have to anonymize
331 * both the SID and the username. The name is already
332 * anonymized if needed, by the calling function.
334 usersid
= dom_sid_string( common_data_count_str
,
335 &handle
->conn
->session_info
->security_token
->sids
[0]);
337 sidstr
= smb_traffic_analyzer_anonymize(
338 common_data_count_str
,
343 timestr
= talloc_asprintf( common_data_count_str
, \
344 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
352 len
= strlen( timestr
);
353 /* create the string of common data */
354 buf
= talloc_asprintf(ctx
,
355 "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
356 common_data_count_str
,
357 (unsigned int) strlen(vfs_operation_str
),
359 (unsigned int) strlen(username
),
361 (unsigned int) strlen(sidstr
),
363 (unsigned int) strlen(service_name
),
366 strlen(handle
->conn
->session_info
->info3
->base
.domain
.string
),
367 handle
->conn
->session_info
->info3
->base
.domain
.string
,
368 (unsigned int) strlen(timestr
),
370 (unsigned int) strlen(handle
->conn
->sconn
->client_id
.addr
),
371 handle
->conn
->sconn
->client_id
.addr
);
373 talloc_free(common_data_count_str
);
375 /* data blocks depending on the VFS function */
376 va_start( ap
, count
);
378 arg
= va_arg( ap
, char * );
380 * protocol v2 sends a four byte string
381 * as a header to each block, including
382 * the numbers of bytes to come in the
386 buf
= talloc_asprintf_append( buf
, "%04u%s", len
, arg
);
392 static void smb_traffic_analyzer_send_data(vfs_handle_struct
*handle
,
394 enum vfs_id vfs_operation
)
396 struct refcounted_sock
*rf_sock
= NULL
;
399 struct tm
*tm
= NULL
;
402 char *username
= NULL
;
404 const char *protocol_version
= NULL
;
411 * The state flags are part of the header
412 * and are descripted in the protocol description
413 * in vfs_smb_traffic_analyzer.h. They begin at byte
416 char state_flags
[9] = "000000\0";
418 SMB_VFS_HANDLE_GET_DATA(handle
, rf_sock
, struct refcounted_sock
, return);
420 if (rf_sock
== NULL
|| rf_sock
->sock
== -1) {
421 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
428 tm
= localtime(&tv_sec
);
432 seconds
=(float) (tv
.tv_usec
/ 1000);
435 * Check if anonymization is required, and if yes do this only for
436 * the username here, needed vor protocol version 1. In v2 we
437 * additionally anonymize the SID, which is done in it's marshalling
440 username
= smb_traffic_analyzer_anonymize( talloc_tos(),
441 handle
->conn
->session_info
->sanitized_username
,
448 protocol_version
= lp_parm_const_string(SNUM(handle
->conn
),
449 "smb_traffic_analyzer",
450 "protocol_version", NULL
);
453 if ( protocol_version
== NULL
|| strcmp( protocol_version
,"V1") == 0) {
455 struct rw_data
*s_data
= (struct rw_data
*) data
;
458 * in case of protocol v1, ignore any vfs operations
459 * except read,pread,write,pwrite, and set the "Write"
460 * bool accordingly, send data and return.
462 if ( vfs_operation
> vfs_id_pwrite
) return;
464 if ( vfs_operation
<= vfs_id_pread
) Write
=false;
467 str
= talloc_asprintf(talloc_tos(),
468 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
469 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
470 (unsigned int) s_data
->len
,
472 handle
->conn
->session_info
->info3
->base
.domain
.string
,
474 handle
->conn
->connectpath
,
484 if (write_data(rf_sock
->sock
, str
, len
) != len
) {
485 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
486 "error sending V1 protocol data to socket!\n"));
490 } else if ( strcmp( protocol_version
, "V2") == 0) {
492 switch( vfs_operation
) {
494 str
= smb_traffic_analyzer_create_string( talloc_tos(),
495 tm
, seconds
, handle
, username
, vfs_id_open
,
496 3, ((struct open_data
*) data
)->filename
,
497 talloc_asprintf( talloc_tos(), "%u",
498 ((struct open_data
*) data
)->mode
),
499 talloc_asprintf( talloc_tos(), "%u",
500 ((struct open_data
*) data
)->result
));
503 str
= smb_traffic_analyzer_create_string( talloc_tos(),
504 tm
, seconds
, handle
, username
, vfs_id_close
,
505 2, ((struct close_data
*) data
)->filename
,
506 talloc_asprintf( talloc_tos(), "%u",
507 ((struct close_data
*) data
)->result
));
510 str
= smb_traffic_analyzer_create_string( talloc_tos(),
511 tm
, seconds
, handle
, username
, vfs_id_mkdir
, \
512 3, ((struct mkdir_data
*) data
)->path
, \
513 talloc_asprintf( talloc_tos(), "%u", \
514 ((struct mkdir_data
*) data
)->mode
), \
515 talloc_asprintf( talloc_tos(), "%u", \
516 ((struct mkdir_data
*) data
)->result
));
519 str
= smb_traffic_analyzer_create_string( talloc_tos(),
520 tm
, seconds
, handle
, username
, vfs_id_rmdir
,
521 2, ((struct rmdir_data
*) data
)->path
, \
522 talloc_asprintf( talloc_tos(), "%u", \
523 ((struct rmdir_data
*) data
)->result
));
525 case vfs_id_rename
: ;
526 str
= smb_traffic_analyzer_create_string( talloc_tos(),
527 tm
, seconds
, handle
, username
, vfs_id_rename
,
528 3, ((struct rename_data
*) data
)->src
, \
529 ((struct rename_data
*) data
)->dst
,
530 talloc_asprintf(talloc_tos(), "%u", \
531 ((struct rename_data
*) data
)->result
));
534 str
= smb_traffic_analyzer_create_string( talloc_tos(),
535 tm
, seconds
, handle
, username
, vfs_id_chdir
,
536 2, ((struct chdir_data
*) data
)->path
, \
537 talloc_asprintf(talloc_tos(), "%u", \
538 ((struct chdir_data
*) data
)->result
));
545 str
= smb_traffic_analyzer_create_string( talloc_tos(),
546 tm
, seconds
, handle
, username
, vfs_operation
,
547 2, ((struct rw_data
*) data
)->filename
, \
548 talloc_asprintf(talloc_tos(), "%u", \
550 ((struct rw_data
*) data
)->len
));
553 DEBUG(1, ("smb_traffic_analyzer: error! "
554 "wrong VFS operation id detected!\n"));
559 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
560 "error, unknown protocol given!\n"));
565 DEBUG(1, ("smb_traffic_analyzer_send_data: "
566 "unable to create string to send!\n"));
572 * If configured, optain the key and run AES encryption
576 akey
= (char *) secrets_fetch("smb_traffic_analyzer_key", &size
);
578 if ( akey
!= NULL
) {
579 state_flags
[2] = 'E';
580 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
581 " found, encrypting data!\n"));
582 output
= smb_traffic_analyzer_encrypt( talloc_tos(),
584 header
= smb_traffic_analyzer_create_header( talloc_tos(),
587 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
588 " header created for crypted data: %s\n", header
));
589 smb_traffic_analyzer_write_data(header
, output
, len
,
596 header
= smb_traffic_analyzer_create_header( talloc_tos(),
598 smb_traffic_analyzer_write_data(header
, str
, strlen(str
),
603 static struct refcounted_sock
*sock_list
;
605 static void smb_traffic_analyzer_free_data(void **pptr
)
607 struct refcounted_sock
*rf_sock
= *(struct refcounted_sock
**)pptr
;
608 if (rf_sock
== NULL
) {
611 rf_sock
->ref_count
--;
612 if (rf_sock
->ref_count
!= 0) {
615 if (rf_sock
->sock
!= -1) {
616 close(rf_sock
->sock
);
618 DLIST_REMOVE(sock_list
, rf_sock
);
619 TALLOC_FREE(rf_sock
);
622 static int smb_traffic_analyzer_connect(struct vfs_handle_struct
*handle
,
626 connection_struct
*conn
= handle
->conn
;
627 enum sock_type st
= smb_traffic_analyzer_connMode(handle
);
628 struct refcounted_sock
*rf_sock
= NULL
;
629 const char *name
= (st
== UNIX_DOMAIN_SOCKET
) ? LOCAL_PATHNAME
:
630 lp_parm_const_string(SNUM(conn
),
631 "smb_traffic_analyzer",
632 "host", "localhost");
633 uint16_t port
= (st
== UNIX_DOMAIN_SOCKET
) ? 0 :
634 atoi( lp_parm_const_string(SNUM(conn
),
635 "smb_traffic_analyzer", "port", "9430"));
636 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
642 /* Are we already connected ? */
643 for (rf_sock
= sock_list
; rf_sock
; rf_sock
= rf_sock
->next
) {
644 if (port
== rf_sock
->port
&&
645 (strcmp(name
, rf_sock
->name
) == 0)) {
650 /* If we're connected already, just increase the
651 * reference count. */
653 rf_sock
->ref_count
++;
655 /* New connection. */
656 rf_sock
= TALLOC_ZERO_P(NULL
, struct refcounted_sock
);
657 if (rf_sock
== NULL
) {
658 SMB_VFS_NEXT_DISCONNECT(handle
);
662 rf_sock
->name
= talloc_strdup(rf_sock
, name
);
663 if (rf_sock
->name
== NULL
) {
664 SMB_VFS_NEXT_DISCONNECT(handle
);
665 TALLOC_FREE(rf_sock
);
669 rf_sock
->port
= port
;
670 rf_sock
->ref_count
= 1;
672 if (st
== UNIX_DOMAIN_SOCKET
) {
673 rf_sock
->sock
= smb_traffic_analyzer_connect_unix_socket(handle
,
677 rf_sock
->sock
= smb_traffic_analyzer_connect_inet_socket(handle
,
681 if (rf_sock
->sock
== -1) {
682 SMB_VFS_NEXT_DISCONNECT(handle
);
683 TALLOC_FREE(rf_sock
);
686 DLIST_ADD(sock_list
, rf_sock
);
689 /* Store the private data. */
690 SMB_VFS_HANDLE_SET_DATA(handle
, rf_sock
, smb_traffic_analyzer_free_data
,
691 struct refcounted_sock
, return -1);
696 static int smb_traffic_analyzer_chdir(vfs_handle_struct
*handle
, \
699 struct chdir_data s_data
;
700 s_data
.result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
702 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path
));
703 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_chdir
);
704 return s_data
.result
;
707 static int smb_traffic_analyzer_rename(vfs_handle_struct
*handle
, \
708 const struct smb_filename
*smb_fname_src
,
709 const struct smb_filename
*smb_fname_dst
)
711 struct rename_data s_data
;
712 s_data
.result
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, \
714 s_data
.src
= smb_fname_src
->base_name
;
715 s_data
.dst
= smb_fname_dst
->base_name
;
716 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
717 smb_fname_src
->base_name
,
718 smb_fname_dst
->base_name
));
719 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rename
);
720 return s_data
.result
;
723 static int smb_traffic_analyzer_rmdir(vfs_handle_struct
*handle
, \
726 struct rmdir_data s_data
;
727 s_data
.result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
729 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path
));
730 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rmdir
);
731 return s_data
.result
;
734 static int smb_traffic_analyzer_mkdir(vfs_handle_struct
*handle
, \
735 const char *path
, mode_t mode
)
737 struct mkdir_data s_data
;
738 s_data
.result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
741 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path
));
742 smb_traffic_analyzer_send_data(handle
,
745 return s_data
.result
;
748 static ssize_t
smb_traffic_analyzer_read(vfs_handle_struct
*handle
, \
749 files_struct
*fsp
, void *data
, size_t n
)
751 struct rw_data s_data
;
753 s_data
.len
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
754 s_data
.filename
= fsp
->fsp_name
->base_name
;
755 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp
)));
757 smb_traffic_analyzer_send_data(handle
,
764 static ssize_t
smb_traffic_analyzer_pread(vfs_handle_struct
*handle
, \
765 files_struct
*fsp
, void *data
, size_t n
, SMB_OFF_T offset
)
767 struct rw_data s_data
;
769 s_data
.len
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
770 s_data
.filename
= fsp
->fsp_name
->base_name
;
771 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
774 smb_traffic_analyzer_send_data(handle
,
781 static ssize_t
smb_traffic_analyzer_write(vfs_handle_struct
*handle
, \
782 files_struct
*fsp
, const void *data
, size_t n
)
784 struct rw_data s_data
;
786 s_data
.len
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
787 s_data
.filename
= fsp
->fsp_name
->base_name
;
788 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
791 smb_traffic_analyzer_send_data(handle
,
797 static ssize_t
smb_traffic_analyzer_pwrite(vfs_handle_struct
*handle
, \
798 files_struct
*fsp
, const void *data
, size_t n
, SMB_OFF_T offset
)
800 struct rw_data s_data
;
802 s_data
.len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
803 s_data
.filename
= fsp
->fsp_name
->base_name
;
804 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
807 smb_traffic_analyzer_send_data(handle
,
813 static int smb_traffic_analyzer_open(vfs_handle_struct
*handle
, \
814 struct smb_filename
*smb_fname
, files_struct
*fsp
,\
815 int flags
, mode_t mode
)
817 struct open_data s_data
;
819 s_data
.result
= SMB_VFS_NEXT_OPEN( handle
, smb_fname
, fsp
,
821 DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
823 s_data
.filename
= fsp
->fsp_name
->base_name
;
825 smb_traffic_analyzer_send_data(handle
,
828 return s_data
.result
;
831 static int smb_traffic_analyzer_close(vfs_handle_struct
*handle
, \
834 struct close_data s_data
;
835 s_data
.result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
836 DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
838 s_data
.filename
= fsp
->fsp_name
->base_name
;
839 smb_traffic_analyzer_send_data(handle
,
842 return s_data
.result
;
846 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns
= {
847 .connect_fn
= smb_traffic_analyzer_connect
,
848 .vfs_read
= smb_traffic_analyzer_read
,
849 .pread
= smb_traffic_analyzer_pread
,
850 .write
= smb_traffic_analyzer_write
,
851 .pwrite
= smb_traffic_analyzer_pwrite
,
852 .mkdir
= smb_traffic_analyzer_mkdir
,
853 .rename
= smb_traffic_analyzer_rename
,
854 .chdir
= smb_traffic_analyzer_chdir
,
855 .open
= smb_traffic_analyzer_open
,
856 .rmdir
= smb_traffic_analyzer_rmdir
,
857 .close_fn
= smb_traffic_analyzer_close
860 /* Module initialization */
861 NTSTATUS
vfs_smb_traffic_analyzer_init(void)
863 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
864 "smb_traffic_analyzer",
865 &vfs_smb_traffic_analyzer_fns
);
867 if (!NT_STATUS_IS_OK(ret
)) {
871 vfs_smb_traffic_analyzer_debug_level
=
872 debug_add_class("smb_traffic_analyzer");
874 if (vfs_smb_traffic_analyzer_debug_level
== -1) {
875 vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
876 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
877 "debugging class!\n"));
879 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
880 "'smb_traffic_analyzer': %d\n", \
881 vfs_smb_traffic_analyzer_debug_level
));