~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/include/libssh2/libssh2_priv.h

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2013-09-10 16:16:38 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20130910161638-wwup1q553ylww7dr
Tags: 1.18.0-1
* New upstream release.
* Don't install /usr/bin/png2c anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2004-2008, 2010, Sara Golemon <sarag@libssh2.org>
 
2
 * Copyright (c) 2009-2011 by Daniel Stenberg
 
3
 * Copyright (c) 2010 Simon Josefsson
 
4
 * All rights reserved.
 
5
 *
 
6
 * Redistribution and use in source and binary forms,
 
7
 * with or without modification, are permitted provided
 
8
 * that the following conditions are met:
 
9
 *
 
10
 *   Redistributions of source code must retain the above
 
11
 *   copyright notice, this list of conditions and the
 
12
 *   following disclaimer.
 
13
 *
 
14
 *   Redistributions in binary form must reproduce the above
 
15
 *   copyright notice, this list of conditions and the following
 
16
 *   disclaimer in the documentation and/or other materials
 
17
 *   provided with the distribution.
 
18
 *
 
19
 *   Neither the name of the copyright holder nor the names
 
20
 *   of any other contributors may be used to endorse or
 
21
 *   promote products derived from this software without
 
22
 *   specific prior written permission.
 
23
 *
 
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
25
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
26
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
27
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
28
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
29
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
31
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
32
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
33
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
34
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
35
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
36
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 
37
 * OF SUCH DAMAGE.
 
38
 */
 
39
 
 
40
#ifndef LIBSSH2_PRIV_H
 
41
#define LIBSSH2_PRIV_H 1
 
42
 
 
43
#define LIBSSH2_LIBRARY
 
44
#include "libssh2_config.h"
 
45
 
 
46
#ifdef HAVE_WINDOWS_H
 
47
#ifndef WIN32_LEAN_AND_MEAN
 
48
#define WIN32_LEAN_AND_MEAN
 
49
#endif
 
50
#include <windows.h>
 
51
#undef WIN32_LEAN_AND_MEAN
 
52
#endif
 
53
 
 
54
#ifdef HAVE_WS2TCPIP_H
 
55
#include <ws2tcpip.h>
 
56
#endif
 
57
 
 
58
#include <stdio.h>
 
59
#include <time.h>
 
60
 
 
61
/* The following CPP block should really only be in session.c and
 
62
   packet.c.  However, AIX have #define's for 'events' and 'revents'
 
63
   and we are using those names in libssh2.h, so we need to include
 
64
   the AIX headers first, to make sure all code is compiled with
 
65
   consistent names of these fields.  While arguable the best would to
 
66
   change libssh2.h to use other names, that would break backwards
 
67
   compatibility.  For more information, see:
 
68
   http://www.mail-archive.com/libssh2-devel%40lists.sourceforge.net/msg00003.html
 
69
   http://www.mail-archive.com/libssh2-devel%40lists.sourceforge.net/msg00224.html
 
70
*/
 
71
#ifdef HAVE_POLL
 
72
# include <sys/poll.h>
 
73
#else
 
74
# if defined(HAVE_SELECT) && !defined(WIN32)
 
75
# ifdef HAVE_SYS_SELECT_H
 
76
# include <sys/select.h>
 
77
# else
 
78
# include <sys/time.h>
 
79
# include <sys/types.h>
 
80
# endif
 
81
# endif
 
82
#endif
 
83
 
 
84
/* Needed for struct iovec on some platforms */
 
85
#ifdef HAVE_SYS_UIO_H
 
86
#include <sys/uio.h>
 
87
#endif
 
88
 
 
89
#ifdef HAVE_SYS_SOCKET_H
 
90
# include <sys/socket.h>
 
91
#endif
 
92
#ifdef HAVE_SYS_IOCTL_H
 
93
# include <sys/ioctl.h>
 
94
#endif
 
95
#ifdef HAVE_INTTYPES_H
 
96
#include <inttypes.h>
 
97
#endif
 
98
 
 
99
#include "libssh2.h"
 
100
#include "libssh2_publickey.h"
 
101
#include "libssh2_sftp.h"
 
102
#include "misc.h" /* for the linked list stuff */
 
103
 
 
104
#ifndef FALSE
 
105
#define FALSE 0
 
106
#endif
 
107
#ifndef TRUE
 
108
#define TRUE 1
 
109
#endif
 
110
 
 
111
/* Provide iovec / writev on WIN32 platform. */
 
112
#ifdef WIN32
 
113
 
 
114
struct iovec {
 
115
    size_t iov_len;
 
116
    void * iov_base;
 
117
};
 
118
 
 
119
#define inline __inline
 
120
 
 
121
static inline int writev(int sock, struct iovec *iov, int nvecs)
 
122
{
 
123
    DWORD ret;
 
124
    if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) {
 
125
        return ret;
 
126
    }
 
127
    return -1;
 
128
}
 
129
 
 
130
#endif /* WIN32 */
 
131
 
 
132
#include "crypto.h"
 
133
 
 
134
#ifdef HAVE_WINSOCK2_H
 
135
 
 
136
#include <winsock2.h>
 
137
#include <mswsock.h>
 
138
#include <ws2tcpip.h>
 
139
 
 
140
#ifdef _MSC_VER
 
141
/* "inline" keyword is valid only with C++ engine! */
 
142
#define inline __inline
 
143
#endif
 
144
 
 
145
#endif
 
146
 
 
147
/* RFC4253 section 6.1 Maximum Packet Length says:
 
148
 *
 
149
 * "All implementations MUST be able to process packets with
 
150
 * uncompressed payload length of 32768 bytes or less and
 
151
 * total packet size of 35000 bytes or less (including length,
 
152
 * padding length, payload, padding, and MAC.)."
 
153
 */
 
154
#define MAX_SSH_PACKET_LEN 35000
 
155
 
 
156
#define LIBSSH2_ALLOC(session, count) \
 
157
  session->alloc((count), &(session)->abstract)
 
