summaryrefslogtreecommitdiff
path: root/servconf.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2018-07-09 21:29:36 +0000
committerDamien Miller <djm@mindrot.org>2018-07-10 15:25:25 +1000
commitc3cb7790e9efb14ba74b2d9f543ad593b3d55b31 (patch)
tree54ae8b586e07b7620c2e9f054ff7e2d2d90eed62 /servconf.c
parent2808d18ca47ad3d251836c555f0e22aaca03d15c (diff)
upstream: sshd: switch config to sshbuf API; ok djm@
OpenBSD-Commit-ID: 72b02017bac7feac48c9dceff8355056bea300bd
Diffstat (limited to 'servconf.c')
-rw-r--r--servconf.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/servconf.c b/servconf.c
index 97c268e3c..7ca67ce6b 100644
--- a/servconf.c
+++ b/servconf.c
@@ -1,5 +1,5 @@
1 1
2/* $OpenBSD: servconf.c,v 1.337 2018/07/09 13:37:10 sf Exp $ */ 2/* $OpenBSD: servconf.c,v 1.338 2018/07/09 21:29:36 markus Exp $ */
3/* 3/*
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved 5 * All rights reserved
@@ -45,7 +45,7 @@
45#include "xmalloc.h" 45#include "xmalloc.h"
46#include "ssh.h" 46#include "ssh.h"
47#include "log.h" 47#include "log.h"
48#include "buffer.h" 48#include "sshbuf.h"
49#include "misc.h" 49#include "misc.h"
50#include "servconf.h" 50#include "servconf.h"
51#include "compat.h" 51#include "compat.h"
@@ -59,6 +59,7 @@
59#include "groupaccess.h" 59#include "groupaccess.h"
60#include "canohost.h" 60#include "canohost.h"
61#include "packet.h" 61#include "packet.h"
62#include "ssherr.h"
62#include "hostfile.h" 63#include "hostfile.h"
63#include "auth.h" 64#include "auth.h"
64#include "myproposal.h" 65#include "myproposal.h"
@@ -71,7 +72,7 @@ static void add_one_listen_addr(ServerOptions *, const char *,
71 72
72/* Use of privilege separation or not */ 73/* Use of privilege separation or not */
73extern int use_privsep; 74extern int use_privsep;
74extern Buffer cfg; 75extern struct sshbuf *cfg;
75 76
76/* Initializes the server options to their default values. */ 77/* Initializes the server options to their default values. */
77 78
@@ -2163,19 +2164,19 @@ process_server_config_line(ServerOptions *options, char *line,
2163/* Reads the server configuration file. */ 2164/* Reads the server configuration file. */
2164 2165
2165void 2166void
2166load_server_config(const char *filename, Buffer *conf) 2167load_server_config(const char *filename, struct sshbuf *conf)
2167{ 2168{
2168 char *line = NULL, *cp; 2169 char *line = NULL, *cp;
2169 size_t linesize = 0; 2170 size_t linesize = 0;
2170 FILE *f; 2171 FILE *f;
2171 int lineno = 0; 2172 int r, lineno = 0;
2172 2173
2173 debug2("%s: filename %s", __func__, filename); 2174 debug2("%s: filename %s", __func__, filename);
2174 if ((f = fopen(filename, "r")) == NULL) { 2175 if ((f = fopen(filename, "r")) == NULL) {
2175 perror(filename); 2176 perror(filename);
2176 exit(1); 2177 exit(1);
2177 } 2178 }
2178 buffer_clear(conf); 2179 sshbuf_reset(conf);
2179 while (getline(&line, &linesize, f) != -1) { 2180 while (getline(&line, &linesize, f) != -1) {
2180 lineno++; 2181 lineno++;
2181 /* 2182 /*
@@ -2186,13 +2187,14 @@ load_server_config(const char *filename, Buffer *conf)
2186 if ((cp = strchr(line, '#')) != NULL) 2187 if ((cp = strchr(line, '#')) != NULL)
2187 memcpy(cp, "\n", 2); 2188 memcpy(cp, "\n", 2);
2188 cp = line + strspn(line, " \t\r"); 2189 cp = line + strspn(line, " \t\r");
2189 2190 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2190 buffer_append(conf, cp, strlen(cp)); 2191 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2191 } 2192 }
2192 free(line); 2193 free(line);
2193 buffer_append(conf, "\0", 1); 2194 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2195 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2194 fclose(f); 2196 fclose(f);
2195 debug2("%s: done config len = %d", __func__, buffer_len(conf)); 2197 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
2196} 2198}
2197 2199
2198void 2200void
@@ -2202,7 +2204,7 @@ parse_server_match_config(ServerOptions *options,
2202 ServerOptions mo; 2204 ServerOptions mo;
2203 2205
2204 initialize_server_options(&mo); 2206 initialize_server_options(&mo);
2205 parse_server_config(&mo, "reprocess config", &cfg, connectinfo); 2207 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
2206 copy_set_server_options(options, &mo, 0); 2208 copy_set_server_options(options, &mo, 0);
2207} 2209}
2208 2210
@@ -2346,13 +2348,13 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
2346#undef M_CP_STRARRAYOPT 2348#undef M_CP_STRARRAYOPT
2347 2349
2348void 2350void
2349parse_server_config(ServerOptions *options, const char *filename, Buffer *conf, 2351parse_server_config(ServerOptions *options, const char *filename,
2350 struct connection_info *connectinfo) 2352 struct sshbuf *conf, struct connection_info *connectinfo)
2351{ 2353{
2352 int active, linenum, bad_options = 0; 2354 int active, linenum, bad_options = 0;
2353 char *cp, *obuf, *cbuf; 2355 char *cp, *obuf, *cbuf;
2354 2356
2355 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf)); 2357 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
2356 2358
2357 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL) 2359 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2358 fatal("%s: sshbuf_dup_string failed", __func__); 2360 fatal("%s: sshbuf_dup_string failed", __func__);