Hello community,

here is the log from the commit of package smbtad for openSUSE:Factory checked 
in at 2012-09-14 12:38:42
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/smbtad (Old)
 and      /work/SRC/openSUSE:Factory/.smbtad.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "smbtad", Maintainer is ""

Changes:
--------
--- /work/SRC/openSUSE:Factory/smbtad/smbtad.changes    2011-10-14 
09:54:12.000000000 +0200
+++ /work/SRC/openSUSE:Factory/.smbtad.new/smbtad.changes       2012-09-14 
12:38:43.000000000 +0200
@@ -1,0 +2,11 @@
+Tue Jul 31 11:14:33 UTC 2012 - [email protected]
+
+- update to version 1.2.6
+ - bso#8205 - Simplify the database in SMBTA
+ - bso#8206 - Integrated version control
+ - bso#8232 - smbtad SQL statements need to be escaped
+ - bso#8321 - Support the bind to an IP address in smbtad
+ - bso#8934 - running 3 instances of smbtamonitor and killing
+              the 2nd crashes smbtad
+
+-------------------------------------------------------------------

Old:
----
  smbtad-1.2.5.tar.bz2

New:
----
  smbtad-1.2.6.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ smbtad.spec ++++++
--- /var/tmp/diff_new_pack.g1ugM1/_old  2012-09-14 12:38:44.000000000 +0200
+++ /var/tmp/diff_new_pack.g1ugM1/_new  2012-09-14 12:38:44.000000000 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package smbtad
 #
-# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -15,20 +15,20 @@
 # Please submit bugfixes or comments via http://bugs.opensuse.org/
 #
 
-# norootforbuild
-
 
 Name:           smbtad
-BuildRequires:  cmake libtalloc-devel libdbi-devel
+BuildRequires:  cmake
+BuildRequires:  libdbi-devel
+BuildRequires:  libtalloc-devel
 %if 0%{?suse_version}
 BuildRequires:  libiniparser-devel
 %endif
 
+Version:        1.2.6
+Release:        0
+Summary:        A collector of smbd share usage data
 License:        GPL-3.0+
 Group:          Productivity/Networking/Samba
-Version:        1.2.5
-Release:        1
-Summary:        A collector of smbd share usage data
 Url:            http://github.com/hhetter/smbtad
 Source0:        %{name}-%{version}.tar.bz2
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build

++++++ smbtad-1.2.5.tar.bz2 -> smbtad-1.2.6.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/AUTHORS new/smbtad-1.2.6/AUTHORS
--- old/smbtad-1.2.5/AUTHORS    2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/AUTHORS    2012-07-31 13:06:34.000000000 +0200
@@ -1,3 +1,4 @@
 Holger Hetterich <[email protected]>
 Michael Haefner <[email protected]>
 Bjoern Geuken <[email protected]>
