summaryrefslogtreecommitdiff
path: root/servconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'servconf.c')
-rw-r--r--servconf.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/servconf.c b/servconf.c
index ef8651651..ea67f6288 100644
--- a/servconf.c
+++ b/servconf.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include "includes.h" 12#include "includes.h"
13RCSID("$OpenBSD: servconf.c,v 1.133 2004/05/23 23:59:53 dtucker Exp $"); 13RCSID("$OpenBSD: servconf.c,v 1.134 2004/06/24 19:30:54 djm Exp $");
14 14
15#include "ssh.h" 15#include "ssh.h"
16#include "log.h" 16#include "log.h"
@@ -942,26 +942,50 @@ parse_flag:
942/* Reads the server configuration file. */ 942/* Reads the server configuration file. */
943 943
944void 944void
945read_server_config(ServerOptions *options, const char *filename) 945load_server_config(const char *filename, Buffer *conf)
946{ 946{
947 int linenum, bad_options = 0; 947 char line[1024], *cp;
948 char line[1024];
949 FILE *f; 948 FILE *f;
950 949
951 debug2("read_server_config: filename %s", filename); 950 debug2("%s: filename %s", __func__, filename);
952 f = fopen(filename, "r"); 951 if ((f = fopen(filename, "r")) == NULL) {
953 if (!f) {
954 perror(filename); 952 perror(filename);
955 exit(1); 953 exit(1);
956 } 954 }
957 linenum = 0; 955 buffer_clear(conf);
958 while (fgets(line, sizeof(line), f)) { 956 while (fgets(line, sizeof(line), f)) {
959 /* Update line number counter. */ 957 /*
960 linenum++; 958 * Trim out comments and strip whitespace
961 if (process_server_config_line(options, line, filename, linenum) != 0) 959 * NB - preserve newlines, they are needed to reproduce
962 bad_options++; 960 * line numbers later for error messages
961 */
962 if ((cp = strchr(line, '#')) != NULL)
963 memcpy(cp, "\n", 2);
964 cp = line + strspn(line, " \t\r");
965
966 buffer_append(conf, cp, strlen(cp));
963 } 967 }
968 buffer_append(conf, "\0", 1);
964 fclose(f); 969 fclose(f);
970 debug2("%s: done config len = %d", __func__, buffer_len(conf));
971}
972
973void
974parse_server_config(ServerOptions *options, const char *filename, Buffer *conf)
975{
976 int linenum, bad_options = 0;
977 char *cp, *cbuf;
978
979 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
980
981 cbuf = xstrdup(buffer_ptr(conf));
982 linenum = 0;
983 while((cp = strsep(&cbuf, "\n")) != NULL) {
984 if (process_server_config_line(options, cp, filename,
985 linenum++) != 0)
986 bad_options++;
987 }
988 free(cbuf);
965 if (bad_options > 0) 989 if (bad_options > 0)
966 fatal("%s: terminating, %d bad configuration options", 990 fatal("%s: terminating, %d bad configuration options",
967 filename, bad_options); 991 filename, bad_options);