summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--doc/api-auth.texi17
-rw-r--r--ssh/auth.c35
-rw-r--r--ssh/session-type.h8
4 files changed, 33 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 28d9591..ec8e7cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-07-07 Artyom Poptsov <poptsov.artyom@gmail.com>
+
+ * ssh/auth.c: Throw `wrong-type-arg' instead of `guile-ssh-error' if a
+ disconnected session is passed as an argument to procedures in the
+ module.
+ * ssh/session-type.h (GSSH_VALIDATE_CONNECTED_SESSION): New macro.
+ * doc/api-auth.texi (Auth): Update.
+
2014-07-06 Artyom Poptsov <poptsov.artyom@gmail.com>
* ssh/auth.c (guile_ssh_userauth_public_key_x)
diff --git a/doc/api-auth.texi b/doc/api-auth.texi
index b2c5a76..b2975d2 100644
--- a/doc/api-auth.texi
+++ b/doc/api-auth.texi
@@ -15,11 +15,12 @@ Please note that you must specify a username either on creation of a
session or by @code{session-set!} call (@pxref{Sessions}) before
calling of procedures from this section.
+Also @strong{note} that the session must be connected before calling to these
+procedures, otherwise the @code{wrong-type-arg} exception will be thrown.
+
@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
@@ -44,8 +45,6 @@ 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
@@ -65,8 +64,6 @@ 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.
@@ -91,8 +88,6 @@ 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
@@ -112,8 +107,6 @@ 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
@@ -135,8 +128,6 @@ 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
@@ -158,8 +149,6 @@ 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!}.
diff --git a/ssh/auth.c b/ssh/auth.c
index 668cefb..0c7f2b7 100644
--- a/ssh/auth.c
+++ b/ssh/auth.c
@@ -72,7 +72,7 @@ SCM_DEFINE (guile_ssh_userauth_public_key_x, "userauth-public-key!", 2, 0, 0,
SCM private_key_smob),
"\
Try to authenticate with a public key.\n\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_public_key_x
{
@@ -86,12 +86,10 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
int res;
/* Check types. */
+ GSSH_VALIDATE_CONNECTED_SESSION (session_data, session_smob, SCM_ARG1);
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);
@@ -108,7 +106,7 @@ 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.\n\
\n\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_public_key_auto_x
{
@@ -116,8 +114,7 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
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);
+ GSSH_VALIDATE_CONNECTED_SESSION (sd, session, SCM_ARG1);
int res = ssh_userauth_publickey_auto (sd->ssh_session,
username,
@@ -130,7 +127,7 @@ 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.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_public_key_try
{
@@ -139,6 +136,7 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
char *username = NULL; /* See "On the username" commentary above */
int res;
+ GSSH_VALIDATE_CONNECTED_SESSION (sd, session, SCM_ARG1);
SCM_ASSERT (_public_key_p (kd), public_key, SCM_ARG2, FUNC_NAME);
if (! ssh_is_connected (sd->ssh_session))
@@ -154,7 +152,7 @@ SCM_DEFINE (guile_ssh_userauth_agent_x,
(SCM session),
/* FIXME: Fix the docsring. */
"\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_agent_x
{
@@ -163,8 +161,7 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
char *username = NULL; /* See "On the username" commentary above. */
int res;
- if (! ssh_is_connected (sd->ssh_session))
- guile_ssh_error1 (FUNC_NAME, "Session is not connected", session);
+ GSSH_VALIDATE_CONNECTED_SESSION (sd, session, SCM_ARG1);
res = ssh_userauth_agent (sd->ssh_session, username);
@@ -177,7 +174,7 @@ SCM_DEFINE (guile_ssh_userauth_password_x, "userauth-password!", 2, 0, 0,
(SCM session, SCM password),
"\
Try to authenticate by password.\n\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_password_x
{
@@ -192,11 +189,9 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
scm_dynwind_begin (0);
/* Check types. */
+ GSSH_VALIDATE_CONNECTED_SESSION (session_data, session, SCM_ARG1);
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);
@@ -219,15 +214,14 @@ SCM_DEFINE (guile_ssh_userauth_none_x, "userauth-none!", 1, 0, 0,
(SCM arg1),
"\
Try to authenticate through the \"none\" method.\n\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#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);
+ GSSH_VALIDATE_CONNECTED_SESSION (session_data, arg1, SCM_ARG1);
/* username is deprecated parameter. Should be set to NULL. */
res = ssh_userauth_none (session_data->ssh_session,
@@ -244,7 +238,7 @@ SCM_DEFINE (guile_ssh_userauth_get_list, "userauth-get-list", 1, 0, 0,
(SCM session),
"\
Get available authentication methods for a session SESSION.\n\
-Throw `guile-ssh-error' if the SESSION is not connected.\
+Throw `wrong-type-arg' if a disconnected SESSION is passed as an argument.\
")
#define FUNC_NAME s_guile_ssh_userauth_get_list
{
@@ -252,8 +246,7 @@ Throw `guile-ssh-error' if the SESSION is not connected.\
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);
+ GSSH_VALIDATE_CONNECTED_SESSION (session_data, session, SCM_ARG1);
/* The second argument of the function is a username. According to
the documentation for libssh 0.5.3, this argument is deprecated
diff --git a/ssh/session-type.h b/ssh/session-type.h
index 3801a53..93cd28d 100644
--- a/ssh/session-type.h
+++ b/ssh/session-type.h
@@ -36,6 +36,14 @@ struct session_data {
struct channel_data **channels;
};
+/* Make sure that the session pointed by session data structure pointer SD is
+ connected. */
+#define GSSH_VALIDATE_CONNECTED_SESSION(sd, scm, pos) \
+ do { \
+ SCM_ASSERT_TYPE (ssh_is_connected (sd->ssh_session), scm, \
+ pos, FUNC_NAME, "connected session"); \
+ } while (0)
+
extern SCM guile_ssh_make_session (void);
extern SCM guile_ssh_is_session_p (SCM arg1);