+Robert Piasek <[email protected]>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/dist/dev/fix.sh 
new/smbtad-1.2.6/dist/dev/fix.sh
--- old/smbtad-1.2.5/dist/dev/fix.sh    1970-01-01 01:00:00.000000000 +0100
+++ new/smbtad-1.2.6/dist/dev/fix.sh    2012-07-31 13:06:34.000000000 +0200
@@ -0,0 +1,19 @@
+#!/bin/sh
+# used when developing smbta, easy way to kill everything
+# running and restart, requires /etc/smbtad.conf
+
+
+echo "killing torture and torturesrv..."
+killall smbtatorture
+killall smbtatorturesrv
+sleep 1
+echo "killing smbtad... and waiting 10 seconds"
+killall smbtad
+sleep 10
+echo "restarting smb server"
+rcsmb restart
+sleep 1
+echo "restaring smbtad"
+smbtad -c /etc/smbtad.conf
+echo "now run torture.sh  in /home/holger/SKRIPTE/torture.sh"
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/dist/dev/pg_hba.conf 
new/smbtad-1.2.6/dist/dev/pg_hba.conf
--- old/smbtad-1.2.5/dist/dev/pg_hba.conf       1970-01-01 01:00:00.000000000 
+0100
+++ new/smbtad-1.2.6/dist/dev/pg_hba.conf       2012-07-31 13:06:34.000000000 
+0200
@@ -0,0 +1,93 @@
+# make postgresql trust local connections, used when developing
+# SMBTA on a single machine
+
+
+# PostgreSQL Client Authentication Configuration File
+# ===================================================
+#
+# Refer to the "Client Authentication" section in the PostgreSQL
+# documentation for a complete description of this file.  A short
+# synopsis follows.
+#
+# This file controls: which hosts are allowed to connect, how clients
+# are authenticated, which PostgreSQL user names they can use, which
+# databases they can access.  Records take one of these forms:
+#
+# local      DATABASE  USER  METHOD  [OPTIONS]
+# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+#
+# (The uppercase items must be replaced by actual values.)
+#
+# The first field is the connection type: "local" is a Unix-domain
+# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
+# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
+# plain TCP/IP socket.
+#
+# DATABASE can be "all", "sameuser", "samerole", "replication", a
+# database name, or a comma-separated list thereof. The "all"
+# keyword does not match "replication". Access to replication
+# must be enabled in a separate record (see example below).
+#
+# USER can be "all", a user name, a group name prefixed with "+", or a
+# comma-separated list thereof.  In both the DATABASE and USER fields
+# you can also write a file name prefixed with "@" to include names
+# from a separate file.
+#
+# ADDRESS specifies the set of hosts the record matches.  It can be a
+# host name, or it is made up of an IP address and a CIDR mask that is
+# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
+# specifies the number of significant bits in the mask.  A host name
+# that starts with a dot (.) matches a suffix of the actual host name.
+# Alternatively, you can write an IP address and netmask in separate
+# columns to specify the set of hosts.  Instead of a CIDR-address, you
+# can write "samehost" to match any of the server's own IP addresses,
+# or "samenet" to match any address in any subnet that the server is
+# directly connected to.
+#
+# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
+# "krb5", "ident", "peer", "pam", "ldap", "radius" or "cert".  Note that
+# "password" sends passwords in clear text; "md5" is preferred since
+# it sends encrypted passwords.
+#
+# OPTIONS are a set of options for the authentication in the format
+# NAME=VALUE.  The available options depend on the different
+# authentication methods -- refer to the "Client Authentication"
+# section in the documentation for a list of which options are
+# available for which authentication methods.
+#
+# Database and user names containing spaces, commas, quotes and other
+# special characters must be quoted.  Quoting one of the keywords
+# "all", "sameuser", "samerole" or "replication" makes the name lose
+# its special character, and just match a database or username with
+# that name.
+#
+# This file is read on server startup and when the postmaster receives
+# a SIGHUP signal.  If you edit the file on a running system, you have
+# to SIGHUP the postmaster for the changes to take effect.  You can
+# use "pg_ctl reload" to do that.
+
+# Put your actual configuration here
+# ----------------------------------
+#
+# If you want to allow non-local connections, you need to add more
+# "host" records.  In that case you will also need to make PostgreSQL
+# listen on a non-local interface via the listen_addresses
+# configuration parameter, or via the -i or -h command line switches.
+
+
+
+# TYPE  DATABASE        USER            ADDRESS                 METHOD
+
+# "local" is for Unix domain socket connections only
+local   all             all                                     trust
+# IPv4 local connections:
+host    all             all             127.0.0.1/32            trust
+# IPv6 local connections:
+host    all             all             ::1/128                 trust
+# Allow replication connections from localhost, by a user with the
+# replication privilege.
+#local   replication     postgres                                peer
+#host    replication     postgres        127.0.0.1/32            ident
+#host    replication     postgres        ::1/128                 ident
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/dist/dev/smb.conf 
new/smbtad-1.2.6/dist/dev/smb.conf
--- old/smbtad-1.2.5/dist/dev/smb.conf  1970-01-01 01:00:00.000000000 +0100
+++ new/smbtad-1.2.6/dist/dev/smb.conf  2012-07-31 13:06:34.000000000 +0200
@@ -0,0 +1,38 @@
+# sample smb.conf file for development of SMBTA
+
+
+# smb.conf is the main Samba configuration file. You find a full commented
+# version at /usr/share/doc/packages/samba/examples/smb.conf.SUSE if the
+# samba-doc package is installed.
+# Date: 2011-11-02
+[global]
+       workgroup = WORKGROUP
+       passdb backend = tdbsam
+       printing = cups
+       printcap name = cups
+       printcap cache time = 750
+       cups options = raw
+       map to guest = Bad User
+       include = /etc/samba/dhcp.conf
+       logon path = \\%L\profiles\.msprofile
+       logon home = \\%L\%U\.9xprofile
+       logon drive = P:
+       usershare allow guests = Yes
+
+
+[SHARE1]
+       path = /SHARE1
+       read only = no
+       vfs objects = smb_traffic_analyzer
+       smb_traffic_analyzer:protocol_version = V2
+       smb_traffic_analyzer:mode = unix_domain_socket
+       
+
+[SHARE2]
+       path = /SHARE2
+       read only = no
+       vfs objects = smb_traffic_analyzer
+       smb_traffic_analyzer:protocol_version = V2
+       smb_traffic_analyzer:mode = unix_domain_socket
+
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/dist/dev/smbtad.conf 
new/smbtad-1.2.6/dist/dev/smbtad.conf
--- old/smbtad-1.2.5/dist/dev/smbtad.conf       1970-01-01 01:00:00.000000000 
+0100
+++ new/smbtad-1.2.6/dist/dev/smbtad.conf       2012-07-31 13:06:34.000000000 
+0200
@@ -0,0 +1,17 @@
+[general]
+       debug_level = 0
+
+[network]
+       unix_domain_socket = yes
+       query_port = 3491
+       smbtad_ip = ADD YOUR IP HERE
+[database]
+       name = smbta
+       host = localhost
+       driver = pgsql
+       user = holger
+
+[maintenance]
+       interval = 01:00:00
+       config = 01,00:00:00
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/dist/dev/torture.sh 
new/smbtad-1.2.6/dist/dev/torture.sh
--- old/smbtad-1.2.5/dist/dev/torture.sh        1970-01-01 01:00:00.000000000 
+0100
+++ new/smbtad-1.2.6/dist/dev/torture.sh        2012-07-31 13:06:34.000000000 
+0200
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# This simple script is used when developing SMBTA
+# it requires:
+# two shares (namely SHARE1, SHARE2) with SMBTA enabled on a unix domain socket
+# (see smb.conf)
+# the script runs smbtatorture on these two shares, as user holger with
+# password "linux"
+
+
+
+smbtatorturesrv -p 3493 &
+sleep 5
+
+smbtatorture -P 3493 -t 20 -H localhost -v -u holger -p linux -1 
smb://localhost/SHARE1/ -2 smb://localhost/SHARE2/ &
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/configuration.h 
new/smbtad-1.2.6/include/configuration.h
--- old/smbtad-1.2.5/include/configuration.h    2011-05-17 13:32:51.000000000 
+0200
+++ new/smbtad-1.2.6/include/configuration.h    2012-07-31 13:06:34.000000000 
+0200
@@ -22,6 +22,8 @@
 #include <dbi.h>
 
 typedef struct configuration_data {
+       /* IP Address to bind to, for tracking VFS modules */
+       char *smbtad_ip;
        /* Number of the port to use */
        int port;
        /* portnumber for clients who query */
@@ -85,6 +87,9 @@
        int precision;
        /* if use_db = 0, no db handling will be done. */
        int use_db;
+       /* for the sqlite3 driver: */
+       char *sqlite_dbdir;
+       int sqlite_timeout;
 } config_t;
 pthread_mutex_t *configuration_get_lock();
 int configuration_check_configuration( config_t *c );
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/connection_list.h 
new/smbtad-1.2.6/include/connection_list.h
--- old/smbtad-1.2.5/include/connection_list.h  2011-05-17 13:32:51.000000000 
+0200
+++ new/smbtad-1.2.6/include/connection_list.h  2012-07-31 13:06:34.000000000 
+0200
@@ -45,10 +45,20 @@
        char *body;
        int encrypted;
        TALLOC_CTX *CTX;
+       int stored;
+       struct sockaddr_in addr;
+       struct sockaddr_un uaddr;
+       int internal;
+       int common_data_blocks;
+       int subrelease_number;
+       char addrstr[80];
 };
 
 struct connection_struct *connection_list_identify( int socket );
