diff options
author | Jakub Jelen <jjelen@redhat.com> | 2018-12-05 12:09:07 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-12-07 14:08:27 +0100 |
commit | 21e252236018ce10958b0623837a48f354d5b155 (patch) | |
tree | 05ff6fcf631dbc147bd232f1eda5d7311acb1daa /src | |
parent | 8f887e82c75a92942dea903d9239981f20136efb (diff) | |
download | libssh-21e252236018ce10958b0623837a48f354d5b155.tar.gz libssh-21e252236018ce10958b0623837a48f354d5b155.tar.xz libssh-21e252236018ce10958b0623837a48f354d5b155.zip |
config: Get rid of the dynamic seen array
* This makes the array constant in the session structure, avoiding
allocations and frees while parsing the file
* It also drops passing the seen array to all the functions,
because it is already part of the passed session
* The test cases are adjusted to match these changes
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 80 | ||||
-rw-r--r-- | src/session.c | 1 |
2 files changed, 15 insertions, 66 deletions
diff --git a/src/config.c b/src/config.c index ccb0c75b..121d042f 100644 --- a/src/config.c +++ b/src/config.c @@ -32,6 +32,7 @@ #endif #include <stdbool.h> +#include "libssh/config.h" #include "libssh/priv.h" #include "libssh/session.h" #include "libssh/misc.h" @@ -39,45 +40,6 @@ #define MAX_LINE_SIZE 1024 -enum ssh_config_opcode_e { - /* Unknown opcode */ - SOC_UNKNOWN = -3, - /* Known and not applicable to libssh */ - SOC_NA = -2, - /* Known but not supported by current libssh version */ - SOC_UNSUPPORTED = -1, - SOC_HOST, - SOC_MATCH, - SOC_HOSTNAME, - SOC_PORT, - SOC_USERNAME, - SOC_IDENTITY, - SOC_CIPHERS, - SOC_MACS, - SOC_COMPRESSION, - SOC_TIMEOUT, - SOC_PROTOCOL, - SOC_STRICTHOSTKEYCHECK, - SOC_KNOWNHOSTS, - SOC_PROXYCOMMAND, - SOC_GSSAPISERVERIDENTITY, - SOC_GSSAPICLIENTIDENTITY, - SOC_GSSAPIDELEGATECREDENTIALS, - SOC_INCLUDE, - SOC_BINDADDRESS, - SOC_GLOBALKNOWNHOSTSFILE, - SOC_LOGLEVEL, - SOC_HOSTKEYALGORITHMS, - SOC_KEXALGORITHMS, - SOC_GSSAPIAUTHENTICATION, - SOC_KBDINTERACTIVEAUTHENTICATION, - SOC_PASSWORDAUTHENTICATION, - SOC_PUBKEYAUTHENTICATION, - SOC_PUBKEYACCEPTEDTYPES, - - SOC_END /* Keep this one last in the list */ -}; - struct ssh_config_keyword_table_s { const char *name; enum ssh_config_opcode_e opcode; @@ -213,7 +175,7 @@ static struct ssh_config_match_keyword_table_s ssh_config_match_keyword_table[] }; static int ssh_config_parse_line(ssh_session session, const char *line, - unsigned int count, int *parsing, uint8_t *seen); + unsigned int count, int *parsing); static enum ssh_config_opcode_e ssh_config_get_opcode(char *keyword) { int i; @@ -326,8 +288,7 @@ static int ssh_config_get_yesno(char **str, int notfound) { static void local_parse_file(ssh_session session, const char *filename, - int *parsing, - uint8_t *seen) + int *parsing) { FILE *f; char line[MAX_LINE_SIZE] = {0}; @@ -344,7 +305,7 @@ local_parse_file(ssh_session session, SSH_LOG(SSH_LOG_PACKET, "Reading additional configuration data from %s", filename); while (fgets(line, sizeof(line), f)) { count++; - rv = ssh_config_parse_line(session, line, count, parsing, seen); + rv = ssh_config_parse_line(session, line, count, parsing); if (rv < 0) { fclose(f); return; @@ -358,8 +319,7 @@ local_parse_file(ssh_session session, #if defined(HAVE_GLOB) && defined(HAVE_GLOB_GL_FLAGS_MEMBER) static void local_parse_glob(ssh_session session, const char *fileglob, - int *parsing, - uint8_t *seen) + int *parsing) { glob_t globbuf = { .gl_flags = 0, @@ -379,7 +339,7 @@ static void local_parse_glob(ssh_session session, } for (i = 0; i < globbuf.gl_pathc; i++) { - local_parse_file(session, globbuf.gl_pathv[i], parsing, seen); + local_parse_file(session, globbuf.gl_pathv[i], parsing); } globfree(&globbuf); @@ -420,8 +380,11 @@ ssh_config_match(char *value, const char *pattern, bool negate) return result; } -static int ssh_config_parse_line(ssh_session session, const char *line, - unsigned int count, int *parsing, uint8_t *seen) +static int +ssh_config_parse_line(ssh_session session, + const char *line, + unsigned int count, + int *parsing) { enum ssh_config_opcode_e opcode; const char *p; @@ -430,6 +393,7 @@ static int ssh_config_parse_line(ssh_session session, const char *line, char *lowerhost; size_t len; int i; + uint8_t *seen = session->opts.options_seen; long l; x = s = strdup(line); @@ -473,9 +437,9 @@ static int ssh_config_parse_line(ssh_session session, const char *line, p = ssh_config_get_str_tok(&s, NULL); if (p && *parsing) { #if defined(HAVE_GLOB) && defined(HAVE_GLOB_GL_FLAGS_MEMBER) - local_parse_glob(session, p, parsing, seen); + local_parse_glob(session, p, parsing); #else - local_parse_file(session, p, parsing, seen); + local_parse_file(session, p, parsing); #endif /* HAVE_GLOB */ } break; @@ -844,7 +808,6 @@ int ssh_config_parse_file(ssh_session session, const char *filename) unsigned int count = 0; FILE *f; int parsing, rv; - uint8_t *seen = NULL; f = fopen(filename, "r"); if (f == NULL) { @@ -853,23 +816,10 @@ int ssh_config_parse_file(ssh_session session, const char *filename) SSH_LOG(SSH_LOG_PACKET, "Reading configuration data from %s", filename); - /* Preserve the seen array among invocations throughout the session */ - if (session->opts.options_seen == NULL) { - seen = calloc(SOC_END - SOC_UNSUPPORTED, sizeof(uint8_t)); - if (seen == NULL) { - fclose(f); - ssh_set_error_oom(session); - return -1; - } - session->opts.options_seen = seen; - } else { - seen = session->opts.options_seen; - } - parsing = 1; while (fgets(line, sizeof(line), f)) { count++; - rv = ssh_config_parse_line(session, line, count, &parsing, seen); + rv = ssh_config_parse_line(session, line, count, &parsing); if (rv < 0) { fclose(f); return -1; diff --git a/src/session.c b/src/session.c index 48103cba..157fe1e7 100644 --- a/src/session.c +++ b/src/session.c @@ -283,7 +283,6 @@ void ssh_free(ssh_session session) { SAFE_FREE(session->opts.gss_server_identity); SAFE_FREE(session->opts.gss_client_identity); SAFE_FREE(session->opts.pubkey_accepted_types); - SAFE_FREE(session->opts.options_seen); for (i = 0; i < 10; i++) { if (session->opts.wanted_methods[i]) { |