forked from pult/libssh2_delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibssh2_publickey.pas
225 lines (201 loc) · 8.85 KB
/
libssh2_publickey.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
{ **
* Delphi/Pascal Wrapper around the library "libssh2"
* Base repository:
* https://bitbucket.org/ZeljkoMarjanovic/libssh2-delphi
* Contributors:
* https://bitbucket.org/jeroenp/libssh2-delphi
* https://bitbucket.org/VadimLV/libssh2_delphi
* https://github.com/pult/libssh2_delphi/
* }
unit libssh2_publickey;
// **zm ** translated to pascal
{$i libssh2.inc}
interface
uses
{$IFDEF allow_hvdll}
HVDll, // alternative for: external ?dll_name name '?function_name' delayed;
{$ENDIF}
{$IFDEF WIN32}
Windows,
{$ELSE}
Wintypes, WinProcs,
{$ENDIF}
libssh2;
{+// Copyright (c) 2004-2006, Sara Golemon <[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. }
{= }
{+// Note: This include file is only needed for using the }
{-* publickey SUBSYSTEM which is not the same as publickey }
{-* authentication. For authentication you only need libssh2.h }
{-* }
{-* For more information on the publickey subsystem, }
{-* refer to IETF draft: secsh-publickey }
{= }
type
_LIBSSH2_PUBLICKEY = record end;
TLIBSSH2_PUBLICKEY = _LIBSSH2_PUBLICKEY;
PLIBSSH2_PUBLICKEY = ^TLIBSSH2_PUBLICKEY;
PLIBSSH2_PUBLICKEY_ATTRIBUTE = ^libssh2_publickey_attribute;
libssh2_publickey_attribute = record
name: PAnsiChar;
name_len: ULong;
value: PAnsiChar;
value_len: ULong;
mandatory: AnsiChar;
end {libssh2_publickey_attribute};
_libssh2_publickey_list = record
packet: PByte; {= For freeing }
name: PUCHAR;
name_len: LongInt;
blob: PUCHAR;
blob_len: ULong;
num_attrs: ULong;
attrs: PLIBSSH2_PUBLICKEY_ATTRIBUTE;
{= free me }
end {_libssh2_publickey_list};
libssh2_publickey_list = _libssh2_publickey_list;
Plibssh2_publickey_list = ^libssh2_publickey_list;
{+// Publickey Subsystem*/ }
{$if not declared(uHVDll)}
function libssh2_publickey_init(session: PLIBSSH2_SESSION): PLIBSSH2_PUBLICKEY cdecl;
{$else}
var libssh2_publickey_init: function(session: PLIBSSH2_SESSION): PLIBSSH2_PUBLICKEY cdecl;
{$ifend}
type
LIBSSH2_PUBLICKEY_ATTRIBUTE_ARRAY = array of LIBSSH2_PUBLICKEY_ATTRIBUTE;
{$if not declared(uHVDll)}
function libssh2_publickey_add_ex(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
name_len: ULong;
const blob: PByte;
blob_len: ULong;
overwrite: AnsiChar;
num_attrs: ULong;
const attrs: LIBSSH2_PUBLICKEY_ATTRIBUTE_ARRAY): Integer; cdecl;
{$else}
var libssh2_publickey_add_ex: function(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
name_len: ULong;
const blob: PByte;
blob_len: ULong;
overwrite: AnsiChar;
num_attrs: ULong;
const attrs: LIBSSH2_PUBLICKEY_ATTRIBUTE_ARRAY): Integer; cdecl;
{$ifend}
function libssh2_publickey_add(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
const blob: PByte;
blob_len: ULong;
overwrite: AnsiChar;
num_attrs: ULong;
const attrs: LIBSSH2_PUBLICKEY_ATTRIBUTE_ARRAY): Integer; inline;
{$if not declared(uHVDll)}
function libssh2_publickey_remove_ex(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
name_len: ULong;
const blob: PByte;
blob_len: ULong): Integer; cdecl;
{$else}
var libssh2_publickey_remove_ex: function(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
name_len: ULong;
const blob: PByte;
blob_len: ULong): Integer; cdecl;
{$ifend}
function libssh2_publickey_remove(pkey: PLIBSSH2_PUBLICKEY;
const name: PByte;
const blob: PByte;
blob_len: ULong): Integer; inline;
{$if not declared(uHVDll)}
function libssh2_publickey_list_fetch(pkey: PLIBSSH2_PUBLICKEY;
var num_keys: LongInt;
var pkey_list: PLIBSSH2_PUBLICKEY_LIST): Integer; cdecl;
{$else}
var libssh2_publickey_list_fetch: function(pkey: PLIBSSH2_PUBLICKEY;
var num_keys: LongInt;
var pkey_list: PLIBSSH2_PUBLICKEY_LIST): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
procedure libssh2_publickey_list_free(pkey: PLIBSSH2_PUBLICKEY;
var pkey_list: LIBSSH2_PUBLICKEY_LIST) cdecl;
{$else}
var libssh2_publickey_list_free: procedure(pkey: PLIBSSH2_PUBLICKEY;
var pkey_list: LIBSSH2_PUBLICKEY_LIST) cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_publickey_shutdown(pkey: PLIBSSH2_PUBLICKEY): Integer; cdecl;
{$else}
var libssh2_publickey_shutdown: function(pkey: PLIBSSH2_PUBLICKEY): Integer; cdecl;
{$ifend}
implementation
{$if not declared(uHVDll)}
function libssh2_publickey_init; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_publickey_add_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_publickey_remove_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_publickey_list_fetch; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
procedure libssh2_publickey_list_free; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_publickey_shutdown; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
{$else}
var
dll_libssh2 : TDll;
dll_libssh2_entires : array[0..5] of HVDll.TEntry = (
(Proc: @@libssh2_publickey_init; Name: 'libssh2_publickey_init'),
(Proc: @@libssh2_publickey_add_ex; Name: 'libssh2_publickey_add_ex'),
(Proc: @@libssh2_publickey_remove_ex; Name: 'libssh2_publickey_remove_ex'),
(Proc: @@libssh2_publickey_list_fetch; Name: 'libssh2_publickey_list_fetch'),
(Proc: @@libssh2_publickey_list_free; Name: 'libssh2_publickey_list_free'),
(Proc: @@libssh2_publickey_shutdown; Name: 'libssh2_publickey_shutdown')
);
{$ifend}
function libssh2_publickey_add(pkey: PLIBSSH2_PUBLICKEY; const name: PByte; const blob: PByte;
blob_len: ULong; overwrite: AnsiChar; num_attrs: ULong; const attrs: LIBSSH2_PUBLICKEY_ATTRIBUTE_ARRAY): Integer;
begin
Result := libssh2_publickey_add_ex(pkey, name, Length(PAnsiChar(name)), blob, blob_len, overwrite, num_attrs, attrs);
end;
function libssh2_publickey_remove(pkey: PLIBSSH2_PUBLICKEY; const name: PByte; const blob: PByte; blob_len: ULong): Integer;
begin
Result := libssh2_publickey_remove_ex(pkey, name, Length(PAnsiChar(name)), blob, blob_len);
end;
initialization
{$if declared(uHVDll)}
dll_libssh2 := TDll.Create(libssh2_name, dll_libssh2_entires);
//dll_libssh2.Load(); // @dbg
{$ifend}
finalization
{$if declared(uHVDll)}
dll_libssh2.Unload;
{$ifend}
end.