Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/sun/security/krb5/config/native/libTestDynamicStore.m
66646 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#import <Cocoa/Cocoa.h>
27
#import <SystemConfiguration/SystemConfiguration.h>
28
#import <jni.h>
29
30
#define KERBEROS_DEFAULT_REALMS @"Kerberos-Default-Realms"
31
#define KERBEROS_DEFAULT_REALM_MAPPINGS @"Kerberos-Domain-Realm-Mappings"
32
#define KERBEROS_REALM_INFO @"Kerberos:%@"
33
34
int removeAll(SCDynamicStoreRef store) {
35
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS));
36
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"]));
37
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"B.COM"]));
38
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS));
39
return 1;
40
}
41
42
int removeRealm(SCDynamicStoreRef store) {
43
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"]));
44
return 1;
45
}
46
47
int removeMapping(SCDynamicStoreRef store) {
48
fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS));
49
return 1;
50
}
51
52
int addMapping(SCDynamicStoreRef store) {
53
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
54
@"a", @"A",
55
@"b", @"B",
56
@"c", @"C",
57
@"d", @"D",
58
nil];
59
fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS, [NSArray arrayWithObjects: dict, nil]));
60
return 1;
61
}
62
63
int addAll(SCDynamicStoreRef store) {
64
NSArray *keys = [NSArray arrayWithObjects:@"A.COM", @"B.COM", nil];
65
Boolean b = SCDynamicStoreSetValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS, keys);
66
fprintf(stderr, "%d\n", b);
67
if (!b) return 0;
68
69
NSDictionary *k1 = [NSDictionary dictionaryWithObjectsAndKeys:
70
@"kdc1.a.com", @"host", nil];
71
NSDictionary *k2 = [NSDictionary dictionaryWithObjectsAndKeys:
72
@"kdc2.a.com", @"host", nil];
73
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
74
[NSArray arrayWithObjects: k1, k2, nil], @"kdc",
75
nil];
76
fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"], dict));
77
78
k1 = [NSDictionary dictionaryWithObjectsAndKeys:
79
@"kdc1.b.com", @"host", nil];
80
k2 = [NSDictionary dictionaryWithObjectsAndKeys:
81
@"kdc2.b.com", @"host", nil];
82
dict = [NSDictionary dictionaryWithObjectsAndKeys:
83
[NSArray arrayWithObjects: k1, k2, nil], @"kdc",
84
nil];
85
fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"B.COM"], dict));
86
addMapping(store);
87
return 1;
88
}
89
90
JNIEXPORT jint JNICALL Java_TestDynamicStore_actionInternal(JNIEnv *env, jclass clazz, jchar what, jchar whom) {
91
SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java-kerberos"), NULL, NULL);
92
fprintf(stderr, ">>> action: %c %c\n", what, whom);
93
@try {
94
switch (what) {
95
case 'a':
96
switch (whom) {
97
case 'a': return addAll(store);
98
case 'm': return addMapping(store);
99
}
100
break;
101
case 'r':
102
switch (whom) {
103
case 'a': return removeAll(store);
104
case 'r': return removeRealm(store);
105
case 'm': return removeMapping(store);
106
}
107
break;
108
}
109
return 0;
110
} @finally {
111
CFRelease(store);
112
}
113
}
114
115