diff options
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | doc/api-auth.texi | 14 | ||||
| -rw-r--r-- | ssh/auth.c | 64 |
4 files changed, 77 insertions, 11 deletions
@@ -1,5 +1,14 @@ 2014-07-06 Artyom Poptsov <poptsov.artyom@gmail.com> + * ssh/auth.c (guile_ssh_userauth_public_key_x) + (guile_ssh_userauth_public_key_auto_x) + (guile_ssh_userauth_public_key_try, guile_ssh_userauth_agent_x) + (guile_ssh_userauth_password_x, guile_ssh_userauth_none_x) + (guile_ssh_userauth_get_list): Throw `guile-ssh-error' if the session + is not connected. + * doc/api-auth.texi (Auth): Update. + * NEWS: Update. + * ssh/auth.c, ssh/channel-func.c, ssh/channel-type.c, ssh/key-func.c, ssh/key-type.c, ssh/log.c, ssh/message-func.c, ssh/message-type.c, ssh/server-func.c, ssh/session-type.c, ssh/version.c: Improve the @@ -14,6 +14,7 @@ Copyright (C) Artyom V. Poptsov <poptsov.artyom@gmail.com> *** Accept a public key as the first argument *** Accept a hash type as the second argument Possible types are: 'md5, 'sha1 +** (ssh auth) procedures now throw an exception if the session is not connected ** Change `userauth-pubkey!' *** Rename it to `userauth-public-key!' *** Change arguments diff --git a/doc/api-auth.texi b/doc/api-auth.texi index 9ad8f24..b2c5a76 100644 --- a/doc/api-auth.texi +++ b/doc/api-auth.texi @@ -18,6 +18,8 @@ calling of procedures from this section. @deffn {Scheme Procedure} userauth-public-key! session private-key Try to authenticate with a public/private key. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + Return one of the following symbols: @table @samp @@ -42,6 +44,8 @@ key from a @acronym{SSH} agent and if it fails it will try to read a key from a file. If the key is encrypted the user will be asked for a passphrase. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + Return one of the following symbols: @table @samp @@ -61,6 +65,8 @@ A serious error happened. @deffn {Scheme Procedure} userauth-public-key/try session public-key Try to authenticate with the given @var{public-key}. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + To avoid unnecessary processing and user interaction, the following method is provided for querying whether authentication using the @var{public-key} would be possible. @@ -85,6 +91,8 @@ A serious error happened. @deffn {Scheme Procedure} userauth-agent! session Try to do public key authentication with ssh agent. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + Return one of the following symbols: @table @samp @@ -104,6 +112,8 @@ A serious error happened. @deffn {Scheme Procedure} userauth-password! session password Try to authenticate by @var{password}. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + Return one of the following symbols: @table @samp @@ -125,6 +135,8 @@ In nonblocking mode, you've got to call this again later. @deffn {Scheme Procedure} userauth-none! session Try to authenticate through the @code{none} method. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + Return one of the following symbols: @table @samp @@ -146,6 +158,8 @@ A serious error happened. Get available authentication methods for a @var{session}. Return list of available methods. +Throw @code{guile-ssh-error} if the @var{session} is not connected. + This call will block, even in nonblocking mode, if run for the first time before a (complete) call to @code{userauth-none!}. @@ -71,7 +71,8 @@ SCM_DEFINE (guile_ssh_userauth_public_key_x, "userauth-public-key!", 2, 0, 0, (SCM session_smob, SCM private_key_smob), "\ -Try to authenticate with a public key.\ +Try to authenticate with a public key.\n\ +Throw `guile-ssh-error' if the SESSION is not connected.\ ") #define FUNC_NAME s_guile_ssh_userauth_public_key_x { @@ -88,6 +89,9 @@ Try to authenticate with a public key.\ SCM_ASSERT (_private_key_p (private_key_data), private_key_smob, SCM_ARG2, FUNC_NAME); + if (! ssh_is_connected (session_data->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session_smob); + res = ssh_userauth_publickey (session_data->ssh_session, username, private_key_data->ssh_key); @@ -102,13 +106,19 @@ SCM_DEFINE (guile_ssh_userauth_public_key_auto_x, Try to automatically authenticate with \"none\" method first and then with \n\ public keys. If the key is encrypted the user will be asked for a \n\ passphrase. Return one of the following symbols: error, denied, partial, \n\ -success.\ +success.\n\ +\n\ +Throw `guile-ssh-error' if the SESSION is not connected.\ ") #define FUNC_NAME s_guile_ssh_userauth_public_key_auto_x { struct session_data *sd = _scm_to_session_data (session); char *username = NULL; /* See "On the username" commentary above. */ char *passphrase = NULL; + + if (! ssh_is_connected (sd->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session); + int res = ssh_userauth_publickey_auto (sd->ssh_session, username, passphrase); /* passphrase */ @@ -119,7 +129,9 @@ success.\ SCM_DEFINE (guile_ssh_userauth_public_key_try, "userauth-public-key/try", 2, 0, 0, (SCM session, SCM public_key), - "") + "\ +Throw `guile-ssh-error' if the SESSION is not connected.\ +") #define FUNC_NAME s_guile_ssh_userauth_public_key_try { struct session_data *sd = _scm_to_session_data (session); @@ -129,6 +141,9 @@ SCM_DEFINE (guile_ssh_userauth_public_key_try, SCM_ASSERT (_public_key_p (kd), public_key, SCM_ARG2, FUNC_NAME); + if (! ssh_is_connected (sd->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session); + res = ssh_userauth_try_publickey (sd->ssh_session, username, kd->ssh_key); return ssh_auth_result_to_symbol (res); } @@ -138,13 +153,20 @@ SCM_DEFINE (guile_ssh_userauth_agent_x, "userauth-agent!", 1, 0, 0, (SCM session), /* FIXME: Fix the docsring. */ - "") + "\ +Throw `guile-ssh-error' if the SESSION is not connected.\ +") #define FUNC_NAME s_guile_ssh_userauth_agent_x { struct session_data *sd = _scm_to_session_data (session); char *username = NULL; /* See "On the username" commentary above. */ - int res = ssh_userauth_agent (sd->ssh_session, username); + int res; + + if (! ssh_is_connected (sd->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session); + + res = ssh_userauth_agent (sd->ssh_session, username); return ssh_auth_result_to_symbol (res); } @@ -154,7 +176,8 @@ SCM_DEFINE (guile_ssh_userauth_agent_x, SCM_DEFINE (guile_ssh_userauth_password_x, "userauth-password!", 2, 0, 0, (SCM session, SCM password), "\ -Try to authenticate by password.\ +Try to authenticate by password.\n\ +Throw `guile-ssh-error' if the SESSION is not connected.\ ") #define FUNC_NAME s_guile_ssh_userauth_password_x { @@ -171,6 +194,9 @@ Try to authenticate by password.\ /* Check types. */ SCM_ASSERT (scm_is_string (password), password, SCM_ARG2, FUNC_NAME); + if (! ssh_is_connected (session_data->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session); + c_password = scm_to_locale_string (password); scm_dynwind_free (c_password); @@ -192,15 +218,24 @@ Try to authenticate by password.\ SCM_DEFINE (guile_ssh_userauth_none_x, "userauth-none!", 1, 0, 0, (SCM arg1), "\ -Try to authenticate through the \"none\" method.\ +Try to authenticate through the \"none\" method.\n\ +Throw `guile-ssh-error' if the SESSION is not connected.\ ") +#define FUNC_NAME s_guile_ssh_userauth_none_x { struct session_data *session_data = _scm_to_session_data (arg1); + int res; + + if (! ssh_is_connected (session_data->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", arg1); + /* username is deprecated parameter. Should be set to NULL. */ - int res = ssh_userauth_none (session_data->ssh_session, - NULL); /* Username */ + res = ssh_userauth_none (session_data->ssh_session, + NULL); /* Username */ + return ssh_auth_result_to_symbol (res); } +#undef FUNC_NAME /* Get available authentication methods for a session SESSION_SMOB. @@ -208,16 +243,22 @@ Try to authenticate through the \"none\" method.\ SCM_DEFINE (guile_ssh_userauth_get_list, "userauth-get-list", 1, 0, 0, (SCM session), "\ -Get available authentication methods for a session SESSION.\ +Get available authentication methods for a session SESSION.\n\ +Throw `guile-ssh-error' if the SESSION is not connected.\ ") +#define FUNC_NAME s_guile_ssh_userauth_get_list { struct session_data *session_data = _scm_to_session_data (session); SCM auth_list = SCM_EOL; + int res; + + if (! ssh_is_connected (session_data->ssh_session)) + guile_ssh_error1 (FUNC_NAME, "Session is not connected", session); /* 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. */ - int res = ssh_userauth_list (session_data->ssh_session, NULL); + res = ssh_userauth_list (session_data->ssh_session, NULL); if (res & SSH_AUTH_METHOD_PASSWORD) { @@ -245,6 +286,7 @@ Get available authentication methods for a session SESSION.\ return auth_list; } +#undef FUNC_NAME /* Initialization */ |
