upstream: factor out opt_array_append; ok djm@

OpenBSD-Commit-ID: 571bc5dd35f99c5cf9de6aaeac428b168218e74a
This commit is contained in:
markus@openbsd.org 2021-02-15 20:36:35 +00:00 committed by Darren Tucker
parent ad74fc127c
commit b696858a7f
3 changed files with 51 additions and 43 deletions

28
misc.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.160 2021/01/15 02:58:11 dtucker Exp $ */
/* $OpenBSD: misc.c,v 1.161 2021/02/15 20:36:35 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@ -2439,6 +2439,32 @@ opt_match(const char **opts, const char *term)
return 0;
}
void
opt_array_append2(const char *file, const int line, const char *directive,
char ***array, int **iarray, u_int *lp, const char *s, int i)
{
if (*lp >= INT_MAX)
fatal("%s line %d: Too many %s entries", file, line, directive);
if (iarray != NULL) {
*iarray = xrecallocarray(*iarray, *lp, *lp + 1,
sizeof(**iarray));
(*iarray)[*lp] = i;
}
*array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
(*array)[*lp] = xstrdup(s);
(*lp)++;
}
void
opt_array_append(const char *file, const int line, const char *directive,
char ***array, u_int *lp, const char *s)
{
opt_array_append2(file, line, directive, array, NULL, lp, s, 0);
}
sshsig_t
ssh_signal(int signum, sshsig_t handler)
{

10
misc.h
View File

@ -1,4 +1,4 @@
/* $OpenBSD: misc.h,v 1.92 2021/01/11 02:12:57 dtucker Exp $ */
/* $OpenBSD: misc.h,v 1.93 2021/02/15 20:36:35 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -190,6 +190,13 @@ int opt_flag(const char *opt, int allow_negate, const char **optsp);
char *opt_dequote(const char **sp, const char **errstrp);
int opt_match(const char **opts, const char *term);
/* readconf/servconf option lists */
void opt_array_append(const char *file, const int line,
const char *directive, char ***array, u_int *lp, const char *s);
void opt_array_append2(const char *file, const int line,
const char *directive, char ***array, int **iarray, u_int *lp,
const char *s, int i);
/* readpass.c */
#define RP_ECHO 0x0001
@ -212,4 +219,5 @@ void notify_complete(struct notifier_ctx *, const char *, ...)
typedef void (*sshsig_t)(int);
sshsig_t ssh_signal(int, sshsig_t);
#endif /* _MISC_H */

View File

