forked from ivanhennig/fpc-ssh-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibssh2.pas
executable file
·1562 lines (1335 loc) · 55.9 KB
/
libssh2.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit libssh2;
// Ludo Brands ported to freepascal
// **zm ** translated to pascal
interface
{$ifdef fpc}
{$mode delphi}
uses
ctypes;
{$IFDEF WINDOWS}
const
libssh2_name = 'libssh2.dll';
{$ENDIF}
{$IFDEF LINUX}
const
libssh2_name = 'libssh2.so';
{$ENDIF}
type
Uint=cuint;
ULong=culong;
Short=cshort;
PUCHAR=pcuchar;
{$else}
uses
{$IFDEF WIN32}
Windows;
{$ELSE}
Wintypes, WinProcs;
{$ENDIF}
const
libssh2_name = 'libssh2.dll';
{$ENDIF}
{+// Copyright (c) 2004-2009, Sara Golemon <[email protected]> }
{-* Copyright (c) 2009 by Daniel Stenberg }
{-* Copyright (c) 2010 Simon Josefsson <[email protected]>}
{-* All rights reserved. }
{-* }
{-* Redistribution and use in source and binary forms, }
{-* with or without modification, are permitted provided }
{-* that the following conditions are met: }
{-* }
{-* Redistributions of source code must retain the above }
{-* copyright notice, this list of conditions and the }
{-* following disclaimer. }
{-* }
{-* Redistributions in binary form must reproduce the above }
{-* copyright notice, this list of conditions and the following }
{-* disclaimer in the documentation and/or other materials }
{-* provided with the distribution. }
{-* }
{-* Neither the name of the copyright holder nor the names }
{-* of any other contributors may be used to endorse or }
{-* promote products derived from this software without }
{-* specific prior written permission. }
{-* }
{-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND }
{-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, }
{-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES }
{-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE }
{-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR }
{-* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, }
{-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, }
{-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR }
{-* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS }
{-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, }
{-* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING }
{-* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE }
{-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY }
{-* OF SUCH DAMAGE. }
{= }
type
libssh2_uint64_t = UInt64;
type
libssh2_int64_t = Int64;
type
uint32_t = UInt;
type
ssize_t = Integer;
type
time_t = ULong;
{+// We use underscore instead of dash when appending CVS in dev versions just }
{-to make the BANNER define (used by src/session.c) be a valid SSH }
{-banner. Release versions have no appended strings and may of course not }
{=have dashes either. }
const
_LIBSSH2_VERSION = '1.2.6';
{+// The numeric version number is also available "in parts" by using these }
{=defines: }
const
LIBSSH2_VERSION_MAJOR = 1;
const
LIBSSH2_VERSION_MINOR = 2;
const
LIBSSH2_VERSION_PATCH = 6;
const
SHA_DIGEST_LENGTH = 20;
MD5_DIGEST_LENGTH = 16;
{+// This is the numeric version of the libssh2 version number, meant for easier }
{-parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will }
{-always follow this syntax: }
{-0xXXYYZZ }
{-Where XX, YY and ZZ are the main version, release and patch numbers in }
{-hexadecimal (using 8 bits each). All three numbers are always represented }
{-using two digits. 1.2 would appear as "0x010200" while version 9.11.7 }
{-appears as "0x090b07". }
{-This 6-digit (24 bits) hexadecimal number does not show pre-release number, }
{-and it is always a greater number in a more recent release. It makes }
{-comparisons with greater than and less than work. }
{= }
const
LIBSSH2_VERSION_NUM = $010206;
{+// }
{-* This is the date and time when the full source package was created. The }
{-* timestamp is not stored in CVS, as the timestamp is properly set in the }
{-* tarballs by the maketgz script. }
{-* }
{-* The format of the date should follow this template: }
{-* }
{-* "Mon Feb 12 11:35:33 UTC 2007" }
{= }
const
LIBSSH2_TIMESTAMP = 'Thu Jun 10 08:19:51 UTC 2010';
{+// Part of every banner, user specified or not*/ }
const
LIBSSH2_SSH_BANNER = 'SSH-2.0-libssh2_' + _LIBSSH2_VERSION;
{+// We*could* add a comment here if we so chose*/ }
const
LIBSSH2_SSH_DEFAULT_BANNER = LIBSSH2_SSH_BANNER;
const
LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF = LIBSSH2_SSH_DEFAULT_BANNER + '#13#10';
{+// Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1*/ }
const
LIBSSH2_DH_GEX_MINGROUP = 1024;
const
LIBSSH2_DH_GEX_OPTGROUP = 1536;
const
LIBSSH2_DH_GEX_MAXGROUP = 2048;
{+// Defaults for pty requests*/ }
const
LIBSSH2_TERM_WIDTH = 80;
const
LIBSSH2_TERM_HEIGHT = 24;
const
LIBSSH2_TERM_WIDTH_PX = 0;
const
LIBSSH2_TERM_HEIGHT_PX = 0;
{+// 1/4 second*/ }
const
LIBSSH2_SOCKET_POLL_UDELAY = 250000;
{+// 0.25* 120 == 30 seconds*/ }
const
LIBSSH2_SOCKET_POLL_MAXLOOPS = 120;
{+// Maximum size to allow a payload to compress to, plays it safe by falling }
{=short of spec limits }
const
LIBSSH2_PACKET_MAXCOMP = 32000;
{+// Maximum size to allow a payload to deccompress to, plays it safe by }
{=allowing more than spec requires }
const
LIBSSH2_PACKET_MAXDECOMP = 40000;
{+// Maximum size for an inbound compressed payload, plays it safe by }
{=overshooting spec limits }
const
LIBSSH2_PACKET_MAXPAYLOAD = 40000;
{+// Malloc callbacks*/ }
// ovo je vec definisano u ssh2_priv alloc, realloc, free
type
_LIBSSH2_SESSION = record
end;
_LIBSSH2_CHANNEL = record
end;
_LIBSSH2_LISTENER = record
end;
_LIBSSH2_KNOWNHOSTS = record
end;
_LIBSSH2_AGENT = record
end;
type
LIBSSH2_SESSION = _LIBSSH2_SESSION;
LIBSSH2_CHANNEL = _LIBSSH2_CHANNEL;
LIBSSH2_LISTENER = _LIBSSH2_LISTENER;
LIBSSH2_KNOWNHOSTS = _LIBSSH2_KNOWNHOSTS;
LIBSSH2_AGENT = _LIBSSH2_AGENT;
PLIBSSH2_SESSION = ^LIBSSH2_SESSION;
PLIBSSH2_CHANNEL = ^LIBSSH2_CHANNEL;
PLIBSSH2_LISTENER = ^LIBSSH2_LISTENER;
PLIBSSH2_KNOWNHOSTS = ^LIBSSH2_KNOWNHOSTS;
PLIBSSH2_AGENT = ^LIBSSH2_AGENT;
SIZE_T = UINT;
type
_LIBSSH2_USERAUTH_KBDINT_PROMPT = record
text: PAnsiChar;
length: UInt;
echo: Byte;
end {_LIBSSH2_USERAUTH_KBDINT_PROMPT};
LIBSSH2_USERAUTH_KBDINT_PROMPT = _LIBSSH2_USERAUTH_KBDINT_PROMPT;
PLIBSSH2_USERAUTH_KBDINT_PROMPT = ^LIBSSH2_USERAUTH_KBDINT_PROMPT;
type
_LIBSSH2_USERAUTH_KBDINT_RESPONSE = record
text: PAnsiChar;
length: UInt;
end {_LIBSSH2_USERAUTH_KBDINT_RESPONSE};
LIBSSH2_USERAUTH_KBDINT_RESPONSE = _LIBSSH2_USERAUTH_KBDINT_RESPONSE;
{/* 'publickey' authentication callback */}
type
LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC = function(
session: PLIBSSH2_SESSION; var sig: PByte; sig_len: size_t;
const data: PByte; data_len: size_t; abstract: Pointer): Integer; cdecl;
{+// 'keyboard-interactive' authentication callback*/ }
type
LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC = procedure (const name: PAnsiChar;
name_len: Integer;
const instruction: PAnsiChar;
instruction_len: Integer;
num_prompts: Integer;
const prompts: PLIBSSH2_USERAUTH_KBDINT_PROMPT;
var responses: LIBSSH2_USERAUTH_KBDINT_RESPONSE;
abstract: Pointer); cdecl;
{+// Callbacks for special SSH packets*/ }
type
LIBSSH2_IGNORE_FUNC = procedure (session: PLIBSSH2_SESSION;
const message: PAnsiChar;
message_len: Integer;
abstract: Pointer); cdecl ;
type
LIBSSH2_DEBUG_FUNC = procedure (session: PLIBSSH2_SESSION;
always_display: Integer;
const message: PAnsiChar;
message_len: Integer;
const language: PAnsiChar;
language_len: Integer;
abstract: Pointer); cdecl ;
type
LIBSSH2_DISCONNECT_FUNC = procedure(session: PLIBSSH2_SESSION;
reason: Integer;
const message: PAnsiChar;
message_len: Integer;
const language: PAnsiChar;
language_len: Integer;
abstract: Pointer); cdecl ;
type
LIBSSH2_PASSWD_CHANGEREQ_FUNC = procedure(session: PLIBSSH2_SESSION;
var newpw: PAnsiChar;
var newpw_len: Integer;
abstract: Pointer); cdecl ;
type
LIBSSH2_MACERROR_FUNC = function (session: PLIBSSH2_SESSION;
const packet: PAnsiChar;
packet_len: Integer;
abstract: Pointer): Integer; cdecl ;
type
LIBSSH2_X11_OPEN_FUNC = procedure (session: PLIBSSH2_SESSION;
channel: PLIBSSH2_CHANNEL;
const shost: PAnsiChar;
sport: Integer;
abstract: Pointer); cdecl ;
type
LIBSSH2_CHANNEL_CLOSE_FUNC = procedure (session: PLIBSSH2_SESSION;
var session_abstract: Pointer;
channel: PLIBSSH2_CHANNEL;
var channel_abstract: Pointer); cdecl ;
{+// libssh2_session_callback_set() constants*/ }
const
LIBSSH2_CALLBACK_IGNORE = 0;
const
LIBSSH2_CALLBACK_DEBUG = 1;
const
LIBSSH2_CALLBACK_DISCONNECT = 2;
const
LIBSSH2_CALLBACK_MACERROR = 3;
const
LIBSSH2_CALLBACK_X11 = 4;
{+// libssh2_session_method_pref() constants*/ }
const
LIBSSH2_METHOD_KEX = 0;
const
LIBSSH2_METHOD_HOSTKEY = 1;
const
LIBSSH2_METHOD_CRYPT_CS = 2;
const
LIBSSH2_METHOD_CRYPT_SC = 3;
const
LIBSSH2_METHOD_MAC_CS = 4;
const
LIBSSH2_METHOD_MAC_SC = 5;
const
LIBSSH2_METHOD_COMP_CS = 6;
const
LIBSSH2_METHOD_COMP_SC = 7;
const
LIBSSH2_METHOD_LANG_CS = 8;
const
LIBSSH2_METHOD_LANG_SC = 9;
{+// session.flags bits*/ }
const
LIBSSH2_FLAG_SIGPIPE = $00000001;
type
PLIBSSH2_POLLFD = ^_LIBSSH2_POLLFD;
_LIBSSH2_POLLFD = record
_type: Byte;
{= LIBSSH2_POLLFD_* below }
socket: Integer;
{= File descriptors -- examined with system select() call }
channel: PLIBSSH2_CHANNEL;
{= Examined by checking internal state }
listener: PLIBSSH2_LISTENER;
{- Read polls only -- are inbound }
{=connections waiting to be accepted? }
end {fd};
LIBSSH2_POLLFD = _LIBSSH2_POLLFD;
{= Requested Events }
{= Returned Events }
{+// Poll FD Descriptor Types*/ }
const
LIBSSH2_POLLFD_SOCKET = 1;
const
LIBSSH2_POLLFD_CHANNEL = 2;
const
LIBSSH2_POLLFD_LISTENER = 3;
{+// Note: Win32 Doesn't actually have a poll() implementation, so some of these }
{=values are faked with select() data }
{+// Poll FD events/revents -- Match sys/poll.h where possible*/ }
const
LIBSSH2_POLLFD_POLLIN = $0001; {/* Data available to be read or}
const
LIBSSH2_POLLFD_POLLPRI = $0002; {/* Priority data available to
be read -- Socket only */}
const
LIBSSH2_POLLFD_POLLEXT = $0002; {/* Extended data available to
be read -- Channel only */}
const
LIBSSH2_POLLFD_POLLOUT = $0004; {/* Can may be written --
Socket/Channel */}
const
LIBSSH2_POLLFD_POLLERR = $0008; {/* Error Condition -- Socket*/}
const
LIBSSH2_POLLFD_POLLHUP = $0010; {/* HangUp/EOF -- Socket*/}
const
LIBSSH2_POLLFD_SESSION_CLOSED = $0010; {/* Session Disconnect*/}
const
LIBSSH2_POLLFD_POLLNVAL = $0020; {/* Invalid request -- Socket
Only */}
const
LIBSSH2_POLLFD_POLLEX = $0040; {/* Exception Condition --
Socket/Win32 */}
const
LIBSSH2_POLLFD_CHANNEL_CLOSED = $0080; {/* Channel Disconnect */}
const
LIBSSH2_POLLFD_LISTENER_CLOSED = $0080; {/* Listener Disconnect*/}
const
HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION = 1;
{+// Block Direction Types*/ }
const
LIBSSH2_SESSION_BLOCK_INBOUND = $0001;
const
LIBSSH2_SESSION_BLOCK_OUTBOUND = $0002;
{+// Hash Types*/ }
const
LIBSSH2_HOSTKEY_HASH_MD5 = 1;
const
LIBSSH2_HOSTKEY_HASH_SHA1 = 2;
{+// Hostkey Types */ }
const
LIBSSH2_HOSTKEY_TYPE_UNKNOWN = 0;
const
LIBSSH2_HOSTKEY_TYPE_RSA = 1;
const
LIBSSH2_HOSTKEY_TYPE_DSS = 2;
{+// Disconnect Codes (defined by SSH protocol)*/ }
const
SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1;
const
SSH_DISCONNECT_PROTOCOL_ERROR = 2;
const
SSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3;
const
SSH_DISCONNECT_RESERVED = 4;
const
SSH_DISCONNECT_MAC_ERROR = 5;
const
SSH_DISCONNECT_COMPRESSION_ERROR = 6;
const
SSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7;
const
SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8;
const
SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9;
const
SSH_DISCONNECT_CONNECTION_LOST = 10;
const
SSH_DISCONNECT_BY_APPLICATION = 11;
const
SSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12;
const
SSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13;
const
SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14;
const
SSH_DISCONNECT_ILLEGAL_USER_NAME = 15;
{+// Error Codes (defined by libssh2)*/ }
const
LIBSSH2_ERROR_NONE = 0;
const
LIBSSH2_ERROR_SOCKET_NONE = -1;
const
LIBSSH2_ERROR_BANNER_NONE = -2;
const
LIBSSH2_ERROR_BANNER_SEND = -3;
const
LIBSSH2_ERROR_INVALID_MAC = -4;
const
LIBSSH2_ERROR_KEX_FAILURE = -5;
const
LIBSSH2_ERROR_ALLOC = -6;
const
LIBSSH2_ERROR_SOCKET_SEND = -7;
const
LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE = -8;
const
LIBSSH2_ERROR_TIMEOUT = -9;
const
LIBSSH2_ERROR_HOSTKEY_INIT = -10;
const
LIBSSH2_ERROR_HOSTKEY_SIGN = -11;
const
LIBSSH2_ERROR_DECRYPT = -12;
const
LIBSSH2_ERROR_SOCKET_DISCONNECT = -13;
const
LIBSSH2_ERROR_PROTO = -14;
const
LIBSSH2_ERROR_PASSWORD_EXPIRED = -15;
const
LIBSSH2_ERROR_FILE = -16;
const
LIBSSH2_ERROR_METHOD_NONE = -17;
const
LIBSSH2_ERROR_AUTHENTICATION_FAILED = -18;
const
LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
const
LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED = -19;
const
LIBSSH2_ERROR_CHANNEL_OUTOFORDER = -20;
const
LIBSSH2_ERROR_CHANNEL_FAILURE = -21;
const
LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED = -22;
const
LIBSSH2_ERROR_CHANNEL_UNKNOWN = -23;
const
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED = -24;
const
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED = -25;
const
LIBSSH2_ERROR_CHANNEL_CLOSED = -26;
const
LIBSSH2_ERROR_CHANNEL_EOF_SENT = -27;
const
LIBSSH2_ERROR_SCP_PROTOCOL = -28;
const
LIBSSH2_ERROR_ZLIB = -29;
const
LIBSSH2_ERROR_SOCKET_TIMEOUT = -30;
const
LIBSSH2_ERROR_SFTP_PROTOCOL = -31;
const
LIBSSH2_ERROR_REQUEST_DENIED = -32;
const
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED = -33;
const
LIBSSH2_ERROR_INVAL = -34;
const
LIBSSH2_ERROR_INVALID_POLL_TYPE = -35;
const
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL = -36;
const
LIBSSH2_ERROR_EAGAIN = -37;
const
LIBSSH2_ERROR_BUFFER_TOO_SMALL = -38;
const
LIBSSH2_ERROR_BAD_USE = -39;
const
LIBSSH2_ERROR_COMPRESS = -40;
const
LIBSSH2_ERROR_OUT_OF_BOUNDARY = -41;
const
LIBSSH2_ERROR_AGENT_PROTOCOL = -42;
{+// Global API*/}
const
LIBSSH2_INIT_NO_CRYPTO = $0001;
{/*
* libssh2_init()
*
* Initialize the libssh2 functions. This typically initialize the
* crypto library. It uses a global state, and is not thread safe --
* you must make sure this function is not called concurrently.
*
* Flags can be:
* 0: Normal initialize
* LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
* OPENSSL_add_cipher_algoritms() for OpenSSL
*
* Returns 0 if succeeded, or a negative value for error.
*/}
function libssh2_init(flags: Integer): Integer; cdecl;
{/*
* libssh2_exit()
*
* Exit the libssh2 functions and free's all memory used internal.
*/}
procedure libssh2_exit; cdecl;
type
// abstract je void**, tako da pazite!!!!
LIBSSH2_ALLOC_FUNC = function(count: UINT; abstract: Pointer): Pointer; cdecl;
LIBSSH2_REALLOC_FUNC = function(ptr: Pointer; count: UINT; abstract: Pointer): Pointer; cdecl;
LIBSSH2_FREE_FUNC = procedure(ptr: Pointer; abstract: Pointer); cdecl;
{+// Session API*/ }
function libssh2_session_init_ex(my_alloc: LIBSSH2_ALLOC_FUNC;
my_free: LIBSSH2_FREE_FUNC;
my_realloc: LIBSSH2_REALLOC_FUNC;
abstract: Pointer): PLIBSSH2_SESSION; cdecl;
function libssh2_session_init: PLIBSSH2_SESSION; inline;
function libssh2_session_abstract(session: PLIBSSH2_SESSION): Pointer; cdecl;
function libssh2_session_callback_set(session: PLIBSSH2_SESSION;
cbtype: Integer;
callback: Pointer): Pointer; cdecl;
function libssh2_banner_set(session: PLIBSSH2_SESSION;
const banner: PAnsiChar): Integer; cdecl;
function libssh2_session_startup(session: PLIBSSH2_SESSION;
sock: Integer): Integer; cdecl;
function libssh2_session_disconnect_ex(session: PLIBSSH2_SESSION;
reason: Integer;
const description: PAnsiChar;
const lang: PAnsiChar): Integer; cdecl ;
function libssh2_session_disconnect(session: PLIBSSH2_SESSION; const description: PAnsiChar): Integer; inline;
function libssh2_session_free(session: PLIBSSH2_SESSION): Integer; cdecl ;
function libssh2_hostkey_hash(session: PLIBSSH2_SESSION;
hash_type: Integer): PAnsiChar; cdecl ;
function libssh2_session_hostkey(session: PLIBSSH2_SESSION;
var len: size_t;
var _type: Integer): PAnsiChar; cdecl;
function libssh2_session_method_pref(session: PLIBSSH2_SESSION;
method_type: Integer;
const prefs: PAnsiChar): Integer; cdecl ;
function libssh2_session_methods(session: PLIBSSH2_SESSION;
method_type: Integer): PAnsiChar; cdecl ;
function libssh2_session_last_error(session: PLIBSSH2_SESSION;
var errmsg: PAnsiChar;
var errmsg_len: Integer;
want_buf: Integer): Integer; cdecl;
function libssh2_session_last_errno(session: PLIBSSH2_SESSION): Integer; cdecl ;
function libssh2_session_block_directions(session: PLIBSSH2_SESSION): Integer; cdecl ;
function libssh2_session_flag(session: PLIBSSH2_SESSION;
flag: Integer;
value: Integer): Integer; cdecl ;
{+// Userauth API*/ }
function libssh2_userauth_list(session: PLIBSSH2_SESSION;
const username: PAnsiChar;
username_len: UINT): PAnsiChar; cdecl ;
function libssh2_userauth_authenticated(session: PLIBSSH2_SESSION): Integer; cdecl ;
function libssh2_userauth_password_ex(session: PLIBSSH2_SESSION;
const username: PAnsiChar;
username_len: Uint;
const password: PAnsiChar;
password_len: Uint;
passwd_change_cb: LIBSSH2_PASSWD_CHANGEREQ_FUNC): Integer; cdecl ;
function libssh2_userauth_password(session: PLIBSSH2_SESSION; const username: PAnsiChar; const password: PAnsiChar): Integer; inline;
function libssh2_userauth_publickey_fromfile_ex(session: PLIBSSH2_SESSION;
const username: PAnsiChar;
username_len: Uint;
const publickey: PAnsiChar;
const privatekey: PAnsiChar;
const passphrase: PAnsiChar): Integer; cdecl ;
function libssh2_userauth_publickey_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar;
const publickey: PAnsiChar; const privatekey: PAnsiChar; const passphrase: PAnsiChar): Integer; inline;
function libssh2_userauth_hostbased_fromfile_ex(session: PLIBSSH2_SESSION;
const username: PAnsiChar;
username_len: Uint;
const publickey: PAnsiChar;
const privatekey: PAnsiChar;
const passphrase: PAnsiChar;
const hostname: PAnsiChar;
hostname_len: UInt;
local_username: PAnsiChar;
local_username_len: UInt): Integer; cdecl ;
function libssh2_userauth_hostbased_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar; const publickey: PAnsiChar;
const privatekey: PAnsiChar; const passphrase: PAnsiChar; const hostname: PAnsiChar): Integer; inline;
{+// }
{-* response_callback is provided with filled by library prompts array, }
{-* but client must allocate and fill individual responses. Responses }
{-* array is already allocated. Responses data will be freed by libssh2 }
{-* after callback return, but before subsequent callback invokation. }
{= }
function libssh2_userauth_keyboard_interactive_ex(session: PLIBSSH2_SESSION;
const username: PAnsiChar;
username_len: UInt;
response_callback: LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC): Integer; cdecl ;
function libssh2_userauth_keyboard_interactive(session: PLIBSSH2_SESSION; const username: PAnsiChar; response_callback: LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC): Integer; inline;
function libssh2_poll(var fds: LIBSSH2_POLLFD;
nfds: UInt;
timeout: LongInt): Integer; cdecl ;
{+// Channel API*/ }
const
LIBSSH2_CHANNEL_WINDOW_DEFAULT = 65536;
const
LIBSSH2_CHANNEL_PACKET_DEFAULT = 32768;
const
LIBSSH2_CHANNEL_MINADJUST = 1024;
{+// Extended Data Handling*/ }
const
LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL = 0;
const
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE = 1;
const
LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE = 2;
const
SSH_EXTENDED_DATA_STDERR = 1;
{+// Returned by any function that would block during a read/write opperation*/ }
const
LIBSSH2CHANNEL_EAGAIN = LIBSSH2_ERROR_EAGAIN;
function libssh2_channel_open_ex(session: PLIBSSH2_SESSION;
const channel_type: PAnsiChar;
channel_type_len: Uint;
window_size: Uint;
packet_size: Uint;
const message: PAnsiChar;
message_len: Uint): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_channel_open_session(session: PLIBSSH2_SESSION): PLIBSSH2_CHANNEL; inline;
function libssh2_channel_direct_tcpip_ex(session: PLIBSSH2_SESSION;
const host: PAnsiChar;
port: Integer;
const shost: PAnsiChar;
sport: Integer): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_channel_direct_tcpip(session: PLIBSSH2_SESSION; const host: PAnsiChar; port: Integer): PLIBSSH2_CHANNEL; inline;
function libssh2_channel_forward_listen_ex(session: PLIBSSH2_SESSION;
const host: PAnsiChar;
port: Integer;
var bound_port: Integer;
queue_maxsize: Integer): PLIBSSH2_LISTENER cdecl ;
function libssh2_channel_forward_listen(session: PLIBSSH2_SESSION; port: Integer): PLIBSSH2_LISTENER; inline;
function libssh2_channel_forward_cancel(listener: PLIBSSH2_LISTENER): Integer; cdecl ;
function libssh2_channel_forward_accept(listener: PLIBSSH2_LISTENER): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_channel_setenv_ex(channel: PLIBSSH2_CHANNEL;
const varname: PAnsiChar;
varname_len: Uint;
const value: PAnsiChar;
value_len: UInt): Integer; cdecl ;
function libssh2_channel_setenv(channel: PLIBSSH2_CHANNEL; const varname: PAnsiChar; const value: PAnsiChar): Integer; inline;
function libssh2_channel_request_pty_ex(channel: PLIBSSH2_CHANNEL;
const term: PAnsiChar;
term_len: Uint;
const modes: PAnsiChar;
modes_len: Uint;
width: Integer;
height: Integer;
width_px: Integer;
height_px: Integer): Integer; cdecl ;
function libssh2_channel_request_pty(channel: PLIBSSH2_CHANNEL; const term: PAnsiChar): Integer; inline;
function libssh2_channel_request_pty_size_ex(channel: PLIBSSH2_CHANNEL;
width: Integer;
height: Integer;
width_px: Integer;
height_px: Integer): Integer; cdecl ;
function libssh2_channel_request_pty_size(channel: PLIBSSH2_CHANNEL; width: Integer; height: Integer): Integer; inline;
function libssh2_channel_x11_req_ex(channel: PLIBSSH2_CHANNEL;
single_connection: Integer;
const auth_proto: PAnsiChar;
const auth_cookie: PAnsiChar;
screen_number: Integer): Integer; cdecl ;
function libssh2_channel_x11_req(channel: PLIBSSH2_CHANNEL; screen_number: Integer): Integer; inline;
function libssh2_channel_process_startup(channel: PLIBSSH2_CHANNEL;
const request: PAnsiChar;
request_len: UInt;
const message: PAnsiChar;
message_len: UInt): Integer; cdecl ;
function libssh2_channel_shell(channel: PLIBSSH2_CHANNEL): Integer; inline;
function libssh2_channel_exec(channel: PLIBSSH2_CHANNEL; const command: PAnsiChar): Integer; inline;
function libssh2_channel_subsystem(channel: PLIBSSH2_CHANNEL; const subsystem: PAnsiChar): Integer; inline;
function libssh2_channel_read_ex(channel: PLIBSSH2_CHANNEL;
stream_id: Integer;
buf: PAnsiChar;
buflen: SIZE_T): Integer; cdecl ;
function libssh2_channel_read(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer; inline;
function libssh2_channel_read_stderr(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer; inline;
function libssh2_poll_channel_read(channel: PLIBSSH2_CHANNEL;
extended: Integer): Integer; cdecl ;
function libssh2_channel_window_read_ex(channel: PLIBSSH2_CHANNEL;
var read_avail: LongInt;
var window_size_initial: LongInt): ULong; cdecl ;
function libssh2_channel_window_read(channel: PLIBSSH2_CHANNEL): ULong; inline;
{+// libssh2_channel_receive_window_adjust is DEPRECATED, do not use!*/ }
function libssh2_channel_receive_window_adjust(channel: PLIBSSH2_CHANNEL;
adjustment: LongInt;
force: Byte): LongInt; cdecl ;
function libssh2_channel_receive_window_adjust2(channel: PLIBSSH2_CHANNEL;
adjustment: LongInt;
force: Byte;
var storewindow: ULong): Integer; cdecl ;
function libssh2_channel_write_ex(channel: PLIBSSH2_CHANNEL;
stream_id: Integer;
const buf: PAnsiChar;
buflen: ULong): Integer; cdecl ;
function libssh2_channel_write(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer; inline;
function libssh2_channel_write_stderr(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer; inline;
function libssh2_channel_window_write_ex(channel: PLIBSSH2_CHANNEL;
var window_size_initial: LongInt): ULong; cdecl ;
function libssh2_channel_window_write(channel: PLIBSSH2_CHANNEL): ULong; inline;
procedure libssh2_session_set_blocking(session: PLIBSSH2_SESSION;
blocking: Integer); cdecl ;
function libssh2_session_get_blocking(session: PLIBSSH2_SESSION): Integer; cdecl ;
procedure libssh2_channel_set_blocking(channel: PLIBSSH2_CHANNEL;
blocking: Integer); cdecl ;
{+// libssh2_channel_handle_extended_data is DEPRECATED, do not use!*/ }
procedure libssh2_channel_handle_extended_data(channel: PLIBSSH2_CHANNEL;
ignore_mode: Integer); cdecl ;
function libssh2_channel_handle_extended_data2(channel: PLIBSSH2_CHANNEL;
ignore_mode: Integer): Integer; cdecl ;
{+// libssh2_channel_ignore_extended_data() is defined below for BC with version }
{-* 0.1 }
{-* }
{-* Future uses should use libssh2_channel_handle_extended_data() directly if }
{-* LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read }
{-* (FIFO) from the standard data channel }
{= }
{+// DEPRECATED*/ }
procedure libssh2_channel_ignore_extended_data(channel: PLIBSSH2_CHANNEL; ignore: Integer); inline;
const
LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA = -1;
const
LIBSSH2_CHANNEL_FLUSH_ALL = -2;
function libssh2_channel_flush_ex(channel: PLIBSSH2_CHANNEL;
streamid: Integer): Integer; cdecl ;
function libssh2_channel_flush(channel: PLIBSSH2_CHANNEL): Integer; inline;
function libssh2_channel_flush_stderr(channel: PLIBSSH2_CHANNEL): Integer; inline;
function libssh2_channel_get_exit_status(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_send_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_wait_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_close(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_wait_closed(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
function libssh2_channel_free(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
type
Pstruct_stat = ^struct_stat;
struct_stat = record
st_dev: UINT;
st_ino: Word;
st_mode: Word;
st_nlink: Short;
st_uid: Short;
st_gid: Short;
st_rdev: UINT;
st_size: LongInt;
st_atime: Int64;
st_mtime: Int64;
st_ctime: Int64;
end;
function libssh2_scp_recv(session: PLIBSSH2_SESSION;
const path: PAnsiChar;
var sb: struct_stat): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_scp_send_ex(session: PLIBSSH2_SESSION;
const path: PAnsiChar;
mode: Integer;
size: SIZE_T;
mtime: LongInt;
atime: LongInt): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_scp_send64(session: PLIBSSH2_SESSION; const path: PAnsiChar; mode: Integer;
size: Int64; mtime: time_t; atime: time_t): PLIBSSH2_CHANNEL; cdecl ;
function libssh2_scp_send(session: PLIBSSH2_SESSION; const path: PAnsiChar; mode: Integer; size: SIZE_T): PLIBSSH2_CHANNEL; inline;
function libssh2_base64_decode(session: PLIBSSH2_SESSION;
var dest: PAnsiChar;
var dest_len: Uint;
const src: PAnsiChar;
src_len: Uint): Integer; cdecl;
function libssh2_version(req_version_num: Integer): PAnsiChar; cdecl ;
const
HAVE_LIBSSH2_KNOWNHOST_API = $010101; {/* since 1.1.1 */}
const
HAVE_LIBSSH2_VERSION_API = $010100; {/* libssh2_version since 1.1 */}
type
PLIBSSH2_KNOWNHOST = ^LIBSSH2_KNOWNHOST;
LIBSSH2_KNOWNHOST = record
magic: UInt; {/* magic stored by the library */}
node: Pointer; {/* handle to the internal representation of this host */}
name: PAnsiChar; {/* this is NULL if no plain text host name exists */}
key: PAnsiChar; {/* key in base64/printable format */}
typemask: Integer;
end;
{/*
* libssh2_knownhost_init
*
* Init a collection of known hosts. Returns the pointer to a collection.
*
*/}
function libssh2_knownhost_init(session: PLIBSSH2_SESSION): PLIBSSH2_KNOWNHOSTS; cdecl;
{/*
* libssh2_knownhost_add
*
* Add a host and its associated key to the collection of known hosts.
*
* The 'type' argument specifies on what format the given host is:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
* custom - another hash
*
* If 'sha1' is selected as type, the salt must be provided to the salt
* argument. This too base64 encoded.
*
* The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
*/}
{/* host format (2 bits) */}
const
LIBSSH2_KNOWNHOST_TYPE_MASK = $ffff;
const
LIBSSH2_KNOWNHOST_TYPE_PLAIN = 1;
const
LIBSSH2_KNOWNHOST_TYPE_SHA1 = 2; {/* always base64 encoded */}
const
LIBSSH2_KNOWNHOST_TYPE_CUSTOM = 3;
{/* key format (2 bits) */}
const LIBSSH2_KNOWNHOST_KEYENC_MASK = (3 shl 16);
const LIBSSH2_KNOWNHOST_KEYENC_RAW = (1 shl 16);
const LIBSSH2_KNOWNHOST_KEYENC_BASE64 = (2 shl 16);
{/* type of key (2 bits) */}
const LIBSSH2_KNOWNHOST_KEY_MASK = (3 shl 18);
const LIBSSH2_KNOWNHOST_KEY_SHIFT = 18;
const LIBSSH2_KNOWNHOST_KEY_RSA1 = (1 shl 18);
const LIBSSH2_KNOWNHOST_KEY_SSHRSA = (2 shl 18);
const LIBSSH2_KNOWNHOST_KEY_SSHDSS = (3 shl 18);
function libssh2_knownhost_add(hosts: PLIBSSH2_KNOWNHOSTS;
host,
salt,
key: PAnsiChar; keylen: size_t; typemask: Integer;
var store: PLIBSSH2_KNOWNHOST): Integer; cdecl ;