diff options
| author | Artyom Poptsov <poptsov.artyom@gmail.com> | 2013-06-16 21:06:26 +0400 |
|---|---|---|
| committer | Artyom Poptsov <poptsov.artyom@gmail.com> | 2013-06-16 21:07:32 +0400 |
| commit | 94622bf8e9cfba6eb6e907c2cd62cbc2e5719ed9 (patch) | |
| tree | 36e8c86f1bb5e963edda6ba0a2d63ae1d32be7c7 /src | |
| parent | src/key-func.c: Fix a comment. (diff) | |
| download | guile-ssh-94622bf8e9cfba6eb6e907c2cd62cbc2e5719ed9.tar.gz | |
src/auth.{c,h,scm}: Implement ssh:userauth-get-list.
Implement ssh:userauth-get-list that returns a list of available
authentication methods for a given SSH session.
* src/auth.c (guile_ssh_userauth_get_list): New function.
(init_auth_func): Define ssh:userauth-get-list.
* src/auth.h: Likewise.
* src/auth.scm: Add ssh:userauth-get-list.
Diffstat (limited to 'src')
| -rw-r--r-- | src/auth.c | 49 | ||||
| -rw-r--r-- | src/auth.h | 1 | ||||
| -rw-r--r-- | src/auth.scm | 3 |
3 files changed, 52 insertions, 1 deletions
@@ -180,6 +180,52 @@ guile_ssh_userauth_none (SCM session_smob) return ssh_auth_result_to_symbol (res); } +/* Get available authentication methods for a session SESSION_SMOB. + + Return list of available methods. */ +SCM +guile_ssh_userauth_get_list (SCM session_smob) +{ + struct session_data *session_data; + SCM auth_list = SCM_EOL; + int res; + + scm_assert_smob_type (session_tag, session_smob); + + session_data = (struct session_data *) SCM_SMOB_DATA (session_smob); + + /* The second argument of the function is a username. According to + the documentation for libssh 0.5.3, this argument is deprecated + and must be set to NULL. */ + res = ssh_userauth_list (session_data->ssh_session, NULL); + + if (res & SSH_AUTH_METHOD_PASSWORD) + { + SCM method = scm_from_locale_symbol ("password"); + auth_list = scm_append (scm_list_2 (auth_list, method)); + } + + if (res & SSH_AUTH_METHOD_PUBLICKEY) + { + SCM method = scm_from_locale_symbol ("public-key"); + auth_list = scm_append (scm_list_2 (auth_list, method)); + } + + if (res & SSH_AUTH_METHOD_HOSTBASED) + { + SCM method = scm_from_locale_symbol ("host-based"); + auth_list = scm_append (scm_list_2 (auth_list, method)); + } + + if (res & SSH_AUTH_METHOD_INTERACTIVE) + { + SCM method = scm_from_locale_symbol ("interactive"); + auth_list = scm_append (scm_list_2 (auth_list, method)); + } + + return auth_list; +} + /* Initialization */ void @@ -191,6 +237,9 @@ init_auth_func (void) guile_ssh_userauth_password); scm_c_define_gsubr ("ssh:userauth-none!", 1, 0, 0, guile_ssh_userauth_none); + + scm_c_define_gsubr ("ssh:userauth-get-list", 1, 0, 0, + guile_ssh_userauth_get_list); } /* auth.c ends here */ @@ -22,6 +22,7 @@ extern SCM guile_ssh_userauth_pubkey (SCM arg1, SCM arg2, SCM arg3, SCM arg4); extern SCM guile_ssh_userauth_password (SCM arg1, SCM arg2, SCM arg3); extern SCM guile_ssh_userauth_none (SCM arg1); +extern SCM guile_ssh_userauth_get_list (SCM arg1); extern void init_auth_func (void); diff --git a/src/auth.scm b/src/auth.scm index 556f405..f701574 100644 --- a/src/auth.scm +++ b/src/auth.scm @@ -36,7 +36,8 @@ #:use-module (ssh session) #:export (ssh:userauth-pubkey! ssh:userauth-password! - ssh:userauth-none!)) + ssh:userauth-none! + ssh:userauth-get-list)) (load-extension "libguile-ssh" "init_auth_func") |
