diff options
author | Jakub Jelen <jjelen@redhat.com> | 2018-12-05 11:12:31 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-12-07 14:07:31 +0100 |
commit | 993e24a361b69e3f5315ece9480bae3aa000fe8f (patch) | |
tree | 0daa5eb032f8b54aa85dc015efed4c0a155ac193 | |
parent | cf6f1e7a6463213cbc1d1104f03ad35f266170a5 (diff) | |
download | libssh-993e24a361b69e3f5315ece9480bae3aa000fe8f.tar.gz libssh-993e24a361b69e3f5315ece9480bae3aa000fe8f.tar.xz libssh-993e24a361b69e3f5315ece9480bae3aa000fe8f.zip |
config: Reformat ssh_config_parse_file
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | src/config.c | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/src/config.c b/src/config.c index 7461d7d9..c5c992bb 100644 --- a/src/config.c +++ b/src/config.c @@ -825,43 +825,51 @@ static int ssh_config_parse_line(ssh_session session, const char *line, return 0; } -/* ssh_config_parse_file */ +/* @brief Parse configuration file and set the options to the given session + * + * @params[in] session The ssh session + * @params[in] filename The path to the ssh configuration file + * + * @returns 0 on successful parsing the configuration file, -1 on error + */ int ssh_config_parse_file(ssh_session session, const char *filename) { - char line[MAX_LINE_SIZE] = {0}; - unsigned int count = 0; - FILE *f; - int parsing; - uint8_t *seen = NULL; - - if ((f = fopen(filename, "r")) == NULL) { - return 0; - } + char line[MAX_LINE_SIZE] = {0}; + unsigned int count = 0; + FILE *f; + int parsing, rv; + uint8_t *seen = NULL; + + f = fopen(filename, "r"); + if (f == NULL) { + return 0; + } - SSH_LOG(SSH_LOG_PACKET, "Reading configuration data from %s", 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; + /* 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; } - session->opts.options_seen = seen; - } else { - seen = session->opts.options_seen; - } - parsing = 1; - while (fgets(line, sizeof(line), f)) { - count++; - if (ssh_config_parse_line(session, line, count, &parsing, seen) < 0) { - fclose(f); - return -1; + parsing = 1; + while (fgets(line, sizeof(line), f)) { + count++; + rv = ssh_config_parse_line(session, line, count, &parsing, seen); + if (rv < 0) { + fclose(f); + return -1; + } } - } - fclose(f); - return 0; + fclose(f); + return 0; } |