158
#define LIBSSH2_REALLOC(session, ptr, count) \
 
159
 ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : \
 
160
 session->alloc((count), &(session)->abstract))
 
161
#define LIBSSH2_FREE(session, ptr) \
 
162
 session->free((ptr), &(session)->abstract)
 
163
#define LIBSSH2_IGNORE(session, data, datalen) \
 
164
 session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
 
165
#define LIBSSH2_DEBUG(session, always_display, message, message_len, \
 
166
                      language, language_len)    \
 
167
    session->ssh_msg_debug((session), (always_display), (message), \
 
168
                           (message_len), (language), (language_len), \
 
169
                           &(session)->abstract)
 
170
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, \
 
171
                           language, language_len)                \
 
172
    session->ssh_msg_disconnect((session), (reason), (message),   \
 
173
                                (message_len), (language), (language_len), \
 
174
                                &(session)->abstract)
 
175
 
 
176
#define LIBSSH2_MACERROR(session, data, datalen)         \
 
177
    session->macerror((session), (data), (datalen), &(session)->abstract)
 
178
#define LIBSSH2_X11_OPEN(channel, shost, sport)          \
 
179
    channel->session->x11(((channel)->session), (channel), \
 
180
                          (shost), (sport), (&(channel)->session->abstract))
 
181
 
 
182
#define LIBSSH2_CHANNEL_CLOSE(session, channel)          \
 
183
    channel->close_cb((session), &(session)->abstract, \
 
184
                      (channel), &(channel)->abstract)
 
185
 
 
186
#define LIBSSH2_SEND_FD(session, fd, buffer, length, flags) \
 
187
    session->send(fd, buffer, length, flags, &session->abstract)
 
188
#define LIBSSH2_RECV_FD(session, fd, buffer, length, flags) \
 
189
    session->recv(fd, buffer, length, flags, &session->abstract)
 
190
 
 
191
#define LIBSSH2_SEND(session, buffer, length, flags)  \
 
192
    LIBSSH2_SEND_FD(session, session->socket_fd, buffer, length, flags)
 
193
#define LIBSSH2_RECV(session, buffer, length, flags)                    \
 
194
    LIBSSH2_RECV_FD(session, session->socket_fd, buffer, length, flags)
 
195
 
 
196
typedef struct _LIBSSH2_KEX_METHOD LIBSSH2_KEX_METHOD;
 
197
typedef struct _LIBSSH2_HOSTKEY_METHOD LIBSSH2_HOSTKEY_METHOD;
 
198
typedef struct _LIBSSH2_CRYPT_METHOD LIBSSH2_CRYPT_METHOD;
 
199
typedef struct _LIBSSH2_COMP_METHOD LIBSSH2_COMP_METHOD;
 
200
 
 
201
typedef struct _LIBSSH2_PACKET LIBSSH2_PACKET;
 
202
 
 
203
typedef enum
 
204
{
 
205
    libssh2_NB_state_idle = 0,
 
206
    libssh2_NB_state_allocated,
 
207
    libssh2_NB_state_created,
 
208
    libssh2_NB_state_sent,
 
209
    libssh2_NB_state_sent1,
 
210
    libssh2_NB_state_sent2,
 
211
    libssh2_NB_state_sent3,
 
212
    libssh2_NB_state_sent4,
 
213
    libssh2_NB_state_sent5,
 
214
    libssh2_NB_state_sent6,
 
215
    libssh2_NB_state_sent7,
 
216
    libssh2_NB_state_jump1,
 
217
    libssh2_NB_state_jump2,
 
218
    libssh2_NB_state_jump3,
 
219
    libssh2_NB_state_jump4,
 
220
    libssh2_NB_state_jump5
 
221
} libssh2_nonblocking_states;
 
222
 
 
223
typedef struct packet_require_state_t
 
224
{
 
225
    libssh2_nonblocking_states state;
 
226
    time_t start;
 
227
} packet_require_state_t;
 
228
 
 
229
typedef struct packet_requirev_state_t
 
230
{
 
231
    time_t start;
 
232
} packet_requirev_state_t;
 
233
 
 
234
typedef struct kmdhgGPsha1kex_state_t
 
235
{
 
236
    libssh2_nonblocking_states state;
 
237
    unsigned char *e_packet;
 
238
    unsigned char *s_packet;
 
239
    unsigned char *tmp;
 
240
    unsigned char h_sig_comp[SHA_DIGEST_LENGTH];
 
241
    unsigned char c;
 
242
    size_t e_packet_len;
 
243
    size_t s_packet_len;
 
244
    size_t tmp_len;
 
245
    _libssh2_bn_ctx *ctx;
 
246
    _libssh2_bn *x;
 
247
    _libssh2_bn *e;
 
248
    _libssh2_bn *f;
 
249
    _libssh2_bn *k;
 
250
    unsigned char *s;
 
251
    unsigned char *f_value;
 
252
    unsigned char *k_value;
 
253
    unsigned char *h_sig;
 
254
    size_t f_value_len;
 
255
    size_t k_value_len;
 
256
    size_t h_sig_len;
 
257
    libssh2_sha1_ctx exchange_hash;
 
258
    packet_require_state_t req_state;
 
259
    libssh2_nonblocking_states burn_state;
 
260
} kmdhgGPsha1kex_state_t;
 
261
 
 
262
typedef struct key_exchange_state_low_t
 
263
{
 
264
    libssh2_nonblocking_states state;
 
265
    packet_require_state_t req_state;
 
266
    kmdhgGPsha1kex_state_t exchange_state;
 
267
    _libssh2_bn *p;             /* SSH2 defined value (p_value) */
 
268
    _libssh2_bn *g;             /* SSH2 defined value (2) */
 
269
    unsigned char request[13];
 
270
    unsigned char *data;
 
271
    size_t request_len;
 
272
    size_t data_len;
 
273
} key_exchange_state_low_t;
 
274
 
 
275
typedef struct key_exchange_state_t
 
