version 1.337, 2018/07/09 13:37:10 |
version 1.338, 2018/07/09 21:29:36 |
|
|
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "ssh.h" |
#include "ssh.h" |
#include "log.h" |
#include "log.h" |
#include "buffer.h" |
#include "sshbuf.h" |
#include "misc.h" |
#include "misc.h" |
#include "servconf.h" |
#include "servconf.h" |
#include "compat.h" |
#include "compat.h" |
|
|
#include "groupaccess.h" |
#include "groupaccess.h" |
#include "canohost.h" |
#include "canohost.h" |
#include "packet.h" |
#include "packet.h" |
|
#include "ssherr.h" |
#include "hostfile.h" |
#include "hostfile.h" |
#include "auth.h" |
#include "auth.h" |
#include "myproposal.h" |
#include "myproposal.h" |
|
|
|
|
/* Use of privilege separation or not */ |
/* Use of privilege separation or not */ |
extern int use_privsep; |
extern int use_privsep; |
extern Buffer cfg; |
extern struct sshbuf *cfg; |
|
|
/* Initializes the server options to their default values. */ |
/* Initializes the server options to their default values. */ |
|
|
|
|
/* Reads the server configuration file. */ |
/* Reads the server configuration file. */ |
|
|
void |
void |
load_server_config(const char *filename, Buffer *conf) |
load_server_config(const char *filename, struct sshbuf *conf) |
{ |
{ |
char *line = NULL, *cp; |
char *line = NULL, *cp; |
size_t linesize = 0; |
size_t linesize = 0; |
FILE *f; |
FILE *f; |
int lineno = 0; |
int r, lineno = 0; |
|
|
debug2("%s: filename %s", __func__, filename); |
debug2("%s: filename %s", __func__, filename); |
if ((f = fopen(filename, "r")) == NULL) { |
if ((f = fopen(filename, "r")) == NULL) { |
perror(filename); |
perror(filename); |
exit(1); |
exit(1); |
} |
} |
buffer_clear(conf); |
sshbuf_reset(conf); |
while (getline(&line, &linesize, f) != -1) { |
while (getline(&line, &linesize, f) != -1) { |
lineno++; |
lineno++; |
/* |
/* |
|
|
if ((cp = strchr(line, '#')) != NULL) |
if ((cp = strchr(line, '#')) != NULL) |
memcpy(cp, "\n", 2); |
memcpy(cp, "\n", 2); |
cp = line + strspn(line, " \t\r"); |
cp = line + strspn(line, " \t\r"); |
|
if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0) |
buffer_append(conf, cp, strlen(cp)); |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
} |
} |
free(line); |
free(line); |
buffer_append(conf, "\0", 1); |
if ((r = sshbuf_put_u8(conf, 0)) != 0) |
|
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fclose(f); |
fclose(f); |
debug2("%s: done config len = %d", __func__, buffer_len(conf)); |
debug2("%s: done config len = %zu", __func__, sshbuf_len(conf)); |
} |
} |
|
|
void |
void |
|
|
ServerOptions mo; |
ServerOptions mo; |
|
|
initialize_server_options(&mo); |
initialize_server_options(&mo); |
parse_server_config(&mo, "reprocess config", &cfg, connectinfo); |
parse_server_config(&mo, "reprocess config", cfg, connectinfo); |
copy_set_server_options(options, &mo, 0); |
copy_set_server_options(options, &mo, 0); |
} |
} |
|
|
|
|
#undef M_CP_STRARRAYOPT |
#undef M_CP_STRARRAYOPT |
|
|
void |
void |
parse_server_config(ServerOptions *options, const char *filename, Buffer *conf, |
parse_server_config(ServerOptions *options, const char *filename, |
struct connection_info *connectinfo) |
struct sshbuf *conf, struct connection_info *connectinfo) |
{ |
{ |
int active, linenum, bad_options = 0; |
int active, linenum, bad_options = 0; |
char *cp, *obuf, *cbuf; |
char *cp, *obuf, *cbuf; |
|
|
debug2("%s: config %s len %d", __func__, filename, buffer_len(conf)); |
debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf)); |
|
|
if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL) |
if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL) |
fatal("%s: sshbuf_dup_string failed", __func__); |
fatal("%s: sshbuf_dup_string failed", __func__); |