summaryrefslogtreecommitdiffstats
path: root/libssh/options.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-09-08 11:33:46 +0200
committerAndreas Schneider <mail@cynapses.org>2009-09-15 17:26:13 +0200
commit48456426112eefd3a852138d9c9e3eb4cf84d29b (patch)
treec7fc17fb7197979d4f4160b6d56035880d59ae1e /libssh/options.c
parentde8808cb47470638359dc7eb8343552d3b94ec38 (diff)
downloadlibssh-48456426112eefd3a852138d9c9e3eb4cf84d29b.tar.gz
libssh-48456426112eefd3a852138d9c9e3eb4cf84d29b.tar.xz
libssh-48456426112eefd3a852138d9c9e3eb4cf84d29b.zip
Added support for ~/.ssh/config.
Diffstat (limited to 'libssh/options.c')
-rw-r--r--libssh/options.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libssh/options.c b/libssh/options.c
index 4e22b77..5d21408 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -1018,5 +1018,40 @@ int ssh_options_set_auth_callback(SSH_OPTIONS *opt, ssh_auth_callback cb,
return 0;
}
+/**
+ * @brief Parse the ssh config file.
+ *
+ * This must be the last call of all options, it may overwrite options which
+ * are already set. It requires at least the hostname to be set.
+ *
+ * @param opt The options structure to use.
+ *
+ * @param filename The options file to use, if NULL the default
+ * ~/.ssh/config will be used.
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int ssh_options_parse_config(ssh_options opt, const char *filename) {
+ char buffer[1024] = {0};
+
+ if (opt == NULL || opt->host == NULL) {
+ return -1;
+ }
+
+ if (opt->ssh_dir == NULL) {
+ if (ssh_options_default_ssh_dir(opt) < 0) {
+ return -1;
+ }
+ }
+
+ /* set default filename */
+ if (filename == NULL) {
+ snprintf(buffer, 1024, "%s/config", opt->ssh_dir);
+ filename = buffer;
+ }
+
+ return ssh_config_parse_file(opt, filename);
+}
+
/** @} */
/* vim: set ts=2 sw=2 et cindent: */