-int connection_list_add( int socket, enum conn_fn_enum conn_fn );
+int connection_list_add( int socket,
+               enum conn_fn_enum conn_fn,
+               char *addstr,
+               struct configuration_data *c);
 int connection_list_remove( int socket );
 int connection_list_max();
 void connection_list_recreate_fs_sets(  fd_set *active_read_fd_set,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/database.h 
new/smbtad-1.2.6/include/database.h
--- old/smbtad-1.2.5/include/database.h 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/include/database.h 2012-07-31 13:06:34.000000000 +0200
@@ -22,6 +22,10 @@
 /*
  * Create a database and setup the required tables
  */
-int database_connect( struct configuration_data *conf );
 
 
+int database_connect( struct configuration_data *conf );
+void database_make_conf_table( struct configuration_data *conf );
+void database_check_db_version( struct configuration_data *conf );
+void database_update_module_table( struct connection_struct *c,
+                               struct configuration_data *conf);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/includes.h 
new/smbtad-1.2.6/include/includes.h
--- old/smbtad-1.2.5/include/includes.h 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/include/includes.h 2012-07-31 13:06:34.000000000 +0200
@@ -33,6 +33,7 @@
 #include <sys/select.h>
 #include <dlfcn.h>
 #include <dbi.h>
+#include <netdb.h>
 
 #include <talloc.h>
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/protocol.h 
new/smbtad-1.2.6/include/protocol.h
--- old/smbtad-1.2.5/include/protocol.h 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/include/protocol.h 2012-07-31 13:06:34.000000000 +0200
@@ -22,7 +22,7 @@
 #include <talloc.h>
 
 #define PROTOCOL_SUBRELEASE 0
-
+#define SMBTAD_COMMON_DATA_BLOCKS 6
 
 
 enum header_states {
@@ -48,3 +48,4 @@
 char *protocol_decrypt( TALLOC_CTX *ctx, char *body, int len, const unsigned 
char *thekey);
 char *protocol_encrypt( TALLOC_CTX *ctx,
         const char *akey, const char *str, size_t *len);
+int protocol_common_blocks( char *data );
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/version.h 
new/smbtad-1.2.6/include/version.h
--- old/smbtad-1.2.5/include/version.h  2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/include/version.h  2012-07-31 13:06:34.000000000 +0200
@@ -1,2 +1,2 @@
 #define SMBTA_LICENSE "License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>"
-#define STAD2_VERSION "1.2.5"
+#define STAD2_VERSION "1.2.6"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/include/vfs_smb_traffic_analyzer.h 
new/smbtad-1.2.6/include/vfs_smb_traffic_analyzer.h
--- old/smbtad-1.2.5/include/vfs_smb_traffic_analyzer.h 2011-05-17 
13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/include/vfs_smb_traffic_analyzer.h 2012-07-31 
13:06:34.000000000 +0200
@@ -106,7 +106,8 @@
         vfs_id_rename,
         vfs_id_chdir,
        vfs_id_open,
-       vfs_id_close
+       vfs_id_close,
+       vfs_id_max
 };
 
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/cache.c new/smbtad-1.2.6/src/cache.c
--- old/smbtad-1.2.5/src/cache.c        2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/cache.c        2012-07-31 13:06:34.000000000 +0200
@@ -236,7 +236,7 @@
         /**
          * don't run a newer smbtad with an older VFS module
          */
-        if (common_blocks_num < 6) {
+        if (common_blocks_num < SMBTAD_COMMON_DATA_BLOCKS) {
                 syslog(LOG_DEBUG, "FATAL: Protocol error!"
                        " Too less common data blocks! (%i), ignoring data!",
                        common_blocks_num);
@@ -247,37 +247,9 @@
         /* vfs_operation_identifier */
        str = protocol_get_single_data_block( data, &go_through);
        entry->op_id = atoi(str);
-       switch(entry->op_id) {
-       case vfs_id_read:
-       case vfs_id_pread:
-               entry->vfs_id = talloc_strdup( data, "read");
-               break;
-       case vfs_id_write:
-       case vfs_id_pwrite:
-               entry->vfs_id = talloc_strdup(data, "write");
-               break;
-       case vfs_id_mkdir:
-               entry->vfs_id = talloc_strdup(data, "mkdir");
-               break;
-       case vfs_id_chdir:
-               entry->vfs_id = talloc_strdup(data, "chdir");
-               break;
-       case vfs_id_rename:
-               entry->vfs_id = talloc_strdup(data, "rename");
-               break;
-       case vfs_id_rmdir:
-               entry->vfs_id = talloc_strdup(data, "rmdir");
-               break;
-       case vfs_id_open:
-               entry->vfs_id = talloc_strdup(data, "open");
-               break;
-       case vfs_id_close:
-               entry->vfs_id = talloc_strdup(data, "close");
-               break;
-       }
 
        /* in case we received a vfs_id that we don't support, return NULL */
-       if (entry->vfs_id == NULL) {
+       if (entry->op_id < 0 || entry->op_id >  vfs_id_max -1 ) {
                syslog(LOG_DEBUG,"Unsupported VFS function!");
                TALLOC_FREE(data);
                return -2;
@@ -353,57 +325,109 @@
 }
 
 
-char *cache_create_database_string(TALLOC_CTX *ctx,struct cache_entry *entry)
+char *cache_create_database_string(TALLOC_CTX *ctx,struct cache_entry *entry,
+               struct configuration_data *conf)
 {
        /*
         * create a database string from the given metadata in a cache entry
         */
        char *retstr=NULL;
+
+       /**
+        * qoute required strings, that need potientially be qouted
+        * .. allocate other quote in the specific functions
+        * We are bound to not use talloc here.
+        */
+       char *username;
+       char *share;
+       char *domain;
+       char *timestamp;
+       char *usersid;
+       /* fn depending strings */
+       char *source, *destination, *result, *filename, *mode;
+
+       dbi_conn_quote_string_copy( conf->DBIconn, entry->username, &username);
+       dbi_conn_quote_string_copy( conf->DBIconn, entry->share, &share);
+       dbi_conn_quote_string_copy( conf->DBIconn, entry->domain, &domain);
+       dbi_conn_quote_string_copy( conf->DBIconn, entry->timestamp, 
&timestamp);
+       dbi_conn_quote_string_copy( conf->DBIconn, entry->usersid, &usersid);
        switch( entry->op_id ) {
         case vfs_id_rename: ;
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "source, destination, result) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s','%s',%s);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->source,entry->destination,entry->result);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->source,
+                               &source);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->destination,
+                               &destination);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->result,
+                               &result);
+
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, string2, result) VALUES ("
+                        "%i, %s,%s,%s,%s,"
+                        "%s,%s,%s,%s);",
+                        entry->op_id,username,usersid,share,domain,timestamp,
+                        source,destination,result);
+               free(source);
+               free(destination);
+               free(result);
                break;
         case vfs_id_close: ;
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "filename, result) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%s);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->filename,entry->result);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->filename, 
&filename);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->result, 
&result);
+
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, result) VALUES ("
+                        "%i,%s,%s,%s,%s,"
+                        "%s,%s,%s);",
+                        entry->op_id,username,usersid,share,domain,timestamp,
+                        filename,result);
+               free(result);
+               free(filename);
                 break;
         case vfs_id_open: ;
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "filename, mode, result) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%s,%s);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->filename,entry->mode,entry->result);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->filename, 
&filename);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->mode, &mode);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->result, 
&result);
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, string2, result) VALUES ("
+                        "%i,%s,%s,%s,%s,"
+                        "%s,%s,%s,%s);",
+                        entry->op_id,username,usersid,share,domain,timestamp,
+                        filename,mode,result);
+               free(mode);
+               free(result);
+               free(filename);
                 break;
         case vfs_id_chdir: ;
-                retstr = talloc_asprintf( ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "path, result) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%s);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->path,entry->result);
+               char *path;
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->path, &path);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->result, 
&result);
+                retstr = talloc_asprintf( ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, result) VALUES ("
+                        "%i,%s,%s,%s,%s,"
+                        "%s,%s,%s);",
+                        entry->op_id,username,usersid,share,domain,timestamp,
+                        path,result);
+               free(path);
+               free(result);
                 break;
         case vfs_id_mkdir: ;
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "path, mode, result) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%s,%s);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->path, entry->mode, entry->result);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->path, &path);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->mode, &mode);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->result, 
&result);
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, string2, result) VALUES ("
+                        "%i,%s,%s,%s,%s,"
+                        "%s,%s,%s,%s);",
+                        entry->op_id,username,usersid,share,domain,timestamp,
+                        path, mode, result);
+               free(mode);
+               free(result);
+               free(path);
                 break;
         case vfs_id_write:
         case vfs_id_pwrite: ;
@@ -411,13 +435,15 @@
                         retstr=NULL;
                         break;
                 }
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "filename, length) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%lu);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->filename,entry->len);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->filename, 
&filename);
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, length) VALUES ("
+                        "%i,%s,%s,%s,%s,%s,"
+                        "%s,%lu);",
+                        vfs_id_write,username,usersid,share,domain,timestamp,
+                        filename,entry->len);
+               free(filename);
                 break; 
         case vfs_id_read:
         case vfs_id_pread: ;
