summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>1999-11-19 16:04:18 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>1999-11-19 16:04:18 +0000
commitddf3d725d299d119ca439c72b169b56b24453671 (patch)
tree0c9e14fffb5a30bff2fcc9f6bb7f0b65135c7dc9
parent9cec6e8177be909a054ef58bd3ba8ff69888236b (diff)
bugfix: loglevels are per host in clientconfig,
factor out common log-level parsing code.
-rw-r--r--usr.bin/ssh/log.c62
-rw-r--r--usr.bin/ssh/readconf.c48
-rw-r--r--usr.bin/ssh/servconf.c85
-rw-r--r--usr.bin/ssh/ssh.h6
4 files changed, 92 insertions, 109 deletions
diff --git a/usr.bin/ssh/log.c b/usr.bin/ssh/log.c
index 3e840ecb5c9..1ce534ea57d 100644
--- a/usr.bin/ssh/log.c
+++ b/usr.bin/ssh/log.c
@@ -5,7 +5,7 @@ Shared versions of debug(), log(), etc.
*/
#include "includes.h"
-RCSID("$OpenBSD: log.c,v 1.1 1999/11/10 23:36:44 markus Exp $");
+RCSID("$OpenBSD: log.c,v 1.2 1999/11/19 16:04:17 markus Exp $");
#include "ssh.h"
#include "xmalloc.h"
@@ -133,3 +133,63 @@ fatal_cleanup(void)
exit(255);
}
+
+/* textual representation of log-facilities/levels */
+
+
+static struct
+{
+ const char *name;
+ SyslogFacility val;
+} log_facilities[] =
+{
+ { "DAEMON", SYSLOG_FACILITY_DAEMON },
+ { "USER", SYSLOG_FACILITY_USER },
+ { "AUTH", SYSLOG_FACILITY_AUTH },
+ { "LOCAL0", SYSLOG_FACILITY_LOCAL0 },
+ { "LOCAL1", SYSLOG_FACILITY_LOCAL1 },
+ { "LOCAL2", SYSLOG_FACILITY_LOCAL2 },
+ { "LOCAL3", SYSLOG_FACILITY_LOCAL3 },
+ { "LOCAL4", SYSLOG_FACILITY_LOCAL4 },
+ { "LOCAL5", SYSLOG_FACILITY_LOCAL5 },
+ { "LOCAL6", SYSLOG_FACILITY_LOCAL6 },
+ { "LOCAL7", SYSLOG_FACILITY_LOCAL7 },
+ { NULL, 0 }
+};
+
+static struct
+{
+ const char *name;
+ LogLevel val;
+} log_levels[] =
+{
+ { "QUIET", SYSLOG_LEVEL_QUIET },
+ { "FATAL", SYSLOG_LEVEL_FATAL },
+ { "ERROR", SYSLOG_LEVEL_ERROR },
+ { "INFO", SYSLOG_LEVEL_INFO },
+ { "CHAT", SYSLOG_LEVEL_CHAT },
+ { "DEBUG", SYSLOG_LEVEL_DEBUG },
+ { NULL, 0 }
+};
+
+SyslogFacility
+log_facility_number(char *name)
+{
+ int i;
+ if (name != NULL)
+ for (i = 0; log_facilities[i].name; i++)
+ if (strcasecmp(log_facilities[i].name, name) == 0)
+ return log_facilities[i].val;
+ return (SyslogFacility)-1;
+}
+
+LogLevel
+log_level_number(char *name)
+{
+ int i;
+ if (name != NULL)
+ for (i = 0; log_levels[i].name; i++)
+ if (strcasecmp(log_levels[i].name, name) == 0)
+ return log_levels[i].val;
+ return (LogLevel)-1;
+}
diff --git a/usr.bin/ssh/readconf.c b/usr.bin/ssh/readconf.c
index ab04f37cd1f..219035d5c65 100644
--- a/usr.bin/ssh/readconf.c
+++ b/usr.bin/ssh/readconf.c
@@ -14,7 +14,7 @@ Functions for reading the configuration files.
*/
#include "includes.h"
-RCSID("$Id: readconf.c,v 1.14 1999/11/14 21:45:07 markus Exp $");
+RCSID("$Id: readconf.c,v 1.15 1999/11/19 16:04:17 markus Exp $");
#include "ssh.h"
#include "cipher.h"
@@ -155,23 +155,6 @@ static struct
{ NULL, 0 }
};
-/* textual representation of log-levels */
-
-static struct
-{
- const char *name;
- LogLevel level;
-} log_levels[] =
-{
- { "QUIET", SYSLOG_LEVEL_QUIET },
- { "FATAL", SYSLOG_LEVEL_FATAL },
- { "ERROR", SYSLOG_LEVEL_ERROR },
- { "INFO", SYSLOG_LEVEL_INFO },
- { "CHAT", SYSLOG_LEVEL_CHAT },
- { "DEBUG", SYSLOG_LEVEL_DEBUG },
- { NULL, 0 }
-};
-
/* Characters considered whitespace in strtok calls. */
#define WHITESPACE " \t\r\n"
@@ -237,7 +220,7 @@ process_config_line(Options *options, const char *host,
int *activep)
{
char buf[256], *cp, *string, **charptr;
- int opcode, *intptr, value, fwd_port, fwd_host_port, i;
+ int opcode, *intptr, value, fwd_port, fwd_host_port;
/* Skip leading whitespace. */
cp = line + strspn(line, WHITESPACE);
@@ -462,30 +445,21 @@ process_config_line(Options *options, const char *host,
cp = strtok(NULL, WHITESPACE);
value = cipher_number(cp);
if (value == -1)
- fatal("%.200s line %d: Bad cipher.", filename, linenum);
+ fatal("%.200s line %d: Bad cipher '%s'.",
+ filename, linenum, cp ? cp : "<NONE>");
if (*activep && *intptr == -1)
*intptr = value;
break;
case oLogLevel:
+ intptr = (int *)&options->log_level;
cp = strtok(NULL, WHITESPACE);
- if (!cp)
- {
- fprintf(stderr, "%s line %d: missing level name.\n",
- filename, linenum);
- exit(1);
- }
- for (i = 0; log_levels[i].name; i++)
- if (strcasecmp(log_levels[i].name, cp) == 0)
- break;
- if (!log_levels[i].name)
- {
- fprintf(stderr, "%s line %d: unsupported log level %s\n",
- filename, linenum, cp);
- exit(1);
- }
- if (options->log_level == (LogLevel)(-1))
- options->log_level = log_levels[i].level;
+ value = log_level_number(cp);
+ if (value == (LogLevel)-1)
+ fatal("%.200s line %d: unsupported log level '%s'\n",
+ filename, linenum, cp ? cp : "<NONE>");
+ if (*activep && (LogLevel)*intptr == -1)
+ *intptr = (LogLevel)value;
break;
case oRemoteForward:
diff --git a/usr.bin/ssh/servconf.c b/usr.bin/ssh/servconf.c
index cf5368c7510..d9bc870f9e9 100644
--- a/usr.bin/ssh/servconf.c
+++ b/usr.bin/ssh/servconf.c
@@ -12,7 +12,7 @@ Created: Mon Aug 21 15:48:58 1995 ylo
*/
#include "includes.h"
-RCSID("$Id: servconf.c,v 1.22 1999/11/11 23:26:53 markus Exp $");
+RCSID("$Id: servconf.c,v 1.23 1999/11/19 16:04:17 markus Exp $");
#include "ssh.h"
#include "servconf.h"
@@ -214,41 +214,6 @@ static struct
{ NULL, 0 }
};
-static struct
-{
- const char *name;
- SyslogFacility facility;
-} log_facilities[] =
-{
- { "DAEMON", SYSLOG_FACILITY_DAEMON },
- { "USER", SYSLOG_FACILITY_USER },
- { "AUTH", SYSLOG_FACILITY_AUTH },
- { "LOCAL0", SYSLOG_FACILITY_LOCAL0 },
- { "LOCAL1", SYSLOG_FACILITY_LOCAL1 },
- { "LOCAL2", SYSLOG_FACILITY_LOCAL2 },
- { "LOCAL3", SYSLOG_FACILITY_LOCAL3 },
- { "LOCAL4", SYSLOG_FACILITY_LOCAL4 },
- { "LOCAL5", SYSLOG_FACILITY_LOCAL5 },
- { "LOCAL6", SYSLOG_FACILITY_LOCAL6 },
- { "LOCAL7", SYSLOG_FACILITY_LOCAL7 },
- { NULL, 0 }
-};
-
-static struct
-{
- const char *name;
- LogLevel level;
-} log_levels[] =
-{
- { "QUIET", SYSLOG_LEVEL_QUIET },
- { "FATAL", SYSLOG_LEVEL_FATAL },
- { "ERROR", SYSLOG_LEVEL_ERROR },
- { "INFO", SYSLOG_LEVEL_INFO },
- { "CHAT", SYSLOG_LEVEL_CHAT },
- { "DEBUG", SYSLOG_LEVEL_DEBUG },
- { NULL, 0 }
-};
-
/* Returns the number of the token pointed to by cp of length len.
Never returns if the token is not known. */
@@ -495,45 +460,25 @@ void read_server_config(ServerOptions *options, const char *filename)
goto parse_flag;
case sLogFacility:
+ intptr = (int *)&options->log_facility;
cp = strtok(NULL, WHITESPACE);
- if (!cp)
- {
- fprintf(stderr, "%s line %d: missing facility name.\n",
- filename, linenum);
- exit(1);
- }
- for (i = 0; log_facilities[i].name; i++)
- if (strcasecmp(log_facilities[i].name, cp) == 0)
- break;
- if (!log_facilities[i].name)
- {
- fprintf(stderr, "%s line %d: unsupported log facility %s\n",
- filename, linenum, cp);
- exit(1);
- }
- if (options->log_facility == (SyslogFacility)(-1))
- options->log_facility = log_facilities[i].facility;
+ value = log_facility_number(cp);
+ if (value == (SyslogFacility)-1)
+ fatal("%.200s line %d: unsupported log facility '%s'\n",
+ filename, linenum, cp ? cp : "<NONE>");
+ if (*intptr == -1)
+ *intptr = (SyslogFacility)value;
break;
case sLogLevel:
+ intptr = (int *)&options->log_level;
cp = strtok(NULL, WHITESPACE);
- if (!cp)
- {
- fprintf(stderr, "%s line %d: missing level name.\n",
- filename, linenum);
- exit(1);
- }
- for (i = 0; log_levels[i].name; i++)
- if (strcasecmp(log_levels[i].name, cp) == 0)
- break;
- if (!log_levels[i].name)
- {
- fprintf(stderr, "%s line %d: unsupported log level %s\n",
- filename, linenum, cp);
- exit(1);
- }
- if (options->log_level == (LogLevel)(-1))
- options->log_level = log_levels[i].level;
+ value = log_level_number(cp);
+ if (value == (LogLevel)-1)
+ fatal("%.200s line %d: unsupported log level '%s'\n",
+ filename, linenum, cp ? cp : "<NONE>");
+ if (*intptr == -1)
+ *intptr = (LogLevel)value;
break;
case sAllowUsers:
diff --git a/usr.bin/ssh/ssh.h b/usr.bin/ssh/ssh.h
index b8d103de333..b1de3d26564 100644
--- a/usr.bin/ssh/ssh.h
+++ b/usr.bin/ssh/ssh.h
@@ -13,7 +13,7 @@ Generic header file for ssh.
*/
-/* RCSID("$Id: ssh.h,v 1.21 1999/11/15 20:53:25 markus Exp $"); */
+/* RCSID("$Id: ssh.h,v 1.22 1999/11/19 16:04:17 markus Exp $"); */
#ifndef SSH_H
#define SSH_H
@@ -375,6 +375,10 @@ void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
/* Logging implementation, depending on server or client */
void do_log(LogLevel level, const char *fmt, va_list args);
+/* name to facility/level */
+SyslogFacility log_facility_number(char *name);
+LogLevel log_level_number(char *name);
+
/* Output a message to syslog or stderr */
void fatal(const char *fmt, ...);
void error(const char *fmt, ...);