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"
32 /* abstraction for the send_over_network function */
33 enum sock_type
{INTERNET_SOCKET
= 0, UNIX_DOMAIN_SOCKET
};
35 #define LOCAL_PATHNAME "/var/tmp/stadsocket"
37 static int vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
39 static enum sock_type
smb_traffic_analyzer_connMode(vfs_handle_struct
*handle
)
41 connection_struct
*conn
= handle
->conn
;
43 Mode
=lp_parm_const_string(SNUM(conn
), "smb_traffic_analyzer","mode", \
45 if (strstr(Mode
,"unix_domain_socket")) {
46 return UNIX_DOMAIN_SOCKET
;
48 return INTERNET_SOCKET
;
53 /* Connect to an internet socket */
54 static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct
*handle
,
55 const char *name
, uint16_t port
)
57 /* Create a streaming Socket */
59 struct addrinfo hints
;
60 struct addrinfo
*ailist
= NULL
;
61 struct addrinfo
*res
= NULL
;
65 /* By default make sure it supports TCP. */
66 hints
.ai_socktype
= SOCK_STREAM
;
67 hints
.ai_flags
= AI_ADDRCONFIG
;
69 ret
= getaddrinfo(name
,
75 DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
76 "getaddrinfo failed for name %s [%s]\n",
82 DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
83 "Port: %i\n", name
, port
));
85 for (res
= ailist
; res
; res
= res
->ai_next
) {
86 struct sockaddr_storage ss
;
89 if (!res
->ai_addr
|| res
->ai_addrlen
== 0) {
94 memcpy(&ss
, res
->ai_addr
, res
->ai_addrlen
);
96 status
= open_socket_out(&ss
, port
, 10000, &sockfd
);
97 if (NT_STATUS_IS_OK(status
)) {
103 freeaddrinfo(ailist
);
107 DEBUG(1, ("smb_traffic_analyzer: unable to create "
108 "socket, error is %s",
116 /* Connect to a unix domain socket */
117 static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct
*handle
,
120 /* Create the socket to stad */
122 struct sockaddr_un remote
;
124 DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
125 "Unix domain socket mode. Using %s\n",
128 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
129 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
130 "Couldn't create socket, "
131 "make sure stad is running!\n"));
134 remote
.sun_family
= AF_UNIX
;
135 strlcpy(remote
.sun_path
, name
,
136 sizeof(remote
.sun_path
));
137 len
=strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
138 if (connect(sock
, (struct sockaddr
*)&remote
, len
) == -1 ) {
139 DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
140 "Could not connect to "
141 "socket, make sure\nstad is running!\n"));
148 /* Private data allowing shared connection sockets. */
149 struct refcounted_sock
{
150 struct refcounted_sock
*next
, *prev
;
154 unsigned int ref_count
;
159 * Encryption of a data block with AES
160 * TALLOC_CTX *ctx Talloc context to work on
161 * const char *akey 128bit key for the encryption
162 * const char *str Data buffer to encrypt, \0 terminated
163 * int *len Will be set to the length of the
164 * resulting data block
165 * The caller has to take care for the memory
166 * allocated on the context.
168 static char *smb_traffic_analyzer_encrypt( TALLOC_CTX
*ctx
,
169 const char *akey
, const char *str
, size_t *len
)
173 unsigned char filler
[17]= "................";
175 unsigned char crypted
[18];
176 if (akey
== NULL
) return NULL
;
177 samba_AES_set_encrypt_key((unsigned char *) akey
, 128, &key
);
178 s1
= strlen(str
) / 16;
179 s2
= strlen(str
) % 16;
180 for (h
= 0; h
< s2
; h
++) *(filler
+h
)=*(str
+(s1
*16)+h
);
181 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
182 " as filling block.\n", filler
));
183 output
= talloc_array(ctx
, char, (s1
*16)+17 );
185 for (h
= 0; h
< s1
; h
++) {
186 samba_AES_encrypt((unsigned char *) str
+(16*h
), crypted
, &key
);
187 for (d
= 0; d
<16; d
++) output
[d
+(16*h
)]=crypted
[d
];
189 samba_AES_encrypt( (unsigned char *) str
+(16*h
), filler
, &key
);
190 for (d
= 0;d
< 16; d
++) output
[d
+(16*h
)]=*(filler
+d
);
196 * Create a v2 header.
197 * TALLLOC_CTX *ctx Talloc context to work on
198 * const char *state_flags State flag string
199 * int len length of the data block
201 static char *smb_traffic_analyzer_create_header( TALLOC_CTX
*ctx
,
202 const char *state_flags
, size_t data_len
)
204 char *header
= talloc_asprintf( ctx
, "V2.%s%017u",
205 state_flags
, (unsigned int) data_len
);
206 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
207 dump_data(10, (uint8_t *)header
, strlen(header
));
213 * Actually send header and data over the network
214 * char *header Header data
215 * char *data Data Block
216 * int dlength Length of data block
219 static void smb_traffic_analyzer_write_data( char *header
, char *data
,
220 int dlength
, int _socket
)
222 int len
= strlen(header
);
223 if (write_data( _socket
, header
, len
) != len
) {
224 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
225 "error sending the header"
226 " over the socket!\n"));
228 DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
229 dump_data( 10, (uint8_t *)data
, dlength
);
231 if (write_data( _socket
, data
, dlength
) != dlength
) {
232 DEBUG(1, ("smb_traffic_analyzer_write_data: "
233 "error sending crypted data to socket!\n"));
239 * Anonymize a string if required.
240 * TALLOC_CTX *ctx The talloc context to work on
241 * const char *str The string to anonymize
242 * vfs_handle_struct *handle The handle struct to work on
244 * Returns a newly allocated string, either the anonymized one,
245 * or a copy of const char *str. The caller has to take care for
246 * freeing the allocated memory.
248 static char *smb_traffic_analyzer_anonymize( TALLOC_CTX
*ctx
,
250 vfs_handle_struct
*handle
)
252 const char *total_anonymization
;
253 const char *anon_prefix
;
255 total_anonymization
=lp_parm_const_string(SNUM(handle
->conn
),
256 "smb_traffic_analyzer",
257 "total_anonymization", NULL
);
259 anon_prefix
=lp_parm_const_string(SNUM(handle
->conn
),
260 "smb_traffic_analyzer",
261 "anonymize_prefix", NULL
);
262 if (anon_prefix
!= NULL
) {
263 if (total_anonymization
!= NULL
) {
264 output
= talloc_asprintf(ctx
, "%s",
267 output
= talloc_asprintf(ctx
, "%s%i", anon_prefix
,
271 output
= talloc_asprintf(ctx
, "%s", str
);
279 * The marshalling function for protocol v2.
280 * TALLOC_CTX *ctx Talloc context to work on
281 * struct tm *tm tm struct for the timestamp
282 * int seconds milliseconds of the timestamp
283 * vfs_handle_struct *handle vfs_handle_struct
284 * char *username Name of the user
285 * int vfs_operation VFS operation identifier
286 * int count Number of the common data blocks
287 * [...] variable args data blocks taken from the individual
288 * VFS data structures
290 * Returns the complete data block to send. The caller has to
291 * take care for freeing the allocated buffer.
293 static char *smb_traffic_analyzer_create_string( TALLOC_CTX
*ctx
,
294 struct tm
*tm
, int seconds
, vfs_handle_struct
*handle
, \
295 char *username
, int vfs_operation
, int count
, ... )
301 char *common_data_count_str
= NULL
;
302 char *timestr
= NULL
;
304 char *usersid
= NULL
;
306 char *vfs_operation_str
= NULL
;
307 const char *service_name
= lp_const_servicename(handle
->conn
->params
->service
);
310 * first create the data that is transfered with any VFS op
311 * These are, in the following order:
312 *(0) number of data to come [6 in v2.0]
313 * 1.vfs_operation identifier
319 * 7.IP Addresss of client
323 * number of common data blocks to come,
324 * this is a #define in vfs_smb_traffic_anaylzer.h,
325 * it's length is known at compile time
327 common_data_count_str
= talloc_strdup( ctx
, SMBTA_COMMON_DATA_COUNT
);
328 /* vfs operation identifier */
329 vfs_operation_str
= talloc_asprintf( common_data_count_str
, "%i",
332 * Handle anonymization. In protocol v2, we have to anonymize
333 * both the SID and the username. The name is already
334 * anonymized if needed, by the calling function.
336 usersid
= dom_sid_string( common_data_count_str
,
337 &handle
->conn
->session_info
->security_token
->sids
[0]);
339 sidstr
= smb_traffic_analyzer_anonymize(
340 common_data_count_str
,
345 timestr
= talloc_asprintf( common_data_count_str
, \
346 "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
354 len
= strlen( timestr
);
355 /* create the string of common data */
356 buf
= talloc_asprintf(ctx
,
357 "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
358 common_data_count_str
,
359 (unsigned int) strlen(vfs_operation_str
),
361 (unsigned int) strlen(username
),
363 (unsigned int) strlen(sidstr
),
365 (unsigned int) strlen(service_name
),
368 strlen(handle
->conn
->session_info
->info3
->base
.domain
.string
),
369 handle
->conn
->session_info
->info3
->base
.domain
.string
,
370 (unsigned int) strlen(timestr
),
372 (unsigned int) strlen(handle
->conn
->sconn
->client_id
.addr
),
373 handle
->conn
->sconn
->client_id
.addr
);
375 talloc_free(common_data_count_str
);
377 /* data blocks depending on the VFS function */
378 va_start( ap
, count
);
380 arg
= va_arg( ap
, char * );
382 * protocol v2 sends a four byte string
383 * as a header to each block, including
384 * the numbers of bytes to come in the
388 buf
= talloc_asprintf_append( buf
, "%04u%s", len
, arg
);
394 static void smb_traffic_analyzer_send_data(vfs_handle_struct
*handle
,
396 enum vfs_id vfs_operation
)
398 struct refcounted_sock
*rf_sock
= NULL
;
401 struct tm
*tm
= NULL
;
404 char *username
= NULL
;
406 const char *protocol_version
= NULL
;
413 * The state flags are part of the header
414 * and are descripted in the protocol description
415 * in vfs_smb_traffic_analyzer.h. They begin at byte
418 char state_flags
[9] = "000000\0";
421 * The first byte of the state flag string represents
422 * the modules protocol subversion number, defined
423 * in smb_traffic_analyzer.h. smbtatools/smbtad are designed
424 * to handle not yet implemented protocol enhancements
425 * by ignoring them. By recognizing the SMBTA_SUBRELEASE
426 * smbtatools can tell the user to update the client
429 state_flags
[0] = SMBTA_SUBRELEASE
;
431 SMB_VFS_HANDLE_GET_DATA(handle
, rf_sock
, struct refcounted_sock
, return);
433 if (rf_sock
== NULL
|| rf_sock
->sock
== -1) {
434 DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
441 tm
= localtime(&tv_sec
);
445 seconds
=(float) (tv
.tv_usec
/ 1000);
448 * Check if anonymization is required, and if yes do this only for
449 * the username here, needed vor protocol version 1. In v2 we
450 * additionally anonymize the SID, which is done in it's marshalling
453 username
= smb_traffic_analyzer_anonymize( talloc_tos(),
454 handle
->conn
->session_info
->sanitized_username
,
461 protocol_version
= lp_parm_const_string(SNUM(handle
->conn
),
462 "smb_traffic_analyzer",
463 "protocol_version", NULL
);
466 if (protocol_version
!= NULL
&& strcmp(protocol_version
,"V1") == 0) {
468 struct rw_data
*s_data
= (struct rw_data
*) data
;
471 * in case of protocol v1, ignore any vfs operations
472 * except read,pread,write,pwrite, and set the "Write"
473 * bool accordingly, send data and return.
475 if ( vfs_operation
> vfs_id_pwrite
) return;
477 if ( vfs_operation
<= vfs_id_pread
) Write
=false;
480 str
= talloc_asprintf(talloc_tos(),
481 "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
482 "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
483 (unsigned int) s_data
->len
,
485 handle
->conn
->session_info
->info3
->base
.domain
.string
,
487 handle
->conn
->connectpath
,
497 if (write_data(rf_sock
->sock
, str
, len
) != len
) {
498 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
499 "error sending V1 protocol data to socket!\n"));
505 * Protocol 2 is used by default.
508 switch( vfs_operation
) {
510 str
= smb_traffic_analyzer_create_string( talloc_tos(),
511 tm
, seconds
, handle
, username
, vfs_id_open
,
512 3, ((struct open_data
*) data
)->filename
,
513 talloc_asprintf( talloc_tos(), "%u",
514 ((struct open_data
*) data
)->mode
),
515 talloc_asprintf( talloc_tos(), "%u",
516 ((struct open_data
*) data
)->result
));
519 str
= smb_traffic_analyzer_create_string( talloc_tos(),
520 tm
, seconds
, handle
, username
, vfs_id_close
,
521 2, ((struct close_data
*) data
)->filename
,
522 talloc_asprintf( talloc_tos(), "%u",
523 ((struct close_data
*) data
)->result
));
526 str
= smb_traffic_analyzer_create_string( talloc_tos(),
527 tm
, seconds
, handle
, username
, vfs_id_mkdir
, \
528 3, ((struct mkdir_data
*) data
)->path
, \
529 talloc_asprintf( talloc_tos(), "%u", \
530 ((struct mkdir_data
*) data
)->mode
), \
531 talloc_asprintf( talloc_tos(), "%u", \
532 ((struct mkdir_data
*) data
)->result
));
535 str
= smb_traffic_analyzer_create_string( talloc_tos(),
536 tm
, seconds
, handle
, username
, vfs_id_rmdir
,
537 2, ((struct rmdir_data
*) data
)->path
, \
538 talloc_asprintf( talloc_tos(), "%u", \
539 ((struct rmdir_data
*) data
)->result
));
541 case vfs_id_rename
: ;
542 str
= smb_traffic_analyzer_create_string( talloc_tos(),
543 tm
, seconds
, handle
, username
, vfs_id_rename
,
544 3, ((struct rename_data
*) data
)->src
, \
545 ((struct rename_data
*) data
)->dst
,
546 talloc_asprintf(talloc_tos(), "%u", \
547 ((struct rename_data
*) data
)->result
));
550 str
= smb_traffic_analyzer_create_string( talloc_tos(),
551 tm
, seconds
, handle
, username
, vfs_id_chdir
,
552 2, ((struct chdir_data
*) data
)->path
, \
553 talloc_asprintf(talloc_tos(), "%u", \
554 ((struct chdir_data
*) data
)->result
));
561 str
= smb_traffic_analyzer_create_string( talloc_tos(),
562 tm
, seconds
, handle
, username
, vfs_operation
,
563 2, ((struct rw_data
*) data
)->filename
, \
564 talloc_asprintf(talloc_tos(), "%u", \
566 ((struct rw_data
*) data
)->len
));
569 DEBUG(1, ("smb_traffic_analyzer: error! "
570 "wrong VFS operation id detected!\n"));
577 DEBUG(1, ("smb_traffic_analyzer_send_data: "
578 "unable to create string to send!\n"));
584 * If configured, optain the key and run AES encryption
588 akey
= (char *) secrets_fetch("smb_traffic_analyzer_key", &size
);
590 if ( akey
!= NULL
) {
591 state_flags
[2] = 'E';
592 DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
593 " found, encrypting data!\n"));
594 output
= smb_traffic_analyzer_encrypt( talloc_tos(),
597 header
= smb_traffic_analyzer_create_header( talloc_tos(),
600 DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
601 " header created for crypted data: %s\n", header
));
602 smb_traffic_analyzer_write_data(header
, output
, len
,
609 header
= smb_traffic_analyzer_create_header( talloc_tos(),
611 smb_traffic_analyzer_write_data(header
, str
, strlen(str
),
616 static struct refcounted_sock
*sock_list
;
618 static void smb_traffic_analyzer_free_data(void **pptr
)
620 struct refcounted_sock
*rf_sock
= *(struct refcounted_sock
**)pptr
;
621 if (rf_sock
== NULL
) {
624 rf_sock
->ref_count
--;
625 if (rf_sock
->ref_count
!= 0) {
628 if (rf_sock
->sock
!= -1) {
629 close(rf_sock
->sock
);
631 DLIST_REMOVE(sock_list
, rf_sock
);
632 TALLOC_FREE(rf_sock
);
635 static int smb_traffic_analyzer_connect(struct vfs_handle_struct
*handle
,
639 connection_struct
*conn
= handle
->conn
;
640 enum sock_type st
= smb_traffic_analyzer_connMode(handle
);
641 struct refcounted_sock
*rf_sock
= NULL
;
642 const char *name
= (st
== UNIX_DOMAIN_SOCKET
) ? LOCAL_PATHNAME
:
643 lp_parm_const_string(SNUM(conn
),
644 "smb_traffic_analyzer",
645 "host", "localhost");
646 uint16_t port
= (st
== UNIX_DOMAIN_SOCKET
) ? 0 :
647 atoi( lp_parm_const_string(SNUM(conn
),
648 "smb_traffic_analyzer", "port", "9430"));
649 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
655 /* Are we already connected ? */
656 for (rf_sock
= sock_list
; rf_sock
; rf_sock
= rf_sock
->next
) {
657 if (port
== rf_sock
->port
&&
658 (strcmp(name
, rf_sock
->name
) == 0)) {
663 /* If we're connected already, just increase the
664 * reference count. */
666 rf_sock
->ref_count
++;
668 /* New connection. */
669 rf_sock
= TALLOC_ZERO_P(NULL
, struct refcounted_sock
);
670 if (rf_sock
== NULL
) {
671 SMB_VFS_NEXT_DISCONNECT(handle
);
675 rf_sock
->name
= talloc_strdup(rf_sock
, name
);
676 if (rf_sock
->name
== NULL
) {
677 SMB_VFS_NEXT_DISCONNECT(handle
);
678 TALLOC_FREE(rf_sock
);
682 rf_sock
->port
= port
;
683 rf_sock
->ref_count
= 1;
685 if (st
== UNIX_DOMAIN_SOCKET
) {
686 rf_sock
->sock
= smb_traffic_analyzer_connect_unix_socket(handle
,
690 rf_sock
->sock
= smb_traffic_analyzer_connect_inet_socket(handle
,
694 if (rf_sock
->sock
== -1) {
695 SMB_VFS_NEXT_DISCONNECT(handle
);
696 TALLOC_FREE(rf_sock
);
699 DLIST_ADD(sock_list
, rf_sock
);
702 /* Store the private data. */
703 SMB_VFS_HANDLE_SET_DATA(handle
, rf_sock
, smb_traffic_analyzer_free_data
,
704 struct refcounted_sock
, return -1);
709 static int smb_traffic_analyzer_chdir(vfs_handle_struct
*handle
, \
712 struct chdir_data s_data
;
713 s_data
.result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
715 DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path
));
716 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_chdir
);
717 return s_data
.result
;
720 static int smb_traffic_analyzer_rename(vfs_handle_struct
*handle
, \
721 const struct smb_filename
*smb_fname_src
,
722 const struct smb_filename
*smb_fname_dst
)
724 struct rename_data s_data
;
725 s_data
.result
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, \
727 s_data
.src
= smb_fname_src
->base_name
;
728 s_data
.dst
= smb_fname_dst
->base_name
;
729 DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
730 smb_fname_src
->base_name
,
731 smb_fname_dst
->base_name
));
732 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rename
);
733 return s_data
.result
;
736 static int smb_traffic_analyzer_rmdir(vfs_handle_struct
*handle
, \
739 struct rmdir_data s_data
;
740 s_data
.result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
742 DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path
));
743 smb_traffic_analyzer_send_data(handle
, &s_data
, vfs_id_rmdir
);
744 return s_data
.result
;
747 static int smb_traffic_analyzer_mkdir(vfs_handle_struct
*handle
, \
748 const char *path
, mode_t mode
)
750 struct mkdir_data s_data
;
751 s_data
.result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
754 DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path
));
755 smb_traffic_analyzer_send_data(handle
,
758 return s_data
.result
;
761 static ssize_t
smb_traffic_analyzer_sendfile(vfs_handle_struct
*handle
,
763 files_struct
*fromfsp
,
764 const DATA_BLOB
*hdr
,
768 struct rw_data s_data
;
769 s_data
.len
= SMB_VFS_NEXT_SENDFILE(handle
,
770 tofd
, fromfsp
, hdr
, offset
, n
);
771 s_data
.filename
= fromfsp
->fsp_name
->base_name
;
772 DEBUG(10, ("smb_traffic_analyzer_sendfile: sendfile(r): %s\n",
773 fsp_str_dbg(fromfsp
)));
774 smb_traffic_analyzer_send_data(handle
,
780 static ssize_t
smb_traffic_analyzer_recvfile(vfs_handle_struct
*handle
,
786 struct rw_data s_data
;
787 s_data
.len
= SMB_VFS_NEXT_RECVFILE(handle
,
788 fromfd
, tofsp
, offset
, n
);
789 s_data
.filename
= tofsp
->fsp_name
->base_name
;
790 DEBUG(10, ("smb_traffic_analyzer_recvfile: recvfile(w): %s\n",
791 fsp_str_dbg(tofsp
)));
792 smb_traffic_analyzer_send_data(handle
,
799 static ssize_t
smb_traffic_analyzer_read(vfs_handle_struct
*handle
, \
800 files_struct
*fsp
, void *data
, size_t n
)
802 struct rw_data s_data
;
804 s_data
.len
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
805 s_data
.filename
= fsp
->fsp_name
->base_name
;
806 DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp
)));
808 smb_traffic_analyzer_send_data(handle
,
815 static ssize_t
smb_traffic_analyzer_pread(vfs_handle_struct
*handle
, \
816 files_struct
*fsp
, void *data
, size_t n
, SMB_OFF_T offset
)
818 struct rw_data s_data
;
820 s_data
.len
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
821 s_data
.filename
= fsp
->fsp_name
->base_name
;
822 DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
825 smb_traffic_analyzer_send_data(handle
,
832 static ssize_t
smb_traffic_analyzer_write(vfs_handle_struct
*handle
, \
833 files_struct
*fsp
, const void *data
, size_t n
)
835 struct rw_data s_data
;
837 s_data
.len
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
838 s_data
.filename
= fsp
->fsp_name
->base_name
;
839 DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
842 smb_traffic_analyzer_send_data(handle
,
848 static ssize_t
smb_traffic_analyzer_pwrite(vfs_handle_struct
*handle
, \
849 files_struct
*fsp
, const void *data
, size_t n
, SMB_OFF_T offset
)
851 struct rw_data s_data
;
853 s_data
.len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
854 s_data
.filename
= fsp
->fsp_name
->base_name
;
855 DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
858 smb_traffic_analyzer_send_data(handle
,
864 static int smb_traffic_analyzer_open(vfs_handle_struct
*handle
, \
865 struct smb_filename
*smb_fname
, files_struct
*fsp
,\
866 int flags
, mode_t mode
)
868 struct open_data s_data
;
870 s_data
.result
= SMB_VFS_NEXT_OPEN( handle
, smb_fname
, fsp
,
872 DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
874 s_data
.filename
= fsp
->fsp_name
->base_name
;
876 smb_traffic_analyzer_send_data(handle
,
879 return s_data
.result
;
882 static int smb_traffic_analyzer_close(vfs_handle_struct
*handle
, \
885 struct close_data s_data
;
886 s_data
.result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
887 DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
889 s_data
.filename
= fsp
->fsp_name
->base_name
;
890 smb_traffic_analyzer_send_data(handle
,
893 return s_data
.result
;
897 static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns
= {
898 .connect_fn
= smb_traffic_analyzer_connect
,
899 .vfs_read
= smb_traffic_analyzer_read
,
900 .pread
= smb_traffic_analyzer_pread
,
901 .write
= smb_traffic_analyzer_write
,
902 .pwrite
= smb_traffic_analyzer_pwrite
,
903 .mkdir
= smb_traffic_analyzer_mkdir
,
904 .rename
= smb_traffic_analyzer_rename
,
905 .chdir
= smb_traffic_analyzer_chdir
,
906 .open_fn
= smb_traffic_analyzer_open
,
907 .rmdir
= smb_traffic_analyzer_rmdir
,
908 .close_fn
= smb_traffic_analyzer_close
,
909 .sendfile
= smb_traffic_analyzer_sendfile
,
910 .recvfile
= smb_traffic_analyzer_recvfile
913 /* Module initialization */
914 NTSTATUS
vfs_smb_traffic_analyzer_init(void)
916 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
917 "smb_traffic_analyzer",
918 &vfs_smb_traffic_analyzer_fns
);
920 if (!NT_STATUS_IS_OK(ret
)) {
924 vfs_smb_traffic_analyzer_debug_level
=
925 debug_add_class("smb_traffic_analyzer");
927 if (vfs_smb_traffic_analyzer_debug_level
== -1) {
928 vfs_smb_traffic_analyzer_debug_level
= DBGC_VFS
;
929 DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
930 "debugging class!\n"));
932 DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
933 "'smb_traffic_analyzer': %d\n", \
934 vfs_smb_traffic_analyzer_debug_level
));