276
{
 
277
    libssh2_nonblocking_states state;
 
278
    packet_require_state_t req_state;
 
279
    key_exchange_state_low_t key_state_low;
 
280
    unsigned char *data;
 
281
    size_t data_len;
 
282
    unsigned char *oldlocal;
 
283
    size_t oldlocal_len;
 
284
} key_exchange_state_t;
 
285
 
 
286
#define FwdNotReq "Forward not requested"
 
287
 
 
288
typedef struct packet_queue_listener_state_t
 
289
{
 
290
    libssh2_nonblocking_states state;
 
291
    unsigned char packet[17 + (sizeof(FwdNotReq) - 1)];
 
292
    unsigned char *host;
 
293
    unsigned char *shost;
 
294
    uint32_t sender_channel;
 
295
    uint32_t initial_window_size;
 
296
    uint32_t packet_size;
 
297
    uint32_t port;
 
298
    uint32_t sport;
 
299
    uint32_t host_len;
 
300
    uint32_t shost_len;
 
301
    LIBSSH2_CHANNEL *channel;
 
302
} packet_queue_listener_state_t;
 
303
 
 
304
#define X11FwdUnAvil "X11 Forward Unavailable"
 
305
 
 
306
typedef struct packet_x11_open_state_t
 
307
{
 
308
    libssh2_nonblocking_states state;
 
309
    unsigned char packet[17 + (sizeof(X11FwdUnAvil) - 1)];
 
310
    unsigned char *shost;
 
311
    uint32_t sender_channel;
 
312
    uint32_t initial_window_size;
 
313
    uint32_t packet_size;
 
314
    uint32_t sport;
 
315
    uint32_t shost_len;
 
316
    LIBSSH2_CHANNEL *channel;
 
317
} packet_x11_open_state_t;
 
318
 
 
319
struct _LIBSSH2_PACKET
 
320
{
 
321
    struct list_node node; /* linked list header */
 
322
 
 
323
    /* the raw unencrypted payload */
 
324
    unsigned char *data;
 
325
    size_t data_len;
 
326
 
 
327
    /* Where to start reading data from,
 
328
     * used for channel data that's been partially consumed */
 
329
    size_t data_head;
 
330
};
 
331
 
 
332
typedef struct _libssh2_channel_data
 
333
{
 
334
    /* Identifier */
 
335
    uint32_t id;
 
336
 
 
337
    /* Limits and restrictions */
 
338
    uint32_t window_size_initial, window_size, packet_size;
 
339
 
 
340
    /* Set to 1 when CHANNEL_CLOSE / CHANNEL_EOF sent/received */
 
341
    char close, eof, extended_data_ignore_mode;
 
342
} libssh2_channel_data;
 
343
 
 
344
struct _LIBSSH2_CHANNEL
 
345
{
 
346
    struct list_node node;
 
347
 
 
348
    unsigned char *channel_type;
 
349
    unsigned channel_type_len;
 
350
 
 
351
    /* channel's program exit status */
 
352
    int exit_status;
 
353
 
 
354
    /* channel's program exit signal (without the SIG prefix) */
 
355
    char *exit_signal;
 
356
 
 
357
    libssh2_channel_data local, remote;
 
358
    /* Amount of bytes to be refunded to receive window (but not yet sent) */
 
359
    uint32_t adjust_queue;
 
360
 
 
361
    LIBSSH2_SESSION *session;
 
362
 
 
363
    void *abstract;
 
364
      LIBSSH2_CHANNEL_CLOSE_FUNC((*close_cb));
 
365
 
 
366
    /* State variables used in libssh2_channel_setenv_ex() */
 
367
    libssh2_nonblocking_states setenv_state;
 
368
    unsigned char *setenv_packet;
 
369
    size_t setenv_packet_len;
 
370
    unsigned char setenv_local_channel[4];
 
371
    packet_requirev_state_t setenv_packet_requirev_state;
 
372
 
 
373
    /* State variables used in libssh2_channel_request_pty_ex()
 
374
       libssh2_channel_request_pty_size_ex() */
 
375
    libssh2_nonblocking_states reqPTY_state;
 
376
    unsigned char reqPTY_packet[41 + 256];
 
377
    size_t reqPTY_packet_len;
 
378
    unsigned char reqPTY_local_channel[4];
 
379
    packet_requirev_state_t reqPTY_packet_requirev_state;
 
380
 
 
381
    /* State variables used in libssh2_channel_x11_req_ex() */
 
382
    libssh2_nonblocking_states reqX11_state;
 
383
    unsigned char *reqX11_packet;
 
384
    size_t reqX11_packet_len;
 
385
    unsigned char reqX11_local_channel[4];
 
386
    packet_requirev_state_t reqX11_packet_requirev_state;
 
387
 
 
388
    /* State variables used in libssh2_channel_process_startup() */
 
389
    libssh2_nonblocking_states process_state;
 
390
    unsigned char *process_packet;
 
391
    size_t process_packet_len;
 
392
    unsigned char process_local_channel[4];
 
393
    packet_requirev_state_t process_packet_requirev_state;
 
394
 
 
395
    /* State variables used in libssh2_channel_flush_ex() */
 
396
    libssh2_nonblocking_states flush_state;
 
397
    size_t flush_refund_bytes;
 
398
    size_t flush_flush_bytes;
 
399
 
 
400
    /* State variables used in libssh2_channel_receive_window_adjust() */
 
401
    libssh2_nonblocking_states adjust_state;
 
402
    unsigned char adjust_adjust[9];     /* packet_type(1) + channel(4) + adjustment(4) */
 
403
 
 
404
    /* State variables used in libssh2_channel_read_ex() */
 
405
    libssh2_nonblocking_states read_state;
 
406
 
 
407
    uint32_t read_local_id;
 
408
 
 
409
    /* State variables used in libssh2_channel_write_ex() */
 
410
    libssh2_nonblocking_states write_state;
 
411
    unsigned char write_packet[13];
 
412
    size_t write_packet_len;
 
413
    size_t write_bufwrite;
 
414
 
 
415
    /* State variables used in libssh2_channel_close() */
 
416
    libssh2_nonblocking_states close_state;
 
417
    unsigned char close_packet[5];
 
418
 
 
419
    /* State variables used in libssh2_channel_wait_closedeof() */
 
420
    libssh2_nonblocking_states wait_eof_state;
 
421
 
 
422
    /* State variables used in libssh2_channel_wait_closed() */
 
423
    libssh2_nonblocking_states wait_closed_state;
 
424
 
 
425
    /* State variables used in libssh2_channel_free() */
 
426
    libssh2_nonblocking_states free_state;
 
427
 
 
428
    /* State variables used in libssh2_channel_handle_extended_data2() */
 
429
    libssh2_nonblocking_states extData2_state;
 
430
 
 
431
};
 