@ -1,5 +1,5 @@
/* $OpenBSD: servconf.c,v 1.375 2021/01/26 05:32:21 dtucker Exp $ */
/* $OpenBSD: servconf.c,v 1.376 2021/02/15 20:36:35 markus Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@ -248,39 +248,13 @@ assemble_algorithms(ServerOptions *o)
free(def_sig);
}
static void
array_append2(const char *file, const int line, const char *directive,
char ***array, int **iarray, u_int *lp, const char *s, int i)
{
if (*lp >= INT_MAX)
fatal("%s line %d: Too many %s entries", file, line, directive);
if (iarray != NULL) {
*iarray = xrecallocarray(*iarray, *lp, *lp + 1,
sizeof(**iarray));
(*iarray)[*lp] = i;
}
*array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
(*array)[*lp] = xstrdup(s);
(*lp)++;
}
static void
array_append(const char *file, const int line, const char *directive,
char ***array, u_int *lp, const char *s)
{
array_append2(file, line, directive, array, NULL, lp, s, 0);
}
void
servconf_add_hostkey(const char *file, const int line,
ServerOptions *options, const char *path, int userprovided)
{
char *apath = derelativise_path(path);
array_append2(file, line, "HostKey",
opt_array_append2(file, line, "HostKey",
&options->host_key_files, &options->host_key_file_userprovided,
&options->num_host_key_files, apath, userprovided);
free(apath);
@ -292,7 +266,7 @@ servconf_add_hostcert(const char *file, const int line,
{
char *apath = derelativise_path(path);
array_append(file, line, "HostCertificate",
opt_array_append(file, line, "HostCertificate",
&options->host_cert_files, &options->num_host_cert_files, apath);
free(apath);
}
@ -439,11 +413,11 @@ fill_default_server_options(ServerOptions *options)
if (options->client_alive_count_max == -1)
options->client_alive_count_max = 3;
if (options->num_authkeys_files == 0) {
array_append("[default]", 0, "AuthorizedKeysFiles",
opt_array_append("[default]", 0, "AuthorizedKeysFiles",
&options->authorized_keys_files,
&options->num_authkeys_files,
_PATH_SSH_USER_PERMITTED_KEYS);
array_append("[default]", 0, "AuthorizedKeysFiles",
opt_array_append("[default]", 0, "AuthorizedKeysFiles",
&options->authorized_keys_files,
&options->num_authkeys_files,
_PATH_SSH_USER_PERMITTED_KEYS2);
@ -1737,7 +1711,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
while ((arg = strdelim(&cp)) && *arg != '\0') {
if (!*activep)
continue;
array_append(filename, linenum, "oLogVerbose",
opt_array_append(filename, linenum, "oLogVerbose",
&options->log_verbose, &options->num_log_verbose,
arg);
}
@ -1768,7 +1742,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
"\"%.100s\"", filename, linenum, arg);
if (!*activep)
continue;
array_append(filename, linenum, "AllowUsers",
opt_array_append(filename, linenum, "AllowUsers",
&options->allow_users, &options->num_allow_users,
arg);
}
@ -1781,7 +1755,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
"\"%.100s\"", filename, linenum, arg);
if (!*activep)
continue;
array_append(filename, linenum, "DenyUsers",
opt_array_append(filename, linenum, "DenyUsers",
&options->deny_users, &options->num_deny_users,
arg);
}
@ -1791,7 +1765,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
while ((arg = strdelim(&cp)) && *arg != '\0') {
if (!*activep)
continue;
array_append(filename, linenum, "AllowGroups",
opt_array_append(filename, linenum, "AllowGroups",
&options->allow_groups, &options->num_allow_groups,
arg);
}
@ -1801,7 +1775,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
while ((arg = strdelim(&cp)) && *arg != '\0') {
if (!*activep)
continue;
array_append(filename, linenum, "DenyGroups",
opt_array_append(filename, linenum, "DenyGroups",
&options->deny_groups, &options->num_deny_groups,
arg);
}
@ -1965,7 +1939,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
if (*activep && options->num_authkeys_files == 0) {
while ((arg = strdelim(&cp)) && *arg != '\0') {
arg = tilde_expand_filename(arg, getuid());
array_append(filename, linenum,
opt_array_append(filename, linenum,
"AuthorizedKeysFile",
&options->authorized_keys_files,
&options->num_authkeys_files, arg);
@ -2003,7 +1977,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
filename, linenum);
if (!*activep)
continue;
array_append(filename, linenum, "AcceptEnv",
opt_array_append(filename, linenum, "AcceptEnv",
&options->accept_env, &options->num_accept_env,
arg);
}
@ -2017,7 +1991,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
filename, linenum);
if (!*activep || uvalue != 0)
continue;
array_append(filename, linenum, "SetEnv",
opt_array_append(filename, linenum, "SetEnv",
&options->setenv, &options->num_setenv, arg);
}
break;
@ -2196,7 +2170,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
lookup_opcode_name(opcode));
}
if (*activep && uvalue == 0) {
array_append(filename, linenum,
opt_array_append(filename, linenum,
lookup_opcode_name(opcode),
chararrayptr, uintptr, arg2);
}
@ -2358,7 +2332,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
value2 = 1;
if (!*activep)
continue;
array_append(filename, linenum,
opt_array_append(filename, linenum,
"AuthenticationMethods",
&options->auth_methods,
&options->num_auth_methods, arg);