diff --git a/include/libssh2.h b/include/libssh2.h index 75c563ed..cf7cae1e 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -503,6 +503,7 @@ typedef struct _LIBSSH2_POLLFD { #define LIBSSH2_ERROR_KNOWN_HOSTS -46 #define LIBSSH2_ERROR_CHANNEL_WINDOW_FULL -47 #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48 +#define LIBSSH2_ERROR_MISSING_AUTH_BANNER -49 /* this is a define to provide the old (<= 1.2.7) name */ #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV @@ -611,8 +612,8 @@ LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session); LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len); -LIBSSH2_API char *libssh2_userauth_banner(LIBSSH2_SESSION * session, - size_t *banner_len_out); +LIBSSH2_API int libssh2_userauth_banner(LIBSSH2_SESSION* session, + char **banner_out); LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session); LIBSSH2_API int diff --git a/src/userauth.c b/src/userauth.c index 1e37b9a0..39896607 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -237,24 +237,25 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user, * * Retrieve banner message from server, if available. * If no such message is sent by the server or if no authentication attempt has - * been made, this function returns NULL. + * been made, this function returns LIBSSH2_ERROR_MISSING_AUTH_BANNER. * libssh2_userauth_list makes a "none" authentication attempt and is * sufficient to collect the pre-auth banner message. * * Banner ought to be UTF-8 encoded, and will be truncated to - * LIBSSH2_USERAUTH_MAX_BANNER bytes. Length will be returned in - * banner_len_out. + * LIBSSH2_USERAUTH_MAX_BANNER bytes. */ -LIBSSH2_API char * -libssh2_userauth_banner(LIBSSH2_SESSION * session, - size_t *banner_len_out) +LIBSSH2_API int +libssh2_userauth_banner(LIBSSH2_SESSION* session, + char **banner_out) { - char *ptr = NULL; - if(session->userauth_banner) { - ptr = session->userauth_banner; - *banner_len_out = session->userauth_banner_len; + if(!session->userauth_banner) { + return _libssh2_error(session, + LIBSSH2_ERROR_MISSING_AUTH_BANNER, + "Missing authentication banner"); } - return ptr; + + *banner_out = session->userauth_banner; + return LIBSSH2_ERROR_NONE; } /*