-
Notifications
You must be signed in to change notification settings - Fork 4
/
kll.c
1292 lines (1006 loc) · 31.2 KB
/
kll.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
/*
* $Header$
*
* Copyright 2006 Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
#include <Security/Authorization.h>
#include <CoreFoundation/CoreFoundation.h>
#include <string.h>
#include <syslog.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>
#include <stdio.h>
#include <dispatch/dispatch.h>
#include "heim.h"
#include "mit-KerberosLogin.h"
#include "mit-CredentialsCache.h"
struct KLLoginOptions {
krb5_get_init_creds_opt *opt;
char *service;
};
krb5_context milcontext;
void
mshim_init_context(void)
{
static dispatch_once_t once = 0;
dispatch_once(&once, ^{
heim_krb5_init_context(&milcontext);
});
}
/*
* Deprecated Error codes
*/
enum {
/* Carbon Dialog errors */
klDialogDoesNotExistErr = 19676,
klDialogAlreadyExistsErr,
klNotInForegroundErr,
klNoAppearanceErr,
klFatalDialogErr,
klCarbonUnavailableErr
};
krb5_get_init_creds_opt *__KLLoginOptionsGetKerberos5Options (KLLoginOptions ioOptions);
KLTime __KLLoginOptionsGetStartTime (KLLoginOptions ioOptions);
char *__KLLoginOptionsGetServiceName (KLLoginOptions ioOptions);
KLStatus
KLAcquireTickets (KLPrincipal inPrincipal,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
LOG_ENTRY();
return KLAcquireInitialTickets (inPrincipal,
NULL,
outPrincipal,
outCredCacheName);
}
KLStatus
KLAcquireNewTickets (KLPrincipal inPrincipal,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
LOG_ENTRY();
return KLAcquireNewInitialTickets (inPrincipal,
NULL,
outPrincipal,
outCredCacheName);
}
KLStatus
KLAcquireTicketsWithPassword (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inPassword,
char **outCredCacheName)
{
LOG_ENTRY();
return KLAcquireInitialTicketsWithPassword (inPrincipal,
inLoginOptions,
inPassword,
outCredCacheName);
}
KLStatus
KLAcquireNewTicketsWithPassword (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inPassword,
char **outCredCacheName)
{
LOG_ENTRY();
return KLAcquireNewInitialTicketsWithPassword (inPrincipal,
inLoginOptions,
inPassword,
outCredCacheName);
}
KLStatus
KLSetApplicationOptions (const void *inAppOptions)
{
return klNoErr;
}
KLStatus
KLGetApplicationOptions (void *outAppOptions)
{
return klDialogDoesNotExistErr;
}
#define kCoreAuthPanelKerberosRight "com.apple.KerberosAgent"
#define kCoreAuthPanelKerberosPrincipal "principal"
#define kCoreAuthPanelKerberosTargetUserID "targetUserID"
#define kCoreAuthPanelKerberosOptions "kerberosOptions"
static OSStatus
acquireticket_ui(KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
AuthorizationRef auth;
char userID[10];
OSStatus ret;
char *princ = NULL;
CFDataRef d = NULL;
LOG_ENTRY();
snprintf(userID, sizeof(userID), "%ld", (unsigned long)geteuid());
mshim_init_context();
if (outPrincipal)
*outPrincipal = NULL;
if (outCredCacheName)
*outCredCacheName = NULL;
if (inPrincipal) {
ret = heim_krb5_unparse_name(milcontext, inPrincipal, &princ);
if (ret)
return ret;
}
ret = AuthorizationCreate(NULL, NULL, kAuthorizationFlagDefaults, &auth);
if (ret) {
free(princ);
return ret;
}
AuthorizationItem rightItems[1] = { kCoreAuthPanelKerberosRight, 0, NULL, 0 };
AuthorizationRights rights = { sizeof(rightItems[0])/sizeof(rightItems) , rightItems };
AuthorizationItem envItems[3];
AuthorizationEnvironment env = { 0 , envItems };
AuthorizationFlags authFlags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
envItems[env.count].name = kCoreAuthPanelKerberosTargetUserID;
envItems[env.count].valueLength = strlen(userID);
envItems[env.count].value = userID;
envItems[env.count].flags = 0;
env.count++;
if (princ) {
envItems[env.count].name = kCoreAuthPanelKerberosPrincipal;
envItems[env.count].valueLength = strlen(princ);
envItems[env.count].value = princ;
envItems[env.count].flags = 0;
env.count++;
}
if (inLoginOptions && inLoginOptions->opt) {
CFMutableDictionaryRef dict;
dict = CFDictionaryCreateMutable(NULL, 1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (dict == NULL)
goto out;
if (inLoginOptions->opt->renew_life) {
CFStringRef t;
t = CFStringCreateWithFormat(NULL, 0, CFSTR("%ld"),(long)inLoginOptions->opt->renew_life);
CFDictionarySetValue(dict, CFSTR("renewTime"), t);
}
d = CFPropertyListCreateData(NULL, dict, kCFPropertyListBinaryFormat_v1_0,
0, NULL);
CFRelease(dict);
envItems[env.count].name = kCoreAuthPanelKerberosOptions;
envItems[env.count].valueLength = CFDataGetLength(d);
envItems[env.count].value = (void *)CFDataGetBytePtr(d);
envItems[env.count].flags = 0;
env.count++;
}
ret = AuthorizationCopyRights(auth, &rights, &env, authFlags, NULL);
if (ret == 0 && outPrincipal) {
AuthorizationItemSet *info;
UInt32 i;
ret = AuthorizationCopyInfo(auth, NULL, &info);
if (ret)
goto out;
for(i = 0; i < info->count; i++) {
if (strcmp(info->items[i].name, "out-principal") == 0) {
char *str;
asprintf(&str, "%.s*", (int)info->items[i].valueLength, info->items[i].value);
heim_krb5_parse_name(milcontext, str, outPrincipal);
} else if (strcmp(info->items[i].name, "out-cache-name") == 0) {
asprintf(outCredCacheName, "%.s*", (int)info->items[i].valueLength, info->items[i].value);
}
}
AuthorizationFreeItemSet(info);
if (*outPrincipal == NULL)
ret = EINVAL;
}
out:
if (d)
CFRelease(d);
AuthorizationFree(auth, kAuthorizationFlagDestroyRights);
free(princ);
return ret;
}
KLStatus
KLAcquireInitialTickets(KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
KLBoolean ValidTickets;
KLStatus ret;
LOG_ENTRY();
ret = KLCacheHasValidTickets(inPrincipal,
kerberosVersion_V5,
&ValidTickets,
outPrincipal,
outCredCacheName);
if (ret || !ValidTickets)
ret = acquireticket_ui(inPrincipal, inLoginOptions, outPrincipal, outCredCacheName);
return ret;
}
KLStatus
KLAcquireNewInitialTickets (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
LOG_ENTRY();
return acquireticket_ui(inPrincipal, inLoginOptions, outPrincipal, outCredCacheName);
}
KLStatus
KLDestroyTickets(KLPrincipal inPrincipal)
{
krb5_error_code ret;
krb5_ccache id;
mshim_init_context();
ret = heim_krb5_cc_cache_match(milcontext, inPrincipal, &id);
if (ret)
return ret;
return krb5_cc_destroy((mit_krb5_context)milcontext, (mit_krb5_ccache)id);
}
KLStatus KLChangePassword (KLPrincipal inPrincipal)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
KLStatus
KLAcquireInitialTicketsWithPassword(KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inPassword,
char **outCredCacheName)
{
KLStatus ret;
KLBoolean ValidTickets;
ret = KLCacheHasValidTickets(inPrincipal,
kerberosVersion_V5,
&ValidTickets,
NULL,
outCredCacheName);
if (ret == 0) {
if (ValidTickets)
return klNoErr; /* done */
/* get credential */
if (outCredCacheName)
free(*outCredCacheName);
}
return KLAcquireNewInitialTicketsWithPassword(inPrincipal,
inLoginOptions,
inPassword,
outCredCacheName);
}
KLStatus
KLAcquireNewInitialTicketsWithPassword(KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inPassword,
char **outCredCacheName)
{
krb5_error_code ret;
krb5_ccache cache;
krb5_creds creds;
char *service = NULL;
krb5_get_init_creds_opt *opt = NULL;
LOG_ENTRY();
mshim_init_context();
if (inLoginOptions) {
service = inLoginOptions->service;
opt = inLoginOptions->opt;
}
ret = heim_krb5_get_init_creds_password(milcontext, &creds,
inPrincipal, inPassword,
NULL, NULL, 0,
service,
opt);
if (ret)
return ret;
ret = heim_krb5_cc_cache_match(milcontext, inPrincipal, &cache);
if (ret)
ret = heim_krb5_cc_new_unique(milcontext, NULL, NULL, &cache);
if (ret)
goto out;
ret = heim_krb5_cc_initialize(milcontext, cache, creds.client);
if(ret)
goto out;
ret = heim_krb5_cc_store_cred(milcontext, cache, &creds);
if (ret)
goto out;
if (outCredCacheName)
*outCredCacheName = strdup(heim_krb5_cc_get_name(milcontext, cache));
out:
if (cache) {
if (ret)
krb5_cc_destroy((mit_krb5_context)milcontext, (mit_krb5_ccache)cache);
else
heim_krb5_cc_close(milcontext, cache);
}
heim_krb5_free_cred_contents(milcontext, &creds);
return ret;
}
KLStatus KLAcquireNewInitialTicketCredentialsWithPassword (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inPassword,
void *inV5Context,
KLBoolean *outGotV4Credentials,
KLBoolean *outGotV5Credentials,
void *outV4Credentials,
void *outV5Credentials)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
KLStatus KLStoreNewInitialTicketCredentials (KLPrincipal inPrincipal,
void *inV5Context,
void *inV4Credentials,
void *inV5Credentials,
char **outCredCacheName)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
KLStatus KLVerifyInitialTickets (KLPrincipal inPrincipal,
KLBoolean inFailIfNoHostKey,
char **outCredCacheName)
{
LOG_UNIMPLEMENTED();
return klNoErr;
}
KLStatus KLVerifyInitialTicketCredentials (void *inV4Credentials,
void *inV5Credentials,
KLBoolean inFailIfNoHostKey)
{
LOG_UNIMPLEMENTED();
return klNoErr;
}
KLStatus KLAcquireNewInitialTicketsWithKeytab (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
const char *inKeytabName,
char **outCredCacheName)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
KLStatus
KLRenewInitialTickets(KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
krb5_error_code ret;
krb5_creds in, *cred = NULL;
krb5_ccache id;
krb5_kdc_flags flags;
krb5_const_realm realm;
memset(&in, 0, sizeof(in));
LOG_ENTRY();
mshim_init_context();
if (outPrincipal)
*outPrincipal = NULL;
if (outCredCacheName)
*outCredCacheName = NULL;
ret = heim_krb5_cc_cache_match(milcontext, inPrincipal, &id);
if (ret)
return ret; /* XXX */
in.client = inPrincipal;
realm = heim_krb5_principal_get_realm(milcontext, in.client);
if (inLoginOptions && inLoginOptions->service)
ret = heim_krb5_make_principal(milcontext, &in.server, realm, inLoginOptions->service, NULL);
else
ret = heim_krb5_make_principal(milcontext, &in.server, realm, KRB5_TGS_NAME, realm, NULL);
if (ret) {
heim_krb5_cc_close(milcontext, id);
return ret;
}
flags.i = 0;
if (inLoginOptions)
flags.i = inLoginOptions->opt->flags;
/* Pull out renewable from previous ticket */
ret = heim_krb5_get_credentials(milcontext, KRB5_GC_CACHED, id, &in, &cred);
if (ret == 0 && cred) {
flags.b.renewable = cred->flags.b.renewable;
heim_krb5_free_creds (milcontext, cred);
cred = NULL;
}
flags.b.renew = 1;
ret = heim_krb5_get_kdc_cred(milcontext, id, flags, NULL, NULL, &in, &cred);
heim_krb5_free_principal(milcontext, in.server);
if (ret)
goto out;
ret = heim_krb5_cc_initialize(milcontext, id, in.client);
if (ret)
goto out;
ret = heim_krb5_cc_store_cred(milcontext, id, cred);
out:
if (cred)
heim_krb5_free_creds (milcontext, cred);
heim_krb5_cc_close(milcontext, id);
return ret;
}
KLStatus KLValidateInitialTickets (KLPrincipal inPrincipal,
KLLoginOptions inLoginOptions,
char **outCredCacheName)
{
LOG_UNIMPLEMENTED();
return klNoErr;
}
static krb5_timestamp g_cc_change_time = 0;
static KLTime g_kl_change_time = 0;
static pthread_mutex_t g_change_time_mutex = PTHREAD_MUTEX_INITIALIZER;
KLStatus
KLLastChangedTime(KLTime *outLastChangedTime)
{
krb5_timestamp ccChangeTime;
KLStatus ret;
LOG_ENTRY();
mshim_init_context();
if (outLastChangedTime == NULL)
return klParameterErr;
ret = heim_krb5_cccol_last_change_time(milcontext, "API", &ccChangeTime);
if (ret)
return ret;
pthread_mutex_lock(&g_change_time_mutex);
if (g_kl_change_time == 0)
g_kl_change_time = ccChangeTime;
if (ccChangeTime > g_cc_change_time) {
if (ccChangeTime > g_kl_change_time)
g_kl_change_time = ccChangeTime;
else
g_kl_change_time++;
g_cc_change_time = ccChangeTime;
}
*outLastChangedTime = g_kl_change_time;
pthread_mutex_unlock (&g_change_time_mutex);
return klNoErr;
}
static krb5_error_code
fetch_creds(KLPrincipal inPrincipal, krb5_creds **ocreds,
char **outCredCacheName)
{
krb5_principal princ = NULL;
krb5_creds in_creds;
krb5_const_realm realm;
krb5_error_code ret;
krb5_ccache id = NULL;
LOG_ENTRY();
mshim_init_context();
memset(&in_creds, 0, sizeof(in_creds));
if (inPrincipal) {
ret = heim_krb5_cc_cache_match(milcontext, inPrincipal, &id);
} else {
ret = heim_krb5_cc_default(milcontext, &id);
if (ret == 0)
ret = heim_krb5_cc_get_principal(milcontext, id, &princ);
inPrincipal = princ;
}
if (ret)
goto out;
realm = heim_krb5_principal_get_realm(milcontext, inPrincipal);
ret = heim_krb5_make_principal(milcontext, &in_creds.server, realm, KRB5_TGS_NAME, realm, NULL);
if (ret)
goto out;
in_creds.client = inPrincipal;
ret = heim_krb5_get_credentials(milcontext, KRB5_GC_CACHED, id,
&in_creds, ocreds);
heim_krb5_free_principal(milcontext, in_creds.server);
if (outCredCacheName)
*outCredCacheName = strdup(heim_krb5_cc_get_name(milcontext, id));
out:
if (id)
heim_krb5_cc_close(milcontext, id);
if (princ)
heim_krb5_free_principal(milcontext, princ);
return LOG_FAILURE(ret, "fetch_creds");
}
KLStatus KLCacheHasValidTickets (KLPrincipal inPrincipal,
KLKerberosVersion inKerberosVersion,
KLBoolean *outFoundValidTickets,
KLPrincipal *outPrincipal,
char **outCredCacheName)
{
krb5_error_code ret;
krb5_creds *ocreds;
LOG_ENTRY();
mshim_init_context();
if (inKerberosVersion != kerberosVersion_V5)
return LOG_FAILURE(EINVAL, "wrong version");
ret = fetch_creds(inPrincipal, &ocreds, outCredCacheName);
if (ret == 0) {
time_t t = time(NULL);
/* consinder tickets that are slightly too young as valid
* since might just have fetched them */
*outFoundValidTickets =
(ocreds->times.starttime - 10 < t)
&& (t < ocreds->times.endtime);
heim_krb5_free_creds(milcontext, ocreds);
} else {
LOG_FAILURE(ret, "fetch tickets failed");
ret = 0;
*outFoundValidTickets = 0;
}
if (outPrincipal)
*outPrincipal = NULL;
return LOG_FAILURE(ret, "KLCacheHasValidTickets");
}
KLStatus KLTicketStartTime (KLPrincipal inPrincipal,
KLKerberosVersion inKerberosVersion,
KLTime *outStartTime)
{
krb5_creds *creds;
krb5_error_code ret;
LOG_ENTRY();
mshim_init_context();
ret = fetch_creds(inPrincipal, &creds, NULL);
if (ret)
return LOG_FAILURE(ret, "fetch tickets failed");
*outStartTime = creds->times.starttime;
heim_krb5_free_creds(milcontext, creds);
return klNoErr;
}
KLStatus KLTicketExpirationTime (KLPrincipal inPrincipal,
KLKerberosVersion inKerberosVersion,
KLTime *outExpirationTime)
{
krb5_error_code ret;
krb5_creds *creds;
LOG_ENTRY();
mshim_init_context();
ret = fetch_creds(inPrincipal, &creds, NULL);
if (ret)
return LOG_FAILURE(ret, "fetch tickets failed");
*outExpirationTime = creds->times.endtime;
heim_krb5_free_creds(milcontext, creds);
return klNoErr;
}
KLStatus
KLSetSystemDefaultCache (KLPrincipal inPrincipal)
{
krb5_error_code ret;
krb5_ccache id;
LOG_ENTRY();
mshim_init_context();
ret = heim_krb5_cc_cache_match(milcontext, inPrincipal, &id);
if (ret)
return LOG_FAILURE(ret, "ccache match");
ret = heim_krb5_cc_switch(milcontext, id);
heim_krb5_cc_close(milcontext, id);
if (ret)
return LOG_FAILURE(ret, "cc switch");
return klNoErr;
}
KLStatus KLHandleError (KLStatus inError,
KLDialogIdentifier inDialogIdentifier,
KLBoolean inShowAlert)
{
LOG_UNIMPLEMENTED();
return klNoErr;
}
KLStatus KLGetErrorString (KLStatus inError,
char **outErrorString)
{
LOG_ENTRY();
mshim_init_context();
*outErrorString = heim_krb5_get_error_string(milcontext);
if (*outErrorString == NULL)
asprintf(outErrorString, "unknown error: %d\n", (int)inError);
if (outErrorString == NULL)
return klMemFullErr;
return klNoErr;
}
KLStatus KLCancelAllDialogs (void)
{
return klNoErr;
}
/* Kerberos change password dialog low level functions */
KLStatus KLChangePasswordWithPasswords (KLPrincipal inPrincipal,
const char *inOldPassword,
const char *inNewPassword,
KLBoolean *outRejected,
char **outRejectionError,
char **outRejectionDescription)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
/* Application Configuration functions */
KLStatus KLSetIdleCallback (const KLIdleCallback inCallback,
const KLRefCon inRefCon)
{
return klNoErr;
}
KLStatus KLGetIdleCallback (KLIdleCallback* inCallback,
KLRefCon* inRefCon)
{
return klNoErr;
}
/* Library configuration functions */
/* Deprecated options which we now ignore */
enum {
loginOption_ShowOptions = 'sopt',
loginOption_RememberShowOptions = 'ropt',
loginOption_LongTicketLifetimeDisplay = 'hms ',
loginOption_RememberPassword = 'pass'
};
KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption,
void *ioBuffer,
KLSize *ioBufferSize)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
KLStatus KLSetDefaultLoginOption (const KLDefaultLoginOption inOption,
const void *inBuffer,
const KLSize inBufferSize)
{
LOG_UNIMPLEMENTED();
return EINVAL;
}
/* Realm configuration functions */
KLStatus KLFindKerberosRealmByName (const char *inRealmName,
KLIndex *outIndex)
{
KLStatus ret;
char *realm = NULL;
ret = KLGetKerberosDefaultRealmByName (&realm);
if (ret == klNoErr) {
if (!strcmp (inRealmName, realm)) {
*outIndex = 0;
} else {
ret = klRealmDoesNotExistErr;
}
free(realm);
}
return ret;
}
KLStatus KLGetKerberosRealm (KLIndex inIndex,
char **outRealmName)
{
return KLGetKerberosDefaultRealmByName (outRealmName);
}
KLStatus KLSetKerberosRealm (KLIndex inIndex,
const char *inRealmName)
{
return klNoErr;
}
KLStatus KLRemoveKerberosRealm (KLIndex inIndex)
{
return klNoErr;
}
KLStatus KLInsertKerberosRealm (KLIndex inInsertBeforeIndex,
const char *inRealmName)
{
return klNoErr;
}
KLStatus KLRemoveAllKerberosRealms (void)
{
return klNoErr;
}
KLSize KLCountKerberosRealms (void)
{
return 1;
}
KLStatus KLGetKerberosDefaultRealm(KLIndex *outIndex)
{
if(outIndex)
*outIndex = 0;
return klNoErr;
}
KLStatus KLGetKerberosDefaultRealmByName (char **outRealmName)
{
LOG_ENTRY();
mshim_init_context();
return krb5_get_default_realm((mit_krb5_context)milcontext, outRealmName);
}
KLStatus KLSetKerberosDefaultRealm (KLIndex inIndex)
{
return klNoErr;
}
KLStatus KLSetKerberosDefaultRealmByName (const char *inRealm)
{
return klNoErr;
}
/* KLPrincipal functions */
KLStatus
KLCreatePrincipalFromTriplet (const char *inName,
const char *inInstance,
const char *inRealm,
KLPrincipal *outPrincipal)
{
mshim_init_context();
return heim_krb5_make_principal(milcontext, outPrincipal, inRealm, inName, inInstance, NULL);
}
KLStatus
KLCreatePrincipalFromString (const char *inFullPrincipal,
KLKerberosVersion inKerberosVersion,
KLPrincipal *outPrincipal)
{
LOG_ENTRY();
mshim_init_context();
if (inKerberosVersion != kerberosVersion_V5)
return klInvalidVersionErr;
if (inFullPrincipal == NULL)
return klParameterErr;
return heim_krb5_parse_name(milcontext, inFullPrincipal, outPrincipal);
}
KLStatus KLCreatePrincipalFromKerberos5Principal (void *inKerberos5Principal,
KLPrincipal *outPrincipal)
{
mshim_init_context();
if (inKerberos5Principal == NULL)
return klParameterErr;
return heim_krb5_copy_principal(milcontext, inKerberos5Principal, outPrincipal);
}
KLStatus KLCreatePrincipalFromPrincipal (KLPrincipal inPrincipal,
KLPrincipal *outPrincipal)
{
mshim_init_context();
if (inPrincipal == NULL)
return klParameterErr;
return heim_krb5_copy_principal(milcontext, inPrincipal, outPrincipal);
}
KLStatus
KLGetTripletFromPrincipal(KLPrincipal inPrincipal,
char **outName,
char **outInstance,
char **outRealm)
{
LOG_ENTRY();
mshim_init_context();
*outInstance = NULL;
if (inPrincipal == NULL)
return klParameterErr;
switch (inPrincipal->name.name_string.len) {
case 2:
*outInstance = strdup(inPrincipal->name.name_string.val[1]);
case 1:
*outName = strdup(inPrincipal->name.name_string.val[0]);
break;
default:
return klInvalidOptionErr;
}
*outRealm = strdup(inPrincipal->realm);
return klNoErr;
}
KLStatus
KLGetStringFromPrincipal (KLPrincipal inPrincipal,
KLKerberosVersion inKerberosVersion,