When logging warning messages, there are now three scenarios:

o If a prompt is executing the command, only display the warning to
  that prompt
o If a prompt is executing a ``load'' command, display the warning
  to all prompts *and* syslog
o Otherwise, display the warning to all prompts *and* syslog.
This commit is contained in:
Brian Somers 1999-09-06 08:16:33 +00:00
parent ecab1f6824
commit b4f63b0b8b
4 changed files with 24 additions and 5 deletions

View File

@ -72,6 +72,7 @@ static u_long LogMask = MSK(LogPHASE);
static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
static int LogTunno = -1;
static struct prompt *promptlist; /* Where to log local stuff */
struct prompt *log_PromptContext;
int log_PromptListChanged;
struct prompt *
@ -307,20 +308,23 @@ log_Printf(int lev, const char *fmt,...)
if (log_IsKept(lev)) {
char nfmt[200];
if ((log_IsKept(lev) & LOG_KEPT_LOCAL) && promptlist) {
if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
LogTunno, log_Name(lev), fmt);
else
snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
for (prompt = promptlist; prompt; prompt = prompt->next)
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)
if (lev > LogMAXCONF || (prompt->logmask & MSK(lev)))
prompt_vPrintf(prompt, nfmt, ap);
}
if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
(lev != LogWARN || !promptlist)) {
(lev != LogWARN || !log_PromptContext)) {
if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
LogTunno, log_Name(lev), fmt);

View File

@ -87,6 +87,7 @@ extern int log_ShowLevel(struct cmdargs const *);
extern int log_SetLevel(struct cmdargs const *);
extern int log_ShowWho(struct cmdargs const *);
extern struct prompt *log_PromptContext;
extern int log_PromptListChanged;
extern void log_RegisterPrompt(struct prompt *);
extern void log_UnRegisterPrompt(struct prompt *);

View File

@ -173,6 +173,7 @@ static void
prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
struct prompt *op;
int n;
char ch;
char linebuff[LINE_LEN];
@ -186,8 +187,12 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
linebuff[n] = '\0';
p->nonewline = 1; /* Maybe command_Decode does a prompt */
prompt_Required(p);
if (n)
if (n) {
if ((op = log_PromptContext) == NULL)
log_PromptContext = p;
command_Decode(bundle, linebuff, n, p, p->src.from);
log_PromptContext = op;
}
} else if (n <= 0) {
log_Printf(LogPHASE, "%s: Client connection closed.\n", p->src.from);
if (!p->owner)

View File

@ -267,6 +267,7 @@ ReadSystem(struct bundle *bundle, const char *name, const char *file,
int allowcmd;
int indent;
char arg[LINE_LEN];
struct prompt *op;
if (*file == '/')
snprintf(filename, sizeof filename, "%s", file);
@ -342,9 +343,17 @@ ReadSystem(struct bundle *bundle, const char *name, const char *file,
argc = command_Interpret(cp, len, argv);
allowcmd = argc > 0 && !strcasecmp(argv[0], "allow");
if ((!(how == SYSTEM_EXEC) && allowcmd) ||
((how == SYSTEM_EXEC) && !allowcmd))
((how == SYSTEM_EXEC) && !allowcmd)) {
/*
* Disable any context so that warnings are given to everyone,
* including syslog.
*/
op = log_PromptContext;
log_PromptContext = NULL;
command_Run(bundle, argc, (char const *const *)argv, prompt,
name, cx);
log_PromptContext = op;
}
}
fclose(fp); /* everything read - get out */