432
 
 
433
struct _LIBSSH2_LISTENER
 
434
{
 
435
    struct list_node node; /* linked list header */
 
436
 
 
437
    LIBSSH2_SESSION *session;
 
438
 
 
439
    char *host;
 
440
    int port;
 
441
 
 
442
    /* a list of CHANNELs for this listener */
 
443
    struct list_head queue;
 
444
 
 
445
    int queue_size;
 
446
    int queue_maxsize;
 
447
 
 
448
    /* State variables used in libssh2_channel_forward_cancel() */
 
449
    libssh2_nonblocking_states chanFwdCncl_state;
 
450
    unsigned char *chanFwdCncl_data;
 
451
    size_t chanFwdCncl_data_len;
 
452
};
 
453
 
 
454
typedef struct _libssh2_endpoint_data
 
455
{
 
456
    unsigned char *banner;
 
457
 
 
458
    unsigned char *kexinit;
 
459
    size_t kexinit_len;
 
460
 
 
461
    const LIBSSH2_CRYPT_METHOD *crypt;
 
462
    void *crypt_abstract;
 
463
 
 
464
    const struct _LIBSSH2_MAC_METHOD *mac;
 
465
    uint32_t seqno;
 
466
    void *mac_abstract;
 
467
 
 
468
    const LIBSSH2_COMP_METHOD *comp;
 
469
    void *comp_abstract;
 
470
 
 
471
    /* Method Preferences -- NULL yields "load order" */
 
472
    char *crypt_prefs;
 
473
    char *mac_prefs;
 
474
    char *comp_prefs;
 
475
    char *lang_prefs;
 
476
} libssh2_endpoint_data;
 
477
 
 
478
#define PACKETBUFSIZE (1024*16)
 
479
 
 
480
struct transportpacket
 
481
{
 
482
    /* ------------- for incoming data --------------- */
 
483
    unsigned char buf[PACKETBUFSIZE];
 
484
    unsigned char init[5];  /* first 5 bytes of the incoming data stream,
 
485
                               still encrypted */
 
486
    size_t writeidx;        /* at what array index we do the next write into
 
487
                               the buffer */
 
488
    size_t readidx;         /* at what array index we do the next read from
 
489
                               the buffer */
 
490
    uint32_t packet_length; /* the most recent packet_length as read from the
 
491
                               network data */
 
492
    uint8_t padding_length; /* the most recent padding_length as read from the
 
493
                               network data */
 
494
    size_t data_num;        /* How much of the total package that has been read
 
495
                               so far. */
 
496
    size_t total_num;       /* How much a total package is supposed to be, in
 
497
                               number of bytes. A full package is
 
498
                               packet_length + padding_length + 4 +
 
499
                               mac_length. */
 
500
    unsigned char *payload; /* this is a pointer to a LIBSSH2_ALLOC()
 
501
                               area to which we write decrypted data */
 
502
    unsigned char *wptr;    /* write pointer into the payload to where we
 
503
                               are currently writing decrypted data */
 
504
 
 
505
    /* ------------- for outgoing data --------------- */
 
506
    unsigned char outbuf[MAX_SSH_PACKET_LEN]; /* area for the outgoing data */
 
507
 
 
508
    int ototal_num;         /* size of outbuf in number of bytes */
 
509
    const unsigned char *odata; /* original pointer to the data */
 
510
    size_t olen;            /* original size of the data we stored in
 
511
                               outbuf */
 
512
    size_t osent;           /* number of bytes already sent */
 
513
};
 
514
 
 
515
struct _LIBSSH2_PUBLICKEY
 
516
{
 
517
    LIBSSH2_CHANNEL *channel;
 
518
    uint32_t version;
 
519
 
 
520
    /* State variables used in libssh2_publickey_packet_receive() */
 
521
    libssh2_nonblocking_states receive_state;
 
522
    unsigned char *receive_packet;
 
523
    size_t receive_packet_len;
 
524
 
 
525
    /* State variables used in libssh2_publickey_add_ex() */
 
526
    libssh2_nonblocking_states add_state;
 
527
    unsigned char *add_packet;
 
528
    unsigned char *add_s;
 
529
 
 
530
    /* State variables used in libssh2_publickey_remove_ex() */
 
531
    libssh2_nonblocking_states remove_state;
 
532
    unsigned char *remove_packet;
 
533
    unsigned char *remove_s;
 
534
 
 
535
    /* State variables used in libssh2_publickey_list_fetch() */
 
536
    libssh2_nonblocking_states listFetch_state;
 
537
    unsigned char *listFetch_s;
 
538
    unsigned char listFetch_buffer[12];
 
539
    unsigned char *listFetch_data;
 
540
    size_t listFetch_data_len;
 
541
};
 
542
 
 
543
#define LIBSSH2_SCP_RESPONSE_BUFLEN     256
 
544
 
 
545
struct flags {
 
546
    int sigpipe;  /* LIBSSH2_FLAG_SIGPIPE */
 
547
    int compress; /* LIBSSH2_FLAG_COMPRESS */
 
548
};
 
549
 
 
550
struct _LIBSSH2_SESSION
 
