Skip to content

Commit

Permalink
Added suport for tty path logging
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Sep 24, 2010
1 parent b5c58e1 commit 1ae6dfb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
18 changes: 17 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
$Id: ChangeLog 24 2010-02-11 20:24:49Z bostjanskufca $
-------------------------------------------------------------------------------
SnoopyLogger changelog
-------------------------------------------------------------------------------



2010-09-24 - Version 1.7.2
---------------------------
o Logs current tty


2010-02-11 - Version 1.6.1
---------------------------
o Logs current working directory


2010-02-09 - Version 1.6.0
---------------------------
o Uses autotools now
Expand All @@ -14,26 +24,31 @@ o Program name and argument lengths limited to 4096 bytes
o Many thanks to otheus for supplying a patch on SourceForge one and a half
years ago, it helped tremendously.


2010-02-09 - Version 1.5.0
---------------------------
o Updated to compile and work without segfaults on 32bit and 64bit platforms
o Project maintenance taken over by Bostjan Skufca


Sun December 10 - Version 1.3
------------------------------
o Altered logging mechanism for performance
o Added new way of logging (can choose)
o Added an integrity check (optional)


Wed October 25 - Version 1.2a
-----------------------------
o ROOT_ONLY behavior now works again, thanks to adrian.head@bytecomm.com.au for
notifying us!


Thu October 10 - Version 1.2
-----------------------------
o Fixed small bug with rather adverse side effects.


Thu August 17 - Version 1.1
----------------------------
o Added support for execv(). Although execv() calls execve()
Expand All @@ -42,6 +57,7 @@ o Added support for execv(). Although execv() calls execve()
o Made logging code modular, as to accomodate for the extra
overload that execv() brought.


Thu August 3 - Version 1.00
----------------------------
o Cleaned up the codebase a bit
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT([Snoopy Logger], [1.6.1], [http://sourceforge.net/projects/snoopylogger/], [snoopy])
AC_INIT([Snoopy Logger], [1.7.2], [http://sourceforge.net/projects/snoopylogger/], [snoopy])
AC_DEFINE(PACKAGE_URL, "http://sourceforge.net/projects/snoopylogger/")
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
Expand Down
26 changes: 25 additions & 1 deletion configure.ac.generated
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT([Snoopy Logger], [1.7.2], [http://sourceforge.net/projects/snoopylogger/], [snoopy])
AC_DEFINE(PACKAGE_URL, "http://sourceforge.net/projects/snoopylogger/")
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])

Expand All @@ -26,4 +27,27 @@ AC_FUNC_MALLOC
AC_CHECK_FUNCS([getcwd])

AC_CONFIG_FILES([Makefile])



dnl ============================================================================
AC_ARG_ENABLE(cwd-logging,
[AC_HELP_STRING([--enable-cwd-logging],
[enable logging of Current Working Directory [default=yes]]
)],
[
if test "$enableval" == "yes"; then
enable_cwd_logging=yes
fi
],
[enable_cwd_logging=yes]
)

AS_IF([test "x$enable_cwd_logging" == "xyes"], [
AC_DEFINE(SNOOPY_CWD_LOGGING, 1, [Enable logging of Current Working Directory])
])



dnl ============================================================================
AC_OUTPUT
29 changes: 20 additions & 9 deletions snoopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static inline void snoopy_log(const char *filename, char *const argv[])
size_t logStringLength = 0;
char cwd[PATH_MAX+1];
char *getCwdRet = NULL;
char *ttyPath = NULL;

int i = 0;
int argc = 0;
Expand All @@ -61,19 +62,26 @@ static inline void snoopy_log(const char *filename, char *const argv[])
}
#endif

// Count number of arguments
/* Count number of arguments */
for (argc=0 ; *(argv+argc) != '\0' ; argc++);


// Allocate memory for logString
/* Get ttyname */
ttyPath = ttyname(0);
if (ttyPath == NULL) {
ttyPath = malloc(sizeof(int)*1);
ttyPath = "\0";
}

/* Allocate memory for logString */
logStringLength = 0;
for (i=0 ; i<argc ; i++) {
// Argument length + space
/* Argument length + space */
logStringLength += sizeof(char) * (min(SNOOPY_MAX_ARG_LENGTH, strlen(argv[i])) + 1);
}
logString = (char *) malloc(logStringLength + 1); // +1 for last \0
logString = (char *) malloc(logStringLength + 1); /* +1 for last \0 */

// Create logString
/* Create logString */
strcpy(logString, "");
for (i=0 ; i<argc ; i++) {
argLength = strlen(argv[i]);
Expand All @@ -82,17 +90,20 @@ static inline void snoopy_log(const char *filename, char *const argv[])
}
strcat(logString, "\0");

// Log it
/* Log it */
openlog("snoopy", LOG_PID, LOG_AUTHPRIV);
#if defined(SNOOPY_CWD_LOGGING)
getCwdRet = getcwd(cwd, PATH_MAX+1);
syslog(LOG_INFO, "[uid:%d sid:%d cwd:%s]: %s", getuid(), getsid(0), cwd, logString);
syslog(LOG_INFO, "[uid:%d sid:%d cwd:%s tty:%s]: %s", getuid(), getsid(0), cwd, ttyPath, logString);
#else
syslog(LOG_INFO, "[uid:%d sid:%d]: %s", getuid(), getsid(0), logString);
syslog(LOG_INFO, "[uid:%d sid:%d tty:%s]: %s", getuid(), getsid(0), ttyPath, logString);
#endif

// Free the logString memory
/* Free the logString memory */
free(logString);

/* Should this be done? */
/* free(ttyPath); */
}


Expand Down

0 comments on commit 1ae6dfb

Please sign in to comment.