client: If we have a pre-connected FD, set state to SOCKET_CONNECTED

Otherwise applications providing their own fd end up tripping an
assertion, since the session is just in _CONNECTING.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Add ssh_get_poll_flags()

For integration with an external mainloop, we need to know how to
replicate libssh's internal poll() calls.  We originally through
ssh_get_status() was that API, but it's not really - those flags only
get updated from the *result* of a poll(), where what we really need
is to know how libssh would *start* a poll().

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
session: Always request POLLIN

The assumption is that if libssh functions are being invoked, we want
to read data.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
server: Fix malloc call.
packet: Refactor ssh_packet_socket_callback().

Make error checking more readable and add additional NULL checks.
dh: Avoid possible memory leaks with realloc.
poll: Fix realloc in ssh_poll_ctx_resize().
dh: Fix wrong assignment.

Ups, sorry.
packet: Set the packet to the processed data position.

Else we could end up with packet - current_macsize if to_be_read is 0.
packet: Remove dead code.
socket: Fix connect if we pass in a fd.

BUG: https://red.libssh.org/issues/106

Thanks to Saju Panikulam.
Fix gssapi credential handling.

- Properly acquire and inquitre credentials to get the list of available
credentials.
- Avoid enforcing a specific username it breaks some use cases (k5login).
- Remove confusing references to delegated credentials as there is no code
that actually uses delegated credentials in the initialization case.

Signed-off-by: Siom Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
gssapi: Add suppport to set GSSAPI server identity.
gssapi: Add support for GSSAPIServerIdentity config option.
options: Add SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY option.
gssapi: Add support for GSSAPIClientIdentity config option.
gssapi: Use GSSAPIClientIdentity to acquire creds

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
gssapi: Add error checks and cleanup the code in ssh_gssapi_auth_mic().
options: Add SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS option.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
gssapi: Add support for GSSAPIDelegateCredentials config option.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>