@@ -425,16 +451,24 @@
                         retstr=NULL;
                         break;
                 }
-                retstr = talloc_asprintf(ctx, "INSERT INTO %s ("
-                        "username, usersid, share, domain, timestamp,"
-                        "filename, length) VALUES ("
-                        "'%s','%s','%s','%s','%s',"
-                        "'%s',%lu);",
-                        
entry->vfs_id,entry->username,entry->usersid,entry->share,entry->domain,entry->timestamp,
-                        entry->filename,entry->len);
+               dbi_conn_quote_string_copy( conf->DBIconn, entry->filename, 
&filename);
+                retstr = talloc_asprintf(ctx, "INSERT INTO data ("
+                        "vfs_id, username, usersid, share, domain, timestamp,"
+                        "string1, length) VALUES ("
+                        "%i,%s,%s,%s,%s,%s,"
+                        "%s,%lu);",
+                        vfs_id_read,username,usersid,share,domain,timestamp,
+                        filename,entry->len);
+               free(filename);
                 break;
        default: ;
-       }       
+       }
+
+       free(username);
+       free(share);
+       free(domain);
+       free(timestamp);
+       free(usersid);
        return retstr;
 }
 
@@ -444,6 +478,12 @@
        int try;
        const char *error;
        dbi_result result;
