| 1 | /*
|
|---|
| 2 | * traffic-analyzer VFS module. Measure the smb traffic users create
|
|---|
| 3 | * on the net.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (C) Holger Hetterich, 2008-2010
|
|---|
| 6 | * Copyright (C) Jeremy Allison, 2008
|
|---|
| 7 | *
|
|---|
| 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.
|
|---|
| 12 | *
|
|---|
| 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.
|
|---|
| 17 | *
|
|---|
| 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/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 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"
|
|---|
| 28 | #include "secrets.h"
|
|---|
| 29 | #include "../librpc/gen_ndr/ndr_netlogon.h"
|
|---|
| 30 | #include "auth.h"
|
|---|
| 31 |
|
|---|
| 32 | /* abstraction for the send_over_network function */
|
|---|
| 33 | enum sock_type {INTERNET_SOCKET = 0, UNIX_DOMAIN_SOCKET};
|
|---|
| 34 |
|
|---|
| 35 | #define LOCAL_PATHNAME "/var/tmp/stadsocket"
|
|---|
| 36 |
|
|---|
| 37 | static int vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
|
|---|
| 38 |
|
|---|
| 39 | static enum sock_type smb_traffic_analyzer_connMode(vfs_handle_struct *handle)
|
|---|
| 40 | {
|
|---|
| 41 | connection_struct *conn = handle->conn;
|
|---|
| 42 | const char *Mode;
|
|---|
| 43 | Mode=lp_parm_const_string(SNUM(conn), "smb_traffic_analyzer","mode", \
|
|---|
| 44 | "internet_socket");
|
|---|
| 45 | if (strstr(Mode,"unix_domain_socket")) {
|
|---|
| 46 | return UNIX_DOMAIN_SOCKET;
|
|---|
| 47 | } else {
|
|---|
| 48 | return INTERNET_SOCKET;
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 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)
|
|---|
| 56 | {
|
|---|
| 57 | /* Create a streaming Socket */
|
|---|
| 58 | int sockfd = -1;
|
|---|
| 59 | struct addrinfo hints;
|
|---|
| 60 | struct addrinfo *ailist = NULL;
|
|---|
| 61 | struct addrinfo *res = NULL;
|
|---|
| 62 | int ret;
|
|---|
| 63 |
|
|---|
| 64 | ZERO_STRUCT(hints);
|
|---|
| 65 | /* By default make sure it supports TCP. */
|
|---|
| 66 | hints.ai_socktype = SOCK_STREAM;
|
|---|
| 67 | hints.ai_flags = AI_ADDRCONFIG;
|
|---|
| 68 |
|
|---|
| 69 | ret = getaddrinfo(name,
|
|---|
| 70 | NULL,
|
|---|
| 71 | &hints,
|
|---|
| 72 | &ailist);
|
|---|
| 73 |
|
|---|
| 74 | if (ret) {
|
|---|
| 75 | DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
|
|---|
| 76 | "getaddrinfo failed for name %s [%s]\n",
|
|---|
| 77 | name,
|
|---|
| 78 | gai_strerror(ret) ));
|
|---|
| 79 | return -1;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
|
|---|
| 83 | "Port: %i\n", name, port));
|
|---|
| 84 |
|
|---|
| 85 | for (res = ailist; res; res = res->ai_next) {
|
|---|
| 86 | struct sockaddr_storage ss;
|
|---|
| 87 | NTSTATUS status;
|
|---|
| 88 |
|
|---|
| 89 | if (!res->ai_addr || res->ai_addrlen == 0) {
|
|---|
| 90 | continue;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | ZERO_STRUCT(ss);
|
|---|
| 94 | memcpy(&ss, res->ai_addr, res->ai_addrlen);
|
|---|
| 95 |
|
|---|
| 96 | status = open_socket_out(&ss, port, 10000, &sockfd);
|
|---|
| 97 | if (NT_STATUS_IS_OK(status)) {
|
|---|
| 98 | break;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | if (ailist) {
|
|---|
| 103 | freeaddrinfo(ailist);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | if (sockfd == -1) {
|
|---|
| 107 | DEBUG(1, ("smb_traffic_analyzer: unable to create "
|
|---|
| 108 | "socket, error is %s",
|
|---|
| 109 | strerror(errno)));
|
|---|
| 110 | return -1;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | return sockfd;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /* Connect to a unix domain socket */
|
|---|
| 117 | static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct *handle,
|
|---|
| 118 | const char *name)
|
|---|
| 119 | {
|
|---|
| 120 | /* Create the socket to stad */
|
|---|
| 121 | int len, sock;
|
|---|
| 122 | struct sockaddr_un remote;
|
|---|
| 123 |
|
|---|
| 124 | DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
|
|---|
| 125 | "Unix domain socket mode. Using %s\n",
|
|---|
| 126 | name ));
|
|---|
| 127 |
|
|---|
| 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"));
|
|---|
| 132 | return -1;
|
|---|
| 133 | }
|
|---|
| 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"));
|
|---|
| 142 | close(sock);
|
|---|
| 143 | return -1;
|
|---|
| 144 | }
|
|---|
| 145 | return sock;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /* Private data allowing shared connection sockets. */
|
|---|
| 149 | struct refcounted_sock {
|
|---|
| 150 | struct refcounted_sock *next, *prev;
|
|---|
| 151 | char *name;
|
|---|
| 152 | uint16_t port;
|
|---|
| 153 | int sock;
|
|---|
| 154 | unsigned int ref_count;
|
|---|
| 155 | };
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 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.
|
|---|
| 167 | */
|
|---|
| 168 | static char *smb_traffic_analyzer_encrypt( TALLOC_CTX *ctx,
|
|---|
| 169 | const char *akey, const char *str, size_t *len)
|
|---|
| 170 | {
|
|---|
| 171 | int s1,s2,h;
|
|---|
| 172 | AES_KEY key;
|
|---|
| 173 | unsigned char filler[17]= "................";
|
|---|
| 174 | char *output;
|
|---|
| 175 | if (akey == NULL) return NULL;
|
|---|
| 176 | samba_AES_set_encrypt_key((unsigned char *) akey, 128, &key);
|
|---|
| 177 | s1 = strlen(str) / 16;
|
|---|
| 178 | s2 = strlen(str) % 16;
|
|---|
| 179 | memcpy(filler, str + (s1*16), s2);
|
|---|
| 180 | DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
|
|---|
| 181 | " as filling block.\n", filler));
|
|---|
| 182 |
|
|---|
| 183 | *len = ((s1 + 1)*16);
|
|---|
| 184 | output = talloc_array(ctx, char, *len);
|
|---|
| 185 | for (h = 0; h < s1; h++) {
|
|---|
| 186 | samba_AES_encrypt((unsigned char *) str+(16*h), output+16*h,
|
|---|
| 187 | &key);
|
|---|
| 188 | }
|
|---|
| 189 | samba_AES_encrypt(filler, (unsigned char *)(output+(16*h)), &key);
|
|---|
| 190 | *len = (s1*16)+16;
|
|---|
| 191 | return output;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * Create a v2 header.
|
|---|
| 196 | * TALLLOC_CTX *ctx Talloc context to work on
|
|---|
| 197 | * const char *state_flags State flag string
|
|---|
| 198 | * int len length of the data block
|
|---|
| 199 | */
|
|---|
| 200 | static char *smb_traffic_analyzer_create_header( TALLOC_CTX *ctx,
|
|---|
| 201 | const char *state_flags, size_t data_len)
|
|---|
| 202 | {
|
|---|
| 203 | char *header = talloc_asprintf( ctx, "V2.%s%017u",
|
|---|
| 204 | state_flags, (unsigned int) data_len);
|
|---|
| 205 | DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
|
|---|
| 206 | dump_data(10, (uint8_t *)header, strlen(header));
|
|---|
| 207 | return header;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 | /**
|
|---|
| 212 | * Actually send header and data over the network
|
|---|
| 213 | * char *header Header data
|
|---|
| 214 | * char *data Data Block
|
|---|
| 215 | * int dlength Length of data block
|
|---|
| 216 | * int socket
|
|---|
| 217 | */
|
|---|
| 218 | static void smb_traffic_analyzer_write_data( char *header, char *data,
|
|---|
| 219 | int dlength, int _socket)
|
|---|
| 220 | {
|
|---|
| 221 | int len = strlen(header);
|
|---|
| 222 | if (write_data( _socket, header, len) != len) {
|
|---|
| 223 | DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
|
|---|
| 224 | "error sending the header"
|
|---|
| 225 | " over the socket!\n"));
|
|---|
| 226 | }
|
|---|
| 227 | DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
|
|---|
| 228 | dump_data( 10, (uint8_t *)data, dlength);
|
|---|
| 229 |
|
|---|
| 230 | if (write_data( _socket, data, dlength) != dlength) {
|
|---|
| 231 | DEBUG(1, ("smb_traffic_analyzer_write_data: "
|
|---|
| 232 | "error sending crypted data to socket!\n"));
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | /*
|
|---|
| 238 | * Anonymize a string if required.
|
|---|
| 239 | * TALLOC_CTX *ctx The talloc context to work on
|
|---|
| 240 | * const char *str The string to anonymize
|
|---|
| 241 | * vfs_handle_struct *handle The handle struct to work on
|
|---|
| 242 | *
|
|---|
| 243 | * Returns a newly allocated string, either the anonymized one,
|
|---|
| 244 | * or a copy of const char *str. The caller has to take care for
|
|---|
| 245 | * freeing the allocated memory.
|
|---|
| 246 | */
|
|---|
| 247 | static char *smb_traffic_analyzer_anonymize( TALLOC_CTX *ctx,
|
|---|
| 248 | const char *str,
|
|---|
| 249 | vfs_handle_struct *handle )
|
|---|
| 250 | {
|
|---|
| 251 | const char *total_anonymization;
|
|---|
| 252 | const char *anon_prefix;
|
|---|
| 253 | char *output;
|
|---|
| 254 | total_anonymization=lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 255 | "smb_traffic_analyzer",
|
|---|
| 256 | "total_anonymization", NULL);
|
|---|
| 257 |
|
|---|
| 258 | anon_prefix=lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 259 | "smb_traffic_analyzer",
|
|---|
| 260 | "anonymize_prefix", NULL );
|
|---|
| 261 | if (anon_prefix != NULL) {
|
|---|
| 262 | if (total_anonymization != NULL) {
|
|---|
| 263 | output = talloc_asprintf(ctx, "%s",
|
|---|
| 264 | anon_prefix);
|
|---|
| 265 | } else {
|
|---|
| 266 | output = talloc_asprintf(ctx, "%s%i", anon_prefix,
|
|---|
| 267 | str_checksum(str));
|
|---|
| 268 | }
|
|---|
| 269 | } else {
|
|---|
| 270 | output = talloc_asprintf(ctx, "%s", str);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | return output;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 | /**
|
|---|
| 278 | * The marshalling function for protocol v2.
|
|---|
| 279 | * TALLOC_CTX *ctx Talloc context to work on
|
|---|
| 280 | * struct tm *tm tm struct for the timestamp
|
|---|
| 281 | * int seconds milliseconds of the timestamp
|
|---|
| 282 | * vfs_handle_struct *handle vfs_handle_struct
|
|---|
| 283 | * char *username Name of the user
|
|---|
| 284 | * int vfs_operation VFS operation identifier
|
|---|
| 285 | * int count Number of the common data blocks
|
|---|
| 286 | * [...] variable args data blocks taken from the individual
|
|---|
| 287 | * VFS data structures
|
|---|
| 288 | *
|
|---|
| 289 | * Returns the complete data block to send. The caller has to
|
|---|
| 290 | * take care for freeing the allocated buffer.
|
|---|
| 291 | */
|
|---|
| 292 | static char *smb_traffic_analyzer_create_string( TALLOC_CTX *ctx,
|
|---|
| 293 | struct tm *tm, int seconds, vfs_handle_struct *handle, \
|
|---|
| 294 | char *username, int vfs_operation, int count, ... )
|
|---|
| 295 | {
|
|---|
| 296 |
|
|---|
| 297 | va_list ap;
|
|---|
| 298 | char *arg = NULL;
|
|---|
| 299 | int len;
|
|---|
| 300 | char *common_data_count_str = NULL;
|
|---|
| 301 | char *timestr = NULL;
|
|---|
| 302 | char *sidstr = NULL;
|
|---|
| 303 | char *usersid = NULL;
|
|---|
| 304 | char *buf = NULL;
|
|---|
| 305 | char *vfs_operation_str = NULL;
|
|---|
| 306 | const char *service_name = lp_const_servicename(handle->conn->params->service);
|
|---|
| 307 |
|
|---|
| 308 | /*
|
|---|
| 309 | * first create the data that is transfered with any VFS op
|
|---|
| 310 | * These are, in the following order:
|
|---|
| 311 | *(0) number of data to come [6 in v2.0]
|
|---|
| 312 | * 1.vfs_operation identifier
|
|---|
| 313 | * 2.username
|
|---|
| 314 | * 3.user-SID
|
|---|
| 315 | * 4.affected share
|
|---|
| 316 | * 5.domain
|
|---|
| 317 | * 6.timestamp
|
|---|
| 318 | * 7.IP Addresss of client
|
|---|
| 319 | */
|
|---|
| 320 |
|
|---|
| 321 | /*
|
|---|
| 322 | * number of common data blocks to come,
|
|---|
| 323 | * this is a #define in vfs_smb_traffic_anaylzer.h,
|
|---|
| 324 | * it's length is known at compile time
|
|---|
| 325 | */
|
|---|
| 326 | common_data_count_str = talloc_strdup( ctx, SMBTA_COMMON_DATA_COUNT);
|
|---|
| 327 | /* vfs operation identifier */
|
|---|
| 328 | vfs_operation_str = talloc_asprintf( common_data_count_str, "%i",
|
|---|
| 329 | vfs_operation);
|
|---|
| 330 | /*
|
|---|
| 331 | * Handle anonymization. In protocol v2, we have to anonymize
|
|---|
| 332 | * both the SID and the username. The name is already
|
|---|
| 333 | * anonymized if needed, by the calling function.
|
|---|
| 334 | */
|
|---|
| 335 | usersid = dom_sid_string( common_data_count_str,
|
|---|
| 336 | &handle->conn->session_info->security_token->sids[0]);
|
|---|
| 337 |
|
|---|
| 338 | sidstr = smb_traffic_analyzer_anonymize(
|
|---|
| 339 | common_data_count_str,
|
|---|
| 340 | usersid,
|
|---|
| 341 | handle);
|
|---|
| 342 |
|
|---|
| 343 | /* time stamp */
|
|---|
| 344 | timestr = talloc_asprintf( common_data_count_str, \
|
|---|
| 345 | "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
|
|---|
| 346 | tm->tm_year+1900, \
|
|---|
| 347 | tm->tm_mon+1, \
|
|---|
| 348 | tm->tm_mday, \
|
|---|
| 349 | tm->tm_hour, \
|
|---|
| 350 | tm->tm_min, \
|
|---|
| 351 | tm->tm_sec, \
|
|---|
| 352 | (int)seconds);
|
|---|
| 353 | len = strlen( timestr );
|
|---|
| 354 | /* create the string of common data */
|
|---|
| 355 | buf = talloc_asprintf(ctx,
|
|---|
| 356 | "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
|
|---|
| 357 | common_data_count_str,
|
|---|
| 358 | (unsigned int) strlen(vfs_operation_str),
|
|---|
| 359 | vfs_operation_str,
|
|---|
| 360 | (unsigned int) strlen(username),
|
|---|
| 361 | username,
|
|---|
| 362 | (unsigned int) strlen(sidstr),
|
|---|
| 363 | sidstr,
|
|---|
| 364 | (unsigned int) strlen(service_name),
|
|---|
| 365 | service_name,
|
|---|
| 366 | (unsigned int)
|
|---|
| 367 | strlen(handle->conn->session_info->info3->base.domain.string),
|
|---|
| 368 | handle->conn->session_info->info3->base.domain.string,
|
|---|
| 369 | (unsigned int) strlen(timestr),
|
|---|
| 370 | timestr,
|
|---|
| 371 | (unsigned int) strlen(handle->conn->sconn->client_id.addr),
|
|---|
| 372 | handle->conn->sconn->client_id.addr);
|
|---|
| 373 |
|
|---|
| 374 | talloc_free(common_data_count_str);
|
|---|
| 375 |
|
|---|
| 376 | /* data blocks depending on the VFS function */
|
|---|
| 377 | va_start( ap, count );
|
|---|
| 378 | while ( count-- ) {
|
|---|
| 379 | arg = va_arg( ap, char * );
|
|---|
| 380 | /*
|
|---|
| 381 | * protocol v2 sends a four byte string
|
|---|
| 382 | * as a header to each block, including
|
|---|
| 383 | * the numbers of bytes to come in the
|
|---|
| 384 | * next string.
|
|---|
| 385 | */
|
|---|
| 386 | len = strlen( arg );
|
|---|
| 387 | buf = talloc_asprintf_append( buf, "%04u%s", len, arg);
|
|---|
| 388 | }
|
|---|
| 389 | va_end( ap );
|
|---|
| 390 | return buf;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | static void smb_traffic_analyzer_send_data(vfs_handle_struct *handle,
|
|---|
| 394 | void *data,
|
|---|
| 395 | enum vfs_id vfs_operation )
|
|---|
| 396 | {
|
|---|
| 397 | struct refcounted_sock *rf_sock = NULL;
|
|---|
| 398 | struct timeval tv;
|
|---|
| 399 | time_t tv_sec;
|
|---|
| 400 | struct tm *tm = NULL;
|
|---|
| 401 | int seconds;
|
|---|
| 402 | char *str = NULL;
|
|---|
| 403 | char *username = NULL;
|
|---|
| 404 | char *header = NULL;
|
|---|
| 405 | const char *protocol_version = NULL;
|
|---|
| 406 | bool Write = false;
|
|---|
| 407 | size_t len;
|
|---|
| 408 | size_t size;
|
|---|
| 409 | char *akey, *output;
|
|---|
| 410 |
|
|---|
| 411 | /*
|
|---|
| 412 | * The state flags are part of the header
|
|---|
| 413 | * and are descripted in the protocol description
|
|---|
| 414 | * in vfs_smb_traffic_analyzer.h. They begin at byte
|
|---|
| 415 | * 03 of the header.
|
|---|
| 416 | */
|
|---|
| 417 | char state_flags[9] = "000000\0";
|
|---|
| 418 |
|
|---|
| 419 | /**
|
|---|
| 420 | * The first byte of the state flag string represents
|
|---|
| 421 | * the modules protocol subversion number, defined
|
|---|
| 422 | * in smb_traffic_analyzer.h. smbtatools/smbtad are designed
|
|---|
| 423 | * to handle not yet implemented protocol enhancements
|
|---|
| 424 | * by ignoring them. By recognizing the SMBTA_SUBRELEASE
|
|---|
| 425 | * smbtatools can tell the user to update the client
|
|---|
| 426 | * software.
|
|---|
| 427 | */
|
|---|
| 428 | state_flags[0] = SMBTA_SUBRELEASE;
|
|---|
| 429 |
|
|---|
| 430 | SMB_VFS_HANDLE_GET_DATA(handle, rf_sock, struct refcounted_sock, return);
|
|---|
| 431 |
|
|---|
| 432 | if (rf_sock == NULL || rf_sock->sock == -1) {
|
|---|
| 433 | DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
|
|---|
| 434 | "closed\n"));
|
|---|
| 435 | return;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | GetTimeOfDay(&tv);
|
|---|
| 439 | tv_sec = tv.tv_sec;
|
|---|
| 440 | tm = localtime(&tv_sec);
|
|---|
| 441 | if (!tm) {
|
|---|
| 442 | return;
|
|---|
| 443 | }
|
|---|
| 444 | seconds=(float) (tv.tv_usec / 1000);
|
|---|
| 445 |
|
|---|
| 446 | /*
|
|---|
| 447 | * Check if anonymization is required, and if yes do this only for
|
|---|
| 448 | * the username here, needed vor protocol version 1. In v2 we
|
|---|
| 449 | * additionally anonymize the SID, which is done in it's marshalling
|
|---|
| 450 | * function.
|
|---|
| 451 | */
|
|---|
| 452 | username = smb_traffic_analyzer_anonymize( talloc_tos(),
|
|---|
| 453 | handle->conn->session_info->sanitized_username,
|
|---|
| 454 | handle);
|
|---|
| 455 |
|
|---|
| 456 | if (!username) {
|
|---|
| 457 | return;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | protocol_version = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 461 | "smb_traffic_analyzer",
|
|---|
| 462 | "protocol_version", NULL );
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 | if (protocol_version != NULL && strcmp(protocol_version,"V1") == 0) {
|
|---|
| 466 |
|
|---|
| 467 | struct rw_data *s_data = (struct rw_data *) data;
|
|---|
| 468 |
|
|---|
| 469 | /*
|
|---|
| 470 | * in case of protocol v1, ignore any vfs operations
|
|---|
| 471 | * except read,pread,write,pwrite, and set the "Write"
|
|---|
| 472 | * bool accordingly, send data and return.
|
|---|
| 473 | */
|
|---|
| 474 | if ( vfs_operation > vfs_id_pwrite ) return;
|
|---|
| 475 |
|
|---|
| 476 | if ( vfs_operation <= vfs_id_pread ) Write=false;
|
|---|
| 477 | else Write=true;
|
|---|
| 478 |
|
|---|
| 479 | str = talloc_asprintf(talloc_tos(),
|
|---|
| 480 | "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
|
|---|
| 481 | "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
|
|---|
| 482 | (unsigned int) s_data->len,
|
|---|
| 483 | username,
|
|---|
| 484 | handle->conn->session_info->info3->base.domain.string,
|
|---|
| 485 | Write ? 'W' : 'R',
|
|---|
| 486 | handle->conn->connectpath,
|
|---|
| 487 | s_data->filename,
|
|---|
| 488 | tm->tm_year+1900,
|
|---|
| 489 | tm->tm_mon+1,
|
|---|
| 490 | tm->tm_mday,
|
|---|
| 491 | tm->tm_hour,
|
|---|
| 492 | tm->tm_min,
|
|---|
| 493 | tm->tm_sec,
|
|---|
| 494 | (int)seconds);
|
|---|
| 495 | len = strlen(str);
|
|---|
| 496 | if (write_data(rf_sock->sock, str, len) != len) {
|
|---|
| 497 | DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
|
|---|
| 498 | "error sending V1 protocol data to socket!\n"));
|
|---|
| 499 | return;
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | } else {
|
|---|
| 503 | /**
|
|---|
| 504 | * Protocol 2 is used by default.
|
|---|
| 505 | */
|
|---|
| 506 |
|
|---|
| 507 | switch( vfs_operation ) {
|
|---|
| 508 | case vfs_id_open: ;
|
|---|
| 509 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 510 | tm, seconds, handle, username, vfs_id_open,
|
|---|
| 511 | 3, ((struct open_data *) data)->filename,
|
|---|
| 512 | talloc_asprintf( talloc_tos(), "%u",
|
|---|
| 513 | ((struct open_data *) data)->mode),
|
|---|
| 514 | talloc_asprintf( talloc_tos(), "%u",
|
|---|
| 515 | ((struct open_data *) data)->result));
|
|---|
| 516 | break;
|
|---|
| 517 | case vfs_id_close: ;
|
|---|
| 518 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 519 | tm, seconds, handle, username, vfs_id_close,
|
|---|
| 520 | 2, ((struct close_data *) data)->filename,
|
|---|
| 521 | talloc_asprintf( talloc_tos(), "%u",
|
|---|
| 522 | ((struct close_data *) data)->result));
|
|---|
| 523 | break;
|
|---|
| 524 | case vfs_id_mkdir: ;
|
|---|
| 525 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 526 | tm, seconds, handle, username, vfs_id_mkdir, \
|
|---|
| 527 | 3, ((struct mkdir_data *) data)->path, \
|
|---|
| 528 | talloc_asprintf( talloc_tos(), "%u", \
|
|---|
| 529 | ((struct mkdir_data *) data)->mode), \
|
|---|
| 530 | talloc_asprintf( talloc_tos(), "%u", \
|
|---|
| 531 | ((struct mkdir_data *) data)->result ));
|
|---|
| 532 | break;
|
|---|
| 533 | case vfs_id_rmdir: ;
|
|---|
| 534 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 535 | tm, seconds, handle, username, vfs_id_rmdir,
|
|---|
| 536 | 2, ((struct rmdir_data *) data)->path, \
|
|---|
| 537 | talloc_asprintf( talloc_tos(), "%u", \
|
|---|
| 538 | ((struct rmdir_data *) data)->result ));
|
|---|
| 539 | break;
|
|---|
| 540 | case vfs_id_rename: ;
|
|---|
| 541 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 542 | tm, seconds, handle, username, vfs_id_rename,
|
|---|
| 543 | 3, ((struct rename_data *) data)->src, \
|
|---|
| 544 | ((struct rename_data *) data)->dst,
|
|---|
| 545 | talloc_asprintf(talloc_tos(), "%u", \
|
|---|
| 546 | ((struct rename_data *) data)->result));
|
|---|
| 547 | break;
|
|---|
| 548 | case vfs_id_chdir: ;
|
|---|
| 549 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 550 | tm, seconds, handle, username, vfs_id_chdir,
|
|---|
| 551 | 2, ((struct chdir_data *) data)->path, \
|
|---|
| 552 | talloc_asprintf(talloc_tos(), "%u", \
|
|---|
| 553 | ((struct chdir_data *) data)->result));
|
|---|
| 554 | break;
|
|---|
| 555 |
|
|---|
| 556 | case vfs_id_write:
|
|---|
| 557 | case vfs_id_pwrite:
|
|---|
| 558 | case vfs_id_read:
|
|---|
| 559 | case vfs_id_pread: ;
|
|---|
| 560 | str = smb_traffic_analyzer_create_string( talloc_tos(),
|
|---|
| 561 | tm, seconds, handle, username, vfs_operation,
|
|---|
| 562 | 2, ((struct rw_data *) data)->filename, \
|
|---|
| 563 | talloc_asprintf(talloc_tos(), "%u", \
|
|---|
| 564 | (unsigned int)
|
|---|
| 565 | ((struct rw_data *) data)->len));
|
|---|
| 566 | break;
|
|---|
| 567 | default:
|
|---|
| 568 | DEBUG(1, ("smb_traffic_analyzer: error! "
|
|---|
| 569 | "wrong VFS operation id detected!\n"));
|
|---|
| 570 | return;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | if (!str) {
|
|---|
| 576 | DEBUG(1, ("smb_traffic_analyzer_send_data: "
|
|---|
| 577 | "unable to create string to send!\n"));
|
|---|
| 578 | return;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 | /*
|
|---|
| 583 | * If configured, optain the key and run AES encryption
|
|---|
| 584 | * over the data.
|
|---|
| 585 | */
|
|---|
| 586 | become_root();
|
|---|
| 587 | akey = (char *) secrets_fetch("smb_traffic_analyzer_key", &size);
|
|---|
| 588 | unbecome_root();
|
|---|
| 589 | if ( akey != NULL ) {
|
|---|
| 590 | state_flags[2] = 'E';
|
|---|
| 591 | DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
|
|---|
| 592 | " found, encrypting data!\n"));
|
|---|
| 593 | output = smb_traffic_analyzer_encrypt( talloc_tos(),
|
|---|
| 594 | akey, str, &len);
|
|---|
| 595 | SAFE_FREE(akey);
|
|---|
| 596 | header = smb_traffic_analyzer_create_header( talloc_tos(),
|
|---|
| 597 | state_flags, len);
|
|---|
| 598 |
|
|---|
| 599 | DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
|
|---|
| 600 | " header created for crypted data: %s\n", header));
|
|---|
| 601 | smb_traffic_analyzer_write_data(header, output, len,
|
|---|
| 602 | rf_sock->sock);
|
|---|
| 603 | return;
|
|---|
| 604 |
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | len = strlen(str);
|
|---|
| 608 | header = smb_traffic_analyzer_create_header( talloc_tos(),
|
|---|
| 609 | state_flags, len);
|
|---|
| 610 | smb_traffic_analyzer_write_data(header, str, strlen(str),
|
|---|
| 611 | rf_sock->sock);
|
|---|
| 612 |
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | static struct refcounted_sock *sock_list;
|
|---|
| 616 |
|
|---|
| 617 | static void smb_traffic_analyzer_free_data(void **pptr)
|
|---|
| 618 | {
|
|---|
| 619 | struct refcounted_sock *rf_sock = *(struct refcounted_sock **)pptr;
|
|---|
| 620 | if (rf_sock == NULL) {
|
|---|
| 621 | return;
|
|---|
| 622 | }
|
|---|
| 623 | rf_sock->ref_count--;
|
|---|
| 624 | if (rf_sock->ref_count != 0) {
|
|---|
| 625 | return;
|
|---|
| 626 | }
|
|---|
| 627 | if (rf_sock->sock != -1) {
|
|---|
| 628 | close(rf_sock->sock);
|
|---|
| 629 | }
|
|---|
| 630 | DLIST_REMOVE(sock_list, rf_sock);
|
|---|
| 631 | TALLOC_FREE(rf_sock);
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
|
|---|
| 635 | const char *service,
|
|---|
| 636 | const char *user)
|
|---|
| 637 | {
|
|---|
| 638 | connection_struct *conn = handle->conn;
|
|---|
| 639 | enum sock_type st = smb_traffic_analyzer_connMode(handle);
|
|---|
| 640 | struct refcounted_sock *rf_sock = NULL;
|
|---|
| 641 | const char *name = (st == UNIX_DOMAIN_SOCKET) ? LOCAL_PATHNAME :
|
|---|
| 642 | lp_parm_const_string(SNUM(conn),
|
|---|
| 643 | "smb_traffic_analyzer",
|
|---|
| 644 | "host", "localhost");
|
|---|
| 645 | uint16_t port = (st == UNIX_DOMAIN_SOCKET) ? 0 :
|
|---|
| 646 | atoi( lp_parm_const_string(SNUM(conn),
|
|---|
| 647 | "smb_traffic_analyzer", "port", "9430"));
|
|---|
| 648 | int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
|
|---|
| 649 |
|
|---|
| 650 | if (ret < 0) {
|
|---|
| 651 | return ret;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | /* Are we already connected ? */
|
|---|
| 655 | for (rf_sock = sock_list; rf_sock; rf_sock = rf_sock->next) {
|
|---|
| 656 | if (port == rf_sock->port &&
|
|---|
| 657 | (strcmp(name, rf_sock->name) == 0)) {
|
|---|
| 658 | break;
|
|---|
| 659 | }
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | /* If we're connected already, just increase the
|
|---|
| 663 | * reference count. */
|
|---|
| 664 | if (rf_sock) {
|
|---|
| 665 | rf_sock->ref_count++;
|
|---|
| 666 | } else {
|
|---|
| 667 | /* New connection. */
|
|---|
| 668 | rf_sock = TALLOC_ZERO_P(NULL, struct refcounted_sock);
|
|---|
| 669 | if (rf_sock == NULL) {
|
|---|
| 670 | SMB_VFS_NEXT_DISCONNECT(handle);
|
|---|
| 671 | errno = ENOMEM;
|
|---|
| 672 | return -1;
|
|---|
| 673 | }
|
|---|
| 674 | rf_sock->name = talloc_strdup(rf_sock, name);
|
|---|
| 675 | if (rf_sock->name == NULL) {
|
|---|
| 676 | SMB_VFS_NEXT_DISCONNECT(handle);
|
|---|
| 677 | TALLOC_FREE(rf_sock);
|
|---|
| 678 | errno = ENOMEM;
|
|---|
| 679 | return -1;
|
|---|
| 680 | }
|
|---|
| 681 | rf_sock->port = port;
|
|---|
| 682 | rf_sock->ref_count = 1;
|
|---|
| 683 |
|
|---|
| 684 | if (st == UNIX_DOMAIN_SOCKET) {
|
|---|
| 685 | rf_sock->sock = smb_traffic_analyzer_connect_unix_socket(handle,
|
|---|
| 686 | name);
|
|---|
| 687 | } else {
|
|---|
| 688 |
|
|---|
| 689 | rf_sock->sock = smb_traffic_analyzer_connect_inet_socket(handle,
|
|---|
| 690 | name,
|
|---|
| 691 | port);
|
|---|
| 692 | }
|
|---|
| 693 | if (rf_sock->sock == -1) {
|
|---|
| 694 | SMB_VFS_NEXT_DISCONNECT(handle);
|
|---|
| 695 | TALLOC_FREE(rf_sock);
|
|---|
| 696 | return -1;
|
|---|
| 697 | }
|
|---|
| 698 | DLIST_ADD(sock_list, rf_sock);
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | /* Store the private data. */
|
|---|
| 702 | SMB_VFS_HANDLE_SET_DATA(handle, rf_sock, smb_traffic_analyzer_free_data,
|
|---|
| 703 | struct refcounted_sock, return -1);
|
|---|
| 704 | return 0;
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | /* VFS Functions */
|
|---|
| 708 | static int smb_traffic_analyzer_chdir(vfs_handle_struct *handle, \
|
|---|
| 709 | const char *path)
|
|---|
| 710 | {
|
|---|
| 711 | struct chdir_data s_data;
|
|---|
| 712 | s_data.result = SMB_VFS_NEXT_CHDIR(handle, path);
|
|---|
| 713 | s_data.path = path;
|
|---|
| 714 | DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path));
|
|---|
| 715 | smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_chdir);
|
|---|
| 716 | return s_data.result;
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | static int smb_traffic_analyzer_rename(vfs_handle_struct *handle, \
|
|---|
| 720 | const struct smb_filename *smb_fname_src,
|
|---|
| 721 | const struct smb_filename *smb_fname_dst)
|
|---|
| 722 | {
|
|---|
| 723 | struct rename_data s_data;
|
|---|
| 724 | s_data.result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, \
|
|---|
| 725 | smb_fname_dst);
|
|---|
| 726 | s_data.src = smb_fname_src->base_name;
|
|---|
| 727 | s_data.dst = smb_fname_dst->base_name;
|
|---|
| 728 | DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
|
|---|
| 729 | smb_fname_src->base_name,
|
|---|
| 730 | smb_fname_dst->base_name));
|
|---|
| 731 | smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rename);
|
|---|
| 732 | return s_data.result;
|
|---|
| 733 | }
|
|---|
| 734 |
|
|---|
| 735 | static int smb_traffic_analyzer_rmdir(vfs_handle_struct *handle, \
|
|---|
| 736 | const char *path)
|
|---|
| 737 | {
|
|---|
| 738 | struct rmdir_data s_data;
|
|---|
| 739 | s_data.result = SMB_VFS_NEXT_RMDIR(handle, path);
|
|---|
| 740 | s_data.path = path;
|
|---|
| 741 | DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path));
|
|---|
| 742 | smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rmdir);
|
|---|
| 743 | return s_data.result;
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | static int smb_traffic_analyzer_mkdir(vfs_handle_struct *handle, \
|
|---|
| 747 | const char *path, mode_t mode)
|
|---|
| 748 | {
|
|---|
| 749 | struct mkdir_data s_data;
|
|---|
| 750 | s_data.result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
|
|---|
| 751 | s_data.path = path;
|
|---|
| 752 | s_data.mode = mode;
|
|---|
| 753 | DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path));
|
|---|
| 754 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 755 | &s_data,
|
|---|
| 756 | vfs_id_mkdir);
|
|---|
| 757 | return s_data.result;
|
|---|
| 758 | }
|
|---|
| 759 |
|
|---|
| 760 | static ssize_t smb_traffic_analyzer_sendfile(vfs_handle_struct *handle,
|
|---|
| 761 | int tofd,
|
|---|
| 762 | files_struct *fromfsp,
|
|---|
| 763 | const DATA_BLOB *hdr,
|
|---|
| 764 | SMB_OFF_T offset,
|
|---|
| 765 | size_t n)
|
|---|
| 766 | {
|
|---|
| 767 | struct rw_data s_data;
|
|---|
| 768 | s_data.len = SMB_VFS_NEXT_SENDFILE(handle,
|
|---|
| 769 | tofd, fromfsp, hdr, offset, n);
|
|---|
| 770 | s_data.filename = fromfsp->fsp_name->base_name;
|
|---|
| 771 | DEBUG(10, ("smb_traffic_analyzer_sendfile: sendfile(r): %s\n",
|
|---|
| 772 | fsp_str_dbg(fromfsp)));
|
|---|
| 773 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 774 | &s_data,
|
|---|
| 775 | vfs_id_read);
|
|---|
| 776 | return s_data.len;
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | static ssize_t smb_traffic_analyzer_recvfile(vfs_handle_struct *handle,
|
|---|
| 780 | int fromfd,
|
|---|
| 781 | files_struct *tofsp,
|
|---|
| 782 | SMB_OFF_T offset,
|
|---|
| 783 | size_t n)
|
|---|
| 784 | {
|
|---|
| 785 | struct rw_data s_data;
|
|---|
| 786 | s_data.len = SMB_VFS_NEXT_RECVFILE(handle,
|
|---|
| 787 | fromfd, tofsp, offset, n);
|
|---|
| 788 | s_data.filename = tofsp->fsp_name->base_name;
|
|---|
| 789 | DEBUG(10, ("smb_traffic_analyzer_recvfile: recvfile(w): %s\n",
|
|---|
| 790 | fsp_str_dbg(tofsp)));
|
|---|
| 791 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 792 | &s_data,
|
|---|
| 793 | vfs_id_write);
|
|---|
| 794 | return s_data.len;
|
|---|
| 795 | }
|
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 | static ssize_t smb_traffic_analyzer_read(vfs_handle_struct *handle, \
|
|---|
| 799 | files_struct *fsp, void *data, size_t n)
|
|---|
| 800 | {
|
|---|
| 801 | struct rw_data s_data;
|
|---|
| 802 |
|
|---|
| 803 | s_data.len = SMB_VFS_NEXT_READ(handle, fsp, data, n);
|
|---|
| 804 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 805 | DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp)));
|
|---|
| 806 |
|
|---|
| 807 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 808 | &s_data,
|
|---|
| 809 | vfs_id_read);
|
|---|
| 810 | return s_data.len;
|
|---|
| 811 | }
|
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 | static ssize_t smb_traffic_analyzer_pread(vfs_handle_struct *handle, \
|
|---|
| 815 | files_struct *fsp, void *data, size_t n, SMB_OFF_T offset)
|
|---|
| 816 | {
|
|---|
| 817 | struct rw_data s_data;
|
|---|
| 818 |
|
|---|
| 819 | s_data.len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
|
|---|
| 820 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 821 | DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
|
|---|
| 822 | fsp_str_dbg(fsp)));
|
|---|
| 823 |
|
|---|
| 824 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 825 | &s_data,
|
|---|
| 826 | vfs_id_pread);
|
|---|
| 827 |
|
|---|
| 828 | return s_data.len;
|
|---|
| 829 | }
|
|---|
| 830 |
|
|---|
| 831 | static ssize_t smb_traffic_analyzer_write(vfs_handle_struct *handle, \
|
|---|
| 832 | files_struct *fsp, const void *data, size_t n)
|
|---|
| 833 | {
|
|---|
| 834 | struct rw_data s_data;
|
|---|
| 835 |
|
|---|
| 836 | s_data.len = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
|
|---|
| 837 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 838 | DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
|
|---|
| 839 | fsp_str_dbg(fsp)));
|
|---|
| 840 |
|
|---|
| 841 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 842 | &s_data,
|
|---|
| 843 | vfs_id_write);
|
|---|
| 844 | return s_data.len;
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | static ssize_t smb_traffic_analyzer_pwrite(vfs_handle_struct *handle, \
|
|---|
| 848 | files_struct *fsp, const void *data, size_t n, SMB_OFF_T offset)
|
|---|
| 849 | {
|
|---|
| 850 | struct rw_data s_data;
|
|---|
| 851 |
|
|---|
| 852 | s_data.len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
|
|---|
| 853 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 854 | DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
|
|---|
| 855 | fsp_str_dbg(fsp)));
|
|---|
| 856 |
|
|---|
| 857 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 858 | &s_data,
|
|---|
| 859 | vfs_id_pwrite);
|
|---|
| 860 | return s_data.len;
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | static int smb_traffic_analyzer_open(vfs_handle_struct *handle, \
|
|---|
| 864 | struct smb_filename *smb_fname, files_struct *fsp,\
|
|---|
| 865 | int flags, mode_t mode)
|
|---|
| 866 | {
|
|---|
| 867 | struct open_data s_data;
|
|---|
| 868 |
|
|---|
| 869 | s_data.result = SMB_VFS_NEXT_OPEN( handle, smb_fname, fsp,
|
|---|
| 870 | flags, mode);
|
|---|
| 871 | DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
|
|---|
| 872 | fsp_str_dbg(fsp)));
|
|---|
| 873 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 874 | s_data.mode = mode;
|
|---|
| 875 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 876 | &s_data,
|
|---|
| 877 | vfs_id_open);
|
|---|
| 878 | return s_data.result;
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | static int smb_traffic_analyzer_close(vfs_handle_struct *handle, \
|
|---|
| 882 | files_struct *fsp)
|
|---|
| 883 | {
|
|---|
| 884 | struct close_data s_data;
|
|---|
| 885 | s_data.result = SMB_VFS_NEXT_CLOSE(handle, fsp);
|
|---|
| 886 | DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
|
|---|
| 887 | fsp_str_dbg(fsp)));
|
|---|
| 888 | s_data.filename = fsp->fsp_name->base_name;
|
|---|
| 889 | smb_traffic_analyzer_send_data(handle,
|
|---|
| 890 | &s_data,
|
|---|
| 891 | vfs_id_close);
|
|---|
| 892 | return s_data.result;
|
|---|
| 893 | }
|
|---|
| 894 |
|
|---|
| 895 |
|
|---|
| 896 | static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
|
|---|
| 897 | .connect_fn = smb_traffic_analyzer_connect,
|
|---|
| 898 | .vfs_read = smb_traffic_analyzer_read,
|
|---|
| 899 | .pread = smb_traffic_analyzer_pread,
|
|---|
| 900 | .write = smb_traffic_analyzer_write,
|
|---|
| 901 | .pwrite = smb_traffic_analyzer_pwrite,
|
|---|
| 902 | .mkdir = smb_traffic_analyzer_mkdir,
|
|---|
| 903 | .rename = smb_traffic_analyzer_rename,
|
|---|
| 904 | .chdir = smb_traffic_analyzer_chdir,
|
|---|
| 905 | .open_fn = smb_traffic_analyzer_open,
|
|---|
| 906 | .rmdir = smb_traffic_analyzer_rmdir,
|
|---|
| 907 | .close_fn = smb_traffic_analyzer_close,
|
|---|
| 908 | .sendfile = smb_traffic_analyzer_sendfile,
|
|---|
| 909 | .recvfile = smb_traffic_analyzer_recvfile
|
|---|
| 910 | };
|
|---|
| 911 |
|
|---|
| 912 | /* Module initialization */
|
|---|
| 913 | NTSTATUS vfs_smb_traffic_analyzer_init(void)
|
|---|
| 914 | {
|
|---|
| 915 | NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
|
|---|
| 916 | "smb_traffic_analyzer",
|
|---|
| 917 | &vfs_smb_traffic_analyzer_fns);
|
|---|
| 918 |
|
|---|
| 919 | if (!NT_STATUS_IS_OK(ret)) {
|
|---|
| 920 | return ret;
|
|---|
| 921 | }
|
|---|
| 922 |
|
|---|
| 923 | vfs_smb_traffic_analyzer_debug_level =
|
|---|
| 924 | debug_add_class("smb_traffic_analyzer");
|
|---|
| 925 |
|
|---|
| 926 | if (vfs_smb_traffic_analyzer_debug_level == -1) {
|
|---|
| 927 | vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
|
|---|
| 928 | DEBUG(1, ("smb_traffic_analyzer_init: Couldn't register custom"
|
|---|
| 929 | "debugging class!\n"));
|
|---|
| 930 | } else {
|
|---|
| 931 | DEBUG(3, ("smb_traffic_analyzer_init: Debug class number of"
|
|---|
| 932 | "'smb_traffic_analyzer': %d\n", \
|
|---|
| 933 | vfs_smb_traffic_analyzer_debug_level));
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | return ret;
|
|---|
| 937 | }
|
|---|