551
{
 
552
    /* Memory management callbacks */
 
553
    void *abstract;
 
554
      LIBSSH2_ALLOC_FUNC((*alloc));
 
555
      LIBSSH2_REALLOC_FUNC((*realloc));
 
556
      LIBSSH2_FREE_FUNC((*free));
 
557
 
 
558
    /* Other callbacks */
 
559
      LIBSSH2_IGNORE_FUNC((*ssh_msg_ignore));
 
560
      LIBSSH2_DEBUG_FUNC((*ssh_msg_debug));
 
561
      LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect));
 
562
      LIBSSH2_MACERROR_FUNC((*macerror));
 
563
      LIBSSH2_X11_OPEN_FUNC((*x11));
 
564
      LIBSSH2_SEND_FUNC((*send));
 
565
      LIBSSH2_RECV_FUNC((*recv));
 
566
 
 
567
    /* Method preferences -- NULL yields "load order" */
 
568
    char *kex_prefs;
 
569
    char *hostkey_prefs;
 
570
 
 
571
    int state;
 
572
 
 
573
    /* Flag options */
 
574
    struct flags flag;
 
575
 
 
576
    /* Agreed Key Exchange Method */
 
577
    const LIBSSH2_KEX_METHOD *kex;
 
578
    int burn_optimistic_kexinit:1;
 
579
 
 
580
    unsigned char *session_id;
 
581
    uint32_t session_id_len;
 
582
 
 
583
    /* this is set to TRUE if a blocking API behavior is requested */
 
584
    int api_block_mode;
 
585
 
 
586
    /* Timeout used when blocking API behavior is active */
 
587
    long api_timeout;
 
588
 
 
589
    /* Server's public key */
 
590
    const LIBSSH2_HOSTKEY_METHOD *hostkey;
 
591
    void *server_hostkey_abstract;
 
592
 
 
593
    /* Either set with libssh2_session_hostkey() (for server mode)
 
594
     * Or read from server in (eg) KEXDH_INIT (for client mode)
 
595
     */
 
596
    unsigned char *server_hostkey;
 
597
    uint32_t server_hostkey_len;
 
598
#if LIBSSH2_MD5
 
599
    unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH];
 
600
    int server_hostkey_md5_valid;
 
601
#endif                          /* ! LIBSSH2_MD5 */
 
602
    unsigned char server_hostkey_sha1[SHA_DIGEST_LENGTH];
 
603
 
 
604
    /* (remote as source of data -- packet_read ) */
 
605
    libssh2_endpoint_data remote;
 
606
 
 
607
    /* (local as source of data -- packet_write ) */
 
608
    libssh2_endpoint_data local;
 
609
 
 
610
    /* Inbound Data linked list -- Sometimes the packet that comes in isn't the
 
611
       packet we're ready for */
 
612
    struct list_head packets;
 
613
 
 
614
    /* Active connection channels */
 
615
    struct list_head channels;
 
616
 
 
617
    uint32_t next_channel;
 
618
 
 
619
    struct list_head listeners; /* list of LIBSSH2_LISTENER structs */
 
620
 
 
621
    /* Actual I/O socket */
 
622
    libssh2_socket_t socket_fd;
 
623
    int socket_state;
 
624
    int socket_block_directions;
 
625
    int socket_prev_blockstate; /* stores the state of the socket blockiness
 
626
                                   when libssh2_session_startup() is called */
 
627
 
 
628
    /* Error tracking */
 
629
    const char *err_msg;
 
630
    int err_code;
 
631
 
 
632
    /* struct members for packet-level reading */
 
633
    struct transportpacket packet;
 
634
#ifdef LIBSSH2DEBUG
 
635
    int showmask;               /* what debug/trace messages to display */
 
636
    libssh2_trace_handler_func tracehandler; /* callback to display trace messages */
 
637
    void* tracehandler_context; /* context for the trace handler */
 
638
#endif
 
639
 
 
640
    /* State variables used in libssh2_banner_send() */
 
641
    libssh2_nonblocking_states banner_TxRx_state;
 
642
    char banner_TxRx_banner[256];
 
643
    ssize_t banner_TxRx_total_send;
 
644
 
 
645
    /* State variables used in libssh2_kexinit() */
 
646
    libssh2_nonblocking_states kexinit_state;
 
647
    unsigned char *kexinit_data;
 
648
    size_t kexinit_data_len;
 
649
 
 
650
    /* State variables used in libssh2_session_startup() */
 
651
    libssh2_nonblocking_states startup_state;
 
652
    unsigned char *startup_data;
 
653
    size_t startup_data_len;
 
654
    unsigned char startup_service[sizeof("ssh-userauth") + 5 - 1];
 
655
    size_t startup_service_length;
 
656
    packet_require_state_t startup_req_state;
 
657
    key_exchange_state_t startup_key_state;
 
658
 
 
659
    /* State variables used in libssh2_session_free() */
 
660
    libssh2_nonblocking_states free_state;
 
661
 
 
662
    /* State variables used in libssh2_session_disconnect_ex() */
 
663
    libssh2_nonblocking_states disconnect_state;
 
664
    unsigned char disconnect_data[256 + 13];
 
665
    size_t disconnect_data_len;
 
666
 
 
667
    /* State variables used in libssh2_packet_read() */
 
668
    libssh2_nonblocking_states readPack_state;
 
669
    int readPack_encrypted;
 
670
 
 
671
    /* State variables used in libssh2_userauth_list() */
 
672
    libssh2_nonblocking_states userauth_list_state;
 
673
    unsigned char *userauth_list_data;
 
674
    size_t userauth_list_data_len;
 
675
    packet_requirev_state_t userauth_list_packet_requirev_state;
 
676
 
 
677
    /* State variables used in libssh2_userauth_password_ex() */
 
678
    libssh2_nonblocking_states userauth_pswd_state;
 
679
    unsigned char *userauth_pswd_data;
 
680
    unsigned char userauth_pswd_data0;
 
681
    size_t userauth_pswd_data_len;
 
682
    char *userauth_pswd_newpw;
 
683
    int userauth_pswd_newpw_len;
 
684
    packet_requirev_state_t userauth_pswd_packet_requirev_state;
 