+       /**
+        * a NULL dbstring? May happen when a R/W VFS function
+        * hat 0 bytes to transfer. This data is not relevant
+        * for statistics.
+        */
+       if (dbstring == NULL) return;
        /** 
         * Check if the connection is alive. We try ten times
         * to restore the connection if not
@@ -478,14 +518,14 @@
        go = go->left;
        while (go != NULL) {
                backup = go->left;
-               dbstring = cache_create_database_string(ctx,go);
+               dbstring = cache_create_database_string(ctx,go,config);
                do_db(config,dbstring);
                talloc_free(dbstring);
                // go down
                down = go->down;
                while (down != NULL) {
                        backup2 = down->down;
-                       dbstring = cache_create_database_string(ctx,down);
+                       dbstring = 
cache_create_database_string(ctx,down,config);
                        do_db(config,dbstring);
                        talloc_free(dbstring);
                        talloc_free(down);
@@ -498,14 +538,14 @@
        go = entry->right;
         while (go != NULL) {
                 backup = go->right;
-                dbstring = cache_create_database_string(ctx,go);
+                dbstring = cache_create_database_string(ctx,go,config);
                 do_db(config,dbstring);
                talloc_free(dbstring);
                 // go down
                 down = go->down;
                 while (down != NULL) { 
                         backup2 = down->down;
-                        dbstring = cache_create_database_string(ctx,down);
+                        dbstring = 
cache_create_database_string(ctx,down,config);
                         do_db(config,dbstring);
                         talloc_free(dbstring);
                         talloc_free(down);
@@ -518,14 +558,14 @@
        go = entry->other_ops;
        while (go != NULL) {
                backup = go->other_ops;
-               dbstring = cache_create_database_string(ctx,go);
+               dbstring = cache_create_database_string(ctx,go,config);
                do_db(config,dbstring);
                talloc_free(dbstring);
                talloc_free(go);
                go = backup;
        }
        // delete tree begin
-       dbstring = cache_create_database_string(ctx,entry);
+       dbstring = cache_create_database_string(ctx,entry,config);
        do_db(config,dbstring);
        if (dbstring != NULL) talloc_free(dbstring);
        talloc_free(entry);
@@ -542,17 +582,6 @@
  */
 void cache_manager(struct configuration_data *config )
 {
-       char *fnnames[] = {
-               "write",
-               "read",
-               "close",
-               "rename",
-               "open",
-               "chdir",
-               "rmdir",
-               "mkdir",
-               NULL,
-       };
        int maintenance_c_val;
        if (config->precision>0)
                maintenance_c_val = config->maintenance_seconds / 
config->precision;
@@ -585,26 +614,21 @@
                        char String[400];
                        char dbstring[300];
                        struct tm *tm;
-                       int fncount = 0;
                        do_db(config,"BEGIN TRANSACTION;");
-                       while (fnnames[fncount]!=NULL) {
-                               time_t today=time(NULL);
-                               time_t delete_date=today - 
config->maint_run_time;
-                               tm = localtime ( &delete_date );
-
-
-                               sprintf(String,"%04d-%02d-%02d %02d:%02d:%02d", 
\
-                                       tm->tm_year+1900, tm->tm_mon+1, 
tm->tm_mday, \
-                                       tm->tm_hour, tm->tm_min, tm->tm_sec);
-
-
-                               sprintf(dbstring,"delete from %s where 
timestamp < '",
-                                       fnnames[fncount]);
-                               strcat(dbstring,String);
-                               strcat(dbstring,"';");
-                               do_db(config,dbstring);
-                               fncount++;
-                       }
+                       time_t today=time(NULL);
+                       time_t delete_date=today - config->maint_run_time;
+                       tm = localtime ( &delete_date );
+
+
+                       sprintf(String,"%04d-%02d-%02d %02d:%02d:%02d", \
+                                       tm->tm_year+1900, tm->tm_mon+1, 
tm->tm_mday, \
+                                       tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+
+                               strcpy(dbstring,"delete from data where 
timestamp < '");
+                               strcat(dbstring,String);
+                               strcat(dbstring,"';");
+                       do_db(config,dbstring);
                        do_db(config,"COMMIT;");
                        maintenance_count = 0;
                }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/configuration.c 
new/smbtad-1.2.6/src/configuration.c
--- old/smbtad-1.2.5/src/configuration.c        2011-05-17 13:32:51.000000000 
+0200
+++ new/smbtad-1.2.6/src/configuration.c        2012-07-31 13:06:34.000000000 
+0200
@@ -21,7 +21,6 @@
 
 #include "../include/includes.h"
 #include <sys/stat.h>
-
 pthread_mutex_t config_mutex;
 
 pthread_mutex_t *configuration_get_lock(void) {
@@ -43,11 +42,16 @@
 void configuration_define_defaults( config_t *c )
 {
        c->dbsetup = 0;
+       c->smbtad_ip = NULL; /* null will make it bind to localhost */
        c->dbname = NULL;
        c->dbhost = NULL;
        c->dbuser = NULL;
        c->dbdriver = NULL;
        c->dbpassword = NULL;
+       c->sqlite_dbdir = NULL;
+       c->sqlite_timeout = 10000; /* wait a maximum of 10 seconds */
+                                  /* to release the lock on a */
+                                  /* sqlite connection */
        c->port = 3940;
        c->unix_socket_clients = 0;
        /* AES encryption key from SMBTAD to clients */
@@ -136,6 +140,9 @@
        Mydict=iniparser_load( c->config_file);
        char *cc;
 
+       cc = iniparser_getstring( Mydict, "network:smbtad_ip",NULL);
+       if (cc != NULL) c->smbtad_ip = strdup(cc);
+
        cc = iniparser_getstring( Mydict, "network:query_port",NULL);
        if (cc != NULL) c->query_port = atoi(cc);
 
@@ -169,6 +176,14 @@
        if ( cc != NULL) {
                c->dbpassword = strdup(cc);
        }
+       cc = iniparser_getstring(Mydict,"database:sqlite_dbdir",NULL);
+       if (cc != NULL) {
+               c->sqlite_dbdir = strdup(cc);
+       }
+       cc = iniparser_getstring(Mydict,"database:sqlite_timeout",NULL);
+       if (cc != NULL) {
+               c->sqlite_timeout = atoi(cc);
+       }
        cc = iniparser_getstring(Mydict,"general:precision",NULL);
        if (cc != NULL) c->precision = atoi(cc);
 
@@ -239,6 +254,7 @@
 
                static struct option long_options[] = {\
                        { "inet-port", 1, NULL, 'i' },
+                       { "ip", 1, NULL, 'I' },
                        { "dbdriver",1,NULL,'M'},
                        { "dbname",1,NULL,'N'},
                        { "dbuser",1,NULL,'S'},
@@ -261,11 +277,14 @@
                };
 
                i = getopt_long( argc, argv,
-                       "S:Tnd:i:oc:k:q:t:m:up:U:M:N:H:P:K:", long_options, 
&option_index );
+                       "S:Tnd:i:oc:k:q:t:m:up:U:M:N:H:P:K:I:", long_options, 
&option_index );
 
                if ( i == -1 ) break;
 
                switch (i) {
+                       case 'I':
+                               c->smbtad_ip = strdup(optarg);
+                               break;
                        case 'T':
                                c->dbsetup = 1;
                                break;
@@ -343,6 +362,10 @@
 
 int configuration_check_configuration( config_t *c )
 {
+       if (c->smbtad_ip == NULL) {
+               // localhost
+               c->smbtad_ip = talloc_asprintf(NULL,"localhost");
+       }
        // fixme: add checks
        // create the maintenance timer
         /* initialize the maintenance timer */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/connection_list.c 
new/smbtad-1.2.6/src/connection_list.c
--- old/smbtad-1.2.5/src/connection_list.c      2011-05-17 13:32:51.000000000 
+0200
+++ new/smbtad-1.2.6/src/connection_list.c      2012-07-31 13:06:34.000000000 
+0200
@@ -27,7 +27,9 @@
 
 
 int connection_list_add( int socket,
-                       enum conn_fn_enum conn_fn)
+                       enum conn_fn_enum conn_fn,
+                       char *addrstr,
+                       struct configuration_data *c)
 {
        struct connection_struct *new_entry =
                malloc(sizeof(struct connection_struct));
@@ -40,7 +42,6 @@
                new_entry->connection_function = conn_fn;
                new_entry->data_state = CONN_READ_HEADER;
                new_entry->CTX = talloc_pool( NULL,2048);
-               return 0;
        } else {
                new_entry->mysocket = socket;
                connection_list_end->next = new_entry;
@@ -50,6 +51,26 @@
                new_entry->next = NULL;
                new_entry->CTX = talloc_pool( NULL, 2048);
        }
+       /**
+        * if addr and uaddr are both NULL, this is an
+        * internal connection that doesn't need to be
+        * registered in the module table.
+        */
+       if (addrstr == NULL) { /* set INTERNAL HERE */
+               new_entry->internal = 1;
+       } else { /**
+                * We store the clients IP adress or
+                * unix socket address with the connection list
+                */
+               strcpy(new_entry->addrstr, addrstr);
+       }
+       /**
+        * If a connection is accepted, we set
+        * stored to 0. Upon the first incoming data
+        * we set stored to 1, and store version
+        * and ip address in the database
+        */
+       new_entry->stored = 0;
        return 0;
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/database.c 
new/smbtad-1.2.6/src/database.c
--- old/smbtad-1.2.5/src/database.c     2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/database.c     2012-07-31 13:06:34.000000000 +0200
@@ -58,6 +58,21 @@
        dbi_conn_set_option(conf->DBIconn, "password", conf->dbpassword);
        dbi_conn_set_option(conf->DBIconn, "dbname", conf->dbname);
        dbi_conn_set_option(conf->DBIconn, "encoding", "UTF-8");
+
+       /**
+        * support the sqlite driver(s)
+        */
+       if ( strncmp(conf->dbdriver,"sqlite3",6) == 0 ) {
+               /* options required for sqlite */
+               
dbi_conn_set_option(conf->DBIconn,"sqlite3_dbdir",conf->sqlite_dbdir);
+               dbi_conn_set_option_numeric(
+                               
conf->DBIconn,"sqlite3_timeout",conf->sqlite_timeout);
+       }
+       if ( strcmp(conf->dbdriver,"sqlite") == 0) {
+               
dbi_conn_set_option(conf->DBIconn,"sqlite_dbdir",conf->sqlite_dbdir);
+               dbi_conn_set_option_numeric(
+                               
conf->DBIconn,"sqlite_timeout",conf->sqlite_timeout);
+       }
        if ( dbi_conn_connect(conf->DBIconn) < 0) {
                printf("DBI: could not connect, please check options.\n");
                dbi_conn_error(conf->DBIconn,&dberror);
@@ -76,112 +91,237 @@
        return 0;
 }
 
+
+/**
+ * check the database version
+ */
+void database_check_db_version( struct configuration_data *conf )
+{
+       dbi_result result;
+       result = dbi_conn_query( conf->DBIconn,
+               "SELECT smbtad_database_version FROM status "
+               "WHERE smbtad_control_entry = 'SMBTAD';");
+       if (result == NULL) {
+               printf("ERROR: Error getting the database"
+                       " version.\n");
+               printf("Probably there is no database existing yet,\n");
+               printf("or your existing database is not compatible\n");
+               printf("with this version of smbtad. Please either\n");
+               printf("upgrade your database by using 'smbtaquery -C'\n");
+               printf("or create a new database with 'smbta -T'.\n");
+               printf("\n");
+               printf("Exiting.\n");
+               exit(1);
+       } else {
+               dbi_result_first_row(result);
+               if (strcmp(
+                       dbi_result_get_string_idx(result,1),
+                       STAD2_VERSION) != 0) {
+                       printf("Your existing database is not compatible\n");
+                       printf("with this version of smbtad. Please either\n");
+                       printf("upgrade your database by using 'smbtaquery 
-C'\n");
+                       printf("or create a new database with 'smbta -T'.\n");
+                       printf("\n");
+                       printf("Exiting.\n");
+                       exit(1);
+               }
+       }
+       dbi_result_free(result);
+}
+
+/**
+ * fill the status table with data
+ */
+void database_make_conf_table( struct configuration_data *conf )
+{
+       dbi_result result;
+       result = dbi_conn_queryf( conf->DBIconn,
+               "UPDATE status SET "
+               "smbtad_version = '%s',"
+               "smbtad_client_port = %i,"
+               "smbtad_unix_socket_clients = %i,"
+               "smbtad_dbname = '%s',"
+               "smbtad_dbhost = '%s',"
+               "smbtad_dbuser = '%s',"
+               "smbtad_dbdriver = '%s',"
+               "smbtad_maintenance_timer_str = '%s',"
+               "smbtad_maintenance_run_time = %i,"
+               "smbtad_debug_level = %i,"
+               "smbtad_precision = %i,"
+               "smbtad_daemon = %i,"
+               "smbtad_use_db = %i,"
+               "smbtad_config_file = '%s',"
+               "smbtad_ip = '%s'"
+               " WHERE smbtad_control_entry = 'SMBTAD';",
+               STAD2_VERSION,
+               conf->query_port,
+               conf->unix_socket_clients,
+               conf->dbname,
+               conf->dbhost,
+               conf->dbuser,
+               conf->dbdriver,
+               conf->maintenance_timer_str,
+               conf->maint_run_time,
+               conf->dbg,
+               conf->precision,
+               conf->daemon,
+               conf->use_db,
+               conf->config_file,
+               conf->smbtad_ip);
+       if (result == NULL) {
+               // we're not daemonized at this point, use printf
+               printf("\nERROR: could not update the status table!\n");
+               printf("Exiting.\n");
+               exit(1);
+       }
+}      
+
 /**
  * Create the initial tables of the database, to be called at first
  * startup.
  * return 0 on success, 1 if fail
+ *
+ * ATTENTION: This function is called on the very first setup of
+ * SMBTA. When making changes here, please take care for the
+ * smbtaquery -C function in smbtatools, which has to do the
+ * same changes on update
  */
 int database_create_tables( struct configuration_data *conf )
 {
        dbi_result result;
 
-       /* write/pwrite */
+       /**
+        *  we formerly created single tables for every VFS function,
+        *  let this be in one table now
+        */
+
        result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE write ("
+               "CREATE TABLE data ("
                 CREATE_COMMONS
-               "filename varchar, length integer )");
+               "string1 varchar, length integer, result bigint, string2 
varchar)");
        if (result == NULL) {
                syslog(LOG_DEBUG,"create tables : could not create"
-                       "the write/pwrite table!");
+                       "the data table!");
                return 1;
        }
        dbi_result_free(result);
-
-       /* read/pread */
+       /**
+        * create a table with version information
+        * and configuration status
+        */
        result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE read ("
-                CREATE_COMMONS
-               "filename varchar, length integer )");
+               "CREATE TABLE status ("
+               "smbtad_control_entry varchar,"
+               "smbtad_version varchar,"
+               "smbtad_database_version varchar,"
+               "smbtad_client_port integer,"
+               "smbtad_unix_socket_clients integer,"
+               "smbtad_dbname varchar,"
+               "smbtad_dbhost varchar,"
+               "smbtad_dbuser varchar,"
+               "smbtad_dbdriver varchar,"
+               "smbtad_maintenance_timer_str varchar,"
+               "smbtad_maintenance_run_time integer,"
+               "smbtad_debug_level integer,"
+               "smbtad_precision integer,"
+               "smbtad_daemon integer,"
+               "smbtad_use_db integer,"
+               "smbtad_config_file varchar,"
+               "smbtad_ip varchar);");
        if (result == NULL) {
-               syslog(LOG_DEBUG,"create tables : could not create"
-                       "the read/pread table!");
+               syslog(LOG_DEBUG,"create tables: could not create"
+                       "the status table!");
                return 1;
        }
        dbi_result_free(result);
-
-       /* mkdir */
+       /**
+        * fill in initial data
+        */
        result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE mkdir ("
-                CREATE_COMMONS
-               "path varchar, mode varchar, result bigint )");
+               "INSERT INTO status ("
+               "smbtad_control_entry,"
+               "smbtad_version,"
+               "smbtad_database_version)"
+               "VALUES ("
+               "'SMBTAD','"
+               STAD2_VERSION
+               "','"
+               STAD2_VERSION
+               "');");
        if (result == NULL) {
                syslog(LOG_DEBUG,"create tables: could not create"
-                       "the mkdir table!");
+                       "initial values for status!");
                return 1;
        }
        dbi_result_free(result);
-
-       /* rmdir */
+       /**
+        * create a table for version information on
+        * modules
+        */
        result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE rmdir ("
-                CREATE_COMMONS
-               "path varchar, mode varchar, result bigint )");
+               "CREATE TABLE modules ("
+               "module_subrelease_number integer,"
+               "module_common_blocks_overflow integer,"
+               "module_ip_address varchar UNIQUE);");
        if (result == NULL) {
                syslog(LOG_DEBUG,"create tables: could not create"
-                       "the rmdir table!");
+                       "the modules table!");
                return 1;
        }
        dbi_result_free(result);
 
