aboutsummaryrefslogtreecommitdiff
path: root/src/options.c
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-03-07 17:00:44 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-04-01 08:38:17 +0200
commitfd25beff68a8c61c62a1f43eb1c53d50a7390180 (patch)
tree7fc29d461cb4a870df64c627d7a84598a08c2272 /src/options.c
parentbab4d2b77b820961bc4b6ba081af27673f139b7a (diff)
downloadlibssh-fd25beff68a8c61c62a1f43eb1c53d50a7390180.tar.gz
libssh-fd25beff68a8c61c62a1f43eb1c53d50a7390180.tar.xz
libssh-fd25beff68a8c61c62a1f43eb1c53d50a7390180.zip
options: Introduce ssh_bind_options_parse_config()
The added API allows setting the options of a given bind context through a configuration file. The default global configuration file "/etc/ssh/libssh_server_config" is parsed before the provided configuration file, if it hasn't been parsed yet. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/options.c b/src/options.c
index bdbdcb0e..a61f8a48 100644
--- a/src/options.c
+++ b/src/options.c
@@ -39,6 +39,7 @@
#ifdef WITH_SERVER
#include "libssh/server.h"
#include "libssh/bind.h"
+#include "libssh/bind_config.h"
#endif
/**
@@ -1894,6 +1895,49 @@ int ssh_bind_options_set(ssh_bind sshbind, enum ssh_bind_options_e type,
return 0;
}
+
+/**
+ * @brief Parse a ssh bind options configuration file.
+ *
+ * This parses the options file and set them to the ssh_bind handle provided. If
+ * an option was previously set, it is overridden. If the global configuration
+ * hasn't been processed yet, it is processed prior to the provided file.
+ *
+ * @param sshbind SSH bind handle
+ *
+ * @param filename The options file to use; if NULL only the global
+ * configuration is parsed and applied (if it haven't been
+ * processed before).
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int ssh_bind_options_parse_config(ssh_bind sshbind, const char *filename)
+{
+ int rc = 0;
+
+ if (sshbind == NULL) {
+ return -1;
+ }
+
+ /* If the global default configuration hasn't been processed yet, process it
+ * before the provided configuration. */
+ if (!(sshbind->config_processed)) {
+ rc = ssh_bind_config_parse_file(sshbind,
+ "/etc/ssh/libssh_server_config");
+ if (rc != 0) {
+ return rc;
+ }
+ sshbind->config_processed = true;
+ }
+
+ if (filename != NULL) {
+ /* Apply the user provided configuration */
+ rc = ssh_bind_config_parse_file(sshbind, filename);
+ }
+
+ return rc;
+}
+
#endif
/** @} */