Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/krb5/tools/KtabZero.java
41154 views
1
/*
2
* Copyright (c) 2013, 2019, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import jdk.test.lib.SecurityTools;
25
import jdk.test.lib.process.OutputAnalyzer;
26
import sun.security.krb5.internal.ktab.KeyTab;
27
import sun.security.krb5.internal.ktab.KeyTabConstants;
28
29
import java.lang.reflect.Field;
30
import java.nio.file.Files;
31
import java.nio.file.Path;
32
import java.nio.file.Paths;
33
34
import static jdk.test.lib.SecurityTools.klist;
35
36
/*
37
* @test
38
* @bug 8014196 7002036 7043737
39
* @summary ktab creates a file with zero kt_vno
40
* @requires os.family == "windows"
41
* @library /test/lib
42
* @modules java.security.jgss/sun.security.krb5.internal.ktab:+open
43
*/
44
public class KtabZero {
45
46
static final String NAME = "k.tab";
47
48
public static void main(String[] args) throws Exception {
49
50
// 0. Non-existing keytab
51
Files.deleteIfExists(Paths.get(NAME));
52
ktab("-l").shouldNotHaveExitValue(0);
53
klist("-k " + NAME).shouldNotHaveExitValue(0);
54
check(true);
55
56
// 1. Create with KeyTab
57
Files.deleteIfExists(Paths.get(NAME));
58
KeyTab.getInstance(NAME).save();
59
check(false);
60
61
// 2. Create with the tool
62
Files.deleteIfExists(Paths.get(NAME));
63
ktab("-a me@HERE pass").shouldHaveExitValue(0);
64
ktab("-l").shouldHaveExitValue(0);
65
66
// 7002036: ktab return code changes on a error case
67
ktab("-hello").shouldNotHaveExitValue(0);
68
ktab("").shouldNotHaveExitValue(0);
69
check(false);
70
71
// 3. Invalid keytab
72
Files.write(Path.of(NAME), "garbage".getBytes());
73
ktab("-l").shouldNotHaveExitValue(0);
74
ktab("-a me@HERE pass").shouldNotHaveExitValue(0);
75
klist("-k " + NAME).shouldNotHaveExitValue(0);
76
}
77
78
static OutputAnalyzer ktab(String s) throws Exception {
79
s = ("-k " + NAME + " " + s).trim();
80
return SecurityTools.ktab(s);
81
}
82
83
// Checks existence as well as kt-vno
84
static void check(boolean showBeMissing) throws Exception {
85
KeyTab kt = KeyTab.getInstance(NAME);
86
if (kt.isMissing() != showBeMissing) {
87
throw new Exception("isMissing is not " + showBeMissing);
88
}
89
Field f = KeyTab.class.getDeclaredField("kt_vno");
90
f.setAccessible(true);
91
if (f.getInt(kt) != KeyTabConstants.KRB5_KT_VNO) {
92
throw new Exception("kt_vno is " + f.getInt(kt));
93
}
94
}
95
}
96
97