aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-04-15 19:14:15 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-04-15 19:14:15 +0200
commit8b95328b1b397f425bf30d51da6a5c12a458f3ff (patch)
treea41800cdd5b32b36c708e764d6f64c15e38a0129
parent644145a88caf0ff9cbfa16902c775b922578357b (diff)
downloadlibssh-8b95328b1b397f425bf30d51da6a5c12a458f3ff.tar.gz
libssh-8b95328b1b397f425bf30d51da6a5c12a458f3ff.tar.xz
libssh-8b95328b1b397f425bf30d51da6a5c12a458f3ff.zip
poll: Fix poll input events.
bug#38
-rw-r--r--src/poll.c4
-rw-r--r--src/session.c2
-rw-r--r--src/socket.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/src/poll.c b/src/poll.c
index 094d839..ed2924c 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -303,7 +303,7 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
*
* @param fd Socket that will be polled.
* @param events Poll events that will be monitored for the socket. i.e.
- * POLLIN, POLLPRI, POLLOUT, POLLERR, POLLHUP, POLLNVAL
+ * POLLIN, POLLPRI, POLLOUT
* @param cb Function to be called if any of the events are set.
* The prototype of cb is:
* int (*ssh_poll_callback)(ssh_poll_handle p, socket_t fd,
@@ -750,7 +750,7 @@ static int ssh_event_fd_wrapper_callback(ssh_poll_handle p, socket_t fd, int rev
* @param event The ssh_event
* @param fd Socket that will be polled.
* @param events Poll events that will be monitored for the socket. i.e.
- * POLLIN, POLLPRI, POLLOUT, POLLERR, POLLHUP, POLLNVAL
+ * POLLIN, POLLPRI, POLLOUT
* @param cb Function to be called if any of the events are set.
* The prototype of cb is:
* int (*ssh_event_callback)(socket_t fd, int revents,
diff --git a/src/session.c b/src/session.c
index 4623b4b..18688c6 100644
--- a/src/session.c
+++ b/src/session.c
@@ -421,7 +421,7 @@ int ssh_handle_packets(ssh_session session, int timeout) {
spoll_in=ssh_socket_get_poll_handle_in(session->socket);
spoll_out=ssh_socket_get_poll_handle_out(session->socket);
if(session->server)
- ssh_poll_add_events(spoll_in, POLLIN | POLLERR);
+ ssh_poll_add_events(spoll_in, POLLIN);
ctx=ssh_poll_get_ctx(spoll_in);
if(ctx==NULL){
ctx=ssh_poll_get_default_ctx(session);
diff --git a/src/socket.c b/src/socket.c
index fa7ed52..5097be9 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -270,7 +270,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
if(s->state == SSH_SOCKET_CONNECTING){
ssh_log(s->session,SSH_LOG_PACKET,"Received POLLOUT in connecting state");
s->state = SSH_SOCKET_CONNECTED;
- ssh_poll_set_events(p,POLLOUT | POLLIN | POLLERR);
+ ssh_poll_set_events(p,POLLOUT | POLLIN);
ssh_sock_set_blocking(ssh_socket_get_fd_in(s));
if(s->callbacks && s->callbacks->connected)
s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,0,s->callbacks->userdata);
ld } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* auth1.c deals with authentication with SSH-1 protocol */
/*
Copyright (c) 2005-2008 Aris Adamantiadis

This file is part of the SSH Library

The SSH Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.

The SSH Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the SSH Library; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */

#include "libssh/priv.h"
#include "libssh/ssh1.h"
#include <string.h>
#include <stdlib.h>

/*
static void burn(char *ptr){
    if(ptr)
        memset(ptr,'X',strlen(ptr));
}
*/
#ifdef HAVE_SSH1
static int wait_auth1_status(SSH_SESSION *session){
    /* wait for a packet */
    if(packet_read(session))
        return SSH_AUTH_ERROR;
    if(packet_translate(session))
        return SSH_AUTH_ERROR;
    switch(session->in_packet.type){
        case SSH_SMSG_SUCCESS:
            return SSH_AUTH_SUCCESS;
        case SSH_SMSG_FAILURE:
            return SSH_AUTH_DENIED;
    }
    ssh_set_error(session,SSH_FATAL,"Was waiting for a SUCCESS or "
    "FAILURE, got %d",session->in_packet.type);
    return SSH_AUTH_ERROR;
}
static int send_username(SSH_SESSION *session, char *username){
    STRING *user;
    /* returns SSH_AUTH_SUCCESS or SSH_AUTH_DENIED */
    if(session->auth_service_asked)
        return session->auth_service_asked;
    buffer_add_u8(session->out_buffer,SSH_CMSG_USER);
    if(!username)
        if(!(username=session->options->username)){
            if(ssh_options_default_username(session->options))
                return session->auth_service_asked=SSH_AUTH_ERROR;
            else
                username=session->options->username;
        }
    user=string_from_char(username);
    buffer_add_ssh_string(session->out_buffer,user);
    free(user);
    packet_send(session);
    session->auth_service_asked=wait_auth1_status(session);
    return session->auth_service_asked;
}

/* use the "none" authentication question */

int ssh_userauth1_none(SSH_SESSION *session,char *username){
    return send_username(session,username);
}

/*
int ssh_userauth_offer_pubkey(SSH_SESSION *session, char *username,int type, STRING *publickey){
    STRING *user;
    STRING *service;
    STRING *method;
    STRING *algo;
    int err=SSH_AUTH_ERROR;
    if(!username)
        if(!(username=session->options->username)){
            if(options_default_username(session->options))
                return SSH_AUTH_ERROR;
            else
                username=session->options->username;
        }
    if(ask_userauth(session))
        return SSH_AUTH_ERROR;
    user=string_from_char(username);
    service=string_from_char("ssh-connection");
    method=string_from_char("publickey");
    algo=string_from_char(ssh_type_to_char(type));

    packet_clear_out(session);
    buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_REQUEST);
    buffer_add_ssh_string(session->out_buffer,user);
    buffer_add_ssh_string(session->out_buffer,service);
    buffer_add_ssh_string(session->out_buffer,method);
    buffer_add_u8(session->out_buffer,0);
    buffer_add_ssh_string(session->out_buffer,algo);
    buffer_add_ssh_string(session->out_buffer,publickey);
    packet_send(session);
    err=wait_auth_status(session,0);
    free(user);
    free(method);
    free(service);
    free(algo);
    return err;
}
*/
/** \internal
 * \todo implement ssh1 public key
 */
int ssh_userauth1_offer_pubkey(SSH_SESSION *session, char *username, int type,
        STRING *pubkey){
    return SSH_AUTH_DENIED;
}

/*
int ssh_userauth_pubkey(SSH_SESSION *session, char *username, STRING *publickey, PRIVATE_KEY *privatekey){
    STRING *user;
    STRING *service;
    STRING *method;
    STRING *algo;
    STRING *sign;
    int err=SSH_AUTH_ERROR;
    if(!username)
        if(!(username=session->options->username)){
            if(options_default_username(session->options))
                return err;
            else
                username=session->options->username;
        }
    if(ask_userauth(session))
        return err;
    user=string_from_char(username);
    service=string_from_char("ssh-connection");
    method=string_from_char("publickey");
    algo=string_from_char(ssh_type_to_char(privatekey->type));


*/    /* we said previously the public key was accepted */
/*    packet_clear_out(session);
    buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_REQUEST);
    buffer_add_ssh_string(session->out_buffer,user);
    buffer_add_ssh_string(session->out_buffer,service);
    buffer_add_ssh_string(session->out_buffer,method);
    buffer_add_u8(session->out_buffer,1);
    buffer_add_ssh_string(session->out_buffer,algo);
    buffer_add_ssh_string(session->out_buffer,publickey);
    sign=ssh_do_sign(session,session->out_buffer,privatekey);
    if(sign){
        buffer_add_ssh_string(session->out_buffer,sign);
        free(sign);
        packet_send(session);
        err=wait_auth_status(session,0);
    }
    free(user);
    free(service);
    free(method);
    free(algo);
    return err;
}
*/

int ssh_userauth1_password(SSH_SESSION *session,char *username,char *password){
    STRING *password_s;
    int err;
    err=send_username(session,username);
    if(err!=SSH_AUTH_DENIED)
        return err;
    /* we trick a bit here. A known flaw in SSH1 protocol is that it's
     * easy to guess password sizes.
     * not that sure ...
     */
    /* XXX fix me here ! */
    /* cisco IOS doesn't like when a password is followed by zeroes and random pad. */
    if(strlen(password)>=0){
        /* not risky to disclose the size of such a big password .. */
        password_s=string_from_char(password);
    } else {
        /* fill the password string from random things. the strcpy
         * ensure there is at least a nul byte after the password.
         * most implementation won't see the garbage at end.
         * why garbage ? because nul bytes will be compressed by
         * gzip and disclose password len.
         */
        password_s=string_new(128);
        ssh_get_random(password_s->string,128,0);
        strcpy((char *)password_s->string,password);
    }

    buffer_add_u8(session->out_buffer,SSH_CMSG_AUTH_PASSWORD);
    buffer_add_ssh_string(session->out_buffer,password_s);
    string_burn(password_s);
    free(password_s);
    packet_send(session);
    return wait_auth1_status(session);
}

#endif /* HAVE_SSH1 */