The Samba-Bugzilla – Attachment 2035 Details for
Bug 3933
"broken pipe" problem
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
SQL-logging patch
sqlaudit.patch (text/plain), 8.12 KB, created by
Sven Strickroth
on 2006-07-14 10:39:34 UTC
(
hide
)
Description:
SQL-logging patch
Filename:
MIME Type:
Creator:
Sven Strickroth
Created:
2006-07-14 10:39:34 UTC
Size:
8.12 KB
patch
obsolete
>CREATE TABLE `loginout` ( > `id` int(11) unsigned NOT NULL auto_increment, > `username` varchar(50) collate latin1_german2_ci NOT NULL default '', > `host` varchar(50) collate latin1_german2_ci NOT NULL default '', > `sessionid` varchar(100) collate latin1_german2_ci NOT NULL default '', > `intime` datetime NOT NULL default '0000-00-00 00:00:00', > `outtime` datetime NOT NULL default '0000-00-00 00:00:00', > PRIMARY KEY (`id`), > KEY `host` (`host`), > KEY `intime` (`intime`) >) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci COMMENT='Tabelle für Login-out Rückfolgung'; > >diff -Nur samba-3.0.11-orig/source/Makefile samba-3.0.11/source/Makefile >--- samba-3.0.11-orig/source/Makefile.in 2005-02-05 21:26:27.000000000 +0100 >+++ samba-3.0.11/source/Makefile.in 2005-02-05 21:42:49.000000000 +0100 >@@ -18,5 +18,5 @@ > CC=@CC@ > SHLD=@SHLD@ >-CFLAGS=@CFLAGS@ >+CFLAGS=@CFLAGS@ `mysql_config --include` -Dmysqllogging > CPPFLAGS=-DHAVE_CONFIG_H @CPPFLAGS@ > EXEEXT=@EXEEXT@ >@@ -817,8 +817,8 @@ > bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy > @echo Linking $@ > @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(SMBD_OBJ) $(LDFLAGS) $(LDAP_LIBS) \ > $(KRB5LIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) \ >- $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ @SMBD_LIBS@ >+ $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ @SMBD_LIBS@ `mysql_config --libs` > > bin/nmbd@EXEEXT@: $(NMBD_OBJ) @BUILD_POPT@ bin/.dummy > @echo Linking $@ >@@ -949,5 +949,5 @@ > bin/vfstest@EXEEXT@: $(VFSTEST_OBJ) @BUILD_POPT@ bin/.dummy > @echo Linking $@ >- @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) $(ACL_LIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) @SMBD_LIBS@ >+ @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) $(ACL_LIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) @SMBD_LIBS@ `mysql_config --libs` > > bin/smbiconv@EXEEXT@: $(SMBICONV_OBJ) @BUILD_POPT@ bin/.dummy >diff -Nur samba-3.0.11-orig/source/param/loadparm.c samba-3.0.11/source/param/loadparm.c >--- samba-3.0.11-orig/source/param/loadparm.c 2005-02-04 04:07:46.000000000 +0100 >+++ samba-3.0.11/source/param/loadparm.c 2005-02-06 12:51:32.000000000 +0100 >@@ -163,6 +163,16 @@ > char *szUtmpDir; > char *szWtmpDir; > BOOL bUtmp; >+#ifdef mysqllogging >+ BOOL bMySQLSessionLogging; >+ BOOL bMySQLSessionLogginglog; >+ char *szMySQLSessionLoggingserver; >+ int iMySQLSessionLoggingport; >+ char *szMySQLSessionLoggingusername; >+ char *szMySQLSessionLoggingpw; >+ char *szMySQLSessionLoggingdb; >+ char *szMySQLSessionLoggingtable; >+#endif > char *szIdmapUID; > char *szIdmapGID; > BOOL bEnableRidAlgorithm; >@@ -1118,6 +1125,16 @@ > {"utmp", P_BOOL, P_GLOBAL, &Globals.bUtmp, NULL, NULL, FLAG_ADVANCED}, > #endif > >+#ifdef mysqllogging >+ {"mysqlsessionlogging", P_BOOL, P_GLOBAL, &Globals.bMySQLSessionLogging, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionlogginglog", P_BOOL, P_GLOBAL, &Globals.bMySQLSessionLogginglog, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingserver", P_STRING, P_GLOBAL, &Globals.szMySQLSessionLoggingserver, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingusername", P_STRING, P_GLOBAL, &Globals.szMySQLSessionLoggingusername, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingpassword", P_STRING, P_GLOBAL, &Globals.szMySQLSessionLoggingpw, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingport", P_INTEGER, P_GLOBAL, &Globals.iMySQLSessionLoggingport, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingdb", P_STRING, P_GLOBAL, &Globals.szMySQLSessionLoggingdb, NULL, NULL, FLAG_ADVANCED}, >+ {"mysqlsessionloggingtable", P_STRING, P_GLOBAL, &Globals.szMySQLSessionLoggingtable, NULL, NULL, FLAG_ADVANCED}, >+#endif > {"default service", P_STRING, P_GLOBAL, &Globals.szDefaultService, NULL, NULL, FLAG_ADVANCED}, > {"default", P_STRING, P_GLOBAL, &Globals.szDefaultService, NULL, NULL, FLAG_ADVANCED}, > {"message command", P_STRING, P_GLOBAL, &Globals.szMsgCommand, NULL, NULL, FLAG_ADVANCED}, >@@ -1649,6 +1664,16 @@ > FN_GLOBAL_STRING(lp_utmpdir, &Globals.szUtmpDir) > FN_GLOBAL_STRING(lp_wtmpdir, &Globals.szWtmpDir) > FN_GLOBAL_BOOL(lp_utmp, &Globals.bUtmp) >+#ifdef mysqllogging >+FN_GLOBAL_BOOL(lp_mysqllogging, &Globals.bMySQLSessionLogging) >+FN_GLOBAL_BOOL(lp_mysqllogginglog, &Globals.bMySQLSessionLogginglog) >+FN_GLOBAL_STRING(lp_mysqlloggingserver, &Globals.szMySQLSessionLoggingserver) >+FN_GLOBAL_INTEGER(lp_mysqlloggingport, &Globals.iMySQLSessionLoggingport) >+FN_GLOBAL_STRING(lp_mysqlloggingdb, &Globals.szMySQLSessionLoggingdb) >+FN_GLOBAL_STRING(lp_mysqlloggingtable, &Globals.szMySQLSessionLoggingtable) >+FN_GLOBAL_STRING(lp_mysqlloggingusername, &Globals.szMySQLSessionLoggingusername) >+FN_GLOBAL_STRING(lp_mysqlloggingpw, &Globals.szMySQLSessionLoggingpw) >+#endif > FN_GLOBAL_STRING(lp_rootdir, &Globals.szRootdir) > FN_GLOBAL_STRING(lp_defaultservice, &Globals.szDefaultService) > FN_GLOBAL_STRING(lp_msg_command, &Globals.szMsgCommand) >diff -Nur samba-3.0.11-orig/source/smbd/session.c samba-3.0.11/source/smbd/session.c >--- samba-3.0.11-orig/source/smbd/session.c 2004-12-15 15:33:17.000000000 +0100 >+++ samba-3.0.11/source/smbd/session.c 2005-02-06 12:53:12.000000000 +0100 >@@ -26,6 +26,31 @@ > */ > > #include "includes.h" >+#ifdef mysqllogging >+#include "mysql.h" >+ >+char *sql_escape_string(TALLOC_CTX *mem_ctx, const char *unesc) >+{ >+ char *esc = talloc_array(mem_ctx, char, strlen(unesc) * 2 + 3); >+ size_t pos_unesc = 0, pos_esc = 0; >+ >+ for(pos_unesc = 0; unesc[pos_unesc]; pos_unesc++) { >+ switch(unesc[pos_unesc]) { >+ case '\\': >+ case '\'': >+ case '"': >+ esc[pos_esc] = '\\'; pos_esc++; >+ default: >+ esc[pos_esc] = unesc[pos_unesc]; pos_esc++; >+ break; >+ } >+ } >+ >+ esc[pos_esc] = '\0'; >+ >+ return esc; >+} >+#endif > > static TDB_CONTEXT *tdb; > >@@ -151,6 +152,33 @@ > sessionid.id_str, sessionid.id_num); > } > >+#ifdef mysqllogging >+ if (lp_mysqllogging()) { >+ MYSQL *handle; >+ handle = mysql_init(NULL); >+ if (handle) { >+ if (mysql_real_connect(handle, >+ lp_mysqlloggingserver(), >+ lp_mysqlloggingusername(), >+ lp_mysqlloggingpw(), >+ lp_mysqlloggingdb(), >+ lp_mysqlloggingport(), >+ NULL, 0)) { >+ char *query; >+ int ret; >+ asprintf(&query,"INSERT into %s set username='%s',host='%s',sessionid='%s',intime=NOW();",lp_mysqlloggingtable(),sql_escape_string(NULL,sessionid.username),sql_escape_string(NULL,sessionid.hostname),sql_escape_string(NULL,sessionid.id_str)); >+ ret = mysql_query(handle, query); >+ SAFE_FREE(query); >+ if (ret) { DEBUG(0,("Error executing MySQL query %s\n", mysql_error(handle))); } >+ mysql_close(handle); >+ } else { >+ DEBUG(0,("Failed to connect to mysql database: error: %s\n", mysql_error(handle))); >+ mysql_close(handle); >+ } >+ } else { DEBUG(0, ("Failed to connect to audit-MySQL-server\n")); } >+ } >+#endif >+ > vuser->session_keystr = SMB_STRDUP(keystr); > if (!vuser->session_keystr) { > DEBUG(0, ("session_claim: strdup() failed for session_keystr\n")); >@@ -195,6 +219,34 @@ > sessionid.id_str, sessionid.id_num); > } > >+#ifdef mysqllogging >+ if (lp_mysqllogging()) { >+ MYSQL *handle; >+ handle = mysql_init(NULL); >+ if (handle) { >+ if (mysql_real_connect(handle, >+ lp_mysqlloggingserver(), >+ lp_mysqlloggingusername(), >+ lp_mysqlloggingpw(), >+ lp_mysqlloggingdb(), >+ lp_mysqlloggingport(), >+ NULL, 0)) { >+ char *query; >+ int ret; >+ asprintf(&query,"UPDATE %s set outtime=NOW() WHERE username='%s' and host='%s' and sessionid='%s' and outtime = 0 LIMIT 1;",lp_mysqlloggingtable(),sql_escape_string(NULL,sessionid.username),sql_escape_string(NULL,sessionid.hostname),sql_escape_string(NULL,sessionid.id_str)); >+ ret = mysql_query(handle, query); >+ if (lp_mysqllogginglog()) { DEBUG(0,("executed sql-querry '%s'\n", query)); } >+ SAFE_FREE(query); >+ if (ret) { DEBUG(0,("Error executing MySQL query %s\n", mysql_error(handle))); } >+ mysql_close(handle); >+ } else { >+ DEBUG(0,("Failed to connect to mysql database: error: %s\n", mysql_error(handle))); >+ mysql_close(handle); >+ } >+ } else { DEBUG(0, ("Failed to connect to audit-MySQL-server\n")); } >+ } >+#endif >+ > smb_pam_close_session(sessionid.username, sessionid.id_str, sessionid.hostname); > > tdb_delete(tdb, key);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 3933
: 2035 |
2036
|
2039
|
2040
|
2102
|
2121