685
 
 
686
    /* State variables used in libssh2_userauth_hostbased_fromfile_ex() */
 
687
    libssh2_nonblocking_states userauth_host_state;
 
688
    unsigned char *userauth_host_data;
 
689
    size_t userauth_host_data_len;
 
690
    unsigned char *userauth_host_packet;
 
691
    size_t userauth_host_packet_len;
 
692
    unsigned char *userauth_host_method;
 
693
    size_t userauth_host_method_len;
 
694
    unsigned char *userauth_host_s;
 
695
    packet_requirev_state_t userauth_host_packet_requirev_state;
 
696
 
 
697
    /* State variables used in libssh2_userauth_publickey_fromfile_ex() */
 
698
    libssh2_nonblocking_states userauth_pblc_state;
 
699
    unsigned char *userauth_pblc_data;
 
700
    size_t userauth_pblc_data_len;
 
701
    unsigned char *userauth_pblc_packet;
 
702
    size_t userauth_pblc_packet_len;
 
703
    unsigned char *userauth_pblc_method;
 
704
    size_t userauth_pblc_method_len;
 
705
    unsigned char *userauth_pblc_s;
 
706
    unsigned char *userauth_pblc_b;
 
707
    packet_requirev_state_t userauth_pblc_packet_requirev_state;
 
708
 
 
709
    /* State variables used in libssh2_userauth_keyboard_interactive_ex() */
 
710
    libssh2_nonblocking_states userauth_kybd_state;
 
711
    unsigned char *userauth_kybd_data;
 
712
    size_t userauth_kybd_data_len;
 
713
    unsigned char *userauth_kybd_packet;
 
714
    size_t userauth_kybd_packet_len;
 
715
    unsigned int userauth_kybd_auth_name_len;
 
716
    char *userauth_kybd_auth_name;
 
717
    unsigned userauth_kybd_auth_instruction_len;
 
718
    char *userauth_kybd_auth_instruction;
 
719
    unsigned int userauth_kybd_num_prompts;
 
720
    int userauth_kybd_auth_failure;
 
721
    LIBSSH2_USERAUTH_KBDINT_PROMPT *userauth_kybd_prompts;
 
722
    LIBSSH2_USERAUTH_KBDINT_RESPONSE *userauth_kybd_responses;
 
723
    packet_requirev_state_t userauth_kybd_packet_requirev_state;
 
724
 
 
725
    /* State variables used in libssh2_channel_open_ex() */
 
726
    libssh2_nonblocking_states open_state;
 
727
    packet_requirev_state_t open_packet_requirev_state;
 
728
    LIBSSH2_CHANNEL *open_channel;
 
729
    unsigned char *open_packet;
 
730
    size_t open_packet_len;
 
731
    unsigned char *open_data;
 
732
    size_t open_data_len;
 
733
    uint32_t open_local_channel;
 
734
 
 
735
    /* State variables used in libssh2_channel_direct_tcpip_ex() */
 
736
    libssh2_nonblocking_states direct_state;
 
737
    unsigned char *direct_message;
 
738
    size_t direct_host_len;
 
739
    size_t direct_shost_len;
 
740
    size_t direct_message_len;
 
741
 
 
742
    /* State variables used in libssh2_channel_forward_listen_ex() */
 
743
    libssh2_nonblocking_states fwdLstn_state;
 
744
    unsigned char *fwdLstn_packet;
 
745
    uint32_t fwdLstn_host_len;
 
746
    uint32_t fwdLstn_packet_len;
 
747
    packet_requirev_state_t fwdLstn_packet_requirev_state;
 
748
 
 
749
    /* State variables used in libssh2_publickey_init() */
 
750
    libssh2_nonblocking_states pkeyInit_state;
 
751
    LIBSSH2_PUBLICKEY *pkeyInit_pkey;
 
752
    LIBSSH2_CHANNEL *pkeyInit_channel;
 
753
    unsigned char *pkeyInit_data;
 
754
    size_t pkeyInit_data_len;
 
755
    /* 19 = packet_len(4) + version_len(4) + "version"(7) + version_num(4) */
 
756
    unsigned char pkeyInit_buffer[19];
 
757
    size_t pkeyInit_buffer_sent; /* how much of buffer that has been sent */
 
758
 
 
759
    /* State variables used in libssh2_packet_add() */
 
760
    libssh2_nonblocking_states packAdd_state;
 
761
    LIBSSH2_CHANNEL *packAdd_channelp; /* keeper of the channel during EAGAIN
 
762
                                          states */
 
763
    packet_queue_listener_state_t packAdd_Qlstn_state;
 
764
    packet_x11_open_state_t packAdd_x11open_state;
 
765
 
 
766
    /* State variables used in fullpacket() */
 
767
    libssh2_nonblocking_states fullpacket_state;
 
768
    int fullpacket_macstate;
 
769
    size_t fullpacket_payload_len;
 
770
    int fullpacket_packet_type;
 
771
 
 
772
    /* State variables used in libssh2_sftp_init() */
 
773
    libssh2_nonblocking_states sftpInit_state;
 
774
    LIBSSH2_SFTP *sftpInit_sftp;
 
775
    LIBSSH2_CHANNEL *sftpInit_channel;
 
776
    unsigned char sftpInit_buffer[9];   /* sftp_header(5){excludes request_id}
 
777
                                           + version_id(4) */
 
778
    int sftpInit_sent; /* number of bytes from the buffer that have been
 
779
                          sent */
 
780
 
 
781
    /* State variables used in libssh2_scp_recv() */
 
782
    libssh2_nonblocking_states scpRecv_state;
 
783
    unsigned char *scpRecv_command;
 
784
    size_t scpRecv_command_len;
 
785
    unsigned char scpRecv_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
 
786
    size_t scpRecv_response_len;
 
787
    long scpRecv_mode;
 
788
#if defined(HAVE_LONGLONG) && defined(HAVE_STRTOLL)
 
789
    /* we have the type and we can parse such numbers */
 
790
    long long scpRecv_size;
 