-       /* rename */
-       result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE rename ("
-               CREATE_COMMONS
-               "source varchar, destination varchar, result bigint)");
+       return 0;
+}
+
+void database_update_module_table( struct connection_struct *c,
+               struct configuration_data *conf)
+{
+       dbi_result result;
+       result = dbi_conn_query(conf->DBIconn,
+               "BEGIN;");
        if (result == NULL) {
-               syslog(LOG_DEBUG,"create tables: could not create"
-                       "the rename table!");
-               return 1;
+               syslog(LOG_DEBUG,"ERROR updating the module table!"
+                       " (begin)");
+               exit(1);
        }
        dbi_result_free(result);
 
-       /* chdir */
-       result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE chdir ("
-                CREATE_COMMONS
-               "path varchar, result bigint)");
+       /**
+        * now update the database table
+        */
+       result = dbi_conn_query(conf->DBIconn,
+               "SAVEPOINT SP1;");
        if (result == NULL) {
-               syslog(LOG_DEBUG,"create tables: could not create"
-                       "the chdir table!");
-               return 1;
+               syslog(LOG_DEBUG,"ERROR setting SAVEPOINT!");
+               exit(1);
        }
        dbi_result_free(result);
-
-       /* open */
-       result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE open ("
-                CREATE_COMMONS
-               "filename varchar, mode varchar, result integer)");
+       result = dbi_conn_queryf(conf->DBIconn,
+               "INSERT INTO modules 
(module_ip_address,module_subrelease_number, module_common_blocks_overflow) 
VALUES('%s',%i,%i);",
+               c->addrstr, c->subrelease_number, c->common_data_blocks - 
SMBTAD_COMMON_DATA_BLOCKS );
        if (result == NULL) {
-               syslog(LOG_DEBUG,"create tables: could not create"
-                       "the open table!");
-               return 1;
+               /**
+                * if the first query wasn't succesful, the module does
+                * already exist. So we rollback and insert into with
+                * WHERE module_ip_address = c->addrstr
+                */
+               result = dbi_conn_query(conf->DBIconn,
+                       "ROLLBACK TO SP1;");
+               if (result == NULL) {
+                       syslog(LOG_DEBUG,"ERROR rolling back!");
+                       exit(1);
+               }
+               dbi_result_free(result);
+               result = dbi_conn_queryf(conf->DBIconn,
+                       "UPDATE modules SET module_subrelease_number = %i, 
module_common_blocks_overflow = %i WHERE module_ip_address = '%s';",
+                       c->subrelease_number,c->common_data_blocks - 
SMBTAD_COMMON_DATA_BLOCKS, c->addrstr);
        }
        dbi_result_free(result);
-
-       /* close */
-       result = dbi_conn_query( conf->DBIconn,
-               "CREATE TABLE close ("
-               CREATE_COMMONS
-               "filename varchar, result integer)");
+       result = dbi_conn_query(conf->DBIconn,
+                       "COMMIT;");
        if (result == NULL) {
-               syslog(LOG_DEBUG,"create tables: could not create"
-                       "the close table!");
-               return 1;
+               syslog(LOG_DEBUG,"ERROR: commit!");
+               exit(1);
        }
        dbi_result_free(result);
-
-       return 0;
 }
