-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathckonssh.c
1976 lines (1798 loc) · 70.5 KB
/
ckonssh.c
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
/*
* C K O N S S H . C -- Null Subsystem Interface for Kermit 95
*
* Copyright (C) 2022, David Goodwin <[email protected]>
*
* 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 Columbia University nor the names of any
* 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
* HOLDER 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.
*/
/*
* This is a "null" SSH Subsystem for Kermit 95. It implements the bare
* minimum to be loadable by Kermit 95, but it can't make SSH connections.
*
* It exists to serve as an example of Kermit 95s SSH Subsystem DLL
* interface, and also to allow for performing some basic testing against
* Kermit 95 without getting a full SSH implementation involved.
*
* Note that SSH Subsystems should *not* assume they're being loaded into
* a graphical application. Kermit 95 is available in both GUI and text mode
* (console) variants. The supplied helper functions uq_txt, uq_mtxt, uq_ok
* and uq_file support both GUI and text-mode interfaces for getting user
* input.
*/
#include "ckcdeb.h"
#include "ckossh.h"
#include <stdio.h>
#include <stdarg.h>
#ifdef NT
#include <windows.h>
#else
#define INCL_DOSPROCESS
#include <os2.h>
#undef COMMENT
#endif
/*
* Keyword tables for some of the "set ssh" options - these are the tables whose
* values are most likely to vary from one SSH implementation to another.
*
* These used to live in ckuus3.c
*/
#define SSHA_CRS 1
#define SSHA_DSA 2
#define SSHA_GSS 3
#define SSHA_HOS 4
#define SSHA_KBD 5
#define SSHA_K4 6
#define SSHA_K5 7
#define SSHA_PSW 8
#define SSHA_PK 9
#define SSHA_SKE 10
#define SSHA_TIS 11
#define SSHA_EXT 12
#define SSHA_SRP 13
static struct keytab ssh2aut[] = { /* SET SSH V2 AUTH command table */
{ "external-keyx", SSHA_EXT, 0 },
{ "gssapi", SSHA_GSS, 0 },
{ "hostbased", SSHA_HOS, 0 },
{ "keyboard-interactive", SSHA_KBD, 0 },
{ "password", SSHA_PSW, 0 },
{ "publickey", SSHA_PK, 0 },
{ "srp-gex-sha1", SSHA_SRP, 0 },
{ "", 0, 0 }
};
static int nssh2aut = (sizeof(ssh2aut) / sizeof(struct keytab)) - 1;
#define SSHC_3DES 1 /* 3DES */
#define SSHC_3CBC 2 /* 3DES-CBC */
#define SSHC_A128 3 /* AES128-CBC */
#define SSHC_A192 4 /* AES192-CBC */
#define SSHC_A256 5 /* AES256-CBC */
#define SSHC_ARC4 6 /* ARCFOUR */
#define SSHC_FISH 7 /* BLOWFISH */
#define SSHC_C128 8 /* CAST128-CBC */
#define SSHC_BCBC 9 /* BLOWFISH-CBC */
#define SSHC_1DES 10 /* DES */
#define SSHC_CHPO 11 /* chachae20-poly1305 */
#define SSHC_A1GC 12 /* [email protected] */
#define SSHC_A2GC 13 /* [email protected] */
#define SSHC_A12C 14 /* aes128-ctr */
#define SSHC_A19C 15 /* aes192-ctr */
#define SSHC_A25C 16 /* aes256-ctr */
static struct keytab ssh2ciphers[] = { /* SET SSH V2 CIPHERS command table */
{ "3des-cbc", SSHC_3CBC, 0 },
{ "aes128-cbc", SSHC_A128, 0 },
{ "aes192-cbc", SSHC_A192, 0 },
{ "aes256-cbc", SSHC_A256, 0 },
{ "arcfour", SSHC_ARC4, 0 },
{ "blowfish-cbc", SSHC_FISH, 0 },
{ "cast128-cbc", SSHC_C128, 0 },
{ "rijndael128-cbc", SSHC_A128, 0 },
{ "rijndael192-cbc", SSHC_A192, 0 },
{ "rijndael256-cbc", SSHC_A256, 0 },
{ "aes128-ctr", SSHC_A12C, 0 },
{ "aes192-ctr", SSHC_A19C, 0 },
{ "aes256-ctr", SSHC_A25C, 0 },
{ "[email protected]", SSHC_A1GC, 0 },
{ "[email protected]", SSHC_A2GC, 0 },
{ "chachae20-poly1305", SSHC_CHPO, 0 },
{ "", 0, 0 }
};
static int nssh2ciphers = (sizeof(ssh2ciphers) / sizeof(struct keytab)) - 1;
static struct keytab ssh1ciphers[] = {
{ "3des", SSHC_3DES, 0 },
{ "blowfish", SSHC_FISH, 0 },
{ "des", SSHC_1DES, 0 },
{ "", 0, 0 }
};
static int nssh1ciphers = (sizeof(ssh1ciphers) / sizeof(struct keytab)) - 1;
#define SSHM_SHA 1 /* HMAC-SHA1 */
#define SSHM_SHA_96 2 /* HMAC-SHA1-96 */
#define SSHM_MD5 3 /* HMAC-MD5 */
#define SSHM_MD5_96 4 /* HMAC-MD5-96 */
#define SSHM_RIPE 5 /* HMAC-RIPEMD160 */
#define SSHM_SHA1_ETM 6 /* [email protected] */
#define SSHM_SHA2_256 7 /* hmac-sha2-256 */
#define SSHM_SHA2_2ETM 8 /* [email protected] */
#define SSHM_SHA2_512 9 /* hmac-sha2-512 */
#define SSHM_SHA2_5ETM 10 /* [email protected] */
#define SSHM_NONE 11 /* none */
static struct keytab ssh2macs[] = { /* SET SSH V2 MACS command table */
{ "hmac-md5", SSHM_MD5, 0 },
{ "hmac-md5-96", SSHM_MD5_96, 0 },
{ "hmac-ripemd160", SSHM_RIPE, 0 },
{ "hmac-sha1", SSHM_SHA, 0 },
{ "hmac-sha1-96", SSHM_SHA_96, 0 },
{ "[email protected]", SSHM_SHA1_ETM, 0 },
{ "hmac-sha2-256", SSHM_SHA2_256, 0 },
{ "[email protected]", SSHM_SHA2_2ETM, 0 },
{ "hmac-sha2-512", SSHM_SHA2_512, 0 },
{ "[email protected]", SSHM_SHA2_5ETM, 0 },
{ "none", SSHM_NONE, 0 },
{ "", 0, 0 }
};
static int nssh2macs = (sizeof(ssh2macs) / sizeof(struct keytab)) - 1;
#define HKA_RSA 1
#define HKA_DSS 2
#define HKA_EC2 3
#define HKA_EC3 4
#define HKA_EC5 5
#define HKA_ED2 6
#define HKA_S22 7
#define HKA_S25 8
static struct keytab hkatab[] = {
{ "ecdsa-sha2-nistp256", HKA_EC2, 0, },
{ "ecdsa-sha2-nistp384", HKA_EC3, 0, },
{ "ecdsa-sha2-nistp521", HKA_EC5, 0, },
{ "rsa-sha2-256", HKA_S22, 0, },
{ "rsa-sha2-512", HKA_S25, 0, },
{ "ssh-dss", HKA_DSS, 0, },
{ "ssh-ed25519", HKA_ED2, 0, },
{ "ssh-rsa", HKA_RSA, 0, },
{ "", 0, 0 }
};
static int nhkatab = (sizeof(hkatab) / sizeof(struct keytab)) - 1;
static struct keytab sshkextab[] = {
{ "curve25519-sha256", 1, 0, },
{ "[email protected]", 2, 0, },
{ "diffie-hellman-group1-sha1", 3, 0, },
{ "diffie-hellman-group14-sha1", 4, 0, },
{ "diffie-hellman-group14-sha256", 5, 0, },
{ "diffie-hellman-group16-sha512", 6, 0, },
{ "diffie-hellman-group18-sha512", 7, 0, },
{ "diffie-hellman-group-exchange-sha1", 8, 0, },
{ "diffie-hellman-group-exchange-sha256", 9, 0, },
{ "ecdh-sha2-nistp256", 10, 0, },
{ "ecdh-sha2-nistp384", 11, 0, },
{ "ecdh-sha2-nistp521", 12, 0, },
{ "ext-info-c", 13, 0, },
{ "", 0, 0 }
};
static int nsshkextab = (sizeof(sshkextab) / sizeof(struct keytab)) - 1;
#define SET_OFF 0
/* Integer parameters accessed via ssh_set_iparam and ssh_get_iparam */
static int /* SET SSH variables */
ssh_afw = 0, /* agent forwarding */
ssh_xfw = 0, /* x11 forwarding */
ssh_prp = SET_OFF, /* privileged ports */
ssh_cmp = 1, /* compression */
ssh_cas = 0, /* command as subsys */
ssh_shh = 0, /* quiet */
ssh_ver = 0, /* protocol version (auto,1,2) */
ssh_vrb = 2, /* Report errors */
ssh_chkip = 0, /* SSH Check Host IP flag */
ssh_gwp = 0, /* gateway ports */
ssh_dyf = 0, /* dynamic forwarding */
ssh_gsd = 0, /* gssapi delegate credentials */
ssh_k4tgt = 0, /* k4 tgt passing */
ssh_k5tgt = 0, /* k5 tgt passing */
ssh_shk = 2, /* Strict host key (no, yes, ask) */
ssh2_ark = 1, /* Auto re-key */
ssh_cfg = 0, /* use OpenSSH config? */
ssh_gkx = 1, /* gssapi key exchange */
ssh_k5_is_k4 = 1, /* some SSH v1 use same codes */
ssh_hbt = 0, /* heartbeat (seconds) */
ssh_dummy = 0; /* bottom of list */
/* String parameters accessed via ssh_set_sparam and ssh_get_sparam */
static char /* The following are to be malloc'd */
* ssh1_cif = NULL, /* v1 cipher */
* ssh2_cif = NULL, /* v2 cipher list */
* ssh2_mac = NULL, /* v2 mac list */
* ssh2_auth = NULL, /* v2 authentication list */
* ssh2_hka = NULL, /* Host Key Algorithms */
* ssh_hst = NULL, /* hostname */
* ssh_prt = NULL, /* port/service */
* ssh_cmd = NULL, /* command to execute */
* ssh_xal = NULL, /* xauth-location */
* ssh1_gnh = NULL, /* v1 global known hosts file */
* ssh1_unh = NULL, /* v1 user known hosts file */
* ssh2_gnh = NULL, /* v2 global known hosts file */
* ssh2_unh = NULL, /* v2 user known hosts file */
* ssh2_kex = NULL, /* Key Exchange Methods */
* ssh_pxc = NULL, /* Proxy command */
* ssh_dir = NULL, /* SSH Directory */
* xxx_dummy = NULL;
#ifdef SSH_DLL
static get_current_terminal_dimensions_callback *callbackp_get_current_terminal_dimensions = NULL;
static get_current_terminal_type_callback *callbackp_get_current_terminal_type = NULL;
static ssh_get_uid_callback *callbackp_ssh_get_uid = NULL;
static ssh_get_pw_callback *callbackp_ssh_get_pw = NULL;
static ssh_get_nodelay_enabled_callback *callbackp_ssh_get_nodelay_enabled = NULL;
static ssh_open_socket_callback *callbackp_ssh_open_socket = NULL;
static dodebug_callback *callbackp_dodebug = NULL;
static scrnprint_callback *callbackp_scrnprint = NULL;
static uq_txt_callback *callbackp_uq_txt = NULL;
static uq_mtxt_callback *callbackp_uq_mtxt = NULL;
static uq_ok_callback *callbackp_uq_ok = NULL;
static uq_file_callback *callbackp_uq_file = NULL;
static zmkdir_callback *callbackp_zmkdir = NULL;
static ckmakxmsg_callback *callbackp_ckmakxmsg = NULL;
static whoami_callback *callbackp_whoami = NULL;
static GetAppData_callback *callbackp_GetAppData = NULL;
static GetHomePath_callback *callbackp_GetHomePath = NULL;
static GetHomeDrive_callback *callbackp_GetHomeDrive = NULL;
static ckstrncpy_callback *callbackp_ckstrncpy = NULL;
static debug_logging_callback *callbackp_debug_logging = NULL;
static get_display_callback *callbackp_get_display = NULL;
static parse_displayname_callback *callbackp_parse_displayname = NULL;
void get_current_terminal_dimensions(int* rows, int* cols) {
callbackp_get_current_terminal_dimensions(rows, cols);
}
const char* get_current_terminal_type(void) {
return callbackp_get_current_terminal_type();
}
const char* ssh_get_uid(void) {
return callbackp_ssh_get_uid();
}
const char* ssh_get_pw(void) {
return callbackp_ssh_get_pw();
}
int ssh_get_nodelay_enabled(void) {
return callbackp_ssh_get_nodelay_enabled();
}
SOCKET ssh_open_socket(char* host, char* port) {
return callbackp_ssh_open_socket(host, port);
}
int dodebug(int flag, char * s1, char * s2, CK_OFF_T n)
{
if ( callbackp_dodebug )
return(callbackp_dodebug(flag,s1,s2,n));
else
return(-1);
}
static char myprtfstr[4096];
int Vscrnprintf(const char * format, ...) {
int i, len, rc=0;
char *cp;
va_list ap;
va_start(ap, format);
#ifdef NT
rc = _vsnprintf(myprtfstr, sizeof(myprtfstr)-1, format, ap);
#else /* NT */
rc = vsprintf(myprtfstr, format, ap);
#endif /* NT */
va_end(ap);
if ( callbackp_scrnprint )
return(callbackp_scrnprint(myprtfstr));
else
return(-1);
}
int uq_txt(char * preface, char * prompt, int echo, char ** help, char * buf,
int buflen, char *dflt, int timer) {
return callbackp_uq_txt(preface, prompt, echo, help, buf, buflen, dflt, timer);
}
int uq_mtxt(char * preface,char **help, int n, struct txtbox field[]) {
return callbackp_uq_mtxt(preface, help, n, field);
}
int uq_ok(char * preface, char * prompt, int mask,char ** help, int dflt) {
return callbackp_uq_ok(preface, prompt, mask, help, dflt);
}
int uq_file(char * preface, char * fprompt, int fc, char ** help,
char * dflt, char * result, int rlength) {
return callbackp_uq_file(preface, fprompt, fc, help, dflt, result, rlength);
}
int zmkdir(char *path) {
return callbackp_zmkdir(path);
}
int ckmakxmsg(char * buf, int len, char *s1, char *s2, char *s3,
char *s4, char *s5, char *s6, char *s7, char *s8, char *s9,
char *s10, char *s11, char *s12) {
return callbackp_ckmakxmsg(buf, len, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11,
s12);
}
char* whoami(void) {
return callbackp_whoami();
}
char* GetAppData(int common) {
return callbackp_GetAppData(common);
}
char* GetHomePath(void) {
return callbackp_GetHomePath();
}
char* GetHomeDrive(void) {
return callbackp_GetHomeDrive();
}
int ckstrncpy(char * dest, const char * src, int len) {
return callbackp_ckstrncpy(dest, src, len);
}
int debug_logging(void) {
return callbackp_debug_logging();
}
unsigned char* get_display(void) {
return callbackp_get_display();
}
int parse_displayname(char *displayname, int *familyp, char **hostp,
int *dpynump, int *scrnump, char **restp) {
return callbackp_parse_displayname(displayname, familyp, hostp,
dpynump, scrnump, restp);
}
#ifdef SSH_DLL_CALLCONV
/* define prototypes for DLL functions */
static ssh_set_iparam_dllfunc dllfunc_ssh_set_iparam;
static ssh_get_iparam_dllfunc dllfunc_ssh_get_iparam;
static ssh_set_sparam_dllfunc dllfunc_ssh_set_sparam;
static ssh_get_sparam_dllfunc dllfunc_ssh_get_sparam;
static ssh_set_identity_files_dllfunc dllfunc_ssh_set_identity_files;
static ssh_get_socket_dllfunc dllfunc_ssh_get_socket;
static ssh_open_dllfunc dllfunc_ssh_open;
static ssh_clos_dllfunc dllfunc_ssh_clos;
static ssh_tchk_dllfunc dllfunc_ssh_tchk;
static ssh_flui_dllfunc dllfunc_ssh_flui;
static ssh_break_dllfunc dllfunc_ssh_break;
static ssh_inc_dllfunc dllfunc_ssh_inc;
static ssh_xin_dllfunc dllfunc_ssh_xin;
static ssh_toc_dllfunc dllfunc_ssh_toc;
static ssh_tol_dllfunc dllfunc_ssh_tol;
static ssh_snaws_dllfunc dllfunc_ssh_snaws;
static ssh_proto_ver_dllfunc dllfunc_ssh_proto_ver;
static ssh_impl_ver_dllfunc dllfunc_ssh_impl_ver;
static sshkey_create_dllfunc dllfunc_sshkey_create;
static sshkey_display_fingerprint_dllfunc dllfunc_sshkey_display_fingerprint;
static sshkey_display_public_dllfunc dllfunc_sshkey_display_public;
static sshkey_display_public_as_ssh2_dllfunc dllfunc_sshkey_display_public_as_ssh2;
static sshkey_change_passphrase_dllfunc dllfunc_sshkey_change_passphrase;
static ssh_fwd_remote_port_dllfunc dllfunc_ssh_fwd_remote_port;
static ssh_fwd_local_port_dllfunc dllfunc_ssh_fwd_local_port;
static ssh_fwd_clear_remote_ports_dllfunc dllfunc_ssh_fwd_clear_remote_ports;
static ssh_fwd_clear_local_ports_dllfunc dllfunc_ssh_fwd_clear_local_ports;
static ssh_fwd_remove_remote_port_dllfunc dllfunc_ssh_fwd_remove_remote_port;
static ssh_fwd_remove_local_port_dllfunc dllfunc_ssh_fwd_remove_local_port;
static ssh_fwd_get_ports_dllfunc dllfunc_ssh_fwd_get_ports;
static sshkey_v1_change_comment_dllfunc dllfunc_sshkey_v1_change_comment;
static sshkey_default_file_dllfunc dllfunc_sshkey_default_file;
static ssh_v2_rekey_dllfunc dllfunc_ssh_v2_rekey;
static ssh_agent_delete_file_dllfunc dllfunc_ssh_agent_delete_file;
static ssh_agent_delete_all_dllfunc dllfunc_ssh_agent_delete_all;
static ssh_agent_add_file_dllfunc dllfunc_ssh_agent_add_file;
static ssh_agent_list_identities_dllfunc dllfunc_ssh_agent_list_identities;
static ssh_unload_dllfunc dllfunc_ssh_unload;
static ssh_dll_ver_dllfunc dllfunc_ssh_dll_ver;
static ssh_get_keytab_dllfunc dllfunc_ssh_get_keytab;
static ssh_feature_supported_dllfunc dllfunc_ssh_feature_supported;
static ssh_get_set_help_dllfunc dllfunc_ssh_get_set_help;
static ssh_get_help_dllfunc dllfunc_ssh_get_help;
/* calling convention layer for DLL functions on DLL side */
static int CKSSHAPI dllfunc_ssh_set_iparam(int param, int value) {
return ssh_set_iparam(param, value);
}
static int CKSSHAPI dllfunc_ssh_get_iparam(int param) {
return ssh_get_iparam(param);
}
static int CKSSHAPI dllfunc_ssh_set_sparam(int param, const char* value) {
return ssh_set_sparam(param, value);
}
static const char* CKSSHAPI dllfunc_ssh_get_sparam(int param) {
return ssh_get_sparam(param);
}
static int CKSSHAPI dllfunc_ssh_set_identity_files(const char** identity_files) {
return ssh_set_identity_files(identity_files);
}
static int CKSSHAPI dllfunc_ssh_get_socket(void) {
return ssh_get_socket();
}
static int CKSSHAPI dllfunc_ssh_open(void) {
return ssh_open();
}
static int CKSSHAPI dllfunc_ssh_clos(void) {
return ssh_clos();
}
static int CKSSHAPI dllfunc_ssh_tchk(void) {
return ssh_tchk();
}
static int CKSSHAPI dllfunc_ssh_flui(void) {
return ssh_flui();
}
static int CKSSHAPI dllfunc_ssh_break(void) {
return ssh_break();
}
static int CKSSHAPI dllfunc_ssh_inc(int timeout) {
return ssh_inc(timeout);
}
static int CKSSHAPI dllfunc_ssh_xin(int count, char * buffer) {
return ssh_xin(count, buffer);
}
static int CKSSHAPI dllfunc_ssh_toc(int c) {
return ssh_toc(c);
}
static int CKSSHAPI dllfunc_ssh_tol(char * buffer, int count) {
return ssh_tol(buffer, count);
}
static int CKSSHAPI dllfunc_ssh_snaws(void) {
return ssh_snaws();
}
static const char * CKSSHAPI dllfunc_ssh_proto_ver(void) {
return ssh_proto_ver();
}
static const char * CKSSHAPI dllfunc_ssh_impl_ver(void) {
return ssh_impl_ver();
}
#ifdef COMMENT
static int CKSSHAPI dllfunc_sshkey_create(char * filename, int bits, char * pp,
int type, char * cmd_comment) {
return sshkey_create(filename, bits, pp, type, cmd_comment);
}
static int CKSSHAPI dllfunc_sshkey_display_fingerprint(char * filename, int babble) {
return sshkey_display_fingerprint(filename, babble);
}
static int CKSSHAPI dllfunc_sshkey_display_public(char * filename, char *identity_passphrase) {
return sshkey_display_public(filename, identity_passphrase);
}
static int CKSSHAPI dllfunc_sshkey_display_public_as_ssh2(char * filename,char *identity_passphrase) {
return sshkey_display_public_as_ssh2(filename, identity_passphrase);
}
static int CKSSHAPI dllfunc_sshkey_change_passphrase(char * filename, char * oldpp, char * newpp) {
return sshkey_change_passphrase(filename, oldpp, newpp);
}
static int CKSSHAPI dllfunc_ssh_fwd_remote_port(char* address, int port, char * host, int host_port, BOOL apply) {
return ssh_fwd_remote_port(address, port, host, host_port, apply);
}
static int CKSSHAPI dllfunc_ssh_fwd_local_port(char* address, int port,char * host, int host_port, BOOL apply) {
return ssh_fwd_local_port(address, port, host, host_port, apply);
}
static int CKSSHAPI dllfunc_ssh_fwd_clear_remote_ports(BOOL apply) {
return ssh_fwd_clear_remote_ports(apply);
}
static int CKSSHAPI dllfunc_ssh_fwd_clear_local_ports(BOOL apply) {
return ssh_fwd_clear_local_ports(apply);
}
static int CKSSHAPI dllfunc_ssh_fwd_remove_remote_port(int port, BOOL apply) {
return ssh_fwd_remove_remote_port(port, apply);
}
static int CKSSHAPI dllfunc_ssh_fwd_remove_local_port(int port, BOOL apply) {
return ssh_fwd_remove_local_port(port, apply);
}
static const ssh_port_forward_t* CKSSHAPI dllfunc_ssh_fwd_get_ports(void) {
return ssh_fwd_get_ports();
}
#ifdef SSHTEST
static int CKSSHAPI dllfunc_sshkey_v1_change_comment(char * filename, char * comment, char * pp) {
return sshkey_v1_change_comment(filename, comment, pp);
}
#endif /* SSHTEST */
#ifdef COMMENT
static char * CKSSHAPI dllfunc_sshkey_default_file(int a) {
return sshkey_default_file(a);
}
#endif /* COMMENT */
static void CKSSHAPI dllfunc_ssh_v2_rekey(void) {
ssh_v2_rekey();
}
static int CKSSHAPI dllfunc_ssh_agent_delete_file(const char *filename) {
return ssh_agent_delete_file(filename);
}
static int CKSSHAPI dllfunc_ssh_agent_delete_all(void) {
return ssh_agent_delete_all();
}
static int CKSSHAPI dllfunc_ssh_agent_add_file(const char *filename) {
return ssh_agent_add_file(filename);
}
static int CKSSHAPI dllfunc_ssh_agent_list_identities(int do_fp) {
return ssh_agent_list_identities(do_fp);
}
static void CKSSHAPI dllfunc_ssh_unload(void) {
ssh_unload();
}
#endif /* COMMENT */
static const char * CKSSHAPI dllfunc_ssh_dll_ver(void) {
return ssh_dll_ver();
}
static ktab_ret CKSSHAPI dllfunc_ssh_get_keytab(int keytab_id) {
return ssh_get_keytab(keytab_id);
}
static int CKSSHAPI dllfunc_ssh_feature_supported(int feature_id) {
return ssh_feature_supported(feature_id);
}
static const char ** CKSSHAPI dllfunc_ssh_get_set_help(void) {
return ssh_get_set_help();
}
static const char ** CKSSHAPI dllfunc_ssh_get_help(void) {
return ssh_get_help();
}
#else /* SSH_DLL_CALLCONV */
/* directly use DLL functions without calling convention layer */
#define dllfunc_ssh_set_iparam ssh_set_iparam
#define dllfunc_ssh_get_iparam ssh_get_iparam
#define dllfunc_ssh_set_sparam ssh_set_sparam
#define dllfunc_ssh_get_sparam ssh_get_sparam
#define dllfunc_ssh_set_identity_files ssh_set_identity_files
#define dllfunc_ssh_get_socket ssh_get_socket
#define dllfunc_ssh_open ssh_open
#define dllfunc_ssh_clos ssh_clos
#define dllfunc_ssh_tchk ssh_tchk
#define dllfunc_ssh_flui ssh_flui
#define dllfunc_ssh_break ssh_break
#define dllfunc_ssh_inc ssh_inc
#define dllfunc_ssh_xin ssh_xin
#define dllfunc_ssh_toc ssh_toc
#define dllfunc_ssh_tol ssh_tol
#define dllfunc_ssh_snaws ssh_snaws
#define dllfunc_ssh_proto_ver ssh_proto_ver
#define dllfunc_ssh_impl_ver ssh_impl_ver
#ifdef COMMENT
#define dllfunc_sshkey_create sshkey_create
#define dllfunc_sshkey_display_fingerprint sshkey_display_fingerprint
#define dllfunc_sshkey_display_public sshkey_display_public
#define dllfunc_sshkey_display_public_as_ssh2 sshkey_display_public_as_ssh2
#define dllfunc_sshkey_change_passphrase sshkey_change_passphrase
#define dllfunc_ssh_fwd_remote_port ssh_fwd_remote_port
#define dllfunc_ssh_fwd_local_port ssh_fwd_local_port
#define dllfunc_ssh_fwd_clear_remote_ports ssh_fwd_clear_remote_ports
#define dllfunc_ssh_fwd_clear_local_ports ssh_fwd_clear_local_ports
#define dllfunc_ssh_fwd_remove_remote_port ssh_fwd_remove_remote_port
#define dllfunc_ssh_fwd_remove_local_port ssh_fwd_remove_local_port
#define dllfunc_ssh_fwd_get_ports ssh_fwd_get_ports
#ifdef SSHTEST
#define dllfunc_sshkey_v1_change_comment sshkey_v1_change_comment
#endif /* SSHTEST */
#ifdef COMMENT
#define dllfunc_sshkey_default_file sshkey_default_file
#endif /* COMMENT */
#define dllfunc_ssh_v2_rekey ssh_v2_rekey
#define dllfunc_ssh_agent_delete_file ssh_agent_delete_file
#define dllfunc_ssh_agent_delete_all ssh_agent_delete_all
#define dllfunc_ssh_agent_add_file ssh_agent_add_file
#define dllfunc_ssh_agent_list_identities ssh_agent_list_identities
#define dllfunc_ssh_unload ssh_unload
#endif /* COMMENT */
#define dllfunc_ssh_dll_ver ssh_dll_ver
#define dllfunc_ssh_get_keytab ssh_get_keytab
#define dllfunc_ssh_feature_supported ssh_feature_supported
#define dllfunc_ssh_get_set_help ssh_get_set_help
#define dllfunc_ssh_get_help ssh_get_help
#endif /* SSH_DLL_CALLCONV */
/*
* Quick macro to check if a function pointer is null and, if it is, log
* the event and return an error.
*/
#define CHECK_FP(fp)
/** Called by Kermit 95 when the DLL is loaded. This should make
* the DLL ready for use by storing copies of all the needed
* callback functions supplied by Kermit 95, and supplying to
* Kermit 95 via the install_dllfunc all of the SSH functions
* this DLL provides.
* @param params SSH initialisation parameters from Kermit 95
*/
int CKSSHDLLENTRY ssh_dll_init(ssh_dll_init_data *init) {
/* Store pointers to helper functions provided by K95 */
callbackp_get_current_terminal_dimensions = init->callbackp_get_current_terminal_dimensions;
CHECK_FP(callbackp_get_current_terminal_dimensions)
callbackp_get_current_terminal_type = init->callbackp_get_current_terminal_type;
CHECK_FP(callbackp_get_current_terminal_type)
callbackp_ssh_get_uid = init->callbackp_ssh_get_uid;
CHECK_FP(callbackp_ssh_get_uid)
callbackp_ssh_get_pw = init->callbackp_ssh_get_pw;
CHECK_FP(callbackp_ssh_get_pw)
callbackp_ssh_get_nodelay_enabled = init->callbackp_ssh_get_nodelay_enabled;
CHECK_FP(callbackp_ssh_get_nodelay_enabled)
callbackp_ssh_open_socket = init->callbackp_ssh_open_socket;
CHECK_FP(callbackp_ssh_open_socket)
callbackp_dodebug = init->callbackp_dodebug;
CHECK_FP(callbackp_dodebug)
callbackp_scrnprint = init->callbackp_scrnprint;
CHECK_FP(callbackp_scrnprint)
callbackp_uq_txt = init->callbackp_uq_txt;
CHECK_FP(callbackp_uq_txt)
callbackp_uq_mtxt = init->callbackp_uq_mtxt;
CHECK_FP(callbackp_uq_mtxt)
callbackp_uq_ok = init->callbackp_uq_ok;
CHECK_FP(callbackp_uq_ok)
callbackp_uq_file = init->callbackp_uq_file;
CHECK_FP(callbackp_uq_file)
callbackp_zmkdir = init->callbackp_zmkdir;
CHECK_FP(callbackp_zmkdir)
callbackp_ckmakxmsg = init->callbackp_ckmakxmsg;
CHECK_FP(callbackp_ckmakxmsg)
callbackp_whoami = init->callbackp_whoami;
CHECK_FP(callbackp_whoami)
callbackp_GetAppData = init->callbackp_GetAppData;
CHECK_FP(callbackp_GetAppData)
callbackp_GetHomePath = init->callbackp_GetHomePath;
CHECK_FP(callbackp_GetHomePath)
callbackp_GetHomeDrive = init->callbackp_GetHomeDrive;
CHECK_FP(callbackp_GetHomeDrive)
callbackp_ckstrncpy = init->callbackp_ckstrncpy;
CHECK_FP(callbackp_ckstrncpy)
callbackp_debug_logging = init->callbackp_debug_logging;
CHECK_FP(callbackp_debug_logging)
callbackp_get_display = init->callbackp_get_display;
CHECK_FP(callbackp_get_display)
callbackp_parse_displayname = init->callbackp_parse_displayname;
CHECK_FP(callbackp_parse_displayname)
init->callbackp_install_dllfunc("ssh_set_iparam", dllfunc_ssh_set_iparam);
init->callbackp_install_dllfunc("ssh_get_iparam", dllfunc_ssh_get_iparam);
init->callbackp_install_dllfunc("ssh_set_sparam", dllfunc_ssh_set_sparam);
init->callbackp_install_dllfunc("ssh_get_sparam", dllfunc_ssh_get_sparam);
init->callbackp_install_dllfunc("ssh_set_identity_files", dllfunc_ssh_set_identity_files);
init->callbackp_install_dllfunc("ssh_get_socket", dllfunc_ssh_get_socket);
init->callbackp_install_dllfunc("ssh_open", dllfunc_ssh_open);
init->callbackp_install_dllfunc("ssh_clos", dllfunc_ssh_clos);
init->callbackp_install_dllfunc("ssh_tchk", dllfunc_ssh_tchk);
init->callbackp_install_dllfunc("ssh_flui", dllfunc_ssh_flui);
init->callbackp_install_dllfunc("ssh_break", dllfunc_ssh_break);
init->callbackp_install_dllfunc("ssh_inc", dllfunc_ssh_inc);
init->callbackp_install_dllfunc("ssh_xin", dllfunc_ssh_xin);
init->callbackp_install_dllfunc("ssh_toc", dllfunc_ssh_toc);
init->callbackp_install_dllfunc("ssh_tol", dllfunc_ssh_tol);
init->callbackp_install_dllfunc("ssh_snaws", dllfunc_ssh_snaws);
init->callbackp_install_dllfunc("ssh_proto_ver", dllfunc_ssh_proto_ver);
init->callbackp_install_dllfunc("ssh_impl_ver", dllfunc_ssh_impl_ver);
/* These functions are all optional */
#ifdef COMMENT
init->callbackp_install_dllfunc("sshkey_create", dllfunc_sshkey_create);
init->callbackp_install_dllfunc("sshkey_display_fingerprint", dllfunc_sshkey_display_fingerprint);
init->callbackp_install_dllfunc("sshkey_display_public", dllfunc_sshkey_display_public);
init->callbackp_install_dllfunc("sshkey_display_public_as_ssh2", dllfunc_sshkey_display_public_as_ssh2);
init->callbackp_install_dllfunc("sshkey_change_passphrase", dllfunc_sshkey_change_passphrase);
init->callbackp_install_dllfunc("ssh_fwd_remote_port", dllfunc_ssh_fwd_remote_port);
init->callbackp_install_dllfunc("ssh_fwd_local_port", dllfunc_ssh_fwd_local_port);
init->callbackp_install_dllfunc("ssh_fwd_clear_remote_ports", dllfunc_ssh_fwd_clear_remote_ports);
init->callbackp_install_dllfunc("ssh_fwd_clear_local_ports", dllfunc_ssh_fwd_clear_local_ports);
init->callbackp_install_dllfunc("ssh_fwd_remove_remote_port", dllfunc_ssh_fwd_remove_remote_port);
init->callbackp_install_dllfunc("ssh_fwd_remove_local_port", dllfunc_ssh_fwd_remove_local_port);
init->callbackp_install_dllfunc("ssh_fwd_get_ports", dllfunc_ssh_fwd_get_ports);
#ifdef SSHTEST
init->callbackp_install_dllfunc("sshkey_v1_change_comment", dllfunc_sshkey_v1_change_comment); /* TODO */
#endif /* SSHTEST */
#ifdef COMMENT
init->callbackp_install_dllfunc("sshkey_default_file", dllfunc_sshkey_default_file); */ /* TODO */
#endif /* COMMENT */
init->callbackp_install_dllfunc("ssh_v2_rekey", dllfunc_ssh_v2_rekey); /* TODO */
init->callbackp_install_dllfunc("ssh_agent_delete_file", dllfunc_ssh_agent_delete_file); /* TODO */
init->callbackp_install_dllfunc("ssh_agent_delete_all", dllfunc_ssh_agent_delete_all); /* TODO */
init->callbackp_install_dllfunc("ssh_agent_add_file", dllfunc_ssh_agent_add_file); /* TODO */
init->callbackp_install_dllfunc("ssh_agent_list_identities", dllfunc_ssh_agent_list_identities); /* TODO */
#ifdef COMMENT
/* Not supported: */
init->callbackp_install_dllfunc("ssh_unload", dllfunc_ssh_unload);
#endif /* COMMENT */
#endif /* COMMENT */
init->callbackp_install_dllfunc("ssh_dll_ver", dllfunc_ssh_dll_ver);
init->callbackp_install_dllfunc("ssh_get_keytab", dllfunc_ssh_get_keytab);
init->callbackp_install_dllfunc("ssh_feature_supported", dllfunc_ssh_feature_supported);
init->callbackp_install_dllfunc("ssh_get_set_help", dllfunc_ssh_get_set_help);
init->callbackp_install_dllfunc("ssh_get_help", dllfunc_ssh_get_help);
return 0;
}
#undef malloc
#undef realloc
#undef free
#undef strdup
void
fatal(char *msg) {
if (!msg) msg = "";
printf(msg);
exit(1); /* Exit indicating failure */
}
void *
kmalloc(size_t size)
{
void *ptr;
if (size == 0) {
fatal("kmalloc: zero size");
}
ptr = malloc(size);
if (ptr == NULL) {
fatal("kmalloc: out of memory");
}
return ptr;
}
void *
krealloc(void *ptr, size_t new_size)
{
void *new_ptr;
if (new_size == 0) {
fatal("krealloc: zero size");
}
if (ptr == NULL)
new_ptr = malloc(new_size);
else
new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL) {
fatal("krealloc: out of memory");
}
return new_ptr;
}
void
kfree(void *ptr)
{
if (ptr == NULL) {
printf("kfree: NULL pointer given as argument");
return;
}
free(ptr);
}
char *
kstrdup(const char *str)
{
size_t len;
char *cp;
if (str == NULL) {
fatal("kstrdup: NULL pointer given as argument");
}
len = strlen(str) + 1;
cp = kmalloc(len);
if (cp)
memcpy(cp, str, len);
return cp;
}
#endif /* SSH_DLL */
/** Sets an integer parameter
*
* @param param Parameter to set
* @param value New value
* @return
*/
int ssh_set_iparam(int param, int value) {
switch(param) {
case SSH_IPARAM_AFW:
ssh_afw = value;
break;
case SSH_IPARAM_XFW:
ssh_xfw = value;
break;
case SSH_IPARAM_PRP:
ssh_prp = value;
break;
case SSH_IPARAM_CMP:
ssh_cmp = value;
break;
case SSH_IPARAM_CAS:
ssh_cas = value;
break;
case SSH_IPARAM_SHH:
ssh_shh = value;
break;
case SSH_IPARAM_VER:
ssh_ver = value;
break;
case SSH_IPARAM_VRB:
ssh_vrb = value;
break;
case SSH_IPARAM_CHKIP:
ssh_chkip = value;
break;
case SSH_IPARAM_GWP:
ssh_gwp = value;
break;
case SSH_IPARAM_DYF:
ssh_dyf = value;
break;
case SSH_IPARAM_GSD:
ssh_gsd = value;
break;
case SSH_IPARAM_K4TGT:
ssh_k4tgt = value;
break;
case SSH_IPARAM_K5TGT:
ssh_k5tgt = value;
break;
case SSH_IPARAM_SHK:
ssh_shk = value;
break;
case SSH_IPARAM_2_ARK:
ssh2_ark = value;
break;
case SSH_IPARAM_CFG:
ssh_cfg = value;
break;
case SSH_IPARAM_GKX:
ssh_gkx = value;
break;
case SSH_IPARAM_K5_IS_K4:
ssh_k5_is_k4 = value;
break;
case SSH_IPARAM_HBT:
ssh_hbt = value;
break;
default:
return 1;
}
return 0;
}
/** Gets an integer parameter
*
* @param param The parameter to get (SSH_IPARAM_)
* @return Integer parameter value
*/
int ssh_get_iparam(int param) {
switch(param) {
case SSH_IPARAM_AFW:
return ssh_afw;
case SSH_IPARAM_XFW:
return ssh_xfw;
case SSH_IPARAM_PRP:
return ssh_prp;
case SSH_IPARAM_CMP:
return ssh_cmp;
case SSH_IPARAM_CAS:
return ssh_cas;
case SSH_IPARAM_SHH:
return ssh_shh;
case SSH_IPARAM_VER:
return ssh_ver;
case SSH_IPARAM_VRB:
return ssh_vrb;
case SSH_IPARAM_CHKIP:
return ssh_chkip;
case SSH_IPARAM_GWP:
return ssh_gwp;
case SSH_IPARAM_DYF:
return ssh_dyf;
case SSH_IPARAM_GSD:
return ssh_gsd;
case SSH_IPARAM_K4TGT:
return ssh_k4tgt;
case SSH_IPARAM_K5TGT:
return ssh_k5tgt;
case SSH_IPARAM_SHK:
return ssh_shk;
case SSH_IPARAM_2_ARK:
return ssh2_ark;
case SSH_IPARAM_CFG:
return ssh_cfg;
case SSH_IPARAM_GKX:
return ssh_gkx;
case SSH_IPARAM_K5_IS_K4:
return ssh_k5_is_k4;
case SSH_IPARAM_HBT:
return ssh_hbt;
}
return 0;
}
/** Utility function for copying a string to a destination or freeing
* the destination if the source is null
*
* @param dest destination
* @param src new value