791
#define scpsize_strtol strtoll
 
792
#else
 
793
    long scpRecv_size;
 
794
#define scpsize_strtol strtol
 
795
#endif
 
796
    long scpRecv_mtime;
 
797
    long scpRecv_atime;
 
798
    LIBSSH2_CHANNEL *scpRecv_channel;
 
799
 
 
800
    /* State variables used in libssh2_scp_send_ex() */
 
801
    libssh2_nonblocking_states scpSend_state;
 
802
    unsigned char *scpSend_command;
 
803
    size_t scpSend_command_len;
 
804
    unsigned char scpSend_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
 
805
    size_t scpSend_response_len;
 
806
    LIBSSH2_CHANNEL *scpSend_channel;
 
807
 
 
808
    /* Keepalive variables used by keepalive.c. */
 
809
    int keepalive_interval;
 
810
    int keepalive_want_reply;
 
811
    time_t keepalive_last_sent;
 
812
};
 
813
 
 
814
/* session.state bits */
 
815
#define LIBSSH2_STATE_EXCHANGING_KEYS   0x00000001
 
816
#define LIBSSH2_STATE_NEWKEYS           0x00000002
 
817
#define LIBSSH2_STATE_AUTHENTICATED     0x00000004
 
818
#define LIBSSH2_STATE_KEX_ACTIVE        0x00000008
 
819
 
 
820
/* session.flag helpers */
 
821
#ifdef MSG_NOSIGNAL
 
822
#define LIBSSH2_SOCKET_SEND_FLAGS(session)              \
 
823
    (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL)
 
824
#define LIBSSH2_SOCKET_RECV_FLAGS(session)              \
 
825
    (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL)
 
826
#else
 
827
/* If MSG_NOSIGNAL isn't defined we're SOL on blocking SIGPIPE */
 
828
#define LIBSSH2_SOCKET_SEND_FLAGS(session)      0
 
829
#define LIBSSH2_SOCKET_RECV_FLAGS(session)      0
 
830
#endif
 
831
 
 
832
/* --------- */
 
833
 
 
834
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional
 
835
   methods via .so/.dll */
 
836
 
 
837
struct _LIBSSH2_KEX_METHOD
 
838
{
 
839
    const char *name;
 
840
 
 
841
    /* Key exchange, populates session->* and returns 0 on success, non-0 on error */
 
842
    int (*exchange_keys) (LIBSSH2_SESSION * session,
 
843
                          key_exchange_state_low_t * key_state);
 
844
 
 
845
    long flags;
 
846
};
 
847
 
 
848
struct _LIBSSH2_HOSTKEY_METHOD
 
849
{
 
850
    const char *name;
 
851
    unsigned long hash_len;
 
852
 
 
853
    int (*init) (LIBSSH2_SESSION * session, const unsigned char *hostkey_data,
 
854
                 size_t hostkey_data_len, void **abstract);
 
855
    int (*initPEM) (LIBSSH2_SESSION * session, const char *privkeyfile,
 
856
                    unsigned const char *passphrase, void **abstract);
 
857
    int (*sig_verify) (LIBSSH2_SESSION * session, const unsigned char *sig,
 
858
                       size_t sig_len, const unsigned char *m,
 
859
                       size_t m_len, void **abstract);
 
860
    int (*signv) (LIBSSH2_SESSION * session, unsigned char **signature,
 
861
                  size_t *signature_len, int veccount,
 
862
                  const struct iovec datavec[], void **abstract);
 
863
    int (*encrypt) (LIBSSH2_SESSION * session, unsigned char **dst,
 
864
                    size_t *dst_len, const unsigned char *src,
 
865
                    size_t src_len, void **abstract);
 
866
    int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
 
867
};
 
868
 
 
869
struct _LIBSSH2_CRYPT_METHOD
 
870
{
 
871
    const char *name;
 
872
 
 
873
    int blocksize;
 
874
 
 
875
    /* iv and key sizes (-1 for variable length) */
 
876
    int iv_len;
 
877
    int secret_len;
 
878
 
 
879
    long flags;
 
880
 
 
881
    int (*init) (LIBSSH2_SESSION * session,
 
882
                 const LIBSSH2_CRYPT_METHOD * method, unsigned char *iv,
 
883
                 int *free_iv, unsigned char *secret, int *free_secret,
 
884
                 int encrypt, void **abstract);
 
885
    int (*crypt) (LIBSSH2_SESSION * session, unsigned char *block,
 
886
                  size_t blocksize, void **abstract);
 
887
    int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
 
888
 
 
889
      _libssh2_cipher_type(algo);
 
890
};
 
891
 
 
892
struct _LIBSSH2_COMP_METHOD
 
893
{
 
894
    const char *name;
 
895
    int compress; /* 1 if it does compress, 0 if it doesn't */
 
896
    int use_in_auth; /* 1 if compression should be used in userauth */
 
897
    int (*init) (LIBSSH2_SESSION *session, int compress, void **abstract);
 
898
    int (*comp) (LIBSSH2_SESSION *session,
 
899
                 unsigned char *dest,
 
900
                 size_t *dest_len,
 
901
                 const unsigned char *src,
 
902
                 size_t src_len,
 
903
                 void **abstract);
 
904
    int (*decomp) (LIBSSH2_SESSION *session,
 
905
                   unsigned char **dest,
 
906
                   size_t *dest_len,
 
907
                   size_t payload_limit,
 
908
                   const unsigned char *src,
 
909
                   size_t src_len,
 
910
                   void **abstract);
 
911
    int (*dtor) (LIBSSH2_SESSION * session, int compress, void **abstract);
 
912
};
 
913
 
 
914
#ifdef LIBSSH2DEBUG
 
915
void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format,
 
916
                    ...);
 
917
#else
 
918
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__GNUC__)
 
919
/* C99 supported and also by older GCC */
 
920
#define _libssh2_debug(x,y,z,...) do {} while (0)
 
921
#else
 
922
/* no gcc and not C99, do static and hopefully inline */
 
