add WRAP_LOG and HOST_IN_LOG

This commit is contained in:
Todd C. Miller
1998-09-10 22:51:09 +00:00
parent 9c725b5034
commit f9d20e8758

View File

@@ -87,12 +87,6 @@ static void syslog_wrapper __P((int, char *, char *, char *));
static char *logline; static char *logline;
extern int errorlineno; extern int errorlineno;
/*
* length of syslog-like header info used for mail and file logs
* is len("Mon MM HH:MM:SS : username : ")
*/
#define LOG_HEADER_LEN 29
#ifdef BROKEN_SYSLOG #ifdef BROKEN_SYSLOG
#define MAXSYSLOGTRIES 16 /* num of retries for broken syslogs */ #define MAXSYSLOGTRIES 16 /* num of retries for broken syslogs */
#define SYSLOG(a,b,c,d) syslog_wrapper(a,b,c,d) #define SYSLOG(a,b,c,d) syslog_wrapper(a,b,c,d)
@@ -136,7 +130,7 @@ void log_error(code)
int code; int code;
{ {
char *p; char *p;
int count; int count, header_length;
time_t now; time_t now;
#if (LOGGING & SLOG_FILE) #if (LOGGING & SLOG_FILE)
mode_t oldmask; mode_t oldmask;
@@ -147,10 +141,20 @@ void log_error(code)
char *tmp, save; char *tmp, save;
#endif /* LOGGING & SLOG_SYSLOG */ #endif /* LOGGING & SLOG_SYSLOG */
/*
* length of syslog-like header info used for mail and file logs
* is len("DDD MM HH:MM:SS : username : ") with an additional
* len("HOST=hostname : ") if HOST_IN_LOG is defined.
*/
header_length = 21 + strlen(user_name);
#ifdef HOST_IN_LOG
header_length += 8 + strlen(shost);
#endif
/* /*
* Allocate enough memory for logline so we won't overflow it * Allocate enough memory for logline so we won't overflow it
*/ */
count = LOG_HEADER_LEN + 136 + 2 * MAXPATHLEN + strlen(tty) + strlen(cwd) + count = header_length + 136 + 2 * MAXPATHLEN + strlen(tty) + strlen(cwd) +
strlen(runas_user); strlen(runas_user);
if (cmnd_args) if (cmnd_args)
count += strlen(cmnd_args); count += strlen(cmnd_args);
@@ -168,12 +172,16 @@ void log_error(code)
*/ */
now = time((time_t) 0); now = time((time_t) 0);
p = ctime(&now) + 4; p = ctime(&now) + 4;
(void) sprintf(logline, "%15.15s : %8.8s : ", p, user_name); #ifdef HOST_IN_LOG
(void) sprintf(logline, "%15.15s : %s : HOST=%s : ", p, user_name, shost);
#else
(void) sprintf(logline, "%15.15s : %s : ", p, user_name);
#endif
/* /*
* we need a pointer to the end of logline for cheap appends. * we need a pointer to the end of logline for cheap appends.
*/ */
p = logline + LOG_HEADER_LEN; p = logline + header_length;
switch (code) { switch (code) {
@@ -316,7 +324,7 @@ void log_error(code)
/* /*
* Log the full line, breaking into multiple syslog(3) calls if necesary * Log the full line, breaking into multiple syslog(3) calls if necesary
*/ */
p = &logline[LOG_HEADER_LEN]; /* skip past the date and user */ p = &logline[header_length]; /* skip past the date, host, and user */
for (count = 0; count < strlen(logline) / MAXSYSLOGLEN + 1; count++) { for (count = 0; count < strlen(logline) / MAXSYSLOGLEN + 1; count++) {
if (strlen(p) > MAXSYSLOGLEN) { if (strlen(p) > MAXSYSLOGLEN) {
/* /*
@@ -366,6 +374,9 @@ void log_error(code)
char *beg, *oldend, *end; char *beg, *oldend, *end;
int maxlen = MAXLOGFILELEN; int maxlen = MAXLOGFILELEN;
#ifndef WRAP_LOG
(void) fprintf(fp, "%s\n", logline);
#else
/* /*
* Print out logline with word wrap * Print out logline with word wrap
*/ */
@@ -413,6 +424,7 @@ void log_error(code)
beg = NULL; /* exit condition */ beg = NULL; /* exit condition */
} }
} }
#endif
(void) fclose(fp); (void) fclose(fp);
} }