forked from KermitProject/ckermit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckcnet.c
14474 lines (13404 loc) · 439 KB
/
ckcnet.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
char *cknetv = "Network support, 10.0.299, 26 Sep 2022";
/* C K C N E T -- Network support */
/*
Copyright (C) 1985, 2022,
Trustees of Columbia University in the City of New York.
All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
*/
/*
REMINDER: Any changes made to this file that other modules depend must
also be made to cklnet.c (for VOS) until such time as cklnet.c and this
module are merged back together.
NOTE TO CONTRIBUTORS: This file, and all the other shared (ckc and cku)
C-Kermit source files, must be compatible with C preprocessors that support
only #ifdef, #else, #endif, #define, and #undef. Please do not use #if,
logical operators, or other preprocessor features in this module. Also,
don't use any ANSI C constructs except within #ifdef CK_ANSIC..#endif.
Authors:
Frank da Cruz ([email protected]),
Columbia University Academic Information Systems, New York City.
Jeffrey E Altman ([email protected]) -- Primary
maintainer/developer since about 1996.
netopen() routine for TCP/IP originally by Ken Yap, Rochester University
([email protected]) (no longer at that address).
Missing pieces for Excelan sockets library from William Bader.
Telnet protocol by Frank da Cruz and Jeffrey Altman.
Rlogin protocol by Jeffrey E Altman.
SSL support adapted by Jeffrey E Altman from work done by
Tim Hudson <[email protected]> +61 7 32781581
TLS support by Jeffrey E Altman.
HTTP support by Jeffrey E Altman.
TGV MultiNet code by Frank da Cruz.
MultiNet code adapted to WIN/TCP by Ray Hunter of TWG.
MultiNet code adapted to DEC TCP/IP by Lee Tibbert of DEC and Frank da Cruz.
TCP/IP support adapted to IBM TCP/IP 1.2.1,2.0 for OS/2 by Kai Uwe Rommel.
CMU-OpenVMS/IP modifications by Mike O'Malley, Digital (DEC).
X.25 support by Marcello Frutig, Catholic University,
Rio de Janeiro, Brazil ([email protected]) with fixes from
Stefaan Eeckels, Eurokom, Luxembourg.
David Lane added support for Stratus VOS X.25 1996.
Stephen Riehm added support for IBM AIX X.25 in April 1998.
Other contributions as indicated in the code.
*/
#ifdef NORLOGIN
#ifdef RLOGCODE
#undef RLOGCODE
#endif /* RLOGCODE */
#endif /* NORLOGIN */
#define CKCNET_C
#include "ckcsym.h"
#include "ckcdeb.h"
#include "ckcker.h"
#include "ckcasc.h"
#ifdef I386IX /* Has to come before ckcnet.h in */
#include <errno.h> /* this version, but after in others */
#endif /* I386IX */
#include "ckcnet.h" /* which includes ckctel.h */
#ifdef CK_SSL
#include "ck_ssl.h"
#endif /* CK_SSL */
#ifdef CK_DNS_SRV
#ifdef OS2
#ifdef NT
#include <wshelper.h>
#else /* NT */
/* !Error OS/2 does not support DNS Service Records. */
#endif /* NT */
#else /* OS2 */
#include <arpa/inet.h>
#ifdef USE_NAMESER_COMPAT
#include <arpa/nameser_compat.h>
#endif /* USE_NAMESER_COMPAT */
#ifdef MINIX3
#include <net/gen/resolv.h>
#include <net/gen/nameser.h>
#else
#include <arpa/nameser.h>
#include <resolv.h>
#endif /* MINIX 3 */
#ifndef PS2AIX10
#ifndef BSD4
#ifndef I386IX
#ifndef RTAIX
#include <netdb.h>
#endif /* RTAIX */
#endif /* I386IX */
#endif /* BSD4 */
#endif /* PS2AIX10 */
#endif /* OS2 */
#ifndef T_SRV
#define T_SRV 33
#endif /* T_SRV */
#ifndef T_TXT
#define T_TXT 16
#endif /* T_TXT */
/* for old Unixes and friends ... */
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif /* MAXHOSTNAMELEN */
#define MAX_DNS_NAMELEN (15*(MAXHOSTNAMELEN + 1)+1)
#endif /* CK_DNS_SRV */
#ifdef NONET
#ifdef TCPIPLIB
#undef TCPIPLIB
#endif /* TCPIPLIB */
#endif /* NONET */
#ifndef NOMHHOST
#ifdef datageneral
#define NOMHHOST
#else
#ifdef HPUX5WINTCP
#define NOMHHOST
#endif /* HPUX5WINTCP */
#endif /* datageneral */
#endif /* NOMHHOST */
#ifdef INADDRX
struct in_addr inaddrx;
#endif /* INADDRX */
int ttnet = NET_NONE; /* Network type */
int ttnproto = NP_DEFAULT; /* Network virtual terminal protocol */
/* 0 = don't lowercase username for Rlogin/Telnet protocol */
/* nonzero = do lowercase it. Add a SET command if necessary... */
#ifdef VMS
int ck_lcname = 1;
#else
int ck_lcname = 0;
#endif /* VMS */
extern int /* External variables */
duplex, debses, seslog, sessft, wasclosed,
ttyfd, quiet, msgflg, what, nettype, ttmdm;
#ifdef IKSD
extern int inserver;
#endif /* IKSD */
char myipaddr[20] = { '\0' }; /* Global copy of my IP address */
char hostipaddr[64] = { '\0' }; /* Global copy of remote IP address */
#ifdef NETCONN
/* Don't need any of this if there is no network support. */
#ifndef OS2
/* Current fd-swapping hack is not thread-safe */
#define HTTP_BUFFERING
#endif /* OS2 */
#ifdef HTTP_BUFFERING
#define HTTP_INBUFLEN 8192
static char http_inbuf[HTTP_INBUFLEN];
static int http_bufp = 0, http_count;
#endif /* HTTP_BUFFERING */
/*
NETLEBUF is (must be) defined for those platforms that call this
module to do network i/o (e.g. netinc(), nettchk(), etc) rather
than doing it themselves (ttinc(), ttchk(), etc). In this case
the Telnet local-echo buffers and routines are defined and referenced
here, rather than in the ck?tio.c module.
*/
#ifdef NETLEBUF
#define LEBUFSIZ 4096
int ttpush = -1, le_data = 0; /* These are seen from outside */
static CHAR le_buf[LEBUFSIZ]; /* These are used internally */
static int le_start = 0, le_end = 0;
int tt_push_inited = 0;
#endif /* NETLEBUF */
#ifdef CK_SOCKS /* SOCKS Internet relay package */
#ifdef CK_SOCKS5 /* SOCKS 5 */
#define accept SOCKSaccept
#define bind SOCKSbind
#define connect SOCKSconnect
#define getsockname SOCKSgetsockname
#define listen SOCKSlisten
#else /* Not SOCKS 5 */
#define accept Raccept
#define bind Rbind
#define connect Rconnect
#define getsockname Rgetsockname
#define listen Rlisten
#endif /* CK_SOCKS5 */
#endif /* CK_SOCKS */
#ifdef DEC_TCPIP
#include <time.h>
#include <inet.h>
#endif /* DEC_TCPIP */
/* Also see ckcnet.h -- hmmm, why don't we always include inet.h? */
#ifdef HPUX
#ifndef HPUX7 /* HPUX 7.00 doesn't have it */
#ifndef HPUX6 /* HPUX 6.00 doesn't have it */
#include <arpa/inet.h> /* For inet_ntoa() prototype */
#endif /* HPUX6 */
#endif /* HPUX7 */
#endif /* HPUX */
#ifdef CMU_TCPIP
#include <time.h>
#endif /* CMU_TCPIP */
#ifndef NODCLTIMEVAL
#ifdef DCLTIMEVAL /* UnixWare 7 */
struct timeval { /* And define these ourselves. */
long tv_sec; /* (see comments in ckutio.c) */
long tv_usec;
};
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
#endif /* DCLTIMEVAL */
#endif /* NODCLTIMEVAL */
#ifdef WINTCP
#include <setjmp.h>
#include <signal.h>
#include <sys/time.h>
/*
The WIN/TCP code path is the same as that for MultiNet.
Only the routine names have changed ...
*/
#define socket_read netread
#define socket_ioctl ioctl
#define socket_write netwrite
#define socket_close netclose
#ifdef OLD_TWG /* some routines have evolved */
extern int vmserrno, uerrno;
#define socket_errno uerrno
#define socket_perror perror /* which uses errno, not uerrno! */
#else
#define socket_errno errno
#define socket_perror win$perror
#endif /* OLD_TWG */
#else /* Not WINTCP */
#ifdef OSF13
#ifdef CK_ANSIC
#ifdef _NO_PROTO
#undef _NO_PROTO
#endif /* _NO_PROTO */
#endif /* CK_ANSIC */
#endif /* OSF13 */
#ifndef OS2
#ifndef I386IX
#ifndef HPUXPRE65
#include <errno.h> /* Error number symbols */
#else
#ifndef ERRNO_INCLUDED
#include <errno.h> /* Error number symbols */
#endif /* ERRNO_INCLUDED */
#endif /* HPUXPRE65 */
#endif /* I386IX */
#endif /* OS2 */
#ifdef OS2
#ifdef NT
#include <errno.h> /* Error number symbols */
#else /* OS/2 */
#ifdef __WATCOMC__
/*
WatcomC doesn't need errno.h
(definitions conflict with some previous definition
#include <errno.h>
*/
#else
#include <errno.h> /* Error number symbols */
#endif
#endif /* NT */
#endif /* OS2 */
#include <signal.h> /* Everybody needs this */
#ifdef ZILOG /* Zilog has different name for this */
#include <setret.h>
#else
#include <setjmp.h>
#endif /* ZILOG */
#endif /* WINTCP */
#ifdef datageneral /* Data General AOS/VS */
#include <:usr:include:vs_tcp_errno.h>
#include <:usr:include:sys:vs_tcp_types.h>
#ifdef SELECT
/*
NOTE: This can be compiled and linked OK with SELECT defined
but it doesn't work at all. Anybody who cares and knows how
to fix it, feel free.
*/
#include <:usr:include:sys:vs_tcp_time.h>
#endif /* SELECT */
#include <:usr:include:sys:socket.h>
#include <:usr:include:netinet:in.h>
#include <:usr:include:netdb.h>
#endif /* datageneral */
#ifndef socket_errno
#define socket_errno errno
#endif /* socket_errno */
#ifdef TNCODE
extern int tn_deb;
#endif /* TNCODE */
int tcp_rdns = /* Reverse DNS lookup */
#ifdef DEC_TCPIP_OLD
SET_OFF /* Doesn't seem to work in UCX */
#else
SET_AUTO
#endif /* DEC_TCPIP */
;
#ifdef CK_DNS_SRV
int tcp_dns_srv = SET_OFF;
#endif /* CK_DNS_SRV */
_PROTOTYP( char * cmcvtdate, (char *, int) );
#ifdef RLOGCODE
_PROTOTYP( int rlog_ctrl, (CHAR *, int) );
_PROTOTYP( static int rlog_oob, (CHAR *, int) );
#ifndef TCPIPLIB
_PROTOTYP( static SIGTYP rlogoobh, ( int ) );
#endif /* TCPIPLIB */
_PROTOTYP( static int rlog_ini, (CHAR *, int,
struct sockaddr_in *,
struct sockaddr_in *) );
int rlog_mode = RL_COOKED;
int rlog_stopped = 0;
int rlog_inband = 0;
#endif /* RLOGCODE */
#ifndef NOICP
extern int doconx; /* CONNECT-class command active */
#endif /* NOICP */
#ifdef IBMX25
/* This variable should probably be generalised for true client/server
* support - ie: the fd of the listening server, accepted calls should
* be forked or at least handled via a second fd (for IBM's X.25 -
* ttyfd always holds the active fd - ie the server becomes inactive
* as long as a client is connected, and becomes active again when the
* connection is closed)
*/
int x25serverfd = 0; /* extern in ckcnet.h */
int x25seqno = 0; /* Connection sequence number */
int x25lastmsg = -1; /* A cheapskate's state table */
#define X25_CLOSED 0 /* Default state: no connection, no STREAM */
#define X25_SETUP 1 /* X.25 has been set up (no connection) */
#define X25_CONNECTED 2 /* X.25 connection has been established */
int x25_state = X25_CLOSED; /* Default state */
#endif /* IBMX25 */
#ifndef DEBUG
#define deblog 0
#endif /* DEBUG */
#ifdef CK_NAWS /* Negotiate About Window Size */
#ifdef RLOGCODE
_PROTOTYP( int rlog_naws, (void) );
#endif /* RLOGCODE */
#endif /* CK_NAWS */
#ifdef OS2 /* For terminal type name string */
#include "ckuusr.h"
#ifndef NT
#define INCL_DOSSEMAPHORES
#include <os2.h>
#undef COMMENT
#endif /* NT */
#include "ckocon.h"
extern int tt_type, max_tt;
extern struct tt_info_rec tt_info[];
extern char ttname[];
#else
#ifdef CK_AUTHENTICATION
#include "ckuusr.h"
#endif /* CK_AUTHENTICATION */
#endif /* OS2 */
#ifdef NT
extern int winsock_version;
#endif /* NT */
#ifdef CK_AUTHENTICATION
#include "ckuath.h"
#endif /* CK_AUTHENTICATION */
#include "ckcsig.h"
#ifndef OS2 /* For timeout longjumps */
static ckjmpbuf njbuf;
#endif /* OS2 */
#define NAMECPYL 1024 /* Local copy of hostname */
char namecopy[NAMECPYL]; /* Referenced by ckctel.c */
char namecopy2[NAMECPYL]; /* Referenced by ckctel.c */
#ifndef NOHTTP
char http_host_port[NAMECPYL]; /* orig host/port necessary for http */
char http_ip[20] = { '\0' }; /* ip address of host */
char http_port = 0;
int http_ssl = 0;
char * http_agent = 0;
int httpfd = -1; /* socket for http connections */
int http_code = 0;
#define HTTPBUFLEN 1024
char http_reply_str[HTTPBUFLEN] = "";
#endif /* NOHTTP */
char ipaddr[20] = { '\0' }; /* Global copy of IP address */
unsigned long myxipaddr = 0L; /* Ditto as a number */
#endif /* NETCONN */
char *tcp_address = NULL; /* Preferred IP Address */
extern char uidbuf[]; /* User ID buffer */
extern char pwbuf[]; /* Password buffer */
#ifndef NOHTTP
char * tcp_http_proxy = NULL; /* Name[:port] of http proxy server */
int tcp_http_proxy_errno = 0;
char * tcp_http_proxy_user = NULL;
char * tcp_http_proxy_pwd = NULL;
char * tcp_http_proxy_agent = NULL;
#define HTTPCPYL 1024
static char proxycopy[HTTPCPYL];
#endif /* NOHTTP */
#ifdef OS2
extern int tt_rows[], tt_cols[];
extern int tt_status[VNUM];
#else /* OS2 */
extern int tt_rows, tt_cols; /* Everybody has this */
#endif /* OS2 */
extern int cmd_cols, cmd_rows;
#ifdef STREAMING /* Use blocking writes for streaming */
extern int streaming;
#endif /* STREAMING */
#ifdef NT
extern int WSASafeToCancel;
int win95selectbug = 0; /* For TCP/IP stacks whose select() */
/* always fails on write requests such as Cisco and Quarterdeck */
#define stricmp _stricmp
#endif /* NT */
#ifndef NOTCPOPTS
/* Skip all this if NOTCPOPTS specified. */
#ifdef SOL_SOCKET
#ifdef TCP_NODELAY
int tcp_nodelay = 0; /* Nagle algorithm TCP_NODELAY */
#endif /* TCP_NODELAY */
#ifdef SO_DONTROUTE
int tcp_dontroute = 0;
#endif /* SO_DONTROUTE */
#ifdef SO_LINGER
int tcp_linger = 0; /* SO_LINGER */
int tcp_linger_tmo = 0; /* SO_LINGER timeout */
#endif /* SO_LINGER */
#ifdef HPUX /* But the data structures */
#ifndef HPUX8 /* needed for linger are not */
#ifndef HPUX9 /* defined in HP-UX versions */
#ifndef HPUX10 /* prior to 8.00. */
#ifdef SO_LINGER
#undef SO_LINGER
#endif /* SO_LINGER */
#endif /* HPUX10 */
#endif /* HPUX9 */
#endif /* HPUX8 */
#endif /* HPUX */
#ifndef SO_OOBINLINE /* Hopefully only HP-UX 7.0 */
#define SO_OOBINLINE 0x0100
#endif /* SO_OOBINLINE */
#ifndef TCPSNDBUFSIZ
#ifdef VMS
#ifdef __alpha
#define TCPSNDBUFSIZ 16384
#endif /* __alpha */
#endif /* VMS */
#endif /* TCPSNDBUFSIZ */
#ifndef TCPSNDBUFSIZ
#define TCPSNDBUFSIZ -1
#endif /* TCPSNDBUFSIZ */
#ifdef SO_SNDBUF
int tcp_sendbuf = TCPSNDBUFSIZ;
#endif /* SO_SNDBUF */
#ifdef SO_RCVBUF
int tcp_recvbuf = -1;
#endif /* SO_RCVBUF */
#ifdef SO_KEEPALIVE
int tcp_keepalive = 1;
#endif /* SO_KEEPALIVE */
#endif /* SOL_SOCKET */
#endif /* NOTCPOPTS */
#ifndef NETCONN
/*
Network support not defined.
Dummy functions here in case #ifdef's forgotten elsewhere.
*/
int /* Open network connection */
netopen(name, lcl, nett) char *name; int *lcl, nett; {
return(-1);
}
int /* Close network connection */
netclos() {
return(-1);
}
int /* Check network input buffer */
nettchk() {
return(-1);
}
int /* Flush network input buffer */
netflui() {
return(-1);
}
int /* Send network BREAK */
netbreak() {
return(-1);
}
int /* Input character from network */
netinc(timo) int timo; {
return(-1);
}
int /* Output character to network */
#ifdef CK_ANSIC
nettoc(CHAR c)
#else
nettoc(c) CHAR c;
#endif /* CK_ANSIC */
/* nettoc */ {
return(-1);
}
int
nettol(s,n) CHAR *s; int n; {
return(-1);
}
#else /* NETCONN is defined (much of this module...) */
#ifdef NETLEBUF
VOID
le_init() { /* LocalEchoInit() */
int i;
for (i = 0; i < LEBUFSIZ; i++)
le_buf[i] = '\0';
le_start = 0;
le_end = 0;
le_data = 0;
tt_push_inited = 1;
}
VOID
le_clean() { /* LocalEchoCleanup() */
le_init();
return;
}
int
le_inbuf() {
int rc = 0;
if (le_start != le_end) {
rc = (le_end -
le_start +
LEBUFSIZ) % LEBUFSIZ;
}
return(rc);
}
int
#ifdef CK_ANSIC
le_putchar(CHAR ch)
#else
le_putchar(ch) CHAR ch;
#endif /* CK_ANSIC */
/* le_putchar */ {
if ((le_start - le_end + LEBUFSIZ)%LEBUFSIZ == 1) {
debug(F110,"le_putchar","buffer is full",0);
return(-1);
}
le_buf[le_end++] = ch;
if (le_end == LEBUFSIZ)
le_end = 0;
le_data = 1;
return(0);
}
int
#ifdef CK_ANSIC
le_puts(CHAR * s, int n)
#else
le_puts(s,n) CHAR * s; int n;
#endif /* CK_ANSIC */
/* le_puts */ {
int rc = 0;
int i = 0;
CHAR * p = (CHAR *)"le_puts";
ckhexdump(p,s,n);
for (i = 0; i < n; i++)
rc = le_putchar((char)s[i]);
debug(F101,"le_puts","",rc);
return(rc);
}
int
#ifdef CK_ANSIC
le_putstr(CHAR * s)
#else
le_putstr(s) CHAR * s;
#endif /* CK_ANSIC */
/* le_puts */ {
CHAR * p;
int rc = 0;
p = (CHAR *)"le_putstr";
ckhexdump(p,s,(int)strlen((char *)s));
for (p = s; *p && !rc; p++)
rc = le_putchar(*p);
return(rc);
}
int
#ifdef CK_ANSIC
le_getchar(CHAR * pch)
#else /* CK_ANSIC */
le_getchar(pch) CHAR * pch;
#endif /* CK_ANSIC */
/* le_gatchar */ {
int rc = 0;
if (le_start != le_end) {
*pch = le_buf[le_start];
le_buf[le_start] = 0;
le_start++;
if (le_start == LEBUFSIZ)
le_start = 0;
if (le_start == le_end) {
le_data = 0;
}
rc++;
} else {
*pch = 0;
}
return(rc);
}
#endif /* NETLEBUF */
#ifdef VMS
/*
In edit 190, we moved tn_ini() to be called from within netopen().
But tn_ini() calls ttol(), and ttol() checks to see if it's a net
connection, but the flag for that isn't set until after netopen()
is finished. Since, in this module, we are always doing network
output anyway, we just call nettol() directly, instead of going thru
ttol(). Only needed for VMS, since UNIX, AOS/VS, and VOS can handle
net connections just like regular connections in ttol(), and OS/2
has a special routine for this.
*/
#define ttol nettol
#endif /* VMS */
int tcpsrfd = -1;
#ifdef CK_KERBEROS
char * krb5_d_principal = NULL; /* Default principal */
char * krb5_d_instance = NULL; /* Default instance */
char * krb5_d_realm = NULL; /* Default realm */
char * krb5_d_cc = NULL; /* Default credentials cache */
char * krb5_d_srv = NULL; /* Default Service */
int krb5_d_lifetime = 600; /* Default lifetime (10 hours) */
int krb5_d_forwardable = 0; /* creds not forwardable */
int krb5_d_proxiable = 0; /* creds not proxiable */
int krb5_d_renewable = 0; /* creds not renewable (0 min) */
int krb5_autoget = 1; /* Autoget TGTs */
int krb5_autodel = 0; /* Auto delete TGTs */
int krb5_d_getk4 = 0; /* K5 Kinit gets K4 TGTs */
int krb5_checkaddrs = 1; /* Check TGT Addrs */
int krb5_d_no_addresses = 0; /* Do not include IP Addresses */
char * krb5_d_addrs[KRB5_NUM_OF_ADDRS+1]={NULL,NULL}; /* Addrs to include */
int krb5_errno = 0; /* Last K5 errno */
char * krb5_errmsg = NULL; /* Last K5 errmsg */
char * k5_keytab = NULL;
char * krb4_d_principal = NULL; /* Default principal */
char * krb4_d_realm = NULL; /* Default realm */
char * krb4_d_srv = NULL; /* Default Service */
int krb4_d_lifetime = 600; /* Default lifetime (10 hours) */
int krb4_d_preauth = 1; /* Use preauth requests */
char * krb4_d_instance = NULL; /* Default instance */
int krb4_autoget = 1; /* Autoget TGTs */
int krb4_autodel = 0; /* Auto delete TGTs */
int krb4_checkaddrs = 1; /* Check TGT Addrs */
char * k4_keytab = NULL;
int krb4_errno = 0; /* Last K4 errno */
char * krb4_errmsg = NULL; /* Last K4 errmsg */
struct krb_op_data krb_op = { /* Operational data structure */
0, NULL /* (version, cachefile) */
};
struct krb4_init_data krb4_init = { /* Kerberos 4 INIT data structure */
0, NULL, NULL, NULL, NULL
};
struct krb5_init_data krb5_init = { /* Kerberos 5 INIT data structure */
0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0,
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
0
};
struct krb5_list_cred_data krb5_lc = { /* List Credentials data structure */
0, 0, 0
};
int krb_action = -1; /* Kerberos action to perform */
#ifndef CK_AUTHENTICATION
char *
ck_krb4_getrealm() {
return("");
}
char *
ck_krb5_getrealm(cc) char * cc; {
return("");
}
char *
ck_krb4_getprincipal() {
return("");
}
char *
ck_krb5_getprincipal(cc) char * cc; {
return("");
}
#endif /* CK_AUTHENTICATION */
/* I N I _ K E R B -- Initialize Kerberos data */
VOID
ini_kerb() {
int i;
krb_action = -1; /* No action specified */
krb_op.version = 0; /* Kerberos version (none) */
krb_op.cache = NULL; /* Cache file (none) */
/* Kerberos 5 */
krb5_init.forwardable = krb5_d_forwardable; /* Init switch values... */
krb5_init.proxiable = krb5_d_proxiable;
krb5_init.lifetime = krb5_d_lifetime;
krb5_init.renew = 0;
krb5_init.renewable = krb5_d_renewable;
krb5_init.validate = 0;
krb5_init.no_addresses = krb5_d_no_addresses;
krb5_init.getk4 = krb5_d_getk4;
if (krb5_init.postdate) {
free(krb5_init.postdate);
krb5_init.postdate = NULL;
}
if (krb5_init.service) {
free(krb5_init.service);
krb5_init.service = NULL;
}
if (!krb5_d_cc || !krb5_d_cc[0]) { /* Set default cache */
char * p;
p = ck_krb5_get_cc_name();
makestr(&krb5_d_cc,(p && p[0]) ? p : NULL);
}
if (!krb5_d_realm || !krb5_d_realm[0]) { /* Set default realm */
char * p;
p = ck_krb5_getrealm(krb5_d_cc);
makestr(&krb5_d_realm,(p && p[0]) ? p : NULL);
}
makestr(&krb5_init.instance,krb5_d_instance);
makestr(&krb5_init.realm,krb5_d_realm); /* Set realm from default */
if (krb5_init.password) {
memset(krb5_init.password,0xFF,strlen(krb5_init.password));
free(krb5_init.password);
krb5_init.password = NULL;
}
if (!krb5_d_principal) { /* Default principal */
/* a Null principal indicates the user should be prompted */
char * p = ck_krb5_getprincipal(krb5_d_cc);
if (!p || !(*p))
p = (char *)uidbuf; /* Principal = user */
makestr(&krb5_d_principal,(p && p[0]) ? p : NULL);
}
makestr(&krb5_init.principal,krb5_d_principal);
for (i = 0; i <= KRB5_NUM_OF_ADDRS; i++) {
if (krb5_init.addrs[i])
free(krb5_init.addrs[i]);
krb5_init.addrs[i] = NULL;
}
for (i = 0; i <= KRB5_NUM_OF_ADDRS && krb5_d_addrs[i]; i++) {
makestr(&krb5_init.addrs[i],krb5_d_addrs[i]);
}
/* Kerberos 4 */
krb4_init.lifetime = krb4_d_lifetime;
krb4_init.preauth = krb4_d_preauth;
makestr(&krb4_init.instance,krb4_d_instance);
if (!krb4_d_realm || !krb4_d_realm[0]) {/* Set default realm */
char * p;
p = ck_krb4_getrealm();
makestr(&krb4_d_realm,(p && p[0]) ? p : NULL);
}
makestr(&krb4_init.realm,krb4_d_realm);
if (krb4_init.password) {
memset(krb4_init.password,0xFF,strlen(krb4_init.password));
free(krb4_init.password);
krb4_init.password = NULL;
}
if (!krb4_d_principal) { /* Default principal */
/* a Null principal indicates the user should be prompted */
char * p = ck_krb4_getprincipal();
if (!p || !(*p))
p = (char *)uidbuf; /* Principal = user */
makestr(&(krb4_d_principal),(p && p[0]) ? p : NULL);
}
makestr(&(krb4_init.principal),krb4_d_principal);
}
/* D O A U T H -- AUTHENTICATE action routine */
int
doauth(cx) int cx; { /* AUTHENTICATE action routine */
int rc = 0; /* Return code */
#ifdef CK_AUTHENTICATION
#ifdef OS2
if (!ck_security_loaddll()) /* Load various DLLs */
return(rc);
#endif /* OS2 */
if (krb_op.version == 4) { /* Version = 4 */
#ifdef COMMENT
sho_auth(AUTHTYPE_KERBEROS_V4);
#endif /* COMMENT */
if (!ck_krb4_is_installed()) {
printf("?Kerberos 4 is not installed\n");
return(0);
}
switch (krb_action) { /* Perform V4 functions */
case KRB_A_IN: /* INIT */
rc |= !(ck_krb4_initTGT(&krb_op,&krb4_init) < 0);
break;
case KRB_A_DE: /* DESTROY */
rc |= !(ck_krb4_destroy(&krb_op) < 0);
break;
case KRB_A_LC: /* LIST-CREDENTIALS */
rc |= !(ck_krb4_list_creds(&krb_op) < 0);
break;
}
}
if (krb_op.version == 5) { /* V5 functions */
#ifdef COMMENT
sho_auth(AUTHTYPE_KERBEROS_V5);
#endif /* COMMENT */
if (!ck_krb5_is_installed()) {
printf("?Kerberos 5 is not installed\n");
return(0);
}
switch (krb_action) {
case KRB_A_IN: /* INIT */
rc |= !(ck_krb5_initTGT(&krb_op,&krb5_init,
krb5_init.getk4 ? &krb4_init : 0) < 0);
break;
case KRB_A_DE: /* DESTROY */
rc |= !(ck_krb5_destroy(&krb_op) < 0);
break;
case KRB_A_LC: /* LIST-CREDENTIALS */
if (krb_op.version == 0)
printf("\n");
rc |= !(ck_krb5_list_creds(&krb_op,&krb5_lc) < 0);
break;
}
}
#else
#ifndef NOICP
#ifndef NOSHOW
rc = sho_auth(0); /* Show all */
#endif /* NOSHOW */
#endif /* NOICP */
#endif /* CK_AUTHENTICATION */
return(rc);
}
#endif /* CK_KERBEROS */
#ifdef TCPSOCKET
#ifndef OS2
#ifndef NOLISTEN /* For incoming connections */
#ifndef INADDR_ANY
#define INADDR_ANY 0
#endif /* INADDR_ANY */
_PROTOTYP( int ttbufr, ( VOID ) );
_PROTOTYP( int tcpsrv_open, (char *, int *, int, int ) );
static unsigned short tcpsrv_port = 0;
#endif /* NOLISTEN */
#endif /* OS2 */
static char svcbuf[80]; /* TCP service string */
static int svcnum = 0; /* TCP port number */
#endif /* TCPSOCKET */
/*
TCPIPLIB means use separate socket calls for i/o, while on UNIX the
normal file system calls are used for TCP/IP sockets too.
Means "DEC_TCPIP or MULTINET or WINTCP or OS2 or BEBOX" (see ckcnet.h),
*/
#ifdef TCPIPLIB
/* For buffered network reads... */
/*
If the buffering code is written right, it shouldn't matter
how long this buffer is.
*/
#ifdef OS2
#ifdef NT
#define TTIBUFL 64240 /* 44 * 1460 (MSS) */
#else
#define TTIBUFL 32120 /* 22 * 1460 (MSS) */
#endif /* NT */
#else /* OS2 */
#define TTIBUFL 8191 /* Let's use 8K. */
#endif /* OS2 */
CHAR ttibuf[TTIBUFL+1];
/*
select() is used in preference to alarm()/signal(), but different systems
use different forms of select()...
*/
#ifndef NOSELECT /* Option to override BSDSELECT */
#ifdef BELLV10
/*
Note: Although BELLV10 does have TCP/IP support, and does use the unique
form of select() that is evident in this module (and in ckutio.c), it does
not have a sockets library and so we can't build Kermit TCP/IP support for
it. For this, somebody would have to write TCP/IP streams code.
*/
#define BELLSELECT
#ifndef FD_SETSIZE
#define FD_SETSIZE 128
#endif /* FD_SETSIZE */
#else
#ifdef WINTCP /* VMS with Wollongong WIN/TCP */
#ifndef OLD_TWG /* TWG 3.2 has only select(read) */
#define BSDSELECT
#endif /* OLD_TWG */
#else
#ifdef CMU_TCPIP /* LIBCMU can do select */
#define BSDSELECT
#else