923
static inline void
 
924
_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
 
925
{
 
926
}
 
927
#endif
 
928
#endif
 
929
 
 
930
#define LIBSSH2_SOCKET_UNKNOWN                   1
 
931
#define LIBSSH2_SOCKET_CONNECTED                 0
 
932
#define LIBSSH2_SOCKET_DISCONNECTED             -1
 
933
 
 
934
/* Initial packet state, prior to MAC check */
 
935
#define LIBSSH2_MAC_UNCONFIRMED                  1
 
936
/* When MAC type is "none" (proto initiation phase) all packets are deemed "confirmed" */
 
937
#define LIBSSH2_MAC_CONFIRMED                    0
 
938
/* Something very bad is going on */
 
939
#define LIBSSH2_MAC_INVALID                     -1
 
940
 
 
941
/* SSH Packet Types -- Defined by internet draft */
 
942
/* Transport Layer */
 
943
#define SSH_MSG_DISCONNECT                          1
 
944
#define SSH_MSG_IGNORE                              2
 
945
#define SSH_MSG_UNIMPLEMENTED                       3
 
946
#define SSH_MSG_DEBUG                               4
 
947
#define SSH_MSG_SERVICE_REQUEST                     5
 
948
#define SSH_MSG_SERVICE_ACCEPT                      6
 
949
 
 
950
#define SSH_MSG_KEXINIT                             20
 
951
#define SSH_MSG_NEWKEYS                             21
 
952
 
 
953
/* diffie-hellman-group1-sha1 */
 
954
#define SSH_MSG_KEXDH_INIT                          30
 
955
#define SSH_MSG_KEXDH_REPLY                         31
 
956
 
 
957
/* diffie-hellman-group-exchange-sha1 */
 
958
#define SSH_MSG_KEX_DH_GEX_REQUEST_OLD              30
 
959
#define SSH_MSG_KEX_DH_GEX_REQUEST                  34
 
960
#define SSH_MSG_KEX_DH_GEX_GROUP                    31
 
961
#define SSH_MSG_KEX_DH_GEX_INIT                     32
 
962
#define SSH_MSG_KEX_DH_GEX_REPLY                    33
 
963
 
 
964
/* User Authentication */
 
965
#define SSH_MSG_USERAUTH_REQUEST                    50
 
966
#define SSH_MSG_USERAUTH_FAILURE                    51
 
967
#define SSH_MSG_USERAUTH_SUCCESS                    52
 
968
#define SSH_MSG_USERAUTH_BANNER                     53
 
969
 
 
970
/* "public key" method */
 
971
#define SSH_MSG_USERAUTH_PK_OK                      60
 
972
/* "password" method */
 
973
#define SSH_MSG_USERAUTH_PASSWD_CHANGEREQ           60
 
974
/* "keyboard-interactive" method */
 
975
#define SSH_MSG_USERAUTH_INFO_REQUEST               60
 
976
#define SSH_MSG_USERAUTH_INFO_RESPONSE              61
 
977
 
 
978
/* Channels */
 
979
#define SSH_MSG_GLOBAL_REQUEST                      80
 
980
#define SSH_MSG_REQUEST_SUCCESS                     81
 
981
#define SSH_MSG_REQUEST_FAILURE                     82
 
982
 
 
983
#define SSH_MSG_CHANNEL_OPEN                        90
 
984
#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION           91
 
985
#define SSH_MSG_CHANNEL_OPEN_FAILURE                92
 
986
#define SSH_MSG_CHANNEL_WINDOW_ADJUST               93
 
987
#define SSH_MSG_CHANNEL_DATA                        94
 
988
#define SSH_MSG_CHANNEL_EXTENDED_DATA               95
 
989
#define SSH_MSG_CHANNEL_EOF                         96
 
990
#define SSH_MSG_CHANNEL_CLOSE                       97
 
991
#define SSH_MSG_CHANNEL_REQUEST                     98
 
992
#define SSH_MSG_CHANNEL_SUCCESS                     99
 
993
#define SSH_MSG_CHANNEL_FAILURE                     100
 
994
 
 
995
/* Error codes returned in SSH_MSG_CHANNEL_OPEN_FAILURE message
 
996
   (see RFC4254) */
 
997
#define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1
 
998
#define SSH_OPEN_CONNECT_FAILED              2
 
999
#define SSH_OPEN_UNKNOWN_CHANNELTYPE         3
 
1000
#define SSH_OPEN_RESOURCE_SHORTAGE           4
 
1001
 
 
1002
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer,
 
1003
                      size_t length, int flags, void **abstract);
 
1004
ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer,
 
1005
                      size_t length, int flags, void **abstract);
 
1006
 
 
1007
#define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
 
1008
                                   waiting for more data to arrive */
 
1009
 
 
1010
 
 
1011
int _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
 
1012
                          key_exchange_state_t * state);
 
1013
 
 
1014
/* Let crypt.c/hostkey.c expose their method structs */
 
1015
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void);
 
1016
const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void);
 
1017
 
 
1018
/* pem.c */
 
1019
int _libssh2_pem_parse(LIBSSH2_SESSION * session,
 
1020
                       const char *headerbegin,
 
1021
                       const char *headerend,
 
1022
                       FILE * fp, unsigned char **data, unsigned int *datalen);
 
1023
int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen);
 
1024
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
 
1025
                                unsigned char **i, unsigned int *ilen);
 
1026
 
 
1027
/* global.c */
 
1028
void _libssh2_init_if_needed (void);
 
1029
 
 
1030
 
 
1031
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
 
1032
 
 
1033
/* define to output the libssh2_int64_t type in a *printf() */
 
1034
#if defined( __BORLANDC__ ) || defined( _MSC_VER ) || defined( __MINGW32__ )
 
1035
#define LIBSSH2_INT64_T_FORMAT "I64d"
 
1036
#else
 
1037
#define LIBSSH2_INT64_T_FORMAT "lld"
 
1038
#endif
 
1039
 
 
1040
#endif /* LIBSSH2_H */