├── README.md
├── donate.png
├── fpc_ssh_client.lpr
├── fpc_ssh_client_indy10.lpr
└── libssh2.pas
/README.md:
--------------------------------------------------------------------------------
1 | # Free Pascal SSH Client
2 |
3 | Implementing an client demo with libssh2 bindings for Free Pascal
4 |
5 | ## Requirements
6 |
7 | - Lazarus 1.8
8 | - Development package libssh2-dev
9 | - Indy 10 for fpc_ssh_client_indy10
10 |
11 | ## How to build
12 |
13 | ```bash
14 | fpc fpc_ssh_client.lpr
15 | fpc fpc_ssh_client_indy10.lpr
16 | ```
17 |
18 | ## Donate
19 |
20 |
to **17PHL7Rw9rHujmRHkkPQGspLQ7rsDFV574**
21 |
22 | ## References
23 |
24 | - [libssh2 - the SSH library](https://libssh2.org/)
25 | - [libssh2 delphi](https://bitbucket.org/ZeljkoMarjanovic/libssh2-delphi)
26 | - [The Indy Project](http://www.indyproject.org/index.en.aspx)
27 |
--------------------------------------------------------------------------------
/donate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ivanhennig/fpc-ssh-client/0ec6f5e8b4368cf57513da8bfb13922bc5469ce4/donate.png
--------------------------------------------------------------------------------
/fpc_ssh_client.lpr:
--------------------------------------------------------------------------------
1 | program fpc_ssh_client;
2 |
3 | {$mode objfpc}{$H+}
4 | {$define UseCThreads}
5 | uses {$IFDEF UNIX} {$IFDEF UseCThreads}
6 | cthreads, {$ENDIF}
7 | BaseUnix, {$ENDIF}
8 | Classes,
9 | SysUtils,
10 | CustApp,
11 | resolve,
12 | netdb,
13 | libssh2,
14 | Sockets;
15 |
16 | type
17 |
18 | { TMyApplication }
19 |
20 | TMyApplication = class(TCustomApplication)
21 | protected
22 | procedure DoRun; override;
23 | public
24 | constructor Create(TheOwner: TComponent); override;
25 | destructor Destroy; override;
26 | procedure WriteHelp; virtual;
27 |
28 | procedure ssh();
29 |
30 | end;
31 |
32 | { TMyApplication }
33 |
34 | procedure TMyApplication.DoRun;
35 | var
36 | ErrorMsg: string;
37 | begin
38 | // quick check parameters
39 | ErrorMsg := CheckOptions('h', 'help');
40 | if ErrorMsg <> '' then
41 | begin
42 | ShowException(Exception.Create(ErrorMsg));
43 | Terminate;
44 | Exit;
45 | end;
46 |
47 | // parse parameters
48 | if HasOption('h', 'help') then
49 | begin
50 | WriteHelp;
51 | Terminate;
52 | Exit;
53 | end;
54 |
55 | { add your program here }
56 | ssh();
57 |
58 |
59 | // stop program loop
60 | Terminate;
61 | end;
62 |
63 | constructor TMyApplication.Create(TheOwner: TComponent);
64 | begin
65 | inherited Create(TheOwner);
66 | StopOnException := True;
67 | end;
68 |
69 | destructor TMyApplication.Destroy;
70 | begin
71 | inherited Destroy;
72 | end;
73 |
74 | procedure TMyApplication.WriteHelp;
75 | begin
76 | { add your help code here }
77 | writeln('Usage: ', ExeName, ' -h');
78 | end;
79 |
80 | procedure TMyApplication.ssh();
81 | var
82 | l_session: PLIBSSH2_SESSION;
83 | l_khost: PLIBSSH2_KNOWNHOST;
84 | l_khosts: PLIBSSH2_KNOWNHOSTS;
85 | l_channel: PLIBSSH2_CHANNEL;
86 |
87 | SockAddr: TInetSockAddr;
88 | HostAddr: THostAddr;
89 | HostEntry: THostEntry;
90 | l_socket: cint;
91 |
92 | r: integer;
93 |
94 | l_remote_fingerprint: PAnsiChar;
95 | l_session_hostkey: PAnsiChar;
96 | l_userauth_list: PAnsiChar;
97 | l_buffer: PAnsiChar;
98 |
99 | l_host: ansistring;
100 | l_user: PAnsiChar;
101 | l_pass: PAnsiChar;
102 | l_port: integer;
103 |
104 | o_len: SIZE_T;
105 | o_type: integer;
106 | o_out: integer;
107 |
108 | l_buffer2: array [0..4096] of char;
109 |
110 | l_cmd: PAnsiChar;
111 | i: integer;
112 | begin
113 | l_session := nil;
114 | l_channel := nil;
115 |
116 | l_host := '192.168.0.1';
117 | //or
118 | //l_host := 'something.com';
119 | l_user := 'root';
120 | l_pass := 'secretpass';
121 | l_port := 22;
122 |
123 | if (ResolveHostByName(l_host, HostEntry)) then
124 | begin
125 | l_host := NetAddrToStr(HostEntry.Addr);
126 | end;
127 |
128 | r := libssh2_init(0);
129 |
130 | //**********
131 | HostAddr := StrToNetAddr(l_host);
132 | l_socket := fpsocket(AF_INET, SOCK_STREAM, 0);
133 | if l_socket = -1 then
134 | raise Exception.Create('fpsocket');
135 | SockAddr.sin_family := AF_INET;
136 | SockAddr.sin_Port := htons(l_port);
137 | SockAddr.sin_Addr.s_addr := cardinal(HostAddr);
138 |
139 | if fpconnect(l_socket, @SockAddr, SizeOf(SockAddr)) <> 0 then
140 | raise Exception.Create('fpconnect');
141 | //**********
142 |
143 | l_session := libssh2_session_init();
144 |
145 | try
146 | try
147 | if (Assigned(l_session)) then
148 | begin
149 | WriteLn('Session created');
150 | end
151 | else
152 | begin
153 | Exit;
154 | end;
155 |
156 | libssh2_session_set_blocking(l_session, 0);
157 |
158 |
159 | while True do
160 | begin
161 | r := libssh2_session_startup(l_session, l_socket);
162 | if (r = 0) then
163 | Break;
164 | if (r = LIBSSH2_ERROR_EAGAIN) then
165 | Continue;
166 | end;
167 | if (r > 0) then
168 | begin
169 | WriteLn('Handshake failure ');
170 | Exit;
171 | end;
172 |
173 | l_remote_fingerprint := libssh2_hostkey_hash(l_session, LIBSSH2_HOSTKEY_HASH_SHA1);
174 |
175 | Write('Fingerprint: ');
176 | for i := 0 to 19 do
177 | begin
178 | Write(Format('%02X', [Ord(l_remote_fingerprint[i])]));
179 | end;
180 | WriteLn('');
181 |
182 | while True do
183 | begin
184 | l_userauth_list := libssh2_userauth_list(l_session, PAnsiChar(l_user), Length(l_user));
185 | if (Assigned(l_userauth_list)) then
186 | Break;
187 |
188 | l_buffer := nil;
189 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
190 | if (r = LIBSSH2_ERROR_EAGAIN) then
191 | begin
192 | Continue;
193 | end
194 | else
195 | begin
196 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
197 | end;
198 | end;
199 |
200 |
201 | WriteLn(l_userauth_list);
202 |
203 | if Pos('password', l_userauth_list) > 0 then
204 | begin
205 | while True do
206 | begin
207 | r := libssh2_userauth_password(l_session, l_user, l_pass);
208 | if (r = 0) then
209 | Break;
210 |
211 | l_buffer := nil;
212 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
213 | if (r = LIBSSH2_ERROR_EAGAIN) then
214 | begin
215 | Continue;
216 | end
217 | else
218 | begin
219 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
220 | end;
221 | end;
222 |
223 | end
224 | else if Pos('publickey', l_userauth_list) > 0 then
225 | begin
226 |
227 | end;
228 | //is authenticated?
229 | r := libssh2_userauth_authenticated(l_session);
230 | if (r = 0) then
231 | begin
232 | raise Exception.CreateFmt('Failure: (%d) is not authenticated', [r]);
233 | end;
234 |
235 |
236 | while True do
237 | begin
238 | l_channel := libssh2_channel_open_ex(l_session, 'session', Length('session'), LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, nil, 0);
239 | if (Assigned(l_channel)) then
240 | Break;
241 | //waitSock(l_socket, l_session);
242 | l_buffer := nil;
243 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
244 | if (r = LIBSSH2_ERROR_EAGAIN) then
245 | begin
246 | Continue;
247 | end
248 | else
249 | begin
250 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
251 | end;
252 | end;
253 | if (Assigned(l_channel)) then
254 | begin
255 | WriteLn('Channel opened');
256 |
257 |
258 |
259 |
260 | while True do
261 | begin
262 | l_cmd := 'echo "ABCAAAAAAAAAAAAAAAAAAAA"';
263 | l_cmd := 'ls -lash';
264 | r := libssh2_channel_process_startup(l_channel, 'exec', Length('exec'), l_cmd, Length(l_cmd));
265 | if (r = 0) then
266 | Break;
267 | l_buffer := nil;
268 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
269 | if (r = LIBSSH2_ERROR_EAGAIN) then
270 | begin
271 | Continue;
272 | end
273 | else
274 | begin
275 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
276 | end;
277 |
278 | end;
279 |
280 |
281 | if (True) then
282 | begin
283 | WriteLn('Command executed');
284 | while (True) do
285 | begin
286 |
287 | for i := 0 to High(l_buffer2) do
288 | begin
289 | l_buffer2[i] := #0;
290 | end;
291 | r := libssh2_channel_read_ex(l_channel, 0, @l_buffer2, High(l_buffer2));
292 | if (r > 0) then
293 | begin
294 | Write(l_buffer2);
295 | Continue;
296 | end;
297 |
298 | if (r = 0) then
299 | Break;
300 |
301 | l_buffer := nil;
302 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
303 | if (r = LIBSSH2_ERROR_EAGAIN) then
304 | begin
305 | Continue;
306 | end
307 | else
308 | begin
309 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
310 | end;
311 |
312 | end;
313 |
314 | end;
315 |
316 | end;
317 |
318 |
319 | except
320 | on E: Exception do
321 | begin
322 | WriteLn(E.Message);
323 | end;
324 | end;
325 | finally
326 | if (Assigned(l_channel)) then
327 | begin
328 | libssh2_channel_close(l_channel);
329 | libssh2_channel_free(l_channel);
330 | end;
331 | if (Assigned(l_session)) then
332 | begin
333 | libssh2_session_disconnect(l_session, 'Tchau');
334 | libssh2_session_free(l_session);
335 | end;
336 | if (l_socket > 0) then
337 | begin
338 | FpClose(l_socket);
339 | end;
340 | libssh2_exit();
341 | end;
342 |
343 | end;
344 |
345 |
346 | var
347 | Application: TMyApplication;
348 | begin
349 | Application := TMyApplication.Create(nil);
350 | Application.Title := 'fpc_ssh_client';
351 | Application.Run;
352 | Application.Free;
353 | end.
354 |
--------------------------------------------------------------------------------
/fpc_ssh_client_indy10.lpr:
--------------------------------------------------------------------------------
1 | program project1;
2 |
3 | {$mode objfpc}{$H+}
4 | {$define UseCThreads}
5 | uses {$IFDEF UNIX} {$IFDEF UseCThreads}
6 | cthreads, {$ENDIF} {$ENDIF}
7 | Classes,
8 | SysUtils,
9 | CustApp,
10 | libssh2,
11 | libssh2_sftp,
12 | IdGlobal,
13 | IdStack,
14 | IdStackUnix,
15 | IdSocketHandle;
16 |
17 | type
18 |
19 | { TMyApplication }
20 |
21 | TMyApplication = class(TCustomApplication)
22 | protected
23 | procedure DoRun; override;
24 | public
25 | constructor Create(TheOwner: TComponent); override;
26 | destructor Destroy; override;
27 | procedure WriteHelp; virtual;
28 |
29 | procedure ssh();
30 |
31 | end;
32 |
33 | { TMyApplication }
34 |
35 | procedure TMyApplication.DoRun;
36 | var
37 | ErrorMsg: string;
38 | begin
39 | // quick check parameters
40 | ErrorMsg := CheckOptions('h', 'help');
41 | if ErrorMsg <> '' then
42 | begin
43 | ShowException(Exception.Create(ErrorMsg));
44 | Terminate;
45 | Exit;
46 | end;
47 |
48 | // parse parameters
49 | if HasOption('h', 'help') then
50 | begin
51 | WriteHelp;
52 | Terminate;
53 | Exit;
54 | end;
55 |
56 | { add your program here }
57 | ssh();
58 |
59 |
60 | // stop program loop
61 | Terminate;
62 | end;
63 |
64 | constructor TMyApplication.Create(TheOwner: TComponent);
65 | begin
66 | inherited Create(TheOwner);
67 | StopOnException := True;
68 | end;
69 |
70 | destructor TMyApplication.Destroy;
71 | begin
72 | inherited Destroy;
73 | end;
74 |
75 | procedure TMyApplication.WriteHelp;
76 | begin
77 | { add your help code here }
78 | writeln('Usage: ', ExeName, ' -h');
79 | end;
80 |
81 | procedure TMyApplication.ssh();
82 | var
83 | l_session: PLIBSSH2_SESSION;
84 |
85 | l_channel: PLIBSSH2_CHANNEL;
86 |
87 | r: integer;
88 |
89 | l_remote_fingerprint: PAnsiChar;
90 |
91 | l_userauth_list: PAnsiChar;
92 | l_buffer: PAnsiChar;
93 |
94 | l_host: ansistring;
95 | l_user: PAnsiChar;
96 | l_pass: PAnsiChar;
97 | l_port: integer;
98 |
99 | o_out: integer;
100 |
101 | l_buffer2: array [0..16] of char;
102 |
103 | l_cmd: PAnsiChar;
104 | i: integer;
105 |
106 | l_socket3: TIdSocketHandle;
107 | begin
108 | l_session := nil;
109 | l_channel := nil;
110 |
111 |
112 | l_host := '192.168.0.1';
113 | l_pass := 'secret';
114 | l_port := 22;
115 | l_user := 'ivan';
116 |
117 | try
118 | try
119 |
120 |
121 | GStack := TIdStackUnix.Create;
122 | l_socket3 := TIdSocketHandle.Create(nil);
123 | l_socket3.AllocateSocket();
124 | l_socket3.ReuseSocket := rsOSDependent;
125 | l_host := GStack.ResolveHost(l_host);
126 | l_socket3.SetPeer(l_host, l_port);
127 | l_socket3.Connect;
128 |
129 |
130 | l_session := libssh2_session_init();
131 |
132 |
133 |
134 |
135 |
136 | if (Assigned(l_session)) then
137 | begin
138 | WriteLn('Session created');
139 | end
140 | else
141 | begin
142 | Exit;
143 | end;
144 |
145 | libssh2_session_set_blocking(l_session, 0);
146 |
147 |
148 | while True do
149 | begin
150 | r := libssh2_session_startup(l_session, l_socket3.Handle);
151 | if (r = 0) then
152 | Break;
153 | if (r = LIBSSH2_ERROR_EAGAIN) then
154 | Continue;
155 | end;
156 | if (r > 0) then
157 | begin
158 | WriteLn('Handshake failure ');
159 | Exit;
160 | end;
161 |
162 | l_remote_fingerprint := libssh2_hostkey_hash(l_session, LIBSSH2_HOSTKEY_HASH_SHA1);
163 |
164 | Write('Fingerprint: ');
165 | for i := 0 to 19 do
166 | begin
167 | Write(Format('%02X', [Ord(l_remote_fingerprint[i])]));
168 | end;
169 | WriteLn('');
170 |
171 | while True do
172 | begin
173 | l_userauth_list := libssh2_userauth_list(l_session, PAnsiChar(l_user), Length(l_user));
174 | if (Assigned(l_userauth_list)) then
175 | Break;
176 |
177 | l_buffer := nil;
178 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
179 | if (r = LIBSSH2_ERROR_EAGAIN) then
180 | begin
181 | Continue;
182 | end
183 | else
184 | begin
185 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
186 | end;
187 | end;
188 |
189 |
190 | WriteLn(l_userauth_list);
191 |
192 | if Pos('password', l_userauth_list) > 0 then
193 | begin
194 | while True do
195 | begin
196 | r := libssh2_userauth_password(l_session, l_user, l_pass);
197 | if (r = 0) then
198 | Break;
199 |
200 | l_buffer := nil;
201 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
202 | if (r = LIBSSH2_ERROR_EAGAIN) then
203 | begin
204 | Continue;
205 | end
206 | else
207 | begin
208 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
209 | end;
210 | end;
211 |
212 | end
213 | else if Pos('publickey', l_userauth_list) > 0 then
214 | begin
215 |
216 | end;
217 | //is authenticated?
218 | r := libssh2_userauth_authenticated(l_session);
219 | if (r = 0) then
220 | begin
221 | raise Exception.CreateFmt('Failure: (%d) is not authenticated', [r]);
222 | end;
223 |
224 |
225 | while True do
226 | begin
227 | l_channel := libssh2_channel_open_ex(l_session, 'session', Length('session'), LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, nil, 0);
228 | if (Assigned(l_channel)) then
229 | Break;
230 | //waitSock(l_socket, l_session);
231 | l_buffer := nil;
232 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
233 | if (r = LIBSSH2_ERROR_EAGAIN) then
234 | begin
235 | Continue;
236 | end
237 | else
238 | begin
239 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
240 | end;
241 | end;
242 | if (Assigned(l_channel)) then
243 | begin
244 | WriteLn('Channel opened');
245 |
246 |
247 |
248 |
249 | while True do
250 | begin
251 | l_cmd := 'echo "ABCAAAAAAAAAAAAAAAAAAAA"';
252 | l_cmd := 'ls -lash';
253 | r := libssh2_channel_process_startup(l_channel, 'exec', Length('exec'), l_cmd, Length(l_cmd));
254 | if (r = 0) then
255 | Break;
256 | l_buffer := nil;
257 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
258 | if (r = LIBSSH2_ERROR_EAGAIN) then
259 | begin
260 | Continue;
261 | end
262 | else
263 | begin
264 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
265 | end;
266 |
267 | end;
268 |
269 |
270 | if (True) then
271 | begin
272 | WriteLn('Command executed');
273 | while (True) do
274 | begin
275 |
276 | for i := 0 to High(l_buffer2) do
277 | begin
278 | l_buffer2[i] := #0;
279 | end;
280 | r := libssh2_channel_read_ex(l_channel, 0, @l_buffer2, High(l_buffer2));
281 | if (r > 0) then
282 | begin
283 | Write(l_buffer2);
284 | Continue;
285 | end;
286 |
287 | if (r = 0) then
288 | Break;
289 |
290 | l_buffer := nil;
291 | r := libssh2_session_last_error(l_session, l_buffer, o_out, 0);
292 | if (r = LIBSSH2_ERROR_EAGAIN) then
293 | begin
294 | Continue;
295 | end
296 | else
297 | begin
298 | raise Exception.CreateFmt('Failure: (%d) %s', [r, l_buffer]);
299 | end;
300 |
301 | end;
302 |
303 | end;
304 |
305 | end;
306 |
307 |
308 | except
309 | on E: Exception do
310 | begin
311 | WriteLn(E.Message);
312 | end;
313 | end;
314 | finally
315 | if (Assigned(l_channel)) then
316 | begin
317 | libssh2_channel_close(l_channel);
318 | libssh2_channel_free(l_channel);
319 | end;
320 | if (Assigned(l_session)) then
321 | begin
322 | libssh2_session_disconnect(l_session, 'Tchau');
323 | libssh2_session_free(l_session);
324 | end;
325 | if (Assigned(l_socket3)) then
326 | begin
327 | l_socket3.Free;
328 | end;
329 |
330 | libssh2_exit();
331 | end;
332 |
333 | end;
334 |
335 |
336 | var
337 | Application: TMyApplication;
338 | begin
339 | Application := TMyApplication.Create(nil);
340 | Application.Title := 'My Application';
341 | Application.Run;
342 | Application.Free;
343 | end.
344 |
--------------------------------------------------------------------------------
/libssh2.pas:
--------------------------------------------------------------------------------
1 | unit libssh2;
2 |
3 | // Ludo Brands ported to freepascal
4 |
5 | // **zm ** translated to pascal
6 |
7 | interface
8 | {$ifdef fpc}
9 | {$mode delphi}
10 | uses
11 | ctypes;
12 | {$IFDEF WINDOWS}
13 | const
14 | libssh2_name = 'libssh2.dll';
15 | {$ENDIF}
16 | {$IFDEF LINUX}
17 | const
18 | libssh2_name = 'libssh2.so';
19 | {$ENDIF}
20 | type
21 | Uint=cuint;
22 | ULong=culong;
23 | Short=cshort;
24 | PUCHAR=pcuchar;
25 | {$else}
26 | uses
27 | {$IFDEF WIN32}
28 | Windows;
29 | {$ELSE}
30 | Wintypes, WinProcs;
31 | {$ENDIF}
32 | const
33 | libssh2_name = 'libssh2.dll';
34 | {$ENDIF}
35 |
36 | {+// Copyright (c) 2004-2009, Sara Golemon }
37 | {-* Copyright (c) 2009 by Daniel Stenberg }
38 | {-* Copyright (c) 2010 Simon Josefsson }
39 | {-* All rights reserved. }
40 | {-* }
41 | {-* Redistribution and use in source and binary forms, }
42 | {-* with or without modification, are permitted provided }
43 | {-* that the following conditions are met: }
44 | {-* }
45 | {-* Redistributions of source code must retain the above }
46 | {-* copyright notice, this list of conditions and the }
47 | {-* following disclaimer. }
48 | {-* }
49 | {-* Redistributions in binary form must reproduce the above }
50 | {-* copyright notice, this list of conditions and the following }
51 | {-* disclaimer in the documentation and/or other materials }
52 | {-* provided with the distribution. }
53 | {-* }
54 | {-* Neither the name of the copyright holder nor the names }
55 | {-* of any other contributors may be used to endorse or }
56 | {-* promote products derived from this software without }
57 | {-* specific prior written permission. }
58 | {-* }
59 | {-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND }
60 | {-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, }
61 | {-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES }
62 | {-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE }
63 | {-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR }
64 | {-* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, }
65 | {-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, }
66 | {-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR }
67 | {-* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS }
68 | {-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, }
69 | {-* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING }
70 | {-* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE }
71 | {-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY }
72 | {-* OF SUCH DAMAGE. }
73 | {= }
74 |
75 |
76 | type
77 | libssh2_uint64_t = UInt64;
78 | type
79 | libssh2_int64_t = Int64;
80 | type
81 | uint32_t = UInt;
82 | type
83 | ssize_t = Integer;
84 | type
85 | time_t = ULong;
86 |
87 | {+// We use underscore instead of dash when appending CVS in dev versions just }
88 | {-to make the BANNER define (used by src/session.c) be a valid SSH }
89 | {-banner. Release versions have no appended strings and may of course not }
90 | {=have dashes either. }
91 | const
92 | _LIBSSH2_VERSION = '1.2.6';
93 |
94 | {+// The numeric version number is also available "in parts" by using these }
95 | {=defines: }
96 | const
97 | LIBSSH2_VERSION_MAJOR = 1;
98 | const
99 | LIBSSH2_VERSION_MINOR = 2;
100 | const
101 | LIBSSH2_VERSION_PATCH = 6;
102 |
103 | const
104 | SHA_DIGEST_LENGTH = 20;
105 | MD5_DIGEST_LENGTH = 16;
106 |
107 |
108 | {+// This is the numeric version of the libssh2 version number, meant for easier }
109 | {-parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will }
110 | {-always follow this syntax: }
111 |
112 | {-0xXXYYZZ }
113 |
114 | {-Where XX, YY and ZZ are the main version, release and patch numbers in }
115 | {-hexadecimal (using 8 bits each). All three numbers are always represented }
116 | {-using two digits. 1.2 would appear as "0x010200" while version 9.11.7 }
117 | {-appears as "0x090b07". }
118 |
119 | {-This 6-digit (24 bits) hexadecimal number does not show pre-release number, }
120 | {-and it is always a greater number in a more recent release. It makes }
121 | {-comparisons with greater than and less than work. }
122 | {= }
123 | const
124 | LIBSSH2_VERSION_NUM = $010206;
125 |
126 | {+// }
127 | {-* This is the date and time when the full source package was created. The }
128 | {-* timestamp is not stored in CVS, as the timestamp is properly set in the }
129 | {-* tarballs by the maketgz script. }
130 | {-* }
131 | {-* The format of the date should follow this template: }
132 | {-* }
133 | {-* "Mon Feb 12 11:35:33 UTC 2007" }
134 | {= }
135 | const
136 | LIBSSH2_TIMESTAMP = 'Thu Jun 10 08:19:51 UTC 2010';
137 |
138 | {+// Part of every banner, user specified or not*/ }
139 | const
140 | LIBSSH2_SSH_BANNER = 'SSH-2.0-libssh2_' + _LIBSSH2_VERSION;
141 |
142 | {+// We*could* add a comment here if we so chose*/ }
143 | const
144 | LIBSSH2_SSH_DEFAULT_BANNER = LIBSSH2_SSH_BANNER;
145 | const
146 | LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF = LIBSSH2_SSH_DEFAULT_BANNER + '#13#10';
147 |
148 | {+// Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1*/ }
149 | const
150 | LIBSSH2_DH_GEX_MINGROUP = 1024;
151 | const
152 | LIBSSH2_DH_GEX_OPTGROUP = 1536;
153 | const
154 | LIBSSH2_DH_GEX_MAXGROUP = 2048;
155 |
156 | {+// Defaults for pty requests*/ }
157 | const
158 | LIBSSH2_TERM_WIDTH = 80;
159 | const
160 | LIBSSH2_TERM_HEIGHT = 24;
161 | const
162 | LIBSSH2_TERM_WIDTH_PX = 0;
163 | const
164 | LIBSSH2_TERM_HEIGHT_PX = 0;
165 |
166 | {+// 1/4 second*/ }
167 | const
168 | LIBSSH2_SOCKET_POLL_UDELAY = 250000;
169 | {+// 0.25* 120 == 30 seconds*/ }
170 | const
171 | LIBSSH2_SOCKET_POLL_MAXLOOPS = 120;
172 |
173 | {+// Maximum size to allow a payload to compress to, plays it safe by falling }
174 | {=short of spec limits }
175 | const
176 | LIBSSH2_PACKET_MAXCOMP = 32000;
177 |
178 | {+// Maximum size to allow a payload to deccompress to, plays it safe by }
179 | {=allowing more than spec requires }
180 | const
181 | LIBSSH2_PACKET_MAXDECOMP = 40000;
182 |
183 | {+// Maximum size for an inbound compressed payload, plays it safe by }
184 | {=overshooting spec limits }
185 | const
186 | LIBSSH2_PACKET_MAXPAYLOAD = 40000;
187 |
188 | {+// Malloc callbacks*/ }
189 | // ovo je vec definisano u ssh2_priv alloc, realloc, free
190 |
191 | type
192 | _LIBSSH2_SESSION = record
193 | end;
194 | _LIBSSH2_CHANNEL = record
195 | end;
196 | _LIBSSH2_LISTENER = record
197 | end;
198 | _LIBSSH2_KNOWNHOSTS = record
199 | end;
200 | _LIBSSH2_AGENT = record
201 | end;
202 |
203 | type
204 | LIBSSH2_SESSION = _LIBSSH2_SESSION;
205 | LIBSSH2_CHANNEL = _LIBSSH2_CHANNEL;
206 | LIBSSH2_LISTENER = _LIBSSH2_LISTENER;
207 | LIBSSH2_KNOWNHOSTS = _LIBSSH2_KNOWNHOSTS;
208 | LIBSSH2_AGENT = _LIBSSH2_AGENT;
209 | PLIBSSH2_SESSION = ^LIBSSH2_SESSION;
210 | PLIBSSH2_CHANNEL = ^LIBSSH2_CHANNEL;
211 | PLIBSSH2_LISTENER = ^LIBSSH2_LISTENER;
212 | PLIBSSH2_KNOWNHOSTS = ^LIBSSH2_KNOWNHOSTS;
213 | PLIBSSH2_AGENT = ^LIBSSH2_AGENT;
214 |
215 | SIZE_T = UINT;
216 |
217 | type
218 | _LIBSSH2_USERAUTH_KBDINT_PROMPT = record
219 | text: PAnsiChar;
220 | length: UInt;
221 | echo: Byte;
222 | end {_LIBSSH2_USERAUTH_KBDINT_PROMPT};
223 | LIBSSH2_USERAUTH_KBDINT_PROMPT = _LIBSSH2_USERAUTH_KBDINT_PROMPT;
224 | PLIBSSH2_USERAUTH_KBDINT_PROMPT = ^LIBSSH2_USERAUTH_KBDINT_PROMPT;
225 |
226 | type
227 | _LIBSSH2_USERAUTH_KBDINT_RESPONSE = record
228 | text: PAnsiChar;
229 | length: UInt;
230 | end {_LIBSSH2_USERAUTH_KBDINT_RESPONSE};
231 | LIBSSH2_USERAUTH_KBDINT_RESPONSE = _LIBSSH2_USERAUTH_KBDINT_RESPONSE;
232 |
233 | {/* 'publickey' authentication callback */}
234 | type
235 | LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC = function(
236 | session: PLIBSSH2_SESSION; var sig: PByte; sig_len: size_t;
237 | const data: PByte; data_len: size_t; abstract: Pointer): Integer; cdecl;
238 |
239 | {+// 'keyboard-interactive' authentication callback*/ }
240 | type
241 | LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC = procedure (const name: PAnsiChar;
242 | name_len: Integer;
243 | const instruction: PAnsiChar;
244 | instruction_len: Integer;
245 | num_prompts: Integer;
246 | const prompts: PLIBSSH2_USERAUTH_KBDINT_PROMPT;
247 | var responses: LIBSSH2_USERAUTH_KBDINT_RESPONSE;
248 | abstract: Pointer); cdecl;
249 | {+// Callbacks for special SSH packets*/ }
250 | type
251 | LIBSSH2_IGNORE_FUNC = procedure (session: PLIBSSH2_SESSION;
252 | const message: PAnsiChar;
253 | message_len: Integer;
254 | abstract: Pointer); cdecl ;
255 | type
256 | LIBSSH2_DEBUG_FUNC = procedure (session: PLIBSSH2_SESSION;
257 | always_display: Integer;
258 | const message: PAnsiChar;
259 | message_len: Integer;
260 | const language: PAnsiChar;
261 | language_len: Integer;
262 | abstract: Pointer); cdecl ;
263 | type
264 | LIBSSH2_DISCONNECT_FUNC = procedure(session: PLIBSSH2_SESSION;
265 | reason: Integer;
266 | const message: PAnsiChar;
267 | message_len: Integer;
268 | const language: PAnsiChar;
269 | language_len: Integer;
270 | abstract: Pointer); cdecl ;
271 | type
272 | LIBSSH2_PASSWD_CHANGEREQ_FUNC = procedure(session: PLIBSSH2_SESSION;
273 | var newpw: PAnsiChar;
274 | var newpw_len: Integer;
275 | abstract: Pointer); cdecl ;
276 | type
277 | LIBSSH2_MACERROR_FUNC = function (session: PLIBSSH2_SESSION;
278 | const packet: PAnsiChar;
279 | packet_len: Integer;
280 | abstract: Pointer): Integer; cdecl ;
281 | type
282 | LIBSSH2_X11_OPEN_FUNC = procedure (session: PLIBSSH2_SESSION;
283 | channel: PLIBSSH2_CHANNEL;
284 | const shost: PAnsiChar;
285 | sport: Integer;
286 | abstract: Pointer); cdecl ;
287 | type
288 | LIBSSH2_CHANNEL_CLOSE_FUNC = procedure (session: PLIBSSH2_SESSION;
289 | var session_abstract: Pointer;
290 | channel: PLIBSSH2_CHANNEL;
291 | var channel_abstract: Pointer); cdecl ;
292 |
293 | {+// libssh2_session_callback_set() constants*/ }
294 | const
295 | LIBSSH2_CALLBACK_IGNORE = 0;
296 | const
297 | LIBSSH2_CALLBACK_DEBUG = 1;
298 | const
299 | LIBSSH2_CALLBACK_DISCONNECT = 2;
300 | const
301 | LIBSSH2_CALLBACK_MACERROR = 3;
302 | const
303 | LIBSSH2_CALLBACK_X11 = 4;
304 |
305 | {+// libssh2_session_method_pref() constants*/ }
306 | const
307 | LIBSSH2_METHOD_KEX = 0;
308 | const
309 | LIBSSH2_METHOD_HOSTKEY = 1;
310 | const
311 | LIBSSH2_METHOD_CRYPT_CS = 2;
312 | const
313 | LIBSSH2_METHOD_CRYPT_SC = 3;
314 | const
315 | LIBSSH2_METHOD_MAC_CS = 4;
316 | const
317 | LIBSSH2_METHOD_MAC_SC = 5;
318 | const
319 | LIBSSH2_METHOD_COMP_CS = 6;
320 | const
321 | LIBSSH2_METHOD_COMP_SC = 7;
322 | const
323 | LIBSSH2_METHOD_LANG_CS = 8;
324 | const
325 | LIBSSH2_METHOD_LANG_SC = 9;
326 |
327 | {+// session.flags bits*/ }
328 | const
329 | LIBSSH2_FLAG_SIGPIPE = $00000001;
330 |
331 | type
332 | PLIBSSH2_POLLFD = ^_LIBSSH2_POLLFD;
333 | _LIBSSH2_POLLFD = record
334 | _type: Byte;
335 | {= LIBSSH2_POLLFD_* below }
336 | socket: Integer;
337 | {= File descriptors -- examined with system select() call }
338 | channel: PLIBSSH2_CHANNEL;
339 | {= Examined by checking internal state }
340 | listener: PLIBSSH2_LISTENER;
341 | {- Read polls only -- are inbound }
342 | {=connections waiting to be accepted? }
343 | end {fd};
344 | LIBSSH2_POLLFD = _LIBSSH2_POLLFD;
345 |
346 | {= Requested Events }
347 | {= Returned Events }
348 |
349 | {+// Poll FD Descriptor Types*/ }
350 | const
351 | LIBSSH2_POLLFD_SOCKET = 1;
352 | const
353 | LIBSSH2_POLLFD_CHANNEL = 2;
354 | const
355 | LIBSSH2_POLLFD_LISTENER = 3;
356 |
357 | {+// Note: Win32 Doesn't actually have a poll() implementation, so some of these }
358 | {=values are faked with select() data }
359 | {+// Poll FD events/revents -- Match sys/poll.h where possible*/ }
360 | const
361 | LIBSSH2_POLLFD_POLLIN = $0001; {/* Data available to be read or}
362 | const
363 | LIBSSH2_POLLFD_POLLPRI = $0002; {/* Priority data available to
364 | be read -- Socket only */}
365 | const
366 | LIBSSH2_POLLFD_POLLEXT = $0002; {/* Extended data available to
367 | be read -- Channel only */}
368 | const
369 | LIBSSH2_POLLFD_POLLOUT = $0004; {/* Can may be written --
370 | Socket/Channel */}
371 | const
372 | LIBSSH2_POLLFD_POLLERR = $0008; {/* Error Condition -- Socket*/}
373 | const
374 | LIBSSH2_POLLFD_POLLHUP = $0010; {/* HangUp/EOF -- Socket*/}
375 | const
376 | LIBSSH2_POLLFD_SESSION_CLOSED = $0010; {/* Session Disconnect*/}
377 | const
378 | LIBSSH2_POLLFD_POLLNVAL = $0020; {/* Invalid request -- Socket
379 | Only */}
380 | const
381 | LIBSSH2_POLLFD_POLLEX = $0040; {/* Exception Condition --
382 | Socket/Win32 */}
383 | const
384 | LIBSSH2_POLLFD_CHANNEL_CLOSED = $0080; {/* Channel Disconnect */}
385 | const
386 | LIBSSH2_POLLFD_LISTENER_CLOSED = $0080; {/* Listener Disconnect*/}
387 |
388 | const
389 | HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION = 1;
390 |
391 | {+// Block Direction Types*/ }
392 | const
393 | LIBSSH2_SESSION_BLOCK_INBOUND = $0001;
394 | const
395 | LIBSSH2_SESSION_BLOCK_OUTBOUND = $0002;
396 |
397 | {+// Hash Types*/ }
398 | const
399 | LIBSSH2_HOSTKEY_HASH_MD5 = 1;
400 | const
401 | LIBSSH2_HOSTKEY_HASH_SHA1 = 2;
402 |
403 | {+// Hostkey Types */ }
404 | const
405 | LIBSSH2_HOSTKEY_TYPE_UNKNOWN = 0;
406 | const
407 | LIBSSH2_HOSTKEY_TYPE_RSA = 1;
408 | const
409 | LIBSSH2_HOSTKEY_TYPE_DSS = 2;
410 |
411 | {+// Disconnect Codes (defined by SSH protocol)*/ }
412 | const
413 | SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1;
414 | const
415 | SSH_DISCONNECT_PROTOCOL_ERROR = 2;
416 | const
417 | SSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3;
418 | const
419 | SSH_DISCONNECT_RESERVED = 4;
420 | const
421 | SSH_DISCONNECT_MAC_ERROR = 5;
422 | const
423 | SSH_DISCONNECT_COMPRESSION_ERROR = 6;
424 | const
425 | SSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7;
426 | const
427 | SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8;
428 | const
429 | SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9;
430 | const
431 | SSH_DISCONNECT_CONNECTION_LOST = 10;
432 | const
433 | SSH_DISCONNECT_BY_APPLICATION = 11;
434 | const
435 | SSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12;
436 | const
437 | SSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13;
438 | const
439 | SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14;
440 | const
441 | SSH_DISCONNECT_ILLEGAL_USER_NAME = 15;
442 |
443 | {+// Error Codes (defined by libssh2)*/ }
444 | const
445 | LIBSSH2_ERROR_NONE = 0;
446 | const
447 | LIBSSH2_ERROR_SOCKET_NONE = -1;
448 | const
449 | LIBSSH2_ERROR_BANNER_NONE = -2;
450 | const
451 | LIBSSH2_ERROR_BANNER_SEND = -3;
452 | const
453 | LIBSSH2_ERROR_INVALID_MAC = -4;
454 | const
455 | LIBSSH2_ERROR_KEX_FAILURE = -5;
456 | const
457 | LIBSSH2_ERROR_ALLOC = -6;
458 | const
459 | LIBSSH2_ERROR_SOCKET_SEND = -7;
460 | const
461 | LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE = -8;
462 | const
463 | LIBSSH2_ERROR_TIMEOUT = -9;
464 | const
465 | LIBSSH2_ERROR_HOSTKEY_INIT = -10;
466 | const
467 | LIBSSH2_ERROR_HOSTKEY_SIGN = -11;
468 | const
469 | LIBSSH2_ERROR_DECRYPT = -12;
470 | const
471 | LIBSSH2_ERROR_SOCKET_DISCONNECT = -13;
472 | const
473 | LIBSSH2_ERROR_PROTO = -14;
474 | const
475 | LIBSSH2_ERROR_PASSWORD_EXPIRED = -15;
476 | const
477 | LIBSSH2_ERROR_FILE = -16;
478 | const
479 | LIBSSH2_ERROR_METHOD_NONE = -17;
480 | const
481 | LIBSSH2_ERROR_AUTHENTICATION_FAILED = -18;
482 | const
483 | LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
484 | const
485 | LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED = -19;
486 | const
487 | LIBSSH2_ERROR_CHANNEL_OUTOFORDER = -20;
488 | const
489 | LIBSSH2_ERROR_CHANNEL_FAILURE = -21;
490 | const
491 | LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED = -22;
492 | const
493 | LIBSSH2_ERROR_CHANNEL_UNKNOWN = -23;
494 | const
495 | LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED = -24;
496 | const
497 | LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED = -25;
498 | const
499 | LIBSSH2_ERROR_CHANNEL_CLOSED = -26;
500 | const
501 | LIBSSH2_ERROR_CHANNEL_EOF_SENT = -27;
502 | const
503 | LIBSSH2_ERROR_SCP_PROTOCOL = -28;
504 | const
505 | LIBSSH2_ERROR_ZLIB = -29;
506 | const
507 | LIBSSH2_ERROR_SOCKET_TIMEOUT = -30;
508 | const
509 | LIBSSH2_ERROR_SFTP_PROTOCOL = -31;
510 | const
511 | LIBSSH2_ERROR_REQUEST_DENIED = -32;
512 | const
513 | LIBSSH2_ERROR_METHOD_NOT_SUPPORTED = -33;
514 | const
515 | LIBSSH2_ERROR_INVAL = -34;
516 | const
517 | LIBSSH2_ERROR_INVALID_POLL_TYPE = -35;
518 | const
519 | LIBSSH2_ERROR_PUBLICKEY_PROTOCOL = -36;
520 | const
521 | LIBSSH2_ERROR_EAGAIN = -37;
522 | const
523 | LIBSSH2_ERROR_BUFFER_TOO_SMALL = -38;
524 | const
525 | LIBSSH2_ERROR_BAD_USE = -39;
526 | const
527 | LIBSSH2_ERROR_COMPRESS = -40;
528 | const
529 | LIBSSH2_ERROR_OUT_OF_BOUNDARY = -41;
530 | const
531 | LIBSSH2_ERROR_AGENT_PROTOCOL = -42;
532 |
533 | {+// Global API*/}
534 | const
535 | LIBSSH2_INIT_NO_CRYPTO = $0001;
536 | {/*
537 | * libssh2_init()
538 | *
539 | * Initialize the libssh2 functions. This typically initialize the
540 | * crypto library. It uses a global state, and is not thread safe --
541 | * you must make sure this function is not called concurrently.
542 | *
543 | * Flags can be:
544 | * 0: Normal initialize
545 | * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
546 | * OPENSSL_add_cipher_algoritms() for OpenSSL
547 | *
548 | * Returns 0 if succeeded, or a negative value for error.
549 | */}
550 | function libssh2_init(flags: Integer): Integer; cdecl;
551 |
552 | {/*
553 | * libssh2_exit()
554 | *
555 | * Exit the libssh2 functions and free's all memory used internal.
556 | */}
557 | procedure libssh2_exit; cdecl;
558 |
559 | type
560 | // abstract je void**, tako da pazite!!!!
561 | LIBSSH2_ALLOC_FUNC = function(count: UINT; abstract: Pointer): Pointer; cdecl;
562 | LIBSSH2_REALLOC_FUNC = function(ptr: Pointer; count: UINT; abstract: Pointer): Pointer; cdecl;
563 | LIBSSH2_FREE_FUNC = procedure(ptr: Pointer; abstract: Pointer); cdecl;
564 |
565 | {+// Session API*/ }
566 |
567 | function libssh2_session_init_ex(my_alloc: LIBSSH2_ALLOC_FUNC;
568 | my_free: LIBSSH2_FREE_FUNC;
569 | my_realloc: LIBSSH2_REALLOC_FUNC;
570 | abstract: Pointer): PLIBSSH2_SESSION; cdecl;
571 |
572 | function libssh2_session_init: PLIBSSH2_SESSION; inline;
573 |
574 | function libssh2_session_abstract(session: PLIBSSH2_SESSION): Pointer; cdecl;
575 |
576 | function libssh2_session_callback_set(session: PLIBSSH2_SESSION;
577 | cbtype: Integer;
578 | callback: Pointer): Pointer; cdecl;
579 |
580 | function libssh2_banner_set(session: PLIBSSH2_SESSION;
581 | const banner: PAnsiChar): Integer; cdecl;
582 |
583 |
584 | function libssh2_session_startup(session: PLIBSSH2_SESSION;
585 | sock: Integer): Integer; cdecl;
586 |
587 | function libssh2_session_disconnect_ex(session: PLIBSSH2_SESSION;
588 | reason: Integer;
589 | const description: PAnsiChar;
590 | const lang: PAnsiChar): Integer; cdecl ;
591 |
592 | function libssh2_session_disconnect(session: PLIBSSH2_SESSION; const description: PAnsiChar): Integer; inline;
593 |
594 | function libssh2_session_free(session: PLIBSSH2_SESSION): Integer; cdecl ;
595 |
596 |
597 | function libssh2_hostkey_hash(session: PLIBSSH2_SESSION;
598 | hash_type: Integer): PAnsiChar; cdecl ;
599 |
600 | function libssh2_session_hostkey(session: PLIBSSH2_SESSION;
601 | var len: size_t;
602 | var _type: Integer): PAnsiChar; cdecl;
603 |
604 |
605 | function libssh2_session_method_pref(session: PLIBSSH2_SESSION;
606 | method_type: Integer;
607 | const prefs: PAnsiChar): Integer; cdecl ;
608 |
609 | function libssh2_session_methods(session: PLIBSSH2_SESSION;
610 | method_type: Integer): PAnsiChar; cdecl ;
611 |
612 | function libssh2_session_last_error(session: PLIBSSH2_SESSION;
613 | var errmsg: PAnsiChar;
614 | var errmsg_len: Integer;
615 | want_buf: Integer): Integer; cdecl;
616 |
617 | function libssh2_session_last_errno(session: PLIBSSH2_SESSION): Integer; cdecl ;
618 |
619 | function libssh2_session_block_directions(session: PLIBSSH2_SESSION): Integer; cdecl ;
620 |
621 |
622 | function libssh2_session_flag(session: PLIBSSH2_SESSION;
623 | flag: Integer;
624 | value: Integer): Integer; cdecl ;
625 |
626 | {+// Userauth API*/ }
627 |
628 | function libssh2_userauth_list(session: PLIBSSH2_SESSION;
629 | const username: PAnsiChar;
630 | username_len: UINT): PAnsiChar; cdecl ;
631 |
632 | function libssh2_userauth_authenticated(session: PLIBSSH2_SESSION): Integer; cdecl ;
633 |
634 |
635 | function libssh2_userauth_password_ex(session: PLIBSSH2_SESSION;
636 | const username: PAnsiChar;
637 | username_len: Uint;
638 | const password: PAnsiChar;
639 | password_len: Uint;
640 | passwd_change_cb: LIBSSH2_PASSWD_CHANGEREQ_FUNC): Integer; cdecl ;
641 |
642 | function libssh2_userauth_password(session: PLIBSSH2_SESSION; const username: PAnsiChar; const password: PAnsiChar): Integer; inline;
643 |
644 | function libssh2_userauth_publickey_fromfile_ex(session: PLIBSSH2_SESSION;
645 | const username: PAnsiChar;
646 | username_len: Uint;
647 | const publickey: PAnsiChar;
648 | const privatekey: PAnsiChar;
649 | const passphrase: PAnsiChar): Integer; cdecl ;
650 |
651 | function libssh2_userauth_publickey_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar;
652 | const publickey: PAnsiChar; const privatekey: PAnsiChar; const passphrase: PAnsiChar): Integer; inline;
653 |
654 | function libssh2_userauth_hostbased_fromfile_ex(session: PLIBSSH2_SESSION;
655 | const username: PAnsiChar;
656 | username_len: Uint;
657 | const publickey: PAnsiChar;
658 | const privatekey: PAnsiChar;
659 | const passphrase: PAnsiChar;
660 | const hostname: PAnsiChar;
661 | hostname_len: UInt;
662 | local_username: PAnsiChar;
663 | local_username_len: UInt): Integer; cdecl ;
664 |
665 | function libssh2_userauth_hostbased_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar; const publickey: PAnsiChar;
666 | const privatekey: PAnsiChar; const passphrase: PAnsiChar; const hostname: PAnsiChar): Integer; inline;
667 |
668 | {+// }
669 | {-* response_callback is provided with filled by library prompts array, }
670 | {-* but client must allocate and fill individual responses. Responses }
671 | {-* array is already allocated. Responses data will be freed by libssh2 }
672 | {-* after callback return, but before subsequent callback invokation. }
673 | {= }
674 |
675 | function libssh2_userauth_keyboard_interactive_ex(session: PLIBSSH2_SESSION;
676 | const username: PAnsiChar;
677 | username_len: UInt;
678 | response_callback: LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC): Integer; cdecl ;
679 |
680 | function libssh2_userauth_keyboard_interactive(session: PLIBSSH2_SESSION; const username: PAnsiChar; response_callback: LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC): Integer; inline;
681 |
682 | function libssh2_poll(var fds: LIBSSH2_POLLFD;
683 | nfds: UInt;
684 | timeout: LongInt): Integer; cdecl ;
685 |
686 | {+// Channel API*/ }
687 | const
688 | LIBSSH2_CHANNEL_WINDOW_DEFAULT = 65536;
689 | const
690 | LIBSSH2_CHANNEL_PACKET_DEFAULT = 32768;
691 | const
692 | LIBSSH2_CHANNEL_MINADJUST = 1024;
693 |
694 | {+// Extended Data Handling*/ }
695 | const
696 | LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL = 0;
697 | const
698 | LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE = 1;
699 | const
700 | LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE = 2;
701 |
702 | const
703 | SSH_EXTENDED_DATA_STDERR = 1;
704 |
705 | {+// Returned by any function that would block during a read/write opperation*/ }
706 | const
707 | LIBSSH2CHANNEL_EAGAIN = LIBSSH2_ERROR_EAGAIN;
708 |
709 | function libssh2_channel_open_ex(session: PLIBSSH2_SESSION;
710 | const channel_type: PAnsiChar;
711 | channel_type_len: Uint;
712 | window_size: Uint;
713 | packet_size: Uint;
714 | const message: PAnsiChar;
715 | message_len: Uint): PLIBSSH2_CHANNEL; cdecl ;
716 |
717 | function libssh2_channel_open_session(session: PLIBSSH2_SESSION): PLIBSSH2_CHANNEL; inline;
718 |
719 | function libssh2_channel_direct_tcpip_ex(session: PLIBSSH2_SESSION;
720 | const host: PAnsiChar;
721 | port: Integer;
722 | const shost: PAnsiChar;
723 | sport: Integer): PLIBSSH2_CHANNEL; cdecl ;
724 |
725 | function libssh2_channel_direct_tcpip(session: PLIBSSH2_SESSION; const host: PAnsiChar; port: Integer): PLIBSSH2_CHANNEL; inline;
726 |
727 | function libssh2_channel_forward_listen_ex(session: PLIBSSH2_SESSION;
728 | const host: PAnsiChar;
729 | port: Integer;
730 | var bound_port: Integer;
731 | queue_maxsize: Integer): PLIBSSH2_LISTENER cdecl ;
732 |
733 | function libssh2_channel_forward_listen(session: PLIBSSH2_SESSION; port: Integer): PLIBSSH2_LISTENER; inline;
734 |
735 | function libssh2_channel_forward_cancel(listener: PLIBSSH2_LISTENER): Integer; cdecl ;
736 |
737 |
738 | function libssh2_channel_forward_accept(listener: PLIBSSH2_LISTENER): PLIBSSH2_CHANNEL; cdecl ;
739 |
740 |
741 | function libssh2_channel_setenv_ex(channel: PLIBSSH2_CHANNEL;
742 | const varname: PAnsiChar;
743 | varname_len: Uint;
744 | const value: PAnsiChar;
745 | value_len: UInt): Integer; cdecl ;
746 |
747 | function libssh2_channel_setenv(channel: PLIBSSH2_CHANNEL; const varname: PAnsiChar; const value: PAnsiChar): Integer; inline;
748 |
749 | function libssh2_channel_request_pty_ex(channel: PLIBSSH2_CHANNEL;
750 | const term: PAnsiChar;
751 | term_len: Uint;
752 | const modes: PAnsiChar;
753 | modes_len: Uint;
754 | width: Integer;
755 | height: Integer;
756 | width_px: Integer;
757 | height_px: Integer): Integer; cdecl ;
758 |
759 | function libssh2_channel_request_pty(channel: PLIBSSH2_CHANNEL; const term: PAnsiChar): Integer; inline;
760 |
761 | function libssh2_channel_request_pty_size_ex(channel: PLIBSSH2_CHANNEL;
762 | width: Integer;
763 | height: Integer;
764 | width_px: Integer;
765 | height_px: Integer): Integer; cdecl ;
766 |
767 | function libssh2_channel_request_pty_size(channel: PLIBSSH2_CHANNEL; width: Integer; height: Integer): Integer; inline;
768 |
769 | function libssh2_channel_x11_req_ex(channel: PLIBSSH2_CHANNEL;
770 | single_connection: Integer;
771 | const auth_proto: PAnsiChar;
772 | const auth_cookie: PAnsiChar;
773 | screen_number: Integer): Integer; cdecl ;
774 |
775 | function libssh2_channel_x11_req(channel: PLIBSSH2_CHANNEL; screen_number: Integer): Integer; inline;
776 |
777 | function libssh2_channel_process_startup(channel: PLIBSSH2_CHANNEL;
778 | const request: PAnsiChar;
779 | request_len: UInt;
780 | const message: PAnsiChar;
781 | message_len: UInt): Integer; cdecl ;
782 |
783 | function libssh2_channel_shell(channel: PLIBSSH2_CHANNEL): Integer; inline;
784 |
785 | function libssh2_channel_exec(channel: PLIBSSH2_CHANNEL; const command: PAnsiChar): Integer; inline;
786 |
787 | function libssh2_channel_subsystem(channel: PLIBSSH2_CHANNEL; const subsystem: PAnsiChar): Integer; inline;
788 |
789 | function libssh2_channel_read_ex(channel: PLIBSSH2_CHANNEL;
790 | stream_id: Integer;
791 | buf: PAnsiChar;
792 | buflen: SIZE_T): Integer; cdecl ;
793 |
794 | function libssh2_channel_read(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer; inline;
795 |
796 | function libssh2_channel_read_stderr(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer; inline;
797 |
798 | function libssh2_poll_channel_read(channel: PLIBSSH2_CHANNEL;
799 | extended: Integer): Integer; cdecl ;
800 |
801 |
802 | function libssh2_channel_window_read_ex(channel: PLIBSSH2_CHANNEL;
803 | var read_avail: LongInt;
804 | var window_size_initial: LongInt): ULong; cdecl ;
805 |
806 | function libssh2_channel_window_read(channel: PLIBSSH2_CHANNEL): ULong; inline;
807 |
808 | {+// libssh2_channel_receive_window_adjust is DEPRECATED, do not use!*/ }
809 |
810 | function libssh2_channel_receive_window_adjust(channel: PLIBSSH2_CHANNEL;
811 | adjustment: LongInt;
812 | force: Byte): LongInt; cdecl ;
813 |
814 |
815 | function libssh2_channel_receive_window_adjust2(channel: PLIBSSH2_CHANNEL;
816 | adjustment: LongInt;
817 | force: Byte;
818 | var storewindow: ULong): Integer; cdecl ;
819 |
820 |
821 | function libssh2_channel_write_ex(channel: PLIBSSH2_CHANNEL;
822 | stream_id: Integer;
823 | const buf: PAnsiChar;
824 | buflen: ULong): Integer; cdecl ;
825 |
826 | function libssh2_channel_write(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer; inline;
827 |
828 | function libssh2_channel_write_stderr(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer; inline;
829 |
830 |
831 | function libssh2_channel_window_write_ex(channel: PLIBSSH2_CHANNEL;
832 | var window_size_initial: LongInt): ULong; cdecl ;
833 |
834 | function libssh2_channel_window_write(channel: PLIBSSH2_CHANNEL): ULong; inline;
835 |
836 | procedure libssh2_session_set_blocking(session: PLIBSSH2_SESSION;
837 | blocking: Integer); cdecl ;
838 |
839 | function libssh2_session_get_blocking(session: PLIBSSH2_SESSION): Integer; cdecl ;
840 |
841 |
842 | procedure libssh2_channel_set_blocking(channel: PLIBSSH2_CHANNEL;
843 | blocking: Integer); cdecl ;
844 |
845 | {+// libssh2_channel_handle_extended_data is DEPRECATED, do not use!*/ }
846 |
847 | procedure libssh2_channel_handle_extended_data(channel: PLIBSSH2_CHANNEL;
848 | ignore_mode: Integer); cdecl ;
849 |
850 | function libssh2_channel_handle_extended_data2(channel: PLIBSSH2_CHANNEL;
851 | ignore_mode: Integer): Integer; cdecl ;
852 |
853 | {+// libssh2_channel_ignore_extended_data() is defined below for BC with version }
854 | {-* 0.1 }
855 | {-* }
856 | {-* Future uses should use libssh2_channel_handle_extended_data() directly if }
857 | {-* LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read }
858 | {-* (FIFO) from the standard data channel }
859 | {= }
860 | {+// DEPRECATED*/ }
861 | procedure libssh2_channel_ignore_extended_data(channel: PLIBSSH2_CHANNEL; ignore: Integer); inline;
862 |
863 | const
864 | LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA = -1;
865 | const
866 | LIBSSH2_CHANNEL_FLUSH_ALL = -2;
867 |
868 | function libssh2_channel_flush_ex(channel: PLIBSSH2_CHANNEL;
869 | streamid: Integer): Integer; cdecl ;
870 |
871 | function libssh2_channel_flush(channel: PLIBSSH2_CHANNEL): Integer; inline;
872 |
873 | function libssh2_channel_flush_stderr(channel: PLIBSSH2_CHANNEL): Integer; inline;
874 |
875 | function libssh2_channel_get_exit_status(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
876 |
877 | function libssh2_channel_send_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
878 |
879 | function libssh2_channel_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
880 |
881 | function libssh2_channel_wait_eof(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
882 |
883 | function libssh2_channel_close(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
884 |
885 | function libssh2_channel_wait_closed(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
886 |
887 | function libssh2_channel_free(channel: PLIBSSH2_CHANNEL): Integer; cdecl ;
888 |
889 |
890 | type
891 | Pstruct_stat = ^struct_stat;
892 | struct_stat = record
893 | st_dev: UINT;
894 | st_ino: Word;
895 | st_mode: Word;
896 | st_nlink: Short;
897 | st_uid: Short;
898 | st_gid: Short;
899 | st_rdev: UINT;
900 | st_size: LongInt;
901 | st_atime: Int64;
902 | st_mtime: Int64;
903 | st_ctime: Int64;
904 | end;
905 |
906 | function libssh2_scp_recv(session: PLIBSSH2_SESSION;
907 | const path: PAnsiChar;
908 | var sb: struct_stat): PLIBSSH2_CHANNEL; cdecl ;
909 |
910 | function libssh2_scp_send_ex(session: PLIBSSH2_SESSION;
911 | const path: PAnsiChar;
912 | mode: Integer;
913 | size: SIZE_T;
914 | mtime: LongInt;
915 | atime: LongInt): PLIBSSH2_CHANNEL; cdecl ;
916 |
917 | function libssh2_scp_send64(session: PLIBSSH2_SESSION; const path: PAnsiChar; mode: Integer;
918 | size: Int64; mtime: time_t; atime: time_t): PLIBSSH2_CHANNEL; cdecl ;
919 |
920 | function libssh2_scp_send(session: PLIBSSH2_SESSION; const path: PAnsiChar; mode: Integer; size: SIZE_T): PLIBSSH2_CHANNEL; inline;
921 |
922 | function libssh2_base64_decode(session: PLIBSSH2_SESSION;
923 | var dest: PAnsiChar;
924 | var dest_len: Uint;
925 | const src: PAnsiChar;
926 | src_len: Uint): Integer; cdecl;
927 |
928 | function libssh2_version(req_version_num: Integer): PAnsiChar; cdecl ;
929 |
930 | const
931 | HAVE_LIBSSH2_KNOWNHOST_API = $010101; {/* since 1.1.1 */}
932 | const
933 | HAVE_LIBSSH2_VERSION_API = $010100; {/* libssh2_version since 1.1 */}
934 |
935 | type
936 | PLIBSSH2_KNOWNHOST = ^LIBSSH2_KNOWNHOST;
937 | LIBSSH2_KNOWNHOST = record
938 | magic: UInt; {/* magic stored by the library */}
939 | node: Pointer; {/* handle to the internal representation of this host */}
940 | name: PAnsiChar; {/* this is NULL if no plain text host name exists */}
941 | key: PAnsiChar; {/* key in base64/printable format */}
942 | typemask: Integer;
943 | end;
944 |
945 | {/*
946 | * libssh2_knownhost_init
947 | *
948 | * Init a collection of known hosts. Returns the pointer to a collection.
949 | *
950 | */}
951 | function libssh2_knownhost_init(session: PLIBSSH2_SESSION): PLIBSSH2_KNOWNHOSTS; cdecl;
952 |
953 | {/*
954 | * libssh2_knownhost_add
955 | *
956 | * Add a host and its associated key to the collection of known hosts.
957 | *
958 | * The 'type' argument specifies on what format the given host is:
959 | *
960 | * plain - ascii "hostname.domain.tld"
961 | * sha1 - SHA1( ) base64-encoded!
962 | * custom - another hash
963 | *
964 | * If 'sha1' is selected as type, the salt must be provided to the salt
965 | * argument. This too base64 encoded.
966 | *
967 | * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
968 | * a custom type is used, salt is ignored and you must provide the host
969 | * pre-hashed when checking for it in the libssh2_knownhost_check() function.
970 | *
971 | */}
972 |
973 | {/* host format (2 bits) */}
974 | const
975 | LIBSSH2_KNOWNHOST_TYPE_MASK = $ffff;
976 | const
977 | LIBSSH2_KNOWNHOST_TYPE_PLAIN = 1;
978 | const
979 | LIBSSH2_KNOWNHOST_TYPE_SHA1 = 2; {/* always base64 encoded */}
980 | const
981 | LIBSSH2_KNOWNHOST_TYPE_CUSTOM = 3;
982 |
983 | {/* key format (2 bits) */}
984 | const LIBSSH2_KNOWNHOST_KEYENC_MASK = (3 shl 16);
985 | const LIBSSH2_KNOWNHOST_KEYENC_RAW = (1 shl 16);
986 | const LIBSSH2_KNOWNHOST_KEYENC_BASE64 = (2 shl 16);
987 |
988 | {/* type of key (2 bits) */}
989 | const LIBSSH2_KNOWNHOST_KEY_MASK = (3 shl 18);
990 | const LIBSSH2_KNOWNHOST_KEY_SHIFT = 18;
991 | const LIBSSH2_KNOWNHOST_KEY_RSA1 = (1 shl 18);
992 | const LIBSSH2_KNOWNHOST_KEY_SSHRSA = (2 shl 18);
993 | const LIBSSH2_KNOWNHOST_KEY_SSHDSS = (3 shl 18);
994 |
995 | function libssh2_knownhost_add(hosts: PLIBSSH2_KNOWNHOSTS;
996 | host,
997 | salt,
998 | key: PAnsiChar; keylen: size_t; typemask: Integer;
999 | var store: PLIBSSH2_KNOWNHOST): Integer; cdecl ;
1000 |
1001 | {/*
1002 | * libssh2_knownhost_addc
1003 | *
1004 | * Add a host and its associated key to the collection of known hosts.
1005 | *
1006 | * Takes a comment argument that may be NULL. A NULL comment indicates
1007 | * there is no comment and the entry will end directly after the key
1008 | * when written out to a file. An empty string "" comment will indicate an
1009 | * empty comment which will cause a single space to be written after the key.
1010 | *
1011 | * The 'type' argument specifies on what format the given host and keys are:
1012 | *
1013 | * plain - ascii "hostname.domain.tld"
1014 | * sha1 - SHA1( ) base64-encoded!
1015 | * custom - another hash
1016 | *
1017 | * If 'sha1' is selected as type, the salt must be provided to the salt
1018 | * argument. This too base64 encoded.
1019 | *
1020 | * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
1021 | * a custom type is used, salt is ignored and you must provide the host
1022 | * pre-hashed when checking for it in the libssh2_knownhost_check() function.
1023 | *
1024 | * The keylen parameter may be omitted (zero) if the key is provided as a
1025 | * NULL-terminated base64-encoded string.
1026 | */}
1027 |
1028 | function libssh2_knownhost_addc(hosts: PLIBSSH2_KNOWNHOSTS;
1029 | host,
1030 | salt,
1031 | key: PAnsiChar;
1032 | keylen: size_t;
1033 | comment: PAnsiChar;
1034 | commentlen: size_t; typemask: Integer;
1035 | var store: PLIBSSH2_KNOWNHOST): Integer; cdecl ;
1036 |
1037 | {/*
1038 | * libssh2_knownhost_check
1039 | *
1040 | * Check a host and its associated key against the collection of known hosts.
1041 | *
1042 | * The type is the type/format of the given host name.
1043 | *
1044 | * plain - ascii "hostname.domain.tld"
1045 | * custom - prehashed base64 encoded. Note that this cannot use any salts.
1046 | *
1047 | *
1048 | * 'knownhost' may be set to NULL if you don't care about that info.
1049 | *
1050 | * Returns:
1051 | *
1052 | * LIBSSH2_KNOWNHOST_CHECK_* values, see below
1053 | *
1054 | */}
1055 |
1056 | const
1057 | LIBSSH2_KNOWNHOST_CHECK_MATCH = 0;
1058 | const
1059 | LIBSSH2_KNOWNHOST_CHECK_MISMATCH = 1;
1060 | const
1061 | LIBSSH2_KNOWNHOST_CHECK_NOTFOUND = 2;
1062 | const
1063 | LIBSSH2_KNOWNHOST_CHECK_FAILURE = 3;
1064 |
1065 | function libssh2_knownhost_check(hosts: PLIBSSH2_KNOWNHOSTS;
1066 | host, key: PAnsiChar; keylen: size_t;
1067 | typemask: Integer;
1068 | var knownhost: PLIBSSH2_KNOWNHOST): Integer; cdecl;
1069 |
1070 | {/* this function is identital to the above one, but also takes a port
1071 | argument that allows libssh2 to do a better check */}
1072 | function libssh2_knownhost_checkp(hosts: PLIBSSH2_KNOWNHOSTS;
1073 | const host: PAnsiChar; port: Integer;
1074 | const key: PAnsiChar; keylen: size_t;
1075 | typemask: Integer;
1076 | var knownhost: PLIBSSH2_KNOWNHOST): Integer; cdecl ;
1077 |
1078 | {/*
1079 | * libssh2_knownhost_del
1080 | *
1081 | * Remove a host from the collection of known hosts. The 'entry' struct is
1082 | * retrieved by a call to libssh2_knownhost_check().
1083 | *
1084 | */}
1085 | function libssh2_knownhost_del(hosts: PLIBSSH2_KNOWNHOSTS;
1086 | entry: PLIBSSH2_KNOWNHOST): Integer; cdecl;
1087 |
1088 | {/*
1089 | * libssh2_knownhost_free
1090 | *
1091 | * Free an entire collection of known hosts.
1092 | *
1093 | */}
1094 | procedure libssh2_knownhost_free(hosts: PLIBSSH2_KNOWNHOSTS); cdecl;
1095 |
1096 | {/*
1097 | * libssh2_knownhost_readline()
1098 | *
1099 | * Pass in a line of a file of 'type'. It makes libssh2 read this line.
1100 | *
1101 | * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
1102 | *
1103 | */}
1104 | function libssh2_knownhost_readline(hosts: PLIBSSH2_KNOWNHOSTS;
1105 | const line: PAnsiChar; len: size_t; _type: Integer): Integer; cdecl;
1106 |
1107 |
1108 | {/*
1109 | * libssh2_knownhost_readfile
1110 | *
1111 | * Add hosts+key pairs from a given file.
1112 | *
1113 | * Returns a negative value for error or number of successfully added hosts.
1114 | *
1115 | * This implementation currently only knows one 'type' (openssh), all others
1116 | * are reserved for future use.
1117 | */}
1118 |
1119 | const
1120 | LIBSSH2_KNOWNHOST_FILE_OPENSSH = 1;
1121 |
1122 | function libssh2_knownhost_readfile(hosts: PLIBSSH2_KNOWNHOSTS;
1123 | const filename: PAnsiChar; _type: Integer): Integer; cdecl;
1124 |
1125 | {/*
1126 | * libssh2_knownhost_writeline()
1127 | *
1128 | * Ask libssh2 to convert a known host to an output line for storage.
1129 | *
1130 | * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
1131 | * output buffer is too small to hold the desired output.
1132 | *
1133 | * This implementation currently only knows one 'type' (openssh), all others
1134 | * are reserved for future use.
1135 | *
1136 | */}
1137 | function libssh2_knownhost_writeline(hosts: PLIBSSH2_KNOWNHOSTS;
1138 | known: PLIBSSH2_KNOWNHOST;
1139 | buffer: PAnsiChar; buflen: size_t;
1140 | var outlen: size_t; {/* the amount of written data */}
1141 | _type: Integer): Integer; cdecl;
1142 |
1143 | {/*
1144 | * libssh2_knownhost_writefile
1145 | *
1146 | * Write hosts+key pairs to a given file.
1147 | *
1148 | * This implementation currently only knows one 'type' (openssh), all others
1149 | * are reserved for future use.
1150 | */}
1151 |
1152 | function libssh2_knownhost_writefile(hosts: PLIBSSH2_KNOWNHOSTS;
1153 | const filename: PAnsiChar; _type: Integer): Integer; cdecl;
1154 |
1155 | {/*
1156 | * libssh2_knownhost_get()
1157 | *
1158 | * Traverse the internal list of known hosts. Pass NULL to 'prev' to get
1159 | * the first one. Or pass a poiner to the previously returned one to get the
1160 | * next.
1161 | *
1162 | * Returns:
1163 | * 0 if a fine host was stored in 'store'
1164 | * 1 if end of hosts
1165 | * [negative] on errors
1166 | */}
1167 | function libssh2_knownhost_get(hosts: PLIBSSH2_KNOWNHOSTS;
1168 | var store: PLIBSSH2_KNOWNHOST;
1169 | prev: PLIBSSH2_KNOWNHOST): Integer; cdecl;
1170 |
1171 | const
1172 | HAVE_LIBSSH2_AGENT_API = $010202; {/* since 1.2.2 */}
1173 |
1174 |
1175 | type
1176 | libssh2_agent_publickey = record
1177 | magic: UInt; {/* magic stored by the library */}
1178 | node: Pointer; {/* handle to the internal representation of key */}
1179 | blob: PUCHAR; {/* public key blob */}
1180 | blob_len: SIZE_T; {/* length of the public key blob */}
1181 | comment: PAnsiChar; {/* comment in printable format */}
1182 | end;
1183 | PLIBSSH2_AGENT_PUBLICKEY = ^libssh2_agent_publickey;
1184 |
1185 | {/*
1186 | * libssh2_agent_init
1187 | *
1188 | * Init an ssh-agent handle. Returns the pointer to the handle.
1189 | *
1190 | */}
1191 | function libssh2_agent_init(session: PLIBSSH2_SESSION): PLIBSSH2_AGENT; cdecl;
1192 |
1193 | {/*
1194 | * libssh2_agent_connect()
1195 | *
1196 | * Connect to an ssh-agent.
1197 | *
1198 | * Returns 0 if succeeded, or a negative value for error.
1199 | */}
1200 | function libssh2_agent_connect(agent: PLIBSSH2_AGENT): Integer; cdecl;
1201 |
1202 | {/*
1203 | * libssh2_agent_list_identities()
1204 | *
1205 | * Request an ssh-agent to list identities.
1206 | *
1207 | * Returns 0 if succeeded, or a negative value for error.
1208 | */}
1209 | function libssh2_agent_list_identities(agent: PLIBSSH2_AGENT): Integer; cdecl;
1210 |
1211 | {/*
1212 | * libssh2_agent_get_identity()
1213 | *
1214 | * Traverse the internal list of public keys. Pass NULL to 'prev' to get
1215 | * the first one. Or pass a poiner to the previously returned one to get the
1216 | * next.
1217 | *
1218 | * Returns:
1219 | * 0 if a fine public key was stored in 'store'
1220 | * 1 if end of public keys
1221 | * [negative] on errors
1222 | */}
1223 | function libssh2_agent_get_identity(agent: PLIBSSH2_AGENT;
1224 | var store: PLIBSSH2_AGENT_PUBLICKEY;
1225 | prev: PLIBSSH2_AGENT_PUBLICKEY): Integer; cdecl;
1226 |
1227 | {/*
1228 | * libssh2_agent_userauth()
1229 | *
1230 | * Do publickey user authentication with the help of ssh-agent.
1231 | *
1232 | * Returns 0 if succeeded, or a negative value for error.
1233 | */}
1234 | function libssh2_agent_userauth(agent: PLIBSSH2_AGENT;
1235 | const username: PAnsiChar;
1236 | identity: PLIBSSH2_AGENT_PUBLICKEY): Integer; cdecl;
1237 |
1238 | {/*
1239 | * libssh2_agent_disconnect()
1240 | *
1241 | * Close a connection to an ssh-agent.
1242 | *
1243 | * Returns 0 if succeeded, or a negative value for error.
1244 | */}
1245 | function libssh2_agent_disconnect(agent: PLIBSSH2_AGENT): Integer; cdecl;
1246 |
1247 | {/*
1248 | * libssh2_agent_free()
1249 | *
1250 | * Free an ssh-agent handle. This function also frees the internal
1251 | * collection of public keys.
1252 | */}
1253 | procedure libssh2_agent_free(agent: PLIBSSH2_AGENT); cdecl;
1254 |
1255 |
1256 | {/*
1257 | * libssh2_keepalive_config()
1258 | *
1259 | * Set how often keepalive messages should be sent. WANT_REPLY
1260 | * indicates whether the keepalive messages should request a response
1261 | * from the server. INTERVAL is number of seconds that can pass
1262 | * without any I/O, use 0 (the default) to disable keepalives. To
1263 | * avoid some busy-loop corner-cases, if you specify an interval of 1
1264 | * it will be treated as 2.
1265 | *
1266 | * Note that non-blocking applications are responsible for sending the
1267 | * keepalive messages using libssh2_keepalive_send().
1268 | */}
1269 | procedure libssh2_keepalive_config(session: PLIBSSH2_SESSION;
1270 | want_reply: Integer;
1271 | interval: Cardinal); cdecl;
1272 |
1273 | {/*
1274 | * libssh2_keepalive_send()
1275 | *
1276 | * Send a keepalive message if needed. SECONDS_TO_NEXT indicates how
1277 | * many seconds you can sleep after this call before you need to call
1278 | * it again. Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
1279 | * I/O errors.
1280 | */}
1281 | function libssh2_keepalive_send(session: PLIBSSH2_SESSION;
1282 | var seconds_to_next: Integer): Integer; cdecl;
1283 |
1284 |
1285 | {+// NOTE NOTE NOTE }
1286 | {-libssh2_trace() has no function in builds that aren't built with debug }
1287 | {-enabled }
1288 | {= }
1289 |
1290 | function libssh2_trace(session: PLIBSSH2_SESSION;
1291 | bitmask: Integer): Integer; cdecl;
1292 | const
1293 | LIBSSH2_TRACE_TRANS = (1 shl 1);
1294 | const
1295 | LIBSSH2_TRACE_KEX = (1 shl 2);
1296 | const
1297 | LIBSSH2_TRACE_AUTH = (1 shl 3);
1298 | const
1299 | LIBSSH2_TRACE_CONN = (1 shl 4);
1300 | const
1301 | LIBSSH2_TRACE_SCP = (1 shl 5);
1302 | const
1303 | LIBSSH2_TRACE_SFTP = (1shl 6);
1304 | const
1305 | LIBSSH2_TRACE_ERROR = (1 shl 7);
1306 | const
1307 | LIBSSH2_TRACE_PUBLICKEY = (1 shl 8);
1308 | const
1309 | LIBSSH2_TRACE_SOCKET = (1 shl 9);
1310 |
1311 | type
1312 | LIBSSH2_TRACE_HANDLER_FUNC = procedure(session: PLIBSSH2_SESSION; P: Pointer;
1313 | const C: PAnsiChar; S: size_t); cdecl;
1314 |
1315 | function libssh2_trace_sethandler(session: PLIBSSH2_SESSION;
1316 | context: Pointer;
1317 | callback: LIBSSH2_TRACE_HANDLER_FUNC): Integer; cdecl ;
1318 |
1319 |
1320 | implementation
1321 |
1322 | function libssh2_init; external libssh2_name;
1323 | procedure libssh2_exit; external libssh2_name;
1324 | function libssh2_session_init_ex; external libssh2_name;
1325 | function libssh2_session_abstract; external libssh2_name;
1326 | function libssh2_session_callback_set; external libssh2_name;
1327 | function libssh2_banner_set; external libssh2_name;
1328 | function libssh2_session_startup; external libssh2_name;
1329 | function libssh2_session_disconnect_ex; external libssh2_name;
1330 | function libssh2_session_free; external libssh2_name;
1331 | function libssh2_hostkey_hash; external libssh2_name;
1332 | function libssh2_session_hostkey; external libssh2_name;
1333 | function libssh2_session_method_pref; external libssh2_name;
1334 | function libssh2_session_methods; external libssh2_name;
1335 | function libssh2_session_last_error; external libssh2_name;
1336 | function libssh2_session_last_errno; external libssh2_name;
1337 | function libssh2_session_block_directions; external libssh2_name;
1338 | function libssh2_session_flag; external libssh2_name;
1339 | function libssh2_userauth_list; external libssh2_name;
1340 | function libssh2_userauth_authenticated; external libssh2_name;
1341 | function libssh2_userauth_password_ex; external libssh2_name;
1342 | function libssh2_userauth_publickey_fromfile_ex; external libssh2_name;
1343 | function libssh2_userauth_hostbased_fromfile_ex; external libssh2_name;
1344 | function libssh2_userauth_keyboard_interactive_ex; external libssh2_name;
1345 | function libssh2_poll; external libssh2_name;
1346 | function libssh2_channel_open_ex; external libssh2_name;
1347 | function libssh2_channel_direct_tcpip_ex; external libssh2_name;
1348 | function libssh2_channel_forward_listen_ex; external libssh2_name;
1349 | function libssh2_channel_forward_cancel; external libssh2_name;
1350 | function libssh2_channel_forward_accept; external libssh2_name;
1351 | function libssh2_channel_setenv_ex; external libssh2_name;
1352 | function libssh2_channel_request_pty_ex; external libssh2_name;
1353 | function libssh2_channel_request_pty_size_ex; external libssh2_name;
1354 | function libssh2_channel_x11_req_ex; external libssh2_name;
1355 | function libssh2_channel_process_startup; external libssh2_name;
1356 | function libssh2_channel_read_ex; external libssh2_name;
1357 | function libssh2_poll_channel_read; external libssh2_name;
1358 | function libssh2_channel_window_read_ex; external libssh2_name;
1359 | function libssh2_channel_receive_window_adjust; external libssh2_name;
1360 | function libssh2_channel_receive_window_adjust2; external libssh2_name;
1361 | function libssh2_channel_write_ex; external libssh2_name;
1362 | function libssh2_channel_window_write_ex; external libssh2_name;
1363 | procedure libssh2_session_set_blocking; external libssh2_name;
1364 | function libssh2_session_get_blocking; external libssh2_name;
1365 | procedure libssh2_channel_set_blocking; external libssh2_name;
1366 | procedure libssh2_channel_handle_extended_data; external libssh2_name;
1367 | function libssh2_channel_handle_extended_data2; external libssh2_name;
1368 | function libssh2_channel_flush_ex; external libssh2_name;
1369 | function libssh2_channel_get_exit_status; external libssh2_name;
1370 | function libssh2_channel_send_eof; external libssh2_name;
1371 | function libssh2_channel_eof; external libssh2_name;
1372 | function libssh2_channel_wait_eof; external libssh2_name;
1373 | function libssh2_channel_close; external libssh2_name;
1374 | function libssh2_channel_wait_closed; external libssh2_name;
1375 | function libssh2_channel_free; external libssh2_name;
1376 | function libssh2_scp_recv; external libssh2_name;
1377 | function libssh2_scp_send_ex; external libssh2_name;
1378 | function libssh2_scp_send64; external libssh2_name;
1379 | function libssh2_base64_decode; external libssh2_name;
1380 | function libssh2_version; external libssh2_name;
1381 | function libssh2_trace; external libssh2_name;
1382 | function libssh2_knownhost_init; external libssh2_name;
1383 | function libssh2_knownhost_add; external libssh2_name;
1384 | function libssh2_knownhost_addc; external libssh2_name;
1385 | function libssh2_knownhost_check; external libssh2_name;
1386 | function libssh2_knownhost_checkp; external libssh2_name;
1387 | function libssh2_knownhost_del; external libssh2_name;
1388 | procedure libssh2_knownhost_free; external libssh2_name;
1389 | function libssh2_knownhost_readline; external libssh2_name;
1390 | function libssh2_knownhost_readfile; external libssh2_name;
1391 | function libssh2_knownhost_writeline; external libssh2_name;
1392 | function libssh2_knownhost_writefile; external libssh2_name;
1393 | function libssh2_knownhost_get; external libssh2_name;
1394 | function libssh2_agent_init; external libssh2_name;
1395 | function libssh2_agent_connect; external libssh2_name;
1396 | function libssh2_agent_list_identities; external libssh2_name;
1397 | function libssh2_agent_get_identity; external libssh2_name;
1398 | function libssh2_agent_userauth; external libssh2_name;
1399 | function libssh2_agent_disconnect; external libssh2_name;
1400 | procedure libssh2_agent_free; external libssh2_name;
1401 | procedure libssh2_keepalive_config; external libssh2_name;
1402 | function libssh2_keepalive_send; external libssh2_name;
1403 | //function libssh2_trace; external libssh2_name;
1404 | function libssh2_trace_sethandler; external libssh2_name;
1405 |
1406 | function libssh2_session_init: PLIBSSH2_SESSION;
1407 | var
1408 | P1: LIBSSH2_ALLOC_FUNC;
1409 | P2: LIBSSH2_REALLOC_FUNC;
1410 | P3: LIBSSH2_FREE_FUNC;
1411 | P4: Pointer;
1412 | begin
1413 | P1 := nil; P2 := nil; P3 := nil; P4 := nil;
1414 | Result := libssh2_session_init_ex(P1, P3, P2, P4);
1415 | end;
1416 |
1417 | function libssh2_session_disconnect(session: PLIBSSH2_SESSION; const description: PAnsiChar): Integer;
1418 | begin
1419 | Result := libssh2_session_disconnect_ex(session, SSH_DISCONNECT_BY_APPLICATION, description, '');
1420 | end;
1421 |
1422 | function libssh2_userauth_password(session: PLIBSSH2_SESSION; const username: PAnsiChar; const password: PAnsiChar): Integer;
1423 | var
1424 | P: LIBSSH2_PASSWD_CHANGEREQ_FUNC;
1425 | begin
1426 | P := nil;
1427 | Result := libssh2_userauth_password_ex(session, username, Length(username), password, Length(password), P)
1428 | end;
1429 |
1430 | function libssh2_userauth_publickey_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar;
1431 | const publickey: PAnsiChar; const privatekey: PAnsiChar; const passphrase: PAnsiChar): Integer;
1432 | begin
1433 | Result := libssh2_userauth_publickey_fromfile_ex(session, username, Length(username), publickey, privatekey, passphrase);
1434 | end;
1435 |
1436 | function libssh2_userauth_hostbased_fromfile(session: PLIBSSH2_SESSION; const username: PAnsiChar; const publickey: PAnsiChar;
1437 | const privatekey: PAnsiChar; const passphrase: PAnsiChar; const hostname: PAnsiChar): Integer;
1438 | begin
1439 | Result := libssh2_userauth_hostbased_fromfile_ex(session, username, Length(username), publickey, privatekey, passphrase, hostname, Length(hostname), username, Length(username));
1440 | end;
1441 |
1442 | function libssh2_userauth_keyboard_interactive(session: PLIBSSH2_SESSION; const username: PAnsiChar; response_callback: LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC): Integer;
1443 | begin
1444 | Result := libssh2_userauth_keyboard_interactive_ex(session, username, Length(username), response_callback);
1445 | end;
1446 |
1447 | function libssh2_channel_open_session(session: PLIBSSH2_SESSION): PLIBSSH2_CHANNEL;
1448 | begin
1449 | Result := libssh2_channel_open_ex(session, 'session', Length('session') , LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, nil, 0);
1450 | end;
1451 |
1452 | function libssh2_channel_direct_tcpip(session: PLIBSSH2_SESSION; const host: PAnsiChar; port: Integer): PLIBSSH2_CHANNEL;
1453 | begin
1454 | Result := libssh2_channel_direct_tcpip_ex(session, host, port, '127.0.0.1', 22);
1455 | end;
1456 |
1457 | function libssh2_channel_forward_listen(session: PLIBSSH2_SESSION; port: Integer): PLIBSSH2_LISTENER;
1458 | var
1459 | I: Integer;
1460 | begin
1461 | I := 0;
1462 | Result := libssh2_channel_forward_listen_ex(session, nil, port, I, 16);
1463 | end;
1464 |
1465 | function libssh2_channel_setenv(channel: PLIBSSH2_CHANNEL; const varname: PAnsiChar; const value: PAnsiChar): Integer;
1466 | begin
1467 | Result := libssh2_channel_setenv_ex(channel, varname, Length(varname), value, Length(value));
1468 | end;
1469 |
1470 | function libssh2_channel_request_pty(channel: PLIBSSH2_CHANNEL; const term: PAnsiChar): Integer;
1471 | begin
1472 | Result := libssh2_channel_request_pty_ex(channel, term, Length(term), nil, 0, LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX);
1473 | end;
1474 |
1475 | function libssh2_channel_request_pty_size(channel: PLIBSSH2_CHANNEL; width: Integer; height: Integer): Integer;
1476 | begin
1477 | Result := libssh2_channel_request_pty_size_ex(channel, width, height, 0, 0);
1478 | end;
1479 |
1480 | function libssh2_channel_x11_req(channel: PLIBSSH2_CHANNEL; screen_number: Integer): Integer;
1481 | begin
1482 | Result := libssh2_channel_x11_req_ex(channel, 0, nil, nil, screen_number);
1483 | end;
1484 |
1485 | function libssh2_channel_shell(channel: PLIBSSH2_CHANNEL): Integer;
1486 | begin
1487 | Result := libssh2_channel_process_startup(channel, 'shell', Length('shell'), nil, 0);
1488 | end;
1489 |
1490 | function libssh2_channel_exec(channel: PLIBSSH2_CHANNEL; const command: PAnsiChar): Integer;
1491 | begin
1492 | Result := libssh2_channel_process_startup(channel, 'exec', Length('exec'), command, Length(command));
1493 | end;
1494 |
1495 | function libssh2_channel_subsystem(channel: PLIBSSH2_CHANNEL; const subsystem: PAnsiChar): Integer;
1496 | begin
1497 | Result := libssh2_channel_process_startup(channel, 'subsystem', Length('subsystem'), subsystem, Length(subsystem));
1498 | end;
1499 |
1500 | function libssh2_channel_read(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer;
1501 | begin
1502 | Result := libssh2_channel_read_ex(channel, 0, buf, buflen);
1503 | end;
1504 |
1505 | function libssh2_channel_read_stderr(channel: PLIBSSH2_CHANNEL; buf: PAnsiChar; buflen: SIZE_T): Integer;
1506 | begin
1507 | Result := libssh2_channel_read_ex(channel, SSH_EXTENDED_DATA_STDERR, buf, buflen);
1508 | end;
1509 |
1510 | function libssh2_channel_window_read(channel: PLIBSSH2_CHANNEL): ULong;
1511 | var
1512 | I: Integer;
1513 | begin
1514 | I := 0;
1515 | Result := libssh2_channel_window_read_ex(channel, I, I);
1516 | end;
1517 |
1518 | function libssh2_channel_write(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer;
1519 | begin
1520 | Result := libssh2_channel_write_ex(channel, 0, buf, buflen);
1521 | end;
1522 |
1523 | function libssh2_channel_write_stderr(channel: PLIBSSH2_CHANNEL; const buf: PAnsiChar; buflen: ULong): Integer;
1524 | begin
1525 | Result := libssh2_channel_write_ex(channel, SSH_EXTENDED_DATA_STDERR, buf, buflen);
1526 | end;
1527 |
1528 | function libssh2_channel_window_write(channel: PLIBSSH2_CHANNEL): ULong;
1529 | var
1530 | I: Integer;
1531 | begin
1532 | I := 0;
1533 | Result := libssh2_channel_window_write_ex(channel, I);
1534 | end;
1535 |
1536 | procedure libssh2_channel_ignore_extended_data(channel: PLIBSSH2_CHANNEL; ignore: Integer);
1537 | var
1538 | I: Integer;
1539 | begin
1540 | if ignore <> 0 then
1541 | I := LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE
1542 | else
1543 | I := LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL;
1544 | libssh2_channel_handle_extended_data(channel, I);
1545 | end;
1546 |
1547 | function libssh2_channel_flush(channel: PLIBSSH2_CHANNEL): Integer;
1548 | begin
1549 | Result := libssh2_channel_flush_ex(channel, 0);
1550 | end;
1551 |
1552 | function libssh2_channel_flush_stderr(channel: PLIBSSH2_CHANNEL): Integer;
1553 | begin
1554 | Result := libssh2_channel_flush_ex(channel, SSH_EXTENDED_DATA_STDERR);
1555 | end;
1556 |
1557 | function libssh2_scp_send(session: PLIBSSH2_SESSION; const path: PAnsiChar; mode: Integer; size: SIZE_T): PLIBSSH2_CHANNEL; inline;
1558 | begin
1559 | Result := libssh2_scp_send_ex(session, path, mode, size, 0, 0);
1560 | end;
1561 |
1562 | end.
1563 |
--------------------------------------------------------------------------------