1997-12-21 12:11:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1997-10-26 01:04:02 +00:00
|
|
|
*/
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <sys/types.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-06-01 16:01:48 +00:00
|
|
|
#include <ctype.h>
|
1995-02-26 12:18:08 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
1998-03-13 01:55:47 +00:00
|
|
|
#include <string.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <syslog.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.h"
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "descriptor.h"
|
|
|
|
#include "prompt.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
static const char *const LogNames[] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
"Async",
|
1998-08-07 18:42:51 +00:00
|
|
|
"CBCP",
|
1997-08-25 00:29:32 +00:00
|
|
|
"CCP",
|
|
|
|
"Chat",
|
|
|
|
"Command",
|
|
|
|
"Connect",
|
|
|
|
"Debug",
|
2000-03-14 01:46:49 +00:00
|
|
|
"DNS",
|
2000-08-28 23:24:52 +00:00
|
|
|
"Filter", /* Log discarded packets */
|
1997-08-25 00:29:32 +00:00
|
|
|
"HDLC",
|
1997-11-09 06:22:49 +00:00
|
|
|
"ID0",
|
1997-08-25 00:29:32 +00:00
|
|
|
"IPCP",
|
2001-08-14 16:05:52 +00:00
|
|
|
"IPV6CP",
|
1997-08-25 00:29:32 +00:00
|
|
|
"LCP",
|
|
|
|
"LQM",
|
|
|
|
"Phase",
|
1999-05-12 09:49:12 +00:00
|
|
|
"Physical",
|
2004-07-17 01:07:53 +00:00
|
|
|
"Radius",
|
1999-05-12 09:49:12 +00:00
|
|
|
"Sync",
|
1997-08-25 00:29:32 +00:00
|
|
|
"TCP/IP",
|
1998-05-21 21:49:08 +00:00
|
|
|
"Timer",
|
1997-08-25 00:29:32 +00:00
|
|
|
"Tun",
|
|
|
|
"Warning",
|
|
|
|
"Error",
|
|
|
|
"Alert"
|
1997-06-09 03:27:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MSK(n) (1<<((n)-1))
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static u_long LogMask = MSK(LogPHASE);
|
1997-11-04 01:17:05 +00:00
|
|
|
static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
|
1997-06-09 03:27:43 +00:00
|
|
|
static int LogTunno = -1;
|
2011-02-07 11:18:18 +00:00
|
|
|
static const char *LogIfaceName;
|
1998-05-23 22:24:50 +00:00
|
|
|
static struct prompt *promptlist; /* Where to log local stuff */
|
1999-09-06 08:16:33 +00:00
|
|
|
struct prompt *log_PromptContext;
|
1998-08-02 13:01:16 +00:00
|
|
|
int log_PromptListChanged;
|
1998-05-23 22:24:50 +00:00
|
|
|
|
|
|
|
struct prompt *
|
|
|
|
log_PromptList()
|
|
|
|
{
|
|
|
|
return promptlist;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
log_RegisterPrompt(struct prompt *prompt)
|
|
|
|
{
|
1998-05-23 22:24:50 +00:00
|
|
|
prompt->next = promptlist;
|
|
|
|
promptlist = prompt;
|
|
|
|
prompt->active = 1;
|
|
|
|
log_DiscardAllLocal(&prompt->logmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
log_ActivatePrompt(struct prompt *prompt)
|
|
|
|
{
|
|
|
|
prompt->active = 1;
|
|
|
|
LogMaskLocal |= prompt->logmask;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LogSetMaskLocal(void)
|
|
|
|
{
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
|
1998-05-23 22:24:50 +00:00
|
|
|
for (p = promptlist; p; p = p->next)
|
1998-05-21 21:49:08 +00:00
|
|
|
LogMaskLocal |= p->logmask;
|
|
|
|
}
|
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
void
|
|
|
|
log_DeactivatePrompt(struct prompt *prompt)
|
|
|
|
{
|
|
|
|
if (prompt->active) {
|
|
|
|
prompt->active = 0;
|
|
|
|
LogSetMaskLocal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
void
|
|
|
|
log_UnRegisterPrompt(struct prompt *prompt)
|
|
|
|
{
|
|
|
|
if (prompt) {
|
|
|
|
struct prompt **p;
|
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
for (p = &promptlist; *p; p = &(*p)->next)
|
1998-05-21 21:49:08 +00:00
|
|
|
if (*p == prompt) {
|
1998-05-23 22:24:50 +00:00
|
|
|
*p = prompt->next;
|
|
|
|
prompt->next = NULL;
|
1998-05-21 21:49:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
LogSetMaskLocal();
|
1998-08-02 13:01:16 +00:00
|
|
|
log_PromptListChanged++;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
void
|
|
|
|
log_DestroyPrompts(struct server *s)
|
|
|
|
{
|
1999-03-07 11:54:43 +00:00
|
|
|
struct prompt *p, *pn, *pl;
|
1998-05-23 22:24:50 +00:00
|
|
|
|
|
|
|
p = promptlist;
|
1999-03-07 11:54:43 +00:00
|
|
|
pl = NULL;
|
1998-05-23 22:24:50 +00:00
|
|
|
while (p) {
|
|
|
|
pn = p->next;
|
1999-03-07 11:54:43 +00:00
|
|
|
if (s && p->owner == s) {
|
|
|
|
if (pl)
|
|
|
|
pl->next = p->next;
|
|
|
|
else
|
|
|
|
promptlist = p->next;
|
1998-05-23 22:24:50 +00:00
|
|
|
p->next = NULL;
|
|
|
|
prompt_Destroy(p, 1);
|
1999-03-07 11:54:43 +00:00
|
|
|
} else
|
|
|
|
pl = p;
|
1998-05-23 22:24:50 +00:00
|
|
|
p = pn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
log_DisplayPrompts()
|
|
|
|
{
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
for (p = promptlist; p; p = p->next)
|
|
|
|
prompt_Required(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-09 15:34:11 +00:00
|
|
|
log_WritePrompts(struct datalink *dl, const char *fmt,...)
|
1998-05-23 22:24:50 +00:00
|
|
|
{
|
1998-08-09 15:34:11 +00:00
|
|
|
va_list ap;
|
1998-05-23 22:24:50 +00:00
|
|
|
struct prompt *p;
|
|
|
|
|
1998-08-09 15:34:11 +00:00
|
|
|
va_start(ap, fmt);
|
1998-05-23 22:24:50 +00:00
|
|
|
for (p = promptlist; p; p = p->next)
|
|
|
|
if (prompt_IsTermMode(p, dl))
|
1998-08-09 15:34:11 +00:00
|
|
|
prompt_vPrintf(p, fmt, ap);
|
|
|
|
va_end(ap);
|
1998-05-23 22:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
log_SetTtyCommandMode(struct datalink *dl)
|
|
|
|
{
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
for (p = promptlist; p; p = p->next)
|
|
|
|
if (prompt_IsTermMode(p, dl))
|
|
|
|
prompt_TtyCommandMode(p);
|
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
static int
|
|
|
|
syslogLevel(int lev)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
switch (lev) {
|
2001-11-03 21:45:32 +00:00
|
|
|
case LogLOG:
|
|
|
|
return LOG_INFO;
|
1998-05-21 21:49:08 +00:00
|
|
|
case LogDEBUG:
|
|
|
|
case LogTIMER:
|
|
|
|
return LOG_DEBUG;
|
1997-08-25 00:29:32 +00:00
|
|
|
case LogWARN:
|
|
|
|
return LOG_WARNING;
|
|
|
|
case LogERROR:
|
|
|
|
return LOG_ERR;
|
|
|
|
case LogALERT:
|
|
|
|
return LOG_ALERT;
|
|
|
|
}
|
|
|
|
return lev >= LogMIN && lev <= LogMAX ? LOG_INFO : 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
const char *
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Name(int id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2001-11-03 21:45:32 +00:00
|
|
|
if (id == LogLOG)
|
|
|
|
return "LOG";
|
1997-08-25 00:29:32 +00:00
|
|
|
return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id - 1];
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Keep(int id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
if (id >= LogMIN && id <= LogMAXCONF)
|
|
|
|
LogMask |= MSK(id);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-11-04 01:17:05 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_KeepLocal(int id, u_long *mask)
|
1997-11-04 01:17:05 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
if (id >= LogMIN && id <= LogMAXCONF) {
|
1997-11-04 01:17:05 +00:00
|
|
|
LogMaskLocal |= MSK(id);
|
1998-05-21 21:49:08 +00:00
|
|
|
*mask |= MSK(id);
|
|
|
|
}
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Discard(int id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
if (id >= LogMIN && id <= LogMAXCONF)
|
|
|
|
LogMask &= ~MSK(id);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-11-04 01:17:05 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_DiscardLocal(int id, u_long *mask)
|
1997-11-04 01:17:05 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
if (id >= LogMIN && id <= LogMAXCONF) {
|
|
|
|
*mask &= ~MSK(id);
|
|
|
|
LogSetMaskLocal();
|
|
|
|
}
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_DiscardAll()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
LogMask = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-11-04 01:17:05 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_DiscardAllLocal(u_long *mask)
|
1997-11-04 01:17:05 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
*mask = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
|
|
|
|
LogSetMaskLocal();
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
int
|
1998-05-21 21:49:08 +00:00
|
|
|
log_IsKept(int id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2001-11-03 21:45:32 +00:00
|
|
|
if (id == LogLOG)
|
|
|
|
return LOG_KEPT_SYSLOG;
|
1997-11-04 01:17:05 +00:00
|
|
|
if (id < LogMIN || id > LogMAX)
|
1997-08-25 00:29:32 +00:00
|
|
|
return 0;
|
1997-11-04 01:17:05 +00:00
|
|
|
if (id > LogMAXCONF)
|
|
|
|
return LOG_KEPT_LOCAL | LOG_KEPT_SYSLOG;
|
|
|
|
|
|
|
|
return ((LogMaskLocal & MSK(id)) ? LOG_KEPT_LOCAL : 0) |
|
|
|
|
((LogMask & MSK(id)) ? LOG_KEPT_SYSLOG : 0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
int
|
|
|
|
log_IsKeptLocal(int id, u_long mask)
|
|
|
|
{
|
|
|
|
if (id < LogMIN || id > LogMAX)
|
|
|
|
return 0;
|
|
|
|
if (id > LogMAXCONF)
|
|
|
|
return LOG_KEPT_LOCAL | LOG_KEPT_SYSLOG;
|
|
|
|
|
|
|
|
return ((mask & MSK(id)) ? LOG_KEPT_LOCAL : 0) |
|
|
|
|
((LogMask & MSK(id)) ? LOG_KEPT_SYSLOG : 0);
|
|
|
|
}
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Open(const char *Name)
|
1995-02-26 12:18:08 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
openlog(Name, LOG_PID, LOG_DAEMON);
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
2011-02-07 11:18:18 +00:00
|
|
|
log_SetTun(int tunno, const char *ifaceName)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
LogTunno = tunno;
|
2011-02-07 11:18:18 +00:00
|
|
|
LogIfaceName = ifaceName;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Close()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
closelog();
|
|
|
|
LogTunno = -1;
|
2011-02-07 11:18:18 +00:00
|
|
|
LogIfaceName = NULL;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(int lev, const char *fmt,...)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
va_list ap;
|
1998-05-21 21:49:08 +00:00
|
|
|
struct prompt *prompt;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (log_IsKept(lev)) {
|
1998-06-15 19:06:58 +00:00
|
|
|
char nfmt[200];
|
1997-08-25 00:29:32 +00:00
|
|
|
|
2001-06-18 23:24:26 +00:00
|
|
|
va_start(ap, fmt);
|
1999-09-06 08:16:33 +00:00
|
|
|
if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
|
2011-02-07 11:18:18 +00:00
|
|
|
if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) {
|
|
|
|
if (LogIfaceName)
|
|
|
|
snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
|
|
|
|
LogTunno, LogIfaceName, log_Name(lev), fmt);
|
|
|
|
else
|
|
|
|
snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
|
1998-05-21 21:49:08 +00:00
|
|
|
LogTunno, log_Name(lev), fmt);
|
2011-02-07 11:18:18 +00:00
|
|
|
} else
|
1998-05-21 21:49:08 +00:00
|
|
|
snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
|
2002-06-15 08:03:30 +00:00
|
|
|
|
1999-09-06 08:16:33 +00:00
|
|
|
if (log_PromptContext && lev == LogWARN)
|
|
|
|
/* Warnings just go to the current prompt */
|
|
|
|
prompt_vPrintf(log_PromptContext, nfmt, ap);
|
|
|
|
else for (prompt = promptlist; prompt; prompt = prompt->next)
|
1998-05-21 21:49:08 +00:00
|
|
|
if (lev > LogMAXCONF || (prompt->logmask & MSK(lev)))
|
|
|
|
prompt_vPrintf(prompt, nfmt, ap);
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
2001-06-18 23:24:26 +00:00
|
|
|
va_end(ap);
|
1997-11-04 01:17:05 +00:00
|
|
|
|
2001-06-18 23:24:26 +00:00
|
|
|
va_start(ap, fmt);
|
1998-05-23 22:24:50 +00:00
|
|
|
if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
|
1999-09-06 08:16:33 +00:00
|
|
|
(lev != LogWARN || !log_PromptContext)) {
|
2011-02-07 11:18:18 +00:00
|
|
|
if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) {
|
|
|
|
if (LogIfaceName)
|
|
|
|
snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
|
|
|
|
LogTunno, LogIfaceName, log_Name(lev), fmt);
|
|
|
|
else
|
|
|
|
snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
|
1998-05-21 21:49:08 +00:00
|
|
|
LogTunno, log_Name(lev), fmt);
|
2011-02-07 11:18:18 +00:00
|
|
|
} else
|
1998-05-21 21:49:08 +00:00
|
|
|
snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
|
1997-08-25 00:29:32 +00:00
|
|
|
vsyslog(syslogLevel(lev), nfmt, ap);
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
2001-06-18 23:24:26 +00:00
|
|
|
va_end(ap);
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-21 18:10:15 +00:00
|
|
|
log_DumpBp(int lev, const char *hdr, const struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
if (log_IsKept(lev)) {
|
1999-06-01 16:01:48 +00:00
|
|
|
char buf[68];
|
|
|
|
char *b, *c;
|
1998-08-21 18:10:15 +00:00
|
|
|
const u_char *ptr;
|
1997-10-22 01:22:51 +00:00
|
|
|
int f;
|
|
|
|
|
|
|
|
if (hdr && *hdr)
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(lev, "%s\n", hdr);
|
1997-10-22 01:22:51 +00:00
|
|
|
|
|
|
|
b = buf;
|
1999-06-01 16:01:48 +00:00
|
|
|
c = b + 50;
|
1997-10-22 01:22:51 +00:00
|
|
|
do {
|
1999-12-20 20:29:47 +00:00
|
|
|
f = bp->m_len;
|
1998-08-21 18:10:15 +00:00
|
|
|
ptr = CONST_MBUF_CTOP(bp);
|
1997-10-22 01:22:51 +00:00
|
|
|
while (f--) {
|
1999-06-01 16:01:48 +00:00
|
|
|
sprintf(b, " %02x", (int) *ptr);
|
|
|
|
*c++ = isprint(*ptr) ? *ptr : '.';
|
|
|
|
ptr++;
|
1997-10-22 01:22:51 +00:00
|
|
|
b += 3;
|
1999-06-01 16:01:48 +00:00
|
|
|
if (b == buf + 48) {
|
|
|
|
memset(b, ' ', 2);
|
1999-08-08 15:19:00 +00:00
|
|
|
*c = '\0';
|
|
|
|
log_Printf(lev, "%s\n", buf);
|
1997-10-22 01:22:51 +00:00
|
|
|
b = buf;
|
1999-06-01 16:01:48 +00:00
|
|
|
c = b + 50;
|
1997-10-22 01:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
} while ((bp = bp->m_next) != NULL);
|
1997-10-22 01:22:51 +00:00
|
|
|
|
1997-11-04 01:17:05 +00:00
|
|
|
if (b > buf) {
|
1999-06-01 16:01:48 +00:00
|
|
|
memset(b, ' ', 50 - (b - buf));
|
1999-08-08 15:19:00 +00:00
|
|
|
*c = '\0';
|
|
|
|
log_Printf(lev, "%s\n", buf);
|
1997-11-04 01:17:05 +00:00
|
|
|
}
|
1997-10-22 01:22:51 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-03-13 14:53:55 +00:00
|
|
|
|
|
|
|
void
|
1999-05-09 20:02:29 +00:00
|
|
|
log_DumpBuff(int lev, const char *hdr, const u_char *ptr, int n)
|
1997-03-13 14:53:55 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
if (log_IsKept(lev)) {
|
1999-06-01 16:01:48 +00:00
|
|
|
char buf[68];
|
|
|
|
char *b, *c;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
|
|
|
if (hdr && *hdr)
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(lev, "%s\n", hdr);
|
1997-08-25 00:29:32 +00:00
|
|
|
while (n > 0) {
|
|
|
|
b = buf;
|
1999-06-01 16:01:48 +00:00
|
|
|
c = b + 50;
|
|
|
|
for (b = buf; b != buf + 48 && n--; b += 3, ptr++) {
|
|
|
|
sprintf(b, " %02x", (int) *ptr);
|
|
|
|
*c++ = isprint(*ptr) ? *ptr : '.';
|
|
|
|
}
|
|
|
|
memset(b, ' ', 50 - (b - buf));
|
1999-08-08 15:19:00 +00:00
|
|
|
*c = '\0';
|
|
|
|
log_Printf(lev, "%s\n", buf);
|
1997-06-09 03:27:43 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1997-03-13 14:53:55 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
log_ShowLevel(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "Log: ");
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (log_IsKept(i) & LOG_KEPT_SYSLOG)
|
|
|
|
prompt_Printf(arg->prompt, " %s", log_Name(i));
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nLocal:");
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (log_IsKeptLocal(i, arg->prompt->logmask) & LOG_KEPT_LOCAL)
|
|
|
|
prompt_Printf(arg->prompt, " %s", log_Name(i));
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
log_SetLevel(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int i, res, argc, local;
|
|
|
|
char const *const *argv, *argp;
|
|
|
|
|
|
|
|
argc = arg->argc - arg->argn;
|
|
|
|
argv = arg->argv + arg->argn;
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
if (argc == 0 || strcasecmp(argv[0], "local"))
|
|
|
|
local = 0;
|
|
|
|
else {
|
|
|
|
if (arg->prompt == NULL) {
|
2000-10-30 00:15:29 +00:00
|
|
|
log_Printf(LogWARN, "set log local: Only available on the"
|
|
|
|
" command line\n");
|
1998-05-21 21:49:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
local = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-')) {
|
|
|
|
if (local)
|
|
|
|
log_DiscardAllLocal(&arg->prompt->logmask);
|
|
|
|
else
|
|
|
|
log_DiscardAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (argc--) {
|
|
|
|
argp = **argv == '+' || **argv == '-' ? *argv + 1 : *argv;
|
2000-10-30 00:15:35 +00:00
|
|
|
/* Special case 'all' */
|
|
|
|
if (strcasecmp(argp, "all") == 0) {
|
|
|
|
if (**argv == '-') {
|
|
|
|
if (local)
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
log_DiscardLocal(i, &arg->prompt->logmask);
|
|
|
|
else
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
log_Discard(i);
|
|
|
|
} else if (local)
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
log_KeepLocal(i, &arg->prompt->logmask);
|
|
|
|
else
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
log_Keep(i);
|
|
|
|
argv++;
|
|
|
|
continue;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (strcasecmp(argp, log_Name(i)) == 0) {
|
|
|
|
if (**argv == '-') {
|
|
|
|
if (local)
|
|
|
|
log_DiscardLocal(i, &arg->prompt->logmask);
|
|
|
|
else
|
|
|
|
log_Discard(i);
|
|
|
|
} else if (local)
|
|
|
|
log_KeepLocal(i, &arg->prompt->logmask);
|
|
|
|
else
|
|
|
|
log_Keep(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > LogMAX) {
|
|
|
|
log_Printf(LogWARN, "%s: Invalid log value\n", argp);
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
log_ShowWho(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct prompt *p;
|
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
for (p = promptlist; p; p = p->next) {
|
1998-05-21 21:49:08 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s (%s)", p->src.type, p->src.from);
|
|
|
|
if (p == arg->prompt)
|
|
|
|
prompt_Printf(arg->prompt, " *");
|
|
|
|
if (!p->active)
|
|
|
|
prompt_Printf(arg->prompt, " ^Z");
|
|
|
|
prompt_Printf(arg->prompt, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|