diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:19:51 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:19:51 +0000 |
commit | 1fceffa4348b0e13c7590b0afd3ababfabe0d2ef (patch) | |
tree | c9b3435b375456276123c9d50bf7edd8ce4e48c9 /libssh/options.c | |
parent | 3f4c1976fd19bf3cd47502b422c691b6d4b1ed12 (diff) | |
download | libssh-1fceffa4348b0e13c7590b0afd3ababfabe0d2ef.tar.gz libssh-1fceffa4348b0e13c7590b0afd3ababfabe0d2ef.tar.xz libssh-1fceffa4348b0e13c7590b0afd3ababfabe0d2ef.zip |
Improve ssh_options_set_wanted_algos().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@359 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/options.c')
-rw-r--r-- | libssh/options.c | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/libssh/options.c b/libssh/options.c index 2696f6e..8e1f5ce 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -479,7 +479,10 @@ int ssh_options_set_banner(SSH_OPTIONS *opt, const char *banner) { return 0; } -/** the methods are:\n +/** + * @brief Set the algorithms to be used for cryptography and compression. + * + * The methods are:\n * KEX_HOSTKEY (server public key type) : ssh-rsa or ssh-dss\n * KEX_CRYPT_C_S (symmetric cipher client to server)\n * KEX_CRYPT_S_C (symmetric cipher server to client)\n @@ -488,27 +491,42 @@ int ssh_options_set_banner(SSH_OPTIONS *opt, const char *banner) { * You don't have to use this function if using the default ciphers * is okay for you\n * in order to enable compression client to server, do\n - * ret=ssh_options_set_wanted_algos(opt,KEX_COMP_C_S,"zlib"); - * \brief set the algorithms to be used for cryptography and compression - * \param opt options structure - * \param algo method which needs to be changed - * \param list list of algorithms to be used, in order of preference and separated by commas - * \return 0 on success, -1 on error (most likely an algorithm is not available) + * @code + * ret = ssh_options_set_wanted_algos(opt,KEX_COMP_C_S,"zlib"); + * @endcode + * + * @param opt The options structure to use. + * + * @param algo The method which needs to be changed. + * + * @param list A list of algorithms to be used, in order of preference + * and separated by commas. + * + * @return 0 on success, < 0 on error */ -int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list){ - if(algo > SSH_LANG_S_C || algo < 0){ - ssh_set_error(opt,SSH_REQUEST_DENIED,"algo %d out of range",algo); - return -1; - } - if( (!opt->use_nonexisting_algo) && !verify_existing_algo(algo,list)){ - ssh_set_error(opt,SSH_REQUEST_DENIED,"Setting method : no algorithm " - "for method \"%s\" (%s)\n",ssh_kex_nums[algo],list); - return -1; - } - if(opt->wanted_methods[algo]) - free(opt->wanted_methods[algo]); - opt->wanted_methods[algo]=strdup(list); - return 0; +int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list) { + if (opt == NULL || list == NULL) { + return -1; + } + + if(algo > SSH_LANG_S_C || algo < 0) { + ssh_set_error(opt, SSH_REQUEST_DENIED, "algo %d out of range", algo); + return -1; + } + + if ((!opt->use_nonexisting_algo) && !verify_existing_algo(algo, list)) { + ssh_set_error(opt, SSH_REQUEST_DENIED, "Setting method: no algorithm " + "for method \"%s\" (%s)\n", ssh_kex_nums[algo], list); + return -1; + } + + SAFE_FREE(opt->wanted_methods[algo]); + opt->wanted_methods[algo] = strdup(list); + if (opt->wanted_methods[algo] == NULL) { + return -1; + } + + return 0; } #ifndef _WIN32 |