forked from KermitProject/ckermit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckuath.c
13443 lines (12252 loc) · 401 KB
/
ckuath.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 *ckathv = "Authentication, 10.0.239, 30 Sep 2022";
/*
C K U A T H . C -- Authentication for C-Kermit
Copyright (C) 1999, 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.
Author: Jeffrey E Altman ([email protected])
Secure Endpoints Inc., New York City
*/
/*
* Additional copyrights included with affected code.
*/
#ifdef HEIMDAL
/*
Turned off User to User support
Turned off KDESTROY support
Turned off KLIST support
Turned off krb5_prompter() support
Turned off ticket validation
Turned off ticket renewal
Turned off alternative cache support in k5_get_ccache()
Remaining link problems:
ckuath.o: In function `ck_krb5_initTGT':
ckuath.o(.text+0x50c2): undefined reference to `krb5_string_to_deltat'
ckuath.o(.text+0x516d): undefined reference to `krb5_string_to_deltat'
ckuath.o(.text+0x51ef): undefined reference to `krb5_string_to_deltat'
*/
#endif /* HEIMDAL */
/*
* Implements Kerberos 4/5, SRP, SSL, NTLM authentication and START_TLS
*/
#include "ckcsym.h"
#include "ckcdeb.h"
#ifdef CK_SECURITY
#define CKUATH_C
#include "ckcker.h"
#include "ckuusr.h"
#include "ckucmd.h" /* For struct keytab */
#include "ckcnet.h"
#include "ckctel.h"
char szUserNameRequested[UIDBUFLEN+1]; /* for incoming connections */
char szUserNameAuthenticated[UIDBUFLEN+1];/* for incoming connections */
char szHostName[UIDBUFLEN+1];
char szUserName[UIDBUFLEN+1];
static char szIP[16];
static int validUser = AUTH_REJECT; /* User starts out invalid */
int authentication_version = AUTHTYPE_NULL;
int accept_complete = 0;
#ifdef CK_AUTHENTICATION
#ifdef CK_SSL
#ifdef KRB5
#define TLS_VERIFY
#endif /* KRB5 */
#endif /* CK_SSL */
#ifdef CK_DES
#ifdef CK_SSL
#ifndef LIBDES
#define LIBDES
#endif /* LIBDES */
#endif /* CK_SSL */
#endif /* CK_DES */
#ifdef CRYPT_DLL
#ifndef LIBDES
#define LIBDES
#endif /* LIBDES */
#endif /* CRYPT_DLL */
#ifdef OS2
#ifdef NT
#include <windows.h>
#else /* NT */
#define INCL_DOSMODULEMGR
#define INCL_DOSSEMAPHORES
#include <os2.h>
#endif /* NT */
#endif /* OS2 */
#ifdef NT
#define KRB5_AUTOCONF__
#ifndef NONTLM
#define NTLM
#endif /* NONTLM */
#endif /* NT */
#ifdef CK_KERBEROS
#define KINIT
#ifndef HEIMDAL
#define KLIST
#define KDESTROY
#endif /* HEIMDAL */
#define CHECKADDRS
#else /* CK_KERBEROS */
#ifdef KRB4
#undef KRB4
#endif /* KRB4 */
#ifdef KRB5
#undef KRB5
#endif /* KRB5 */
#ifdef KRB524
#undef KRB524
#endif /* KRB524 */
#endif /* CK_KERBEROS */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#ifndef OS2
/* Not OS/2 or NT */
#include <errno.h>
#endif /* OS2 */
#ifdef OS2
#include <io.h>
#ifdef NT
/* Win32 gets errno.h */
#include <errno.h>
#else /* NT */
/* OS2 gets errno.h only if we're not compiling with Watcom C as
* the definitions in its errno.h conflict with those in os2.h */
#ifndef __WATCOMC__
#include <errno.h>
#endif /* __WATCOMC__ */
#endif /* NT */
#endif /* OS2 */
#ifdef KRB5
#ifdef HEIMDAL
#ifdef printf
#define saveprintf printf
#undef printf
#endif /* printf */
#include "krb5.h"
#include "com_err.h"
#ifdef saveprintf
#define printf saveprintf
#endif /* saveprintf */
#else /* HEIMDAL */
#include "krb5.h"
#ifdef BETATEST
#include "profile.h"
#endif /* BETATEST */
#include "com_err.h"
#ifdef KRB5_GET_INIT_CREDS_OPT_TKT_LIFE
#define KRB5_HAVE_GET_INIT_CREDS
#else
#define krb5_free_unparsed_name(con,val) krb5_xfree((char *)(val))
#endif
#ifndef KRB5_HAVE_GET_INIT_CREDS
#define krb5_free_data_contents(c,v) krb5_xfree((char *)(v)->data)
#endif
#endif /* HEIMDAL */
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#endif /* KRB5 */
#ifdef KRB4
#define des_cblock Block
#define const_des_cblock const Block
#define des_key_schedule Schedule
#ifdef KRB524
#ifdef NT
#define _WINDOWS
#endif /* NT */
#include "kerberosIV/krb.h"
#ifndef OS2
#ifdef KRB524_CONV
#include "krb524.h"
#endif /* KRB524_CONV */
_PROTOTYP(const char * krb_get_err_text_entry, (int));
#endif /* OS2 */
#else /* KRB524 */
#ifdef SOLARIS
#ifndef sun
/* for some reason the Makefile entries for the Solaris systems have -Usun */
#define sun
#endif /* sun */
#endif /* SOLARIS */
#include "krb.h"
#define krb_get_err_text_entry krb_get_err_text
#endif /* KRB524 */
#else /* KRB4 */
#ifdef CK_SSL
#define des_cblock Block
#ifdef COMMENT
#define const_des_cblock const Block
#endif /* COMMENT */
#define des_key_schedule Schedule
#endif /* CK_SSL */
#endif /* KRB4 */
#include "ckuath.h"
#ifdef CK_KERBEROS
#ifndef KRB5
#define NOBLOCKDEF
#else /* KRB5 */
#ifdef KRB524
#define NOBLOCKDEF
#endif /* KRB524 */
#endif /* KRB5 */
#endif /* CK_KERBEROS */
#include "ckuat2.h"
#ifdef CK_SSL
#ifdef LIBDES
#ifdef OPENSSL_097
#ifdef CK_DES
#define OPENSSL_ENABLE_OLD_DES_SUPPORT
#include <openssl/des.h>
#endif /* CK_DES */
#endif /* OPENSSL_097 */
#ifndef HEADER_DES_H
#define HEADER_DES_H
#endif /* HEADER_DES_H */
#endif /* LIBDES */
#include "ck_ssl.h"
extern int ssl_finished_messages;
#endif /* SSL */
#define PWD_SZ 128
#ifndef LIBDES
#ifdef UNIX
#define des_set_random_generator_seed(x) des_init_random_number_generator(x)
#endif /* UNIX */
#else /* LIBDES */
#define des_fixup_key_parity des_set_odd_parity
#endif /* LIBDES */
#ifdef OS2
#ifdef CK_ENCRYPTION
#define MAP_DES
#endif /* CK_ENCRYPTION */
#ifdef KRB4
#define MAP_KRB4
#endif /* KRB4 */
#ifdef SRPDLL
#define MAP_SRP
#endif /* SRPDLL */
#ifdef KRB5
#define MAP_KRB5
#endif /* KRB5 */
#ifdef CRYPT_DLL
#define MAP_CRYPT
#endif /* CRYPT_DLL */
#define MAP_NTLM
#include "ckoath.h"
#include "ckosyn.h"
#endif /* OS2 */
/*
* Globals
*/
int auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_AUTO, AUTHTYPE_NULL};
int auth_how=0;
int auth_crypt=0;
int auth_fwd=0;
/* These are state completion variables */
static int mutual_complete = 0;
#ifdef KRB4
#ifdef OS2
static LEASH_CREDENTIALS cred;
#else /* OS2 */
static CREDENTIALS cred;
#endif /* OS2 */
static KTEXT_ST k4_auth;
static char k4_name[ANAME_SZ];
static AUTH_DAT k4_adat = { 0 };
static MSG_DAT k4_msg_data;
#ifdef CK_ENCRYPTION
static Block k4_session_key = { 0 };
static Schedule k4_sched;
static Block k4_challenge = { 0 };
#ifdef MIT_CURRENT
static krb5_keyblock k4_krbkey;
#endif /* MIT_CURRENT */
#endif /* ENCRYPTION */
#define KRB4_SERVICE_NAME "rcmd"
_PROTOTYP(static int k4_auth_send,(VOID));
_PROTOTYP(static int k4_auth_reply,(unsigned char *, int));
_PROTOTYP(static int k4_auth_is,(unsigned char *, int));
#endif /* KRB4 */
#ifdef KRB5
static krb5_data k5_auth;
static krb5_auth_context auth_context;
static krb5_keyblock *k5_session_key = NULL;
static krb5_ticket *k5_ticket = NULL;
#ifndef KRB5_SERVICE_NAME
#define KRB5_SERVICE_NAME "host"
#ifdef MACOSX
#define MIT_CURRENT 1
#define decode_krb5_ticket krb5_decode_ticket
#define krb5_read_message ck_krb5_read_message
#define krb5_write_message ck_krb5_write_message
#endif /* MACOSX */
#endif
_PROTOTYP(static int k5_auth_send,(int,int,int));
_PROTOTYP(static int k5_auth_reply,(int, unsigned char *, int));
_PROTOTYP(static int k5_auth_is,(int,unsigned char *, int));
_PROTOTYP(static int SendK5AuthSB,(int, void *, int));
#ifdef TLS_VERIFY
static int krb5_tls_verified = 0;
#endif /* TLS_VERIFY */
#endif /* KRB5 */
#ifdef GSSAPI_KRB5
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_generic.h>
#include <gssapi/gssapi_krb5.h>
static gss_ctx_id_t gcontext;
#define GSS_BUFSIZ 4096
static gss_buffer_desc gss_send_tok, gss_recv_tok, *gss_token_ptr;
static char gss_stbuf[GSS_BUFSIZ];
static gss_name_t gss_target_name;
static struct gss_channel_bindings_struct gss_chan;
_PROTOTYP(static int gssk5_auth_send,(int,int,int));
_PROTOTYP(static int gssk5_auth_reply,(int, unsigned char *, int));
_PROTOTYP(static int gssk5_auth_is,(int,unsigned char *, int));
_PROTOTYP(static int SendGSSK5AuthSB,(int, void *, int));
#endif /* GSSAPI_KRB5 */
#ifdef CK_SRP
#ifdef PRE_SRP_1_7_3
_PROTOTYP(static int srp_reply,(int, unsigned char *, int));
_PROTOTYP(static int srp_is,(int, unsigned char *, int));
#else /* PRE_SRP_1_7_3 */
_PROTOTYP(static int new_srp_reply,(int, unsigned char *, int));
_PROTOTYP(static int new_srp_is,(int, unsigned char *, int));
#endif /* PRE_SRP_1_7_3 */
#endif /* SRP */
#ifdef CK_ENCRYPTION
int encrypt_flag = 1;
#endif
#ifdef FORWARD
int forward_flag = 0; /* forward tickets? */
int forwardable_flag = 1; /* get forwardable tickets to forward? */
int forwarded_tickets = 0; /* were tickets forwarded? */
#endif
static unsigned char str_data[4096] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
AUTHTYPE_KERBEROS_V5, };
#define AUTHTMPBL 2048
static char strTmp[AUTHTMPBL+1];
static char szLocalHostName[UIDBUFLEN+1];
static kstream g_kstream=NULL;
#ifdef KRB5
krb5_context k5_context=NULL;
static krb5_creds * ret_cred=NULL;
static krb5_context telnet_context=NULL;
static char * telnet_krb5_realm = NULL;
static krb5_principal fwd_server = NULL;
#endif /* KRB5 */
#ifdef CK_SRP
#ifdef PRE_SRP_1_4_4
#ifndef PRE_SRP_1_4_5
#define PRE_SRP_1_4_5
#endif /* PRE_SRP_1_4_5 */
#endif /* PRE_SRP_1_4_5 */
#ifdef PRE_SRP_1_4_5
#ifndef PRE_SRP_1_7_3
#define PRE_SRP_1_7_3
#endif /* PRE_SRP_1_7_3 */
#endif /* PRE_SRP_1_4_5 */
#include <t_pwd.h>
#include <t_client.h>
#include <t_server.h>
static struct t_server * ts = NULL;
static struct t_client * tc = NULL;
#ifdef PRE_SRP_1_4_4
static struct t_pw * tpw = NULL;
static struct t_conf * tconf = NULL;
#endif /* PRE_SRP_1_4_4 */
#ifndef PRE_SRP_1_7_3
#ifndef STDC_HEADERS
#define STDC_HEADERS 1
#endif /* STDC_HEADERS */
#include <srp.h>
static SRP * s_srp = NULL;
static cstr * s_key = NULL;
static SRP * c_srp = NULL;
static cstr * c_key = NULL;
#endif /* PRE_SRP_1_7_3 */
static int srp_waitresp = 0; /* Flag to indicate readiness for response */
static char srp_passwd[PWD_SZ];
#endif /* CK_SRP */
#ifdef CK_KERBEROS
#ifdef RLOGCODE
#define OPTS_FORWARD_CREDS 0x00000020
#define OPTS_FORWARDABLE_CREDS 0x00000010
#define KCMD_KEYUSAGE 1026
#define RLOG_BUFSIZ 5120
static int rlog_encrypt = 0;
char des_inbuf[2*RLOG_BUFSIZ]; /* needs to be > largest read size */
char des_outpkt[2*RLOG_BUFSIZ+4]; /* needs to be > largest write size */
#ifdef KRB5
krb5_data desinbuf,desoutbuf;
static krb5_data encivec_i[2], encivec_o[2];
enum krb5_kcmd_proto {
/* Old protocol: DES encryption only. No subkeys. No protection
for cleartext length. No ivec supplied. OOB hacks used for
rlogin. Checksum may be omitted at connection startup. */
KCMD_OLD_PROTOCOL = 1,
/* New protocol: Any encryption scheme. Client-generated subkey
required. Prepend cleartext-length to cleartext data (but don't
include it in count). Starting ivec defined, chained. In-band
signalling. Checksum required. */
KCMD_NEW_PROTOCOL,
/* Hack: Get credentials, and use the old protocol iff the session
key type is single-DES. */
KCMD_PROTOCOL_COMPAT_HACK,
KCMD_UNKNOWN_PROTOCOL
};
enum krb5_kcmd_proto krb5_rlog_ver = KCMD_PROTOCOL_COMPAT_HACK;
#endif /* KRB5 */
#endif /* RLOGCODE */
static char storage[65536]; /* storage for the decryption */
static int nstored = 0;
static char *store_ptr = storage;
extern char * krb5_d_principal; /* Default principal */
extern char * krb5_d_instance; /* Default instance */
extern char * krb5_d_realm; /* Default realm */
extern char * krb5_d_cc; /* Default credentials cache */
extern char * krb5_d_srv; /* Default service name */
extern int krb5_d_lifetime; /* Default lifetime */
extern int krb5_d_forwardable;
extern int krb5_d_proxiable;
extern int krb5_d_renewable;
extern int krb5_autoget;
extern int krb5_checkaddrs;
extern int krb5_d_getk4;
extern int krb5_d_no_addresses;
extern char * k5_keytab;
extern int krb5_errno;
extern char * krb5_errmsg;
extern char * krb4_d_principal; /* Default principal */
extern char * krb4_d_realm; /* Default realm */
extern char * krb4_d_srv; /* Default service name */
extern int krb4_d_lifetime; /* Default lifetime */
extern int krb4_d_preauth;
extern char * krb4_d_instance;
extern int krb4_autoget;
extern int krb4_checkaddrs;
extern char * k4_keytab;
extern int krb4_errno;
extern char * krb4_errmsg;
#endif /* CK_KERBEROS */
extern char tn_msg[], hexbuf[]; /* from ckcnet.c */
extern CHAR pwbuf[];
extern int pwflg, pwcrypt;
extern int deblog, debses, tn_deb;
extern int sstelnet, inserver;
#ifdef CK_LOGIN
extern int ckxanon;
#endif /* CK_LOGIN */
extern int tn_auth_how;
extern int tn_auth_enc;
#ifdef CK_ENCRYPTION
extern int cx_type;
#endif /* CK_ENCRYPTION */
extern int quiet, ttyfd, ttnproto;
int
ck_gssapi_is_installed()
{
#ifdef KRB5
#ifdef OS2
return(hGSSAPI != NULL);
#else /* OS2 */
return(1);
#endif /* OS2 */
#else /* KRB5 */
return(0);
#endif /* KRB5 */
}
int
ck_krb5_is_installed()
{
#ifdef KRB5
#ifdef OS2
return(hKRB5_32 != NULL);
#else /* OS2 */
return(1);
#endif /* OS2 */
#else /* KRB5 */
return(0);
#endif /* KRB5 */
}
int
ck_krb5_is_installed_as_server()
{
#ifdef KRB5
#ifdef HEIMDAL
krb5_error_code ret;
krb5_keytab kt;
krb5_kt_cursor cursor;
ret = krb5_kt_default(k5_context, &kt);
if ( ret ) {
krb5_kt_close(k5_context, kt);
return(0);
} else {
krb5_kt_end_seq_get(k5_context, kt, &cursor);
krb5_kt_close(k5_context, kt);
return(1);
}
#else /* HEIMDAL */
#ifndef COMMENT
char ktname[CKMAXPATH]="";
if ( k5_keytab ) {
ckstrncpy(ktname,k5_keytab,CKMAXPATH);
} else {
krb5_error_code code;
if ( k5_context == NULL)
if (krb5_init_context(&k5_context))
return(0);
code = krb5_kt_default_name(k5_context,ktname,CKMAXPATH);
debug(F101,"krb5_kt_default_name","",code);
if ( code ) {
/* We can't check the existence of the file since we can't */
/* determine the file name. So we return TRUE and let */
/* Krb5 be offered to the user even though it may fail later */
return(1);
}
}
if ( !strncmp("FILE:",ktname,5) ) {
if ( zchki(&ktname[5]) > 0 )
return(1);
else
return(0);
} else {
if (ktname[0])
return(1);
else
return(0);
}
#else /* COMMENT */
krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
krb5_context krb5context = NULL;
krb5_ccache krb5ccdef = NULL;
krb5_creds krb5creds, *krb5credsp = NULL;
int rc = 0;
if ( !ck_krb5_is_installed() )
return(0);
memset((char *)&krb5creds, 0, sizeof(krb5creds));
if ((krb5rc = krb5_init_context(&krb5context)) != 0)
goto err;
if ((krb5rc = krb5_sname_to_principal(krb5context,
szHostName,
krb5_d_srv ?
krb5_d_srv :
KRB5_SERVICE_NAME,
KRB5_NT_SRV_HST,
&krb5creds.server)) != 0)
goto err;
if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
goto err;
if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
&krb5creds.client)) != 0)
goto err;
if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
&krb5creds, &krb5credsp)) != 0)
goto err;
rc = 1;
err:
if (krb5creds.client)
krb5_free_principal(krb5context, krb5creds.client);
if (krb5creds.server)
krb5_free_principal(krb5context, krb5creds.server);
if (krb5context)
krb5_free_context(krb5context);
return(rc);
#endif /* COMMENT */
#endif /* HEIMDAL */
#else /* KRB5 */
return(0);
#endif /* KRB5 */
}
int
ck_krb4_is_installed()
{
#ifdef KRB4
#ifdef OS2
return(hKRB4_32 != NULL);
#else /* OS2 */
return(1);
#endif /* OS2 */
#else /* KRB4 */
return(0);
#endif /* KRB4 */
}
int
ck_krb4_is_installed_as_server()
{
if ( !ck_krb4_is_installed() )
return(0);
#ifdef KRB4
if ( !k4_keytab ) {
#ifdef NT
char name[CKMAXPATH]="";
DWORD len = CKMAXPATH;
len = GetWindowsDirectory(name,len);
if ( len > 0 )
ckstrncat(name,"/srvtab",CKMAXPATH);
if ( name[0] )
makestr(&k4_keytab,name);
#else /* NT */
makestr(&k4_keytab,"/etc/srvtab");
#endif /* NT */
}
if ( !k4_keytab )
return(0);
if ( zchki(k4_keytab) > 0 )
return(1);
#ifdef KRB524
else if (ck_krb5_is_installed_as_server())
return(1);
#endif /* KRB524 */
else
return(0);
#endif /* KRB4 */
}
int
ck_srp_is_installed_as_server()
{
#ifdef CK_SRP
#ifdef SRPDLL
if ( hSRP == NULL )
return(0);
#endif /* SRPDLL */
#ifdef COMMENT
/* This is the new API as of 1.7.4. However, all it does
is allocate a data structure. It can never fail.
*/
{
SRP * s_srp = SRP_new(SRP_RFC2945_server_method());
if ( s_srp ) {
SRP_free(s_srp);
s_srp = NULL;
return(1);
}
return(0);
}
#else /* COMMENT */
{
struct t_pw * tpw = NULL;
struct t_conf * tconf = NULL;
if((tconf = t_openconf(NULL)) == NULL)
return(0);
if((tpw = t_openpw(NULL)) == NULL) {
t_closeconf(tconf);
return(0);
}
t_closeconf(tconf);
t_closepw(tpw);
return(1);
}
#endif /* COMMENT */
#else /* SRP */
return(0);
#endif /* SRP */
}
int
ck_srp_is_installed()
{
#ifdef CK_SRP
#ifdef SRPDLL
if ( hSRP == NULL )
return(0);
#endif /* SRPDLL */
return(1);
#else /* CK_SRP */
return(0);
#endif /* CK_SRP */
}
int
ck_krypto_is_installed()
{
#ifdef CK_SRP
#ifdef OS2
if ( hLIBKRYPTO == NULL )
return(0);
#endif /* OS2 */
return(1);
#else /* CK_SRP */
return(0);
#endif /* CK_SRP */
}
int
ck_crypt_is_installed()
{
#ifdef CK_ENCRYPTION
#ifdef CRYPT_DLL
return(hCRYPT != NULL);
#else /* CRYPT_DLL */
return(1);
#endif /* CRYPT_DLL */
#else /* ENCRYPTION */
return(0);
#endif /* ENCRYPTION */
}
int
ck_ntlm_is_installed()
{
#ifdef NT
#ifndef NTLM
return(0);
#else
return(hSSPI != NULL);
#endif
#else /* NT */
return(0);
#endif /* NT */
}
int
ck_tn_auth_valid()
{
return(validUser);
}
/* C K _ K R B _ A U T H _ I N _ P R O G R E S S
*
* Is an authentication negotiation still in progress?
*
*/
int
#ifdef CK_ANSIC
ck_tn_auth_in_progress(void)
#else
ck_tn_auth_in_progress()
#endif
{
switch (authentication_version) {
case AUTHTYPE_AUTO:
return(1);
case AUTHTYPE_NULL:
return(0);
#ifdef KRB4
case AUTHTYPE_KERBEROS_V4:
if (!accept_complete) {
debug(F100,"ck_auth_in_progress() Kerberos 4 !accept_complete",
"",0);
return(1);
}
else if ((auth_how & AUTH_HOW_MASK) && !mutual_complete) {
debug(F100,"ck_auth_in_progress() Kerberos 4 !mutual_complete",
"",0);
return(1);
}
else
return(0);
#endif /* KRB4 */
#ifdef KRB5
case AUTHTYPE_KERBEROS_V5:
if (!accept_complete) {
debug(F100,"ck_auth_in_progress() Kerberos 5 !accept_complete",
"",0);
return(1);
}
else if ((auth_how & AUTH_HOW_MASK) && !mutual_complete) {
debug(F100,"ck_auth_in_progress() Kerberos 5 !mutual_complete",
"",0);
return(1);
}
else
return(0);
#ifdef GSSAPI_K5
case AUTHTYPE_GSSAPI_KRB5:
if (!accept_complete) {
debug(F100,
"ck_auth_in_progress() GSSAPI Kerberos 5 !accept_complete",
"",
0
);
return(1);
}
else if ((auth_how & AUTH_HOW_MASK) && !mutual_complete) {
debug(F100,
"ck_auth_in_progress() GSSAPI Kerberos 5 !mutual_complete",
"",
0
);
return(1);
} else
return(0);
break;
#endif /* GSSAPI_K5 */
#endif /* KRB5 */
#ifdef CK_SRP
case AUTHTYPE_SRP:
if (!accept_complete || srp_waitresp)
return(1);
else
return(0);
#endif /* CK_SRP */
#ifdef NTLM
case AUTHTYPE_NTLM:
if (!accept_complete) {
debug(F100,"ck_auth_in_progress() NTLM !accept_complete",
"",0);
return(1);
}
else
return(0);
#endif /* NTLM */
case AUTHTYPE_SSL:
if (!accept_complete) {
debug(F100,"ck_auth_in_progress() SSL !accept_complete",
"",0);
return(1);
}
else
return(0);
default:
return(0);
}
return(0);
}
/* C K _ K R B _ T N _ A U T H _ R E Q U E S T
*
* Builds a Telnet Authentication Send Negotiation providing the
* list of supported authentication methods. To be used only
* when accepting incoming connections as only the server (DO) side of the
* Telnet negotiation is allowed to send an AUTH SEND.
*
* Returns: 0 on success and -1 on failure
*/
static unsigned char str_request[64] = { IAC, SB,
TELOPT_AUTHENTICATION,
TELQUAL_SEND };
#ifdef GSSAPI_K5
static int
ck_tn_auth_request_gsskrb5(int i)
{
if (ck_gssapi_is_installed() && ck_krb5_is_installed_as_server()) {
if ( (tn_auth_how == TN_AUTH_HOW_ANY ||
tn_auth_how == TN_AUTH_HOW_MUTUAL) &&
(tn_auth_enc == TN_AUTH_ENC_ANY ||
tn_auth_enc == TN_AUTH_ENC_EXCH) ) {
str_request[i++] = AUTHTYPE_KERBEROS_V5;
str_request[i] = AUTH_CLIENT_TO_SERVER | AUTH_HOW_MUTUAL;
str_request[i] |= AUTH_ENCRYPT_AFTER_EXCHANGE;
if ( deblog || tn_deb || debses )
ckstrncat(tn_msg,
"KERBEROS_V5 CLIENT_TO_SERVER|MUTUAL|ENCRYPT_AFTER_EXCHANGE ",
TN_MSG_LEN);
i++;
}
}
}
#endif /* GSSAPI_K5 */
#ifdef KRB5
static int
ck_tn_auth_request_krb5(int i)
{
if (ck_krb5_is_installed_as_server()) {
#ifdef CK_SSL
if ( ck_ssleay_is_installed() &&
(tls_active_flag || ssl_active_flag) &&
ssl_finished_messages )
{
#ifdef USE_INI_CRED_FWD
if ( forward_flag &&
(tn_auth_how == TN_AUTH_HOW_ANY ||
tn_auth_how == TN_AUTH_HOW_MUTUAL) &&
(tn_auth_enc == TN_AUTH_ENC_ANY ||
tn_auth_enc == TN_AUTH_ENC_TELOPT)
)
{
str_request[i++] = AUTHTYPE_KERBEROS_V5;
str_request[i] = AUTH_CLIENT_TO_SERVER | AUTH_HOW_MUTUAL;
str_request[i] |= AUTH_ENCRYPT_START_TLS;
str_request[i] |= INI_CRED_FWD_ON;
if ( deblog || tn_deb || debses )
ckstrncat(tn_msg,
"KERBEROS_V5 CLIENT_TO_SERVER|MUTUAL|ENCRYPT_START_TLS|INI_CRED_FWD_ON ",
TN_MSG_LEN);
i++;
}
#endif /* USE_INI_CRED_FWD */
if ( (tn_auth_how == TN_AUTH_HOW_ANY ||
tn_auth_how == TN_AUTH_HOW_MUTUAL) &&
(tn_auth_enc == TN_AUTH_ENC_ANY ||
tn_auth_enc == TN_AUTH_ENC_TELOPT) ) {
str_request[i++] = AUTHTYPE_KERBEROS_V5;
str_request[i] = AUTH_CLIENT_TO_SERVER | AUTH_HOW_MUTUAL;
str_request[i] |= AUTH_ENCRYPT_START_TLS;
if ( deblog || tn_deb || debses )
ckstrncat(tn_msg,
"KERBEROS_V5 CLIENT_TO_SERVER|MUTUAL|ENCRYPT_START_TLS ",
TN_MSG_LEN);
i++;
}
if ( tn_auth_how == TN_AUTH_HOW_ANY ||
tn_auth_how == TN_AUTH_HOW_ONE_WAY ) {
str_request[i++] = AUTHTYPE_KERBEROS_V5;
str_request[i] = AUTH_CLIENT_TO_SERVER | AUTH_HOW_ONE_WAY;
str_request[i] |= AUTH_ENCRYPT_START_TLS;
if ( deblog || tn_deb || debses )
ckstrncat(tn_msg,
"KERBEROS_V5 CLIENT_TO_SERVER|ONE_WAY|ENCRYPT_START_TLS ",
TN_MSG_LEN);
i++;
}
}
#ifdef CK_ENCRYPTION
else
{
#endif /* CK_ENCRYPTION */
#endif /* CK_SSL */
#ifdef CK_ENCRYPTION
#ifdef USE_INI_CRED_FWD
if ( forward_flag &&
TELOPT_ME_MODE(TELOPT_ENCRYPTION) != TN_NG_RF &&
TELOPT_U_MODE(TELOPT_ENCRYPTION) != TN_NG_RF &&
(tn_auth_how == TN_AUTH_HOW_ANY ||
tn_auth_how == TN_AUTH_HOW_MUTUAL) &&
(tn_auth_enc == TN_AUTH_ENC_ANY ||
tn_auth_enc == TN_AUTH_ENC_TELOPT)
)
{
str_request[i++] = AUTHTYPE_KERBEROS_V5;
str_request[i] = AUTH_CLIENT_TO_SERVER | AUTH_HOW_MUTUAL;
str_request[i] |= AUTH_ENCRYPT_USING_TELOPT;
str_request[i] |= INI_CRED_FWD_ON;
if ( deblog || tn_deb || debses )