[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
About bash_syslog_histrory Function!
From: |
address@hidden |
Subject: |
About bash_syslog_histrory Function! |
Date: |
Tue, 17 Jul 2018 16:03:01 +0800 |
Hi:
I found the orginal bash_syslog_history has three flaws:
1、 Ingore the texts that length exceed SYSLOG_MAXLEN,however in our
environment ,we have a lot of db2 command line which exceed SYSLOG_MAXLEN;
2、only get PID and UID, lack some import information such as tty,orginal
host ,user info ...
3、only by compile with SYSLOG_HISTORY=1 ,which is not default. Is there
any possible that by active it by default or where env parameter
BASH_SYSLOG_HISTORY is set to on ?
would you please consider improve about it ?
the original:
#if defined (SYSLOG_HISTORY)
#define SYSLOG_MAXLEN 600
void
bash_syslog_history (line)
const char *line;
{
char trunc[SYSLOG_MAXLEN];
if (strlen(line) < SYSLOG_MAXLEN)
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s",
getpid(), current_user.uid, line);
else
{
strncpy (trunc, line, SYSLOG_MAXLEN);
trunc[SYSLOG_MAXLEN - 1] = '\0';
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d
%s", getpid(), current_user.uid, trunc);
}
}
#endif
#include <utmp.h>
static char TTY[64];
static char SRC[64];
static char ORGHOST[64];
static void getutmpinfo(char*,char*,char*);
void
bash_initialize_history ()
{
history_quotes_inhibit_expansion = 1;
history_search_delimiter_chars = ";&()|<>";
history_inhibit_expansion_function = bash_history_inhibit_expansion;
getutmpinfo(TTY,SRC,ORGHOST);
#if defined (BANG_HISTORY)
sv_histchars ("histchars");
#endif
}
static void getutmpinfo(char* ptty ,char* puser,char* phost)
{
memset(ptty,0,sizeof(ptty));
memset(puser,0,sizeof(puser));
memset(phost,0,sizeof(phost));
struct utmp *p;
char pline[32];
strcpy( ptty ,(char*) ttyname(STDIN_FILENO) ) ;
while( p = getutent() ){
if( p->ut_type == 7){
memset(pline,0,32*sizeof(char));
strcpy(pline,(char*)"/dev/");
strcat(pline,p->ut_line);
if( strcmp(ptty,pline) == 0 ){
strcpy(puser,p->ut_user);
strcpy(phost,p->ut_host);
break;
}
}
}
}
#if defined (SYSLOG_HISTORY)
#define SYSLOG_MAXLEN 1024
#define SYSLOG_HEADERLEN 512
void bash_syslog_history (line)
const char *line;
{
char trunc[SYSLOG_MAXLEN];
char logheader[SYSLOG_HEADERLEN];
snprintf(logheader,sizeof(logheader),"bash-history:
PID=%d,PPID=%d,TTY=%s,ORG=%s,SRC=%s,USER=%s,DIR=%s",getpid(),getppid(),TTY,ORGHOST,SRC,current_user.user_name,get_current_dir_name());
if ( strlen(line) < (SYSLOG_MAXLEN - strlen(logheader)) )
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL,"%s,CMD=%s",logheader , line);
else
{
int seq = 0;
int maxseq = strlen(line) /( SYSLOG_MAXLEN-strlen(logheader)) + 1;
while ( seq++ < maxseq ){
strncpy (trunc, line, (SYSLOG_MAXLEN - strlen(logheader)) );
trunc[SYSLOG_MAXLEN - 1] = '\0';
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "%s,seq=%d,CMD=%s",
logheader,seq, trunc);
line = line + SYSLOG_MAXLEN - strlen(logheader);
}
}
}
#endif
孙会林
中国银联信息总中心
地 址:上海市浦东新区顾唐路1699号
邮 编:201201
电 话:021-38929999-6607
bashhist.c
Description: Binary data
- About bash_syslog_histrory Function!,
address@hidden <=