-
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/help.c new/smbtad-1.2.6/src/help.c
--- old/smbtad-1.2.5/src/help.c 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/help.c 2012-07-31 13:06:34.000000000 +0200
@@ -70,5 +70,7 @@
        printf("                                this is 0, no database 
handling\n");
        printf("                                will be done. Default is 1.\n");
        printf("-T --setup                      Do the initial database setup 
and exit.\n");
+       printf("-I --ip                         Specify the ip-address smbtad 
should listen on.\n");
+
 
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/main.c new/smbtad-1.2.6/src/main.c
--- old/smbtad-1.2.5/src/main.c 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/main.c 2012-07-31 13:06:34.000000000 +0200
@@ -43,6 +43,17 @@
                        "please check syslog.\n");
                exit(1);
        }
+       /**
+        * check for the database version.
+        * If we are starting from a new version, we will
+        * stop here and tell the user to update the
+        * database
+        */
+       database_check_db_version( &conf );
+       /**
+        * update the configuration and status tables
+        */
+       database_make_conf_table( &conf );
 
        /* become a daemon, depending on configuration  */
        daemon_daemonize( &conf );
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/monitor-list.c 
new/smbtad-1.2.6/src/monitor-list.c
--- old/smbtad-1.2.5/src/monitor-list.c 2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/monitor-list.c 2012-07-31 13:06:34.000000000 +0200
@@ -107,6 +107,8 @@
                        if (entry==monlist_start)
                                monlist_start = entry->next;
                        free(entry);
+                       pthread_mutex_unlock(&monlock);
+                       return 0;
                }
                before = entry;
                entry = entry->next;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/network.c 
new/smbtad-1.2.6/src/network.c
--- old/smbtad-1.2.5/src/network.c      2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/network.c      2012-07-31 13:06:34.000000000 +0200
@@ -70,15 +70,18 @@
  * and add it to the list of connections.
  */
 int network_accept_connection( config_t *c,
-       struct sockaddr_in *remote_inet,
+       struct sockaddr_in6 *remote_inet,
        struct sockaddr_un *remote_unix,
        int type)
 {
        socklen_t t;
+       char addrstr[100];
+       const char *test = NULL;
        if ( c->unix_socket ==1 ) t=sizeof(*remote_unix);
        else t=sizeof(*remote_inet);
        int sr;
        int sock = 0;
+
        if (type == SOCK_TYPE_DATA)     sock = c->vfs_socket;
        if (type == SOCK_TYPE_DB_QUERY) sock = c->query_socket;
        if ( (c->unix_socket == 1 && type == SOCK_TYPE_DATA) || 
@@ -89,14 +92,26 @@
                                "ERROR: accept (unix socket) failed.");
                        return -1;
                }
+               strcpy(addrstr,"unix");
        } else {
                if ( (sr = accept( sock,
                                (struct sockaddr *) remote_inet, &t)) == -1) {
                        syslog(LOG_DEBUG,"ERROR: accept (inet) failed.");
                        return -1;
                }
+
+               if (remote_inet->sin6_family == AF_INET) {
+                       test = inet_ntop(AF_INET, &(((struct sockaddr_in 
*)remote_inet)->sin_addr), addrstr, INET_ADDRSTRLEN);
+               } else {
+                       test = inet_ntop(AF_INET6, &(((struct sockaddr_in6 
*)remote_inet)->sin6_addr), addrstr, INET6_ADDRSTRLEN);
+               }
+
+               if (test == NULL) {
+                       syslog(LOG_DEBUG,"ERROR running inet_ntop!\n");
+                       exit(1);
+               }
        }
-       connection_list_add(sr, type);
+       connection_list_add(sr, type, addrstr ,c);
        return sr;
 }
 
@@ -109,7 +124,7 @@
 {
        struct connection_struct *connection = connection_list_identify(i);
        close(connection->mysocket);
-        syslog(LOG_DEBUG,"network_close_connection: closed connection number "
+        DEBUG(1) syslog(LOG_DEBUG,"network_close_connection: closed connection 
number "
                 "%i, socket %i",i,connection->mysocket);
        monitor_list_delete_by_socket(connection->mysocket);
        connection_list_remove(connection->mysocket);
@@ -127,9 +142,9 @@
                monitor_list_delete_by_socket(connection->mysocket);
                connection2=connection->next;
                connection_list_remove(connection->mysocket);
-               syslog(LOG_DEBUG,
+               DEBUG(1) syslog(LOG_DEBUG,
                        "network_close_connections: closed connection on "
-                       "socket %i",connection->mysocket);
+                       "socket %i",connection->mysocket);
                connection=connection2;
        }
 
@@ -149,9 +164,9 @@
 {
        int l;
        enum header_states hstate;
-       struct connection_struct *connection =
+       struct connection_struct *connection =
                connection_list_identify(i);
-        if (connection->connection_function == SOCK_TYPE_DATA ||
+       if (connection->connection_function == SOCK_TYPE_DATA ||
            connection->connection_function == SOCK_TYPE_DB_QUERY) {
                switch(connection->data_state) {
                case CONN_READ_HEADER: ;
@@ -164,6 +179,7 @@
                                &connection->header_position);
                        if ( l == 0) {
                                network_close_connection(i);
+                               return -1;
                                break;
                        }
 
@@ -175,8 +191,9 @@
                        hstate = 
                                protocol_check_header(connection->header);
                        if (hstate == HEADER_CHECK_FAIL ||
-                               hstate == HEADER_CHECK_NULL)
+                               hstate == HEADER_CHECK_NULL) {
                                        network_close_connection(i);
+                                       return -1; }
                        connection->data_state = CONN_READ_DATA;
                        connection->blocklen =
                                
protocol_get_data_block_length(connection->header);
@@ -196,6 +213,7 @@
                                &connection->header_position);
                        if ( l == 0 ) {
                                network_close_connection(i);
+                               return -1;
                                break;
                        }
                        if (connection->header_position != 26) break;
@@ -203,8 +221,9 @@
                        hstate =
                                protocol_check_header(connection->header);
                        if (hstate == HEADER_CHECK_FAIL ||
-                               hstate == HEADER_CHECK_NULL)
+                               hstate == HEADER_CHECK_NULL) {
                                        network_close_connection(i);
+                                       return -1; }
                         connection->data_state = CONN_READ_DATA;
                         connection->blocklen =
                                 
protocol_get_data_block_length(connection->header);
@@ -228,6 +247,7 @@
                                        &connection->body_position);
                        if ( l == 0 ) {
                                network_close_connection(i);
+                               return -1;
                                break;
                        }
                        if (connection->body_position != connection->blocklen) {
@@ -242,7 +262,20 @@
                                                connection->blocklen,
                                                c->key);
                        }
