[SCM] Samba Shared Repository - branch v3-3-stable updated - release-3-3-0pre1-377-g562dce5

Karolin Seeger kseeger at samba.org
Wed Oct 1 07:03:47 GMT 2008


The branch, v3-3-stable has been updated
       via  562dce5505f47c1f505c538b88107e3d9f9eae54 (commit)
       via  1020caf615e5c413363ead70f3930895889edc0b (commit)
       via  ba0cb8c74dd2fdeab014a8b90869725b85b6d557 (commit)
       via  394325b79c9f381e8b4bdaf1b8aec698e2e83cf7 (commit)
       via  f23599f59415f367c7a11b89e5ceac1d6032b87f (commit)
       via  4cfb63a07d7748d58dd869cdbb48f813534a8dea (commit)
       via  cf1786f82c819d3aeaf26e89dd4c8a627c291fa4 (commit)
       via  7fb8734762812808905de737495fbe5e550dbe00 (commit)
       via  bea0a1ee8d931bb95d29acbb74593849167a38fd (commit)
       via  4d2eda0d28380ec04234a75177423d31190a2ef6 (commit)
       via  3d21d7fc44e528bb27350bb373755241cb46e57c (commit)
       via  b381e23c5498f37208772ac1357b272ad931c92a (commit)
       via  64bf96ec26d6b479e6e41ec15e0f5036df4f0cd5 (commit)
       via  3c7f173dff889ba67cf200fe5a6f3b65c276b865 (commit)
       via  79978a4098fda2bcbcdaffc82c035548917781c8 (commit)
      from  a251d1bf1499f2e9f717028ccd3a46ecef8928e3 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-stable


- Log -----------------------------------------------------------------
commit 562dce5505f47c1f505c538b88107e3d9f9eae54
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Sep 30 16:20:43 2008 -0700

    Convert to allocated strings. Use write_data(), not send as this doesn't correctly
    deal with EINTR. Jim and Holger please check this still works.
    Jeremy.
    (cherry picked from commit bec55237c9c5687d947562524124b7aa76209b8f)

commit 1020caf615e5c413363ead70f3930895889edc0b
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Sep 30 15:22:24 2008 -0700

    Remove current_user_info - not needed.
    Jeremy.
    (cherry picked from commit 093fc8c6bf1420c0f1e171598c4894b4df24862c)

commit ba0cb8c74dd2fdeab014a8b90869725b85b6d557
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Sep 30 15:11:26 2008 -0700

    Restructure the module so it connects to the remote data sink
    on connect, and closes the socket on client disconnect. This should
    make it much more efficient. Store the remote fd in a private data
    pointer off the handle. Finally we need to remove the fstrings and
    convert to allocated buffer storage.
    Jeremy.
    (cherry picked from commit e3e89077a5559eda39ea27f0ce6f9f0ebeba8f1e)

commit 394325b79c9f381e8b4bdaf1b8aec698e2e83cf7
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Sep 30 13:22:44 2008 -0700

    Fix the make test problem Karolin reported. Now rename_open_files actually works correctly we must emit the change notify before we change the name, not before.
    Jeremy
    (cherry picked from commit 48c0dff0c5e36313619fb39d2bfb57d49ed2141e)

commit f23599f59415f367c7a11b89e5ceac1d6032b87f
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Sep 29 13:34:58 2008 -0700

    re-added "winbind:ignore domains" patch
    
    This option really is essential, as we discover again and again at
    customer sites. Due to bugs in winbind some domains are toxic. When
    you are installing at a site and a particular domain in a complex
    setup causes winbind to segfault or hang then you need a way to
    disable that domain and continue.
    
    In an ideal world winbind could handle arbitrarily complex ADS
    domains, but we are nowhere near that yet. If we ever get to that
    stage then we won't need this option.
    (cherry picked from commit f0f2fbd4800fb4a1df26f03f37b9972101657fdd)

commit 4cfb63a07d7748d58dd869cdbb48f813534a8dea
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Sep 29 12:04:57 2008 -0700

    fixed an (unlikely) memory leak
    (cherry picked from commit 8b908862ec7de000865cd8dfa691f5643cb3d099)

