From 3fab89b22fb1c39865ab6b71ab79d663923e724f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 9 Apr 2009 11:07:31 +0000 Subject: [PATCH] Improve ssh_message_auth* functions. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@442 7dcaeef0-15fb-0310-b436-a5af3365683c --- include/libssh/server.h | 2 +- libssh/messages.c | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/libssh/server.h b/include/libssh/server.h index 76a64f00..477f9d7e 100644 --- a/include/libssh/server.h +++ b/include/libssh/server.h @@ -80,7 +80,7 @@ void ssh_message_free(SSH_MESSAGE *msg); char *ssh_message_auth_user(SSH_MESSAGE *msg); char *ssh_message_auth_password(SSH_MESSAGE *msg); int ssh_message_auth_reply_success(SSH_MESSAGE *msg,int partial); -void ssh_message_auth_set_methods(SSH_MESSAGE *msg, int methods); +int ssh_message_auth_set_methods(SSH_MESSAGE *msg, int methods); CHANNEL *ssh_message_channel_request_open_reply_accept(SSH_MESSAGE *msg); diff --git a/libssh/messages.c b/libssh/messages.c index 1fdf6854..65d9550d 100644 --- a/libssh/messages.c +++ b/libssh/messages.c @@ -211,16 +211,30 @@ error: return NULL; } -char *ssh_message_auth_user(SSH_MESSAGE *msg){ - return msg->auth_request.username; +char *ssh_message_auth_user(SSH_MESSAGE *msg) { + if (msg == NULL || msg->auth_request == NULL) { + return NULL; + } + + return msg->auth_request.username; } char *ssh_message_auth_password(SSH_MESSAGE *msg){ - return msg->auth_request.password; + if (msg == NULL || msg->auth_request == NULL) { + return NULL; + } + + return msg->auth_request.password; } -void ssh_message_auth_set_methods(SSH_MESSAGE *msg,int methods){ - msg->session->auth_methods=methods; +int ssh_message_auth_set_methods(SSH_MESSAGE *msg, int methods) { + if (msg == NULL || msg->session == NULL) { + return -1; + } + + msg->session->auth_methods = methods; + + return 0; } static int ssh_message_auth_reply_default(SSH_MESSAGE *msg,int partial){