+                       /**
+                        * upon very first data block, we check for the
+                        * stored flag, and in case of it is being unset
+                        * we store the module's data in the database
+                        */
+                       if (connection->stored == 0 && 
connection->connection_function == SOCK_TYPE_DATA) {
+                               connection->common_data_blocks =
+                                       
protocol_common_blocks(connection->body);
+                               connection->subrelease_number =
+                                       
protocol_get_subversion(connection->header);
 
+                               database_update_module_table( connection,c );
+                               connection->stored = 1;
+                       }
                        connection->data_state = CONN_READ_HEADER;
 
                        if (connection->connection_function == SOCK_TYPE_DATA) {
@@ -273,11 +306,12 @@
                                &connection->body_position);
                        if ( l == 0) {
                                network_close_connection(i);
+                               return -1;
                                break;
                        }
                        if (connection->body_position != connection->blocklen)
                                break;
-                       /* we finally have the full data block, encrypt if 
needed */
+                       /* full data block, encrypt if needed */
                        if ( connection->encrypted == 1) {
                                connection->body =
                                        protocol_decrypt(connection->header,
@@ -285,6 +319,20 @@
                                                connection->blocklen,
                                                c->key);
                        }
+                       /**
+                        * upon very first data block, we check for the
+                        * stored flag, and in case of it is being unset
+                        * we store the module's data in the database
+                        */
+                       if (connection->stored == 0) {
+                               connection->common_data_blocks =
+                                       
protocol_common_blocks(connection->body);
+                               connection->subrelease_number =
+                                       
protocol_get_subversion(connection->header);
+
+                               database_update_module_table( connection,c );
+                               connection->stored = 1;
+                       }
                        connection->data_state = CONN_READ_HEADER;
                        if (connection->connection_function == SOCK_TYPE_DATA) {
                                DEBUG(1) syslog(LOG_DEBUG,
@@ -315,31 +363,34 @@
  * Create a listening internet socket on a port.
  * int port            The port-number.
  */     
-int network_create_socket( int port )
+int network_create_socket( int port, char *smbtad_ip )
 {
+       struct addrinfo hints;
+       struct addrinfo *ai;
+       int err;
        int sock_fd;
-       struct sockaddr_in6 my_addr;
+        char buf[5];
 
-       if ( (sock_fd = socket(AF_INET6, SOCK_STREAM,0)) == -1 ) {
-               syslog( LOG_DEBUG, "ERROR: socket creation failed." );
-               exit(1);
+       memset(&hints, 0, sizeof(struct addrinfo));
+       hints.ai_family = AF_UNSPEC;     /* Allow IPv4 or IPv6 */
+       hints.ai_socktype = SOCK_STREAM; /* Stream socket */
+       hints.ai_flags = AI_PASSIVE;     /* For wildcard IP address */
+       hints.ai_protocol = 0;           /* Any protocol */
+
+       sprintf(buf,"%d",port);
+
+       if (( err = getaddrinfo(smbtad_ip, (char*) &buf, &hints, &ai )) == -1 ) 
{
+               syslog( LOG_DAEMON, "ERROR: getaddrinfo: %s\n", 
gai_strerror(err));
+               exit(1);
        }
 
-       int y;
-       if ( setsockopt( sock_fd, SOL_SOCKET, SO_REUSEADDR, &y,
-               sizeof( int )) == -1 ) {
-               syslog( LOG_DEBUG, "ERROR: setsockopt failed." );
+       if (( sock_fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol 
)) == -1) {
+               syslog( LOG_DEBUG, "ERROR: socket creation failed." );
                exit(1);
        }
 
-       bzero (&my_addr, sizeof (my_addr));
-       my_addr.sin6_family = AF_INET6;
-       my_addr.sin6_port = htons( port );
-       my_addr.sin6_addr = in6addr_any;
-
-       if (bind(sock_fd,
-               (struct sockaddr *)&my_addr,
-               sizeof(my_addr)) == -1 ) {
+       if ( bind( sock_fd, ai->ai_addr, ai->ai_addrlen) == -1) {
+               close(sock_fd);
                syslog( LOG_DEBUG, "ERROR: bind failed." );
                exit(1);
        }
@@ -349,6 +400,7 @@
                exit(1);
        }
 
+       freeaddrinfo(ai);
        return sock_fd;
 }
 
@@ -461,7 +513,7 @@
        int i;
        int z=0;
        struct sockaddr_un remote_unix;
-       struct sockaddr_in remote_inet;
+       struct sockaddr_in6 remote_inet;
 
        fd_set read_fd_set;
        fd_set write_fd_set;
@@ -469,17 +521,17 @@
        FD_ZERO(&read_fd_set );
        FD_ZERO(&write_fd_set );
        if (c->unix_socket == 0) 
-               c->vfs_socket = network_create_socket( c->port );
+               c->vfs_socket = network_create_socket( c->port, c->smbtad_ip );
        else
                c->vfs_socket = 
network_create_unix_socket("/var/tmp/stadsocket");
 
        if (c->unix_socket_clients == 0)
-               c->query_socket = network_create_socket( c->query_port );
+               c->query_socket = network_create_socket( c->query_port, 
c->smbtad_ip );
        else
                c->query_socket = 
network_create_unix_socket("/var/tmp/stadsocket_client");
 
-       connection_list_add( c->vfs_socket, SOCK_TYPE_DATA );
-       connection_list_add( c->query_socket, SOCK_TYPE_DB_QUERY);
+       connection_list_add( c->vfs_socket, SOCK_TYPE_DATA, NULL, c );
+       connection_list_add( c->query_socket, SOCK_TYPE_DB_QUERY, NULL, c);
        for (;;) {
                connection_list_recreate_fs_sets(
                        &read_fd_set,
@@ -521,8 +573,8 @@
                                                break;
                                        }
                                } else {
-                                       network_handle_data(i,c);
-                                       monitor_list_process(i);
+                                       int test=network_handle_data(i,c);
+                                       if (test != -1) monitor_list_process(i);
                                }
                        }
                }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/smbtad-1.2.5/src/protocol.c 
new/smbtad-1.2.6/src/protocol.c
--- old/smbtad-1.2.5/src/protocol.c     2011-05-17 13:32:51.000000000 +0200
+++ new/smbtad-1.2.6/src/protocol.c     2012-07-31 13:06:34.000000000 +0200
@@ -31,8 +31,6 @@
  *                                             different sub-release of
  *                                             the protocol
  *
- * the function exits the process if it doesn't see V2 at the beginning
- * of the header
  */
 enum header_states protocol_check_header( char *header )
 {
@@ -71,6 +69,21 @@
        return HEADER_CHECK_OK;
 }
 
+
+/**
+ * return the number of common blocks to come
+ */
+int protocol_common_blocks( char *data )
+{
+       /* the very first data block tells the number of blocks */
+       /* to come */
+       char *str;
+       str = protocol_get_single_data_block( data, &data);
+       int common_blocks_num = atoi(str);
+       return common_blocks_num;
+}
+
+
 /**
  * AES decrypt a data block.
  * returns the encrypted data block, and frees the given block

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to