commit cf1786f82c819d3aeaf26e89dd4c8a627c291fa4
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Sep 29 11:27:31 2008 -0700

    fixed a segfault on the ctdb destructor code
    (cherry picked from commit f495968c88f07b74a943da9e034084b72f5a1c8b)

commit 7fb8734762812808905de737495fbe5e550dbe00
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Sep 29 11:24:48 2008 -0700

    removed unused variables
    (cherry picked from commit c48fd3cee0a91617123d79bccff7ec1f6008fb26)

commit bea0a1ee8d931bb95d29acbb74593849167a38fd
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Sep 29 11:18:21 2008 -0700

    fixed segv on startup with trusted domains
    
    With some setups, idmap_tdb2_allocate_id can be called before the
    allocate backend is initialised, leading to a segv. This change
    ensures that the db is opened in all paths that use it
    (cherry picked from commit 8ec11590f471d2852e5ffd3d1d65da54bd2182ca)

commit 4d2eda0d28380ec04234a75177423d31190a2ef6
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Sep 29 10:56:54 2008 -0700

    Ensure we null out fsp after a close in all paths.
    Jeremy.
    (cherry picked from commit 35a074c24b9b320bb23e82d3f44e17c5fadbcf62)

commit 3d21d7fc44e528bb27350bb373755241cb46e57c
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Sep 29 10:53:17 2008 -0700

    Avoid freeing fsp twice when opening new_file fails. (Debian #431696)
    If opening new_file fails, fsp would still be set to the files_struct of
    old_file.
    (cherry picked from commit bc0a340c61198879dc10ccbcc3c3ceb7f358b270)

commit b381e23c5498f37208772ac1357b272ad931c92a
Author: Karolin Seeger <kseeger at samba.org>
Date:   Mon Sep 29 15:39:43 2008 +0200

    docs: Adapt version strings in man vfs_smb_traffic_analyzer.
    
    Karolin
    (cherry picked from commit 662eda8458a304b224b6bc502f8030a07030b7c2)

commit 64bf96ec26d6b479e6e41ec15e0f5036df4f0cd5
Author: Holger Hetterich <hhetter at novell.com>
Date:   Mon Sep 29 14:34:36 2008 +0200

    Add an initial version of a manpage for the vfs_smb_traffic_analyzer module.
    (cherry picked from commit 7857b783049b19d32a078927a46cb1070e863b45)

commit 3c7f173dff889ba67cf200fe5a6f3b65c276b865
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Sep 26 18:33:07 2008 -0700

    Second part of the fix for bug #5790 - samba returns STATUS_OBJECT_NAME_NOT_FOUND on set file disposition call.
    This was my fault. I use a singleton cache (positive and negative) to speed up pathname based qfileinfo/setfileinfo lookups for alternate fsp's open on the same path. I only invalidated the negative cache on adding a new file fsp, as I incorrectly imagined the new fsp was put at the *end* of the open files list. DLIST_ADD puts it at the start, meaning any subsequent open wasn't seen once the cache was set. Doh !
    Jeremy.
    (cherry picked from commit 857433ec526caf73905dc9cb4fa25fb6355e5004)

commit 79978a4098fda2bcbcdaffc82c035548917781c8
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Sep 24 14:25:00 2008 -0700

    Fix bug #5790 samba returns STATUS_OBJECT_NAME_NOT_FOUND on set file disposition.
    We were checking that fd != -1 in file_find_di_XXX calls which is no longer
    needed due to a change in internal semantics.
    Jeremy.
    (cherry picked from commit 276c8395f15bc18f10d455848f7038e3465f0d52)

-----------------------------------------------------------------------

Summary of changes:
 docs-xml/manpages-3/vfs_smb_traffic_analyzer.8.xml |  157 +++++++++
 source/lib/dbwrap_ctdb.c                           |   14 +-
 source/modules/vfs_smb_traffic_analyzer.c          |  366 ++++++++++----------
 source/printing/nt_printing.c                      |    2 +
 source/smbd/files.c                                |   16 +-
 source/smbd/reply.c                                |    4 +-
 source/winbindd/idmap_tdb2.c                       |   19 +-
 source/winbindd/winbindd_util.c                    |   17 +
 8 files changed, 391 insertions(+), 204 deletions(-)
 create mode 100644 docs-xml/manpages-3/vfs_smb_traffic_analyzer.8.xml


Changeset truncated at 500 lines:

diff --git a/docs-xml/manpages-3/vfs_smb_traffic_analyzer.8.xml b/docs-xml/manpages-3/vfs_smb_traffic_analyzer.8.xml
new file mode 100644
index 0000000..28c8413
--- /dev/null
+++ b/docs-xml/manpages-3/vfs_smb_traffic_analyzer.8.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
+<refentry id="vfs_smb_traffic_analyzer.8">
+
+<refmeta>
+	<refentrytitle>smb_traffic_analyzer</refentrytitle>
+	<manvolnum>8</manvolnum>
+	<refmiscinfo class="source">Samba</refmiscinfo>
+	<refmiscinfo class="manual">System Administration tools</refmiscinfo>
+	<refmiscinfo class="version">3.3</refmiscinfo>
+</refmeta>
+
+
+<refnamediv>
+	<refname>vfs_smb_traffic_analyzer</refname>
+	<refpurpose>log Samba VFS read and write operations through a socket
+	to a helper application</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+	<cmdsynopsis>
+		<command>vfs objects = smb_traffic_analyzer</command>
+	</cmdsynopsis>
+</refsynopsisdiv>
+
+<refsect1>
+	<title>DESCRIPTION</title>
+
+	<para>This VFS module is part of the
+	<citerefentry><refentrytitle>samba</refentrytitle>
+	<manvolnum>7</manvolnum></citerefentry> suite.</para>
+
+	<para>The <command>vfs_smb_traffic_analyzer</command> VFS module logs
+	client write and read operations on a Samba server and sends this data
+	over a socket to a helper program, which feeds a SQL database. More
+	information on the helper programs can be obtained from the
+	homepage of the project at:
+	http://holger123.wordpress.com/smb-traffic-analyzer/
+	</para>
+	<para><command>vfs_smb_traffic_analyzer</command> currently is aware
+	of the following VFS operations:</para>
+
+	<simplelist>
+        <member>write</member>
+        <member>pwrite</member>
+	<member>read</member>
+	<member>pread</member>
+	</simplelist>
+
+	<para><command>vfs_smb_traffic_analyzer</command> sends the following data
+	in a fixed format seperated by a comma through either an internet or a
+	unix domain socket:</para>
+	<programlisting>
+	BYTES|USER|DOMAIN|READ/WRITE|SHARE|FILENAME|TIMESTAMP
+	</programlisting>
+
+	<para>Description of the records:
+
+	<itemizedlist>
+	<listitem><para><command>BYTES</command> - the length in bytes of the VFS operation</para></listitem>
+	<listitem><para><command>USER</command> - the user who initiated the operation</para></listitem>
+	<listitem><para><command>DOMAIN</command> - the domain of the user</para></listitem>
+	<listitem><para><command>READ/WRITE</command> - either "W" for a write operation or "R" for read</para></listitem>
+	<listitem><para><command>SHARE</command> - the name of the share on which the VFS operation occured</para></listitem>
+	<listitem><para><command>FILENAME</command> - the name of the file that was used by the VFS operation</para></listitem>
+	<listitem><para><command>TIMESTAMP</command> - a timestamp, formatted as "yyyy-mm-dd hh-mm-ss.ms" indicating when the VFS operation occured</para></listitem>
+	</itemizedlist>
+
+	</para>
+
+	<para>This module is stackable.</para>
+
+</refsect1>
+
+
+<refsect1>
+	<title>OPTIONS</title>
+
+	<variablelist>
+
+		<varlistentry>
+                <term>smb_traffic_analyzer:mode = STRING</term>
+                <listitem>
+                <para>If STRING matches to "unix_domain_socket", the module will
+		use a unix domain socket located at /var/tmp/stadsocket, if
+		STRING contains an different string or is not defined, the module will
+		use an internet domain socket for data transfer.</para>
+
+                </listitem>
+                </varlistentry>
+
+
+		<varlistentry>
+		<term>smb_traffic_analyzer:host = STRING</term>
+		<listitem>
+		<para>The module will send the data to the system named with
+		the hostname STRING.</para>
+
+		</listitem>
+		</varlistentry>
+
+		<varlistentry>
+		<term>smb_traffic_analyzer:port = STRING</term>
+		<listitem>
+		<para>The module will send the data using the TCP port given
+		in STRING
+		</para>
+
+		</listitem>
+		</varlistentry>
+
+
+	</variablelist>
+</refsect1>
+
+<refsect1>
+	<title>EXAMPLES</title>
+
+	<para>The module running on share "example_share", using a unix domain socket</para>
+	<programlisting>
+	<smbconfsection name="[example_share]"/>
+	<smbconfoption name="path">/data/example</smbconfoption>
+	<smbconfoption name="vfs objects">smb_traffic_analyzer</smbconfoption>
+	<smbconfoption name="smb_traffic_analyzer:mode">unix_domain_socket</smbconfoption>
+	</programlisting>
+
+	<para>The module running on share "example_share", using an internet domain socket,
+	connecting to host "examplehost" on port 3491.</para>
+	<programlisting>
+	<smbconfsection name="[example_share]"/>
+	<smbconfoption name="path">/data/example</smbconfoption>
+	<smbconfoption name="vfs objects">smb_traffic_analyzer</smbconfoption>
+	<smbconfoption name="smb_traffic_analyzer:host">examplehost</smbconfoption>
+	<smbconfoption name="smb_traffic_analyzer:port">3490</smbconfoption>
+	</programlisting>
+
+</refsect1>
+
+<refsect1>
+	<title>VERSION</title>
+	<para>This man page is correct for version 3.3 of the Samba suite.
+	</para>
+</refsect1>
+
+<refsect1>
+	<title>AUTHOR</title>
+
+	<para>The original Samba software and related utilities
+	were created by Andrew Tridgell. Samba is now developed
+	by the Samba Team as an Open Source project similar
+	to the way the Linux kernel is developed.</para>
+
+	<para>The original version of the VFS module and the
+	helper tools were created by Holger Hetterich.</para>
+</refsect1>
+
+</refentry>
diff --git a/source/lib/dbwrap_ctdb.c b/source/lib/dbwrap_ctdb.c
index 7c1ef8f..1e3a97f 100644
--- a/source/lib/dbwrap_ctdb.c
+++ b/source/lib/dbwrap_ctdb.c
@@ -403,8 +403,9 @@ static struct db_record *db_ctdb_fetch_locked_transaction(struct db_ctdb_ctx *ct
 	return result;
 }
 
-static int db_ctdb_record_destructor(struct db_record *rec)
+static int db_ctdb_record_destructor(struct db_record **recp)
 {
+	struct db_record *rec = talloc_get_type_abort(*recp, struct db_record);
 	struct db_ctdb_transaction_handle *h = talloc_get_type_abort(
 		rec->private_data, struct db_ctdb_transaction_handle);
 	int ret = h->ctx->db->transaction_commit(h->ctx->db);
@@ -422,7 +423,7 @@ static struct db_record *db_ctdb_fetch_locked_persistent(struct db_ctdb_ctx *ctx
 							 TDB_DATA key)
 {
 	int res;
-	struct db_record *rec;
+	struct db_record *rec, **recp;
 
 	res = db_ctdb_transaction_start(ctx->db);
 	if (res == -1) {
@@ -436,7 +437,14 @@ static struct db_record *db_ctdb_fetch_locked_persistent(struct db_ctdb_ctx *ctx
 	}
 
 	/* destroy this transaction when we release the lock */
-	talloc_set_destructor((struct db_record *)talloc_new(rec), db_ctdb_record_destructor);
+	recp = talloc(rec, struct db_record *);
+	if (recp == NULL) {
+		ctx->db->transaction_cancel(ctx->db);
+		talloc_free(rec);
+		return NULL;
+	}
+	*recp = rec;
+	talloc_set_destructor(recp, db_ctdb_record_destructor);
 	return rec;
 }
 
diff --git a/source/modules/vfs_smb_traffic_analyzer.c b/source/modules/vfs_smb_traffic_analyzer.c
index 9e4cf81..3925424 100644
--- a/source/modules/vfs_smb_traffic_analyzer.c
+++ b/source/modules/vfs_smb_traffic_analyzer.c
@@ -24,91 +24,9 @@
 #define UNIX_DOMAIN_SOCKET 1
 #define INTERNET_SOCKET 0
 
-
-/* Prototypes */
-
-extern userdom_struct current_user_info;
-
 static int vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
 
-NTSTATUS vfs_smb_traffic_analyzer_init(void);
-
-static ssize_t smb_traffic_analyzer_write(vfs_handle_struct *handle,
-		files_struct *fsp, const void *data, size_t n);
-
-static ssize_t smb_traffic_analyzer_read(vfs_handle_struct *handle,
-		files_struct *fsp, void *data, size_t n);
-
-static ssize_t smb_traffic_analyzer_pwrite(vfs_handle_struct *handle,
-		files_struct *fsp, const void *data, size_t n,
-		SMB_OFF_T offset);
-
-static ssize_t smb_traffic_analyzer_pread(vfs_handle_struct *handle,
-		files_struct *fsp, void *data, size_t n, SMB_OFF_T offset);
-
-
-/* VFS operations we use */
-
-static vfs_op_tuple smb_traffic_analyzer_tuples[] = {
-
-	{SMB_VFS_OP(smb_traffic_analyzer_read),	SMB_VFS_OP_READ,
-	 SMB_VFS_LAYER_LOGGER},
-	{SMB_VFS_OP(smb_traffic_analyzer_pread), SMB_VFS_OP_PREAD,
-	 SMB_VFS_LAYER_LOGGER},
-	{SMB_VFS_OP(smb_traffic_analyzer_write), SMB_VFS_OP_WRITE,
-	 SMB_VFS_LAYER_LOGGER},
-	{SMB_VFS_OP(smb_traffic_analyzer_pwrite), SMB_VFS_OP_PWRITE,
-	 SMB_VFS_LAYER_LOGGER},
-       	{SMB_VFS_OP(NULL),SMB_VFS_OP_NOOP,SMB_VFS_LAYER_NOOP}
-
-	};
-
-
-/* Module initialization */
-
-NTSTATUS vfs_smb_traffic_analyzer_init(void)
-{
-	NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, \
-		"smb_traffic_analyzer",	smb_traffic_analyzer_tuples);
-
-	if (!NT_STATUS_IS_OK(ret))
-		return ret;
-
-	vfs_smb_traffic_analyzer_debug_level =
-		debug_add_class("smb_traffic_analyzer");
-
-	if (vfs_smb_traffic_analyzer_debug_level == -1) {
-		vfs_smb_traffic_analyzer_debug_level = DBGC_VFS;
-		DEBUG(1, ("smb_traffic_analyzer: Couldn't register custom"
-			 "debugging class!\n"));
-	} else {
-		DEBUG(3, ("smb_traffic_analyzer: Debug class number of"
-			"'smb_traffic_analyzer': %d\n", \
-			vfs_smb_traffic_analyzer_debug_level));
-	}
-
-	return ret;
-}
-
-/* create the timestamp in sqlite compatible format */
-static void get_timestamp( char *String )
-{
-	struct timeval tv;
-	struct timezone tz;
-	struct tm *tm;
-	int seconds;
-
-	gettimeofday(&tv, &tz);
- 	tm=localtime(&tv.tv_sec);
-	seconds=(float) (tv.tv_usec / 1000);
-
-	fstr_sprintf(String,"%04d-%02d-%02d %02d:%02d:%02d.%03d", \
-			tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, \
-			tm->tm_hour, tm->tm_min, tm->tm_sec, (int)seconds);
-
-}
-
-static int smb_traffic_analyzer_connMode( vfs_handle_struct *handle)
+static int smb_traffic_analyzer_connMode(vfs_handle_struct *handle)
 {
 	connection_struct *conn = handle->conn;
         const char *Mode;
@@ -119,13 +37,11 @@ static int smb_traffic_analyzer_connMode( vfs_handle_struct *handle)
 	} else {
 		return INTERNET_SOCKET;
 	}
-
 }
 
-/* Send data over a internet socket */
-static void smb_traffic_analyzer_send_data_inet_socket( char *String,
-			vfs_handle_struct *handle, const char *file_name,
-			bool Write)
+/* Connect to an internet socket */
+
+static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct *handle)
 {
 	/* Create a streaming Socket */
 	const char *Hostname;
@@ -134,13 +50,11 @@ static void smb_traffic_analyzer_send_data_inet_socket( char *String,
 	struct addrinfo hints;
 	struct addrinfo *ailist = NULL;
 	struct addrinfo *res = NULL;
-	char Sender[200];
-	char TimeStamp[200];
 	connection_struct *conn = handle->conn;
 	int ret;
 
 	/* get port number, target system from the config parameters */
-	Hostname=lp_parm_const_string(SNUM(conn), "smb_traffic_analyzer", 
+	Hostname=lp_parm_const_string(SNUM(conn), "smb_traffic_analyzer",
 				"host", "localhost");
 
 	ZERO_STRUCT(hints);
@@ -154,14 +68,14 @@ static void smb_traffic_analyzer_send_data_inet_socket( char *String,
 			&ailist);
 
         if (ret) {
-		DEBUG(3,("smb_traffic_analyzer_send_data_inet_socket: "
+		DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: "
 			"getaddrinfo failed for name %s [%s]\n",
                         Hostname,
                         gai_strerror(ret) ));
-		return;
+		return -1;
         }
 
-	port = atoi( lp_parm_const_string(SNUM(conn), 
+	port = atoi( lp_parm_const_string(SNUM(conn),
 				"smb_traffic_analyzer", "port", "9430"));
 
 	DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s,"
@@ -188,116 +102,144 @@ static void smb_traffic_analyzer_send_data_inet_socket( char *String,
 	}
 
         if (sockfd == -1) {
-		DEBUG(1, ("smb_traffic_analyzer: unable to create socket, error is %s", 
+		DEBUG(1, ("smb_traffic_analyzer: unable to create "
+			"socket, error is %s",
 			strerror(errno)));
-		return;
+		return -1;
 	}
 
-	strlcpy(Sender, String, sizeof(Sender));
-	strlcat(Sender, ",\"", sizeof(Sender));
-	strlcat(Sender, get_current_username(), sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	strlcat(Sender, current_user_info.domain, sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-        if (Write)
-		strlcat(Sender, "W", sizeof(Sender));
-	else
-		strlcat(Sender, "R", sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	strlcat(Sender, handle->conn->connectpath, sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender) - 1);
-	strlcat(Sender, file_name, sizeof(Sender) - 1);
-	strlcat(Sender, "\",\"", sizeof(Sender) - 1);
-        get_timestamp(TimeStamp);
-	strlcat(Sender, TimeStamp, sizeof(Sender) - 1);
-	strlcat(Sender, "\");", sizeof(Sender) - 1);
-        DEBUG(10, ("smb_traffic_analyzer: sending %s\n", Sender));
-        if ( send(sockfd, Sender, strlen(Sender), 0) == -1 ) {
-                DEBUG(1, ("smb_traffic_analyzer: error sending data to socket!\n"));
-        	close(sockfd);
-                return ;
-        }
-
-        /* one operation, close the socket */
-        close(sockfd);
+	return sockfd;
 }
 
+/* Connect to a unix domain socket */
 
-
-/* Send data over a unix domain socket */
-static void smb_traffic_analyzer_send_data_unix_socket( char *String ,
-			vfs_handle_struct *handle, const char *file_name, 
-			bool Write)
+static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct *handle)
 {
 	/* Create the socket to stad */
 	int len, sock;
 	struct sockaddr_un remote;
-        char Sender[200];
-        char TimeStamp[200];
 
-	DEBUG(7, ("smb_traffic_analyzer: Unix domain socket mode. Using "
+	DEBUG(7, ("smb_traffic_analyzer_connect_unix_socket: "
+			"Unix domain socket mode. Using "
 			"/var/tmp/stadsocket\n"));
 
 	if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
-		DEBUG(1, ("smb_traffic_analyzer: Couldn create socket,"
+		DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
+			"Couldn't create socket, "
 			"make sure stad is running!\n"));
 	}
 	remote.sun_family = AF_UNIX;
-	strlcpy(remote.sun_path, "/var/tmp/stadsocket", 
+	strlcpy(remote.sun_path, "/var/tmp/stadsocket",
 		    sizeof(remote.sun_path));
 	len=strlen(remote.sun_path) + sizeof(remote.sun_family);
 	if (connect(sock, (struct sockaddr *)&remote, len) == -1 ) {
-		DEBUG(1, ("smb_traffic_analyzer: Could not connect to"
+		DEBUG(1, ("smb_traffic_analyzer_connect_unix_socket: "
+			"Could not connect to "
 			"socket, make sure\nstad is running!\n"));
 		close(sock);
+		return -1;
+	}
+	return sock;
+}
+
+/* Send data over a socket */
+
+static void smb_traffic_analyzer_send_data(vfs_handle_struct *handle,
+					ssize_t result,
+					const char *file_name,
+					bool Write)
+{
+	int *psockfd = NULL;
+	struct timeval tv;
+	struct tm *tm = NULL;
+	int seconds;
+	char *str = NULL;
+	size_t len;
+
+	SMB_VFS_HANDLE_GET_DATA(handle, psockfd, int, return);
+
+	if (psockfd == NULL || *psockfd == -1) {
+		DEBUG(1, ("smb_traffic_analyzer_send_data: socket is "
+			"closed\n"));
 		return;
 	}
-	strlcpy(Sender, String, sizeof(Sender));
-	strlcat(Sender, ",\"", sizeof(Sender));
-	strlcat(Sender, get_current_username(), sizeof(Sender));
-	strlcat(Sender,"\",\"",sizeof(Sender));
-	strlcat(Sender, current_user_info.domain, sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	if (Write)
-		strlcat(Sender, "W", sizeof(Sender));
-	else
-		strlcat(Sender, "R", sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	strlcat(Sender, handle->conn->connectpath, sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	strlcat(Sender, file_name, sizeof(Sender));
-	strlcat(Sender, "\",\"", sizeof(Sender));
-	get_timestamp(TimeStamp);
-	strlcat(Sender, TimeStamp, sizeof(Sender));
-	strlcat(Sender, "\");", sizeof(Sender));
-
-	DEBUG(10, ("smb_traffic_analyzer: sending %s\n", Sender));
-	if ( send(sock, Sender, strlen(Sender), 0) == -1 ) {
-		DEBUG(1, ("smb_traffic_analyzer: error sending data to"
-			"socket!\n"));
-		close(sock);
+
+	GetTimeOfDay(&tv);
+	tm=localtime(&tv.tv_sec);
+	if (!tm) {
 		return;
 	}
+	seconds=(float) (tv.tv_usec / 1000);
 
-	/* one operation, close the socket */
-	close(sock);
-	return;
+	str = talloc_asprintf(talloc_tos(),
+			"%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
+			"\"%04d-%02d-%02d %02d:%02d:%02d.%03d\");",
+			(unsigned int)result,
+			handle->conn->server_info->sanitized_username,
+			pdb_get_domain(handle->conn->server_info->sam_account),
+			Write ? 'W' : 'R',
+			handle->conn->connectpath,
+			file_name,
+			tm->tm_year+1900,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list