-
Notifications
You must be signed in to change notification settings - Fork 1
/
RealmsConfiguration.m
1316 lines (1025 loc) · 41.5 KB
/
RealmsConfiguration.m
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
/*
* RealmsEditor.m
*
* $Header$
*
* Copyright 2004 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.
*/
/*
* Modified by Thibault Martin-Lagardette for AdiumSoul
* Modified the -load method, to allow passing the file we want to load/write
* by using -initWithConfigurationPathString:
*/
#import "RealmsConfiguration.h"
#import "UNIXReadWrite.h"
//#import "krbports.h" // Kerberos 4 port names
//#import "osconf.h" // Kerberos 5 port names
#pragma mark -
@implementation KerberosServer
// Note: typeMenuIndex is the index of menu items in the type popup menu
typedef struct __ServerType {
unsigned int typeMenuIndex;
NSString *string;
} ServerType;
const ServerType kServerTypes[] = {
{ kdcType, @"kdc" },
{ adminType, @"admin_server" },
{ kpasswdType, @"kpasswd_server" },
{ 3, NULL } };
// ---------------------------------------------------------------------------
+ (KerberosServer *) emptyServer
{
return [[[KerberosServer alloc] init] autorelease];
}
// ---------------------------------------------------------------------------
- (id) init
{
if ((self = [super init])) {
hostString = NULL;
customPort = 0;
hasCustomPort = FALSE;
typeMenuIndex = 0;
}
return self;
}
// ---------------------------------------------------------------------------
- (id) initWithTypeString: (NSString *) serverType
profileString: (NSString *) profileString
{
if ((self = [self init])) {
const ServerType *typesPtr;
for (typesPtr = kServerTypes; typesPtr->string != NULL; typesPtr++) {
if ([serverType compare: typesPtr->string] == NSOrderedSame) {
typeMenuIndex = typesPtr->typeMenuIndex;
}
}
NSRange separator = [profileString rangeOfString: @":" options: (NSLiteralSearch | NSBackwardsSearch)];
if (separator.location == NSNotFound) {
hostString = [profileString retain];
} else {
hostString = [[profileString substringToIndex: separator.location] retain];
customPort = [[profileString substringFromIndex: separator.location + separator.length] intValue];
hasCustomPort = TRUE;
}
}
return self;
}
// ---------------------------------------------------------------------------
- (void) dealloc
{
if (hostString) { [hostString release]; }
[super dealloc];
}
// ---------------------------------------------------------------------------
- (NSString *) profileString
{
NSMutableString *string = [NSMutableString stringWithCapacity: [[self host] length]];
if (string) {
[string appendFormat: @"%s:%d", [[self host] UTF8String], [[self port] intValue]];
}
return (string != NULL) ? string : [self host];
}
// ---------------------------------------------------------------------------
- (NSString *) typeString
{
const ServerType *typesPtr;
for (typesPtr = kServerTypes; typesPtr->string != NULL; typesPtr++) {
if (typeMenuIndex == typesPtr->typeMenuIndex) {
return typesPtr->string;
}
}
return NULL;
}
// ---------------------------------------------------------------------------
- (unsigned int) typeMenuIndex
{
return typeMenuIndex;
}
// ---------------------------------------------------------------------------
- (void) setTypeMenuIndex: (unsigned int) newTypeMenuIndex
{
typeMenuIndex = newTypeMenuIndex;
}
// ---------------------------------------------------------------------------
- (NSString *) host
{
return (hostString != NULL) ? hostString : @"";
}
// ---------------------------------------------------------------------------
- (void) setHost: (NSString *) newHost
{
if (hostString) { [hostString release]; }
hostString = [newHost retain];
//NSLog (@"setting host string to '%@'", hostString);
}
// ---------------------------------------------------------------------------
- (NSNumber *) port
{
if (hasCustomPort) {
return [NSNumber numberWithInt: customPort];
} else {
return [self defaultPort];
}
}
// ---------------------------------------------------------------------------
- (void) setPort: (NSNumber *) newPort
{
hasCustomPort = (newPort > 0);
customPort = (hasCustomPort) ? [newPort intValue] : [[self defaultPort] intValue];
}
// ---------------------------------------------------------------------------
- (NSNumber *) defaultPort
{
int port = 0;
if (typeMenuIndex == kdcType) {
port = 88 /* KRB5_DEFAULT_PORT */;
} else if (typeMenuIndex == adminType) {
port = 749 /* DEFAULT_KADM5_PORT */;
} else if (typeMenuIndex == kpasswdType) {
port = 464; // DEFAULT_KPASSWD_PORT
}
return [NSNumber numberWithInt: port];
}
@end
#pragma mark -
@implementation KerberosDomain
// ---------------------------------------------------------------------------
+ (KerberosDomain *) emptyDomain
{
return [[[KerberosDomain alloc] init] autorelease];
}
// ---------------------------------------------------------------------------
- (id) init
{
if ((self = [super init])) {
nameString = NULL;
}
return self;
}
// ---------------------------------------------------------------------------
- (id) initWithName: (NSString *) name
{
if ((self = [self init])) {
nameString = [name retain];
}
return self;
}
// ---------------------------------------------------------------------------
- (void) dealloc
{
if (nameString) { [nameString release]; }
[super dealloc];
}
// ---------------------------------------------------------------------------
- (NSString *) name
{
return ((nameString != NULL) ? nameString : @"");
}
// ---------------------------------------------------------------------------
- (void) setName: (NSString *) newName
{
if (nameString) { [nameString release]; }
nameString = [newName retain];
}
@end
#pragma mark -
@implementation KerberosRealm
// ---------------------------------------------------------------------------
+ (KerberosRealm *) emptyRealm
{
return [[[KerberosRealm alloc] init] autorelease];
}
// ---------------------------------------------------------------------------
- (id) init
{
if ((self = [super init])) {
krb5_error_code err = 0;
nameInProfileString = NULL;
nameString = NULL;
defaultDomainString = NULL;
serversArray = NULL;
displayInDialogPopup = YES;
if (!err) {
serversArray = [[NSMutableArray alloc] init];
if (!serversArray) { err = ENOMEM; }
}
if (!err) {
domainsArray = [[NSMutableArray alloc] init];
if (!domainsArray) { err = ENOMEM; }
}
if (err) {
[self release];
return NULL;
}
}
return self;
}
// ---------------------------------------------------------------------------
- (id) initWithName: (NSString *) name profile: (profile_t) profile
{
if ((self = [self init])) {
krb5_error_code err = 0;
nameInProfileString = [name retain];
nameString = [name retain];
if (!err) {
const char *defaultDomainsList[] = { "realms", [name UTF8String], "default_domain", NULL };
char **defaultDomains = NULL;
err = profile_get_values (profile, defaultDomainsList, &defaultDomains);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
if (!err && (defaultDomains != NULL) && (defaultDomains[0] != NULL)) {
defaultDomainString = [[NSString alloc] initWithUTF8String: defaultDomains[0]];
if (!defaultDomainString) { err = ENOMEM; }
}
if (defaultDomains) { profile_free_list (defaultDomains); }
}
if (!err) {
err = [self addServersFromProfile: profile];
}
// Is the realm in the KLL realms list?
if (!err) {
KLIndex popupIndex = 0;
[self setDisplayInDialogPopup: (KLFindKerberosRealmByName ([name UTF8String], &popupIndex) == klNoErr)];
}
// The reason we don't have the realms load the domains is that some domains don't have a
// realm listed in the profile -- this is common if you have DNS SRV records
// instead the realms configuration will load them so it can create KerberosRealm objects
// for these extra domain_realm mappings
if (err) {
[self release];
return NULL;
}
}
return self;
}
// ---------------------------------------------------------------------------
- (void) dealloc
{
if (nameString ) { [nameString release]; }
if (serversArray) { [serversArray release]; }
if (domainsArray) { [domainsArray release]; }
[super dealloc];
}
// ---------------------------------------------------------------------------
- (krb5_error_code) flushToProfile: (profile_t) profile
{
krb5_error_code err = 0;
if ([[self name] length] <= 0) { err = EINVAL; }
// Note: we do not need to deal with the case of creating empty realm sections.
// Any nonexistent realm sections will be created when we try to write into them.
// Check the v5 realm name to see if we need to rename it:
if (!err) {
const char *realmList[] = { "realms", [[self nameInProfile] UTF8String], NULL };
err = profile_rename_section (profile, realmList, [[self name] UTF8String]);
if (err == PROF_NO_SECTION) { err = 0; } // OK if there isn't one yet
}
// Write out the default domain:
if (!err) {
const char *defaultDomainsList[] = { "realms", [[self name] UTF8String], "default_domain", NULL };
char **defaultDomains = NULL;
if (profile_get_values (profile, defaultDomainsList, &defaultDomains) == 0) {
if ([self hasDefaultDomain]) {
err = profile_update_relation (profile, defaultDomainsList, defaultDomains[0], [[self defaultDomain] UTF8String]);
} else {
err = profile_clear_relation (profile, defaultDomainsList);
}
} else {
if ([self hasDefaultDomain]) {
err = profile_add_relation (profile, defaultDomainsList, [[self defaultDomain] UTF8String]);
}
}
if (defaultDomains) { profile_free_list (defaultDomains); }
}
// Write out the servers:
if (!err) {
err = [self flushServersToProfile: profile];
}
// Write out the domains:
if (!err) {
err = [self flushDomainsToProfile: profile];
}
// Is the realm in the KLL realms list?
if (!err) {
KLIndex popupIndex = 0;
BOOL inPopup = (KLFindKerberosRealmByName ([[self name] UTF8String], &popupIndex) == klNoErr);
if (inPopup && ![self displayInDialogPopup]) {
err = KLRemoveKerberosRealm (popupIndex); // remove it
} else if (!inPopup && [self displayInDialogPopup]) {
err = KLInsertKerberosRealm (realmList_End, [[self name] UTF8String]); // add it
}
}
if (err) {
NSLog (@"[KerberosRealm flush] for realm %@ returning err %d (%s)",
[self name], err, error_message (err));
}
return err;
}
// ---------------------------------------------------------------------------
- (krb5_error_code) addServersFromProfile: (profile_t) profile
{
krb5_error_code err = 0;
const char *serversList[] = { "realms", [[self name] UTF8String], NULL, NULL };
const ServerType *typesPtr = NULL;
for (typesPtr = kServerTypes; typesPtr->string != NULL && !err; typesPtr++) {
NSString *typeString = typesPtr->string;
char **servers = NULL;
serversList[2] = [typeString UTF8String];
err = profile_get_values (profile, serversList, &servers);
if (!err && (servers != NULL)) {
char **s;
for (s = servers; *s != NULL && !err; s++) {
NSString *profileString = [NSString stringWithUTF8String: *s];
KerberosServer *server = [[KerberosServer alloc] initWithTypeString: typeString
profileString: profileString];
if (!server) {
err = ENOMEM;
} else {
//NSLog (@"Adding server '%@' of type '%@' for realm '%@'",
// realmString, typeString, profileString);
[serversArray addObject: server];
[server release];
}
}
}
// These errors are ok... there just aren't servers of this type
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
if (servers) { profile_free_list (servers); }
}
return err;
}
// ---------------------------------------------------------------------------
- (krb5_error_code) flushServersToProfile: (profile_t) profile
{
krb5_error_code err = 0;
const char *serversList[] = { "realms", [[self name] UTF8String], NULL, NULL };
// Clear out old servers:
if (!err) {
const ServerType *typesPtr = NULL;
for (typesPtr = kServerTypes; typesPtr->string != NULL && !err; typesPtr++) {
serversList[2] = [typesPtr->string UTF8String];
err = profile_clear_relation (profile, serversList);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
}
}
// Store the new servers:
if (!err) {
unsigned int i = 0;
for (i = 0; i < [serversArray count] && !err; i++) {
KerberosServer *server = [serversArray objectAtIndex: i];
if (server) {
serversList[2] = [[server typeString] UTF8String];
err = profile_add_relation (profile, serversList, [[server profileString] UTF8String]);
}
}
}
return err;
}
// ---------------------------------------------------------------------------
- (krb5_error_code) flushDomainsToProfile: (profile_t) profile
{
krb5_error_code err = 0;
NSString *realmString = [self name];
const char *domainMappingList[] = { "domain_realm", NULL, NULL };
unsigned int i = 0;
if (!profile) { err = ENOMEM; }
for (i = 0; i < [self numberOfDomains] && !err; i++) {
KerberosDomain *domain = [self domainAtIndex: i];
if (domain) {
char **domainMapping = NULL;
domainMappingList[1] = [[domain name] UTF8String];
if (!err) {
err = profile_get_values (profile, domainMappingList, &domainMapping);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
}
if (!err) {
if (domainMapping) {
if ([realmString compare: [NSString stringWithUTF8String: domainMapping[0]]] != NSOrderedSame) {
// Eek! this domain is already mapped to another realm!
NSLog (@"WARNING! Domain '%s' is mapped to realms '%s' and '%s'",
domainMappingList[1], [realmString UTF8String], domainMapping[0]);
}
} else {
err = profile_add_relation (profile, domainMappingList, [realmString UTF8String]);
}
}
}
}
if (err) {
NSLog (@"[KerberosRealm flush] for realm %@ returning err %d (%s)",
[self name], err, error_message (err));
}
return err;
}
// ---------------------------------------------------------------------------
- (NSString *) nameInProfile
{
return (nameInProfileString != NULL) ? nameInProfileString : @"";
}
// ---------------------------------------------------------------------------
- (NSString *) name
{
return (nameString != NULL) ? nameString : @"";
}
// ---------------------------------------------------------------------------
- (void) setName: (NSString *) newName
{
if (nameString) { [nameString release]; }
nameString = ((newName != NULL) && ([newName length] > 0)) ? [newName retain] : NULL;
}
// ---------------------------------------------------------------------------
- (BOOL) hasDefaultDomain
{
return ((defaultDomainString != NULL) && ([defaultDomainString length] > 0));
}
// ---------------------------------------------------------------------------
- (NSString *) defaultDomain
{
return (defaultDomainString != NULL) ? defaultDomainString : @"";
}
// ---------------------------------------------------------------------------
- (void) setDefaultDomain: (NSString *) defaultDomain
{
if (defaultDomainString) { [defaultDomainString release]; }
defaultDomainString = ((defaultDomain != NULL) && ([defaultDomain length] > 0)) ? [defaultDomain retain] : NULL;
}
// ---------------------------------------------------------------------------
- (BOOL) displayInDialogPopup
{
return displayInDialogPopup;
}
// ---------------------------------------------------------------------------
- (void) setDisplayInDialogPopup: (BOOL) newDisplayInDialogPopup
{
displayInDialogPopup = newDisplayInDialogPopup;
}
// ---------------------------------------------------------------------------
- (unsigned int) numberOfServers
{
return [serversArray count];
}
// ---------------------------------------------------------------------------
- (KerberosServer *) serverAtIndex: (unsigned int) serverIndex
{
if (serverIndex < [serversArray count]) {
return [serversArray objectAtIndex: serverIndex];
} else {
return NULL;
}
}
// ---------------------------------------------------------------------------
- (unsigned int) indexOfServer: (KerberosServer *) server
{
return [serversArray indexOfObject: server];
}
// ---------------------------------------------------------------------------
- (void) addServer: (KerberosServer *) server
{
[serversArray addObject: server];
}
// ---------------------------------------------------------------------------
- (void) removeServer: (KerberosServer *) server
{
[serversArray removeObject: server];
}
// ---------------------------------------------------------------------------
- (unsigned int) numberOfDomains
{
return [domainsArray count];
}
// ---------------------------------------------------------------------------
- (KerberosDomain *) domainAtIndex: (unsigned int) domainIndex
{
if (domainIndex < [domainsArray count]) {
return [domainsArray objectAtIndex: domainIndex];
} else {
return NULL;
}
}
// ---------------------------------------------------------------------------
- (unsigned int) indexOfDomain: (KerberosDomain *) domain
{
return [domainsArray indexOfObject: domain];
}
// ---------------------------------------------------------------------------
- (BOOL) mappedToByDomainString: (NSString *) domain
{
// This differs from indexOfDomain in that it does a string comparison!
unsigned int i = 0;
for (i = 0; i < [domainsArray count]; i++) {
KerberosDomain *d = [domainsArray objectAtIndex: i];
if ([[d name] compare: domain] == NSOrderedSame) {
return YES;
}
}
return NO;
}
// ---------------------------------------------------------------------------
- (void) addDomain: (KerberosDomain *) domain
{
// Make sure this isn't a duplicate (use string comparison)
if (![self mappedToByDomainString: [domain name]]) {
[domainsArray addObject: domain];
}
}
// ---------------------------------------------------------------------------
- (void) removeDomain: (KerberosDomain *) domain
{
[domainsArray removeObject: domain];
}
@end
#pragma mark -
@implementation RealmsConfiguration
// ---------------------------------------------------------------------------
- (id)initWithConfigurationPathString:(NSString *)configurationFilePath
{
if ((self = [super init])) {
krb5_error_code err = 0;
useDNS = YES;
configurationPathString = [configurationFilePath retain];
profile = NULL;
realmsArray = NULL;
defaultRealmString = NULL;
if (!err) {
realmsArray = [[NSMutableArray alloc] init];
if (!realmsArray) { err = ENOMEM; }
}
if (!err) {
err = [self load];
}
if (err) {
[self release];
return NULL;
}
}
return self;
}
- (id)init
{
return [self initWithConfigurationPathString:nil];
}
// ---------------------------------------------------------------------------
- (void) dealloc
{
if (profile ) { profile_abandon (profile); }
if (configurationPathString) { [configurationPathString release]; }
if (defaultRealmString ) { [defaultRealmString release]; }
if (realmsArray ) { [realmsArray release]; }
[super dealloc];
}
// ---------------------------------------------------------------------------
- (krb5_error_code) load
{
krb5_error_code err = 0;
// If the profile is NULL, initialize it
if (!profile) {
NSString *configurationPathStrings[] = {
@"~/Library/Preferences/edu.mit.Kerberos",
@"/Library/Preferences/edu.mit.Kerberos",
@"/etc/krb5.conf", NULL };
NSString **paths = NULL;
NSString *newConfigurationPath = NULL;
// Figure out which config file we should look at
if (configurationPathString)
{
NSString* path = [configurationPathString stringByExpandingTildeInPath];
if ([[NSFileManager defaultManager] isReadableFileAtPath:path])
{
newConfigurationPath = path;
}
}
else
{
for (paths = configurationPathStrings; *paths != NULL; paths++) {
NSString *path = [*paths stringByExpandingTildeInPath];
if ([[NSFileManager defaultManager] isReadableFileAtPath: path]) {
newConfigurationPath = path;
break;
}
}
}
// If there were no config files, we need a new one
// (profiles need to be based on a file, so we use /dev/null at a starting place)
if (!paths || !*paths) { newConfigurationPath = @"/dev/null"; }
// initialize the profile
if (!err) {
const_profile_filespec_t configFiles[] = { [newConfigurationPath fileSystemRepresentation], NULL };
profile_t newProfile = NULL;
err = profile_init (configFiles, &newProfile);
if (!err) {
profile = newProfile;
}
}
if (!err) {
// if (!*paths) { newConfigurationPath = @"/Library/Preferences/edu.mit.Kerberos"; }
if (configurationPathString && (!paths || !*paths))
{
newConfigurationPath = [configurationPathString retain];
}
// if (configurationPathString) { [configurationPathString release]; }
// configurationPathString = [newConfigurationPath retain];
}
}
// Clear out any existing realm state
if (!err) {
[realmsArray removeAllObjects];
}
// Get the default realm
if (!err) {
const char *defaultRealmList[3] = {"libdefaults", "default_realm", NULL};
char **defaultRealm = NULL;
if (!err) {
err = profile_get_values (profile, defaultRealmList, &defaultRealm);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
}
if (!err && (defaultRealm != NULL)) {
defaultRealmString = [[NSString alloc] initWithUTF8String: defaultRealm[0]];
if (!defaultRealmString) { err = ENOMEM; }
}
if (defaultRealm) { profile_free_list (defaultRealm); }
}
// Do we DNS for realm configuration
if (!err) {
const char *dnsFallbackList[3] = {"libdefaults", "dns_fallback", NULL};
char **dnsFallback = NULL;
if (!err) {
err = profile_get_values (profile, dnsFallbackList, &dnsFallback);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
}
if (!err && (dnsFallback != NULL)) {
// In krb5, everything else is considered false
[self setUseDNS: (strcasecmp (dnsFallback[0], "y") == 0 || strcasecmp (dnsFallback[0], "yes") == 0 ||
strcasecmp (dnsFallback[0], "t") == 0 || strcasecmp (dnsFallback[0], "true") == 0 ||
strcasecmp (dnsFallback[0], "1") == 0 || strcasecmp (dnsFallback[0], "on") == 0)];
}
if (dnsFallback) { profile_free_list (dnsFallback); }
}
// Do the v5 realms
if (!err) {
const char *realmsList[] = { "realms", NULL };
char **realms = NULL;
err = profile_get_subsection_names (profile, realmsList, &realms);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
if (!err && (realms != NULL)) {
char **r;
for (r = realms; *r != NULL && !err; r++) {
NSString *name = [NSString stringWithUTF8String: *r];
KerberosRealm *realm = [[KerberosRealm alloc] initWithName: name profile: profile];
if (!realm) {
err = ENOMEM;
} else {
[realmsArray addObject: realm];
[realm release];
}
}
}
if (realms ) { profile_free_list (realms); }
}
// The reason we don't have the realms load the domains is that some domains don't have a
// realm listed in the profile -- this is common if you have DNS SRV records
// Now do the v5 domain-realm mappings (which depend on the realms)
if (!err) {
const char *domainsList[] = { "domain_realm", NULL };
char **domains = NULL;
err = profile_get_relation_names (profile, domainsList, &domains);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
if (!err && (domains != NULL)) {
char **d;
for (d = domains; *d != NULL && !err; d++) {
NSString *domainString = [NSString stringWithUTF8String: *d];
if (domainString) {
const char *domainMappingList[] = { "domain_realm", *d, NULL };
char **domainMapping = NULL;
if (!err) {
err = profile_get_values (profile, domainMappingList, &domainMapping);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
}
if (!err) {
NSString *realmName = [NSString stringWithUTF8String: domainMapping[0]];
KerberosRealm *realm = [self findRealmByName: realmName];
if (!realm) {
// Create it
realm = [KerberosRealm emptyRealm];
if (realm) { [realm setName: realmName]; }
}
if (realm) {
KerberosDomain *domain = [[KerberosDomain alloc] initWithName: domainString];
if (!domain) {
err = ENOMEM;
} else {
[realm addDomain: domain];
[domain release];
}
}
}
if (domainMapping) { profile_free_list (domainMapping); }
}
}
}
if (domains) { profile_free_list (domains); }
}
return err;
}
// ---------------------------------------------------------------------------
- (krb5_error_code) abandon
{
if (profile) {
profile_abandon (profile);
profile = NULL;
}
return [self load];
}
// ---------------------------------------------------------------------------
- (krb5_error_code) flush
{
krb5_error_code err = 0;
int writable = 0;
int modified = 1;
// First flush the realms so all the names, servers and domains get updated:
if (!err) {
unsigned int i = 0;
for (i = 0; i < [self numberOfRealms] && !err; i++) {
KerberosRealm *realm = [self realmAtIndex: i];
if (realm) {
err = [realm flushToProfile: profile];
}
}
}
// Walk over the profile looking for deleted realms:
if (!err) {
const char *realmsList[] = { "realms", NULL };
char **realms = NULL;
err = profile_get_subsection_names (profile, realmsList, &realms);
if ((err == PROF_NO_SECTION) || (err == PROF_NO_RELATION)) { err = 0; }
if (!err && (realms != NULL)) {
char **r;
for (r = realms; *r != NULL && !err; r++) {
NSString *name = [NSString stringWithUTF8String: *r];