Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/tools/KtabZero.java
38853 views
1
/*
2
* Copyright (c) 2013, 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 sun.security.krb5.internal.ktab.KeyTab;
25
import sun.security.krb5.internal.ktab.KeyTabConstants;
26
27
import java.io.File;
28
import java.lang.reflect.Field;
29
import java.nio.file.Files;
30
import java.nio.file.Paths;
31
32
/*
33
* @test
34
* @bug 8014196
35
* @summary ktab creates a file with zero kt_vno
36
*/
37
public class KtabZero {
38
39
static final String NAME = "k.tab";
40
41
public static void main(String[] args) throws Exception {
42
43
// 0. Non-existing keytab
44
Files.deleteIfExists(Paths.get(NAME));
45
check(true);
46
47
// 1. Create with KeyTab
48
Files.deleteIfExists(Paths.get(NAME));
49
KeyTab.getInstance(NAME).save();
50
check(false);
51
52
// 2. Create with the tool
53
Files.deleteIfExists(Paths.get(NAME));
54
try {
55
Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab");
56
ktab.getDeclaredMethod("main", String[].class).invoke(null,
57
(Object)(("-k " + NAME + " -a me@HERE pass").split(" ")));
58
} catch (ClassNotFoundException cnfe) {
59
// Only Windows has ktab tool
60
System.out.println("No ktab tool here. Ignored.");
61
return;
62
}
63
check(false);
64
}
65
66
// Checks existence as well as kt-vno
67
static void check(boolean showBeMissing) throws Exception {
68
KeyTab kt = KeyTab.getInstance(NAME);
69
if (kt.isMissing() != showBeMissing) {
70
throw new Exception("isMissing is not " + showBeMissing);
71
}
72
Field f = KeyTab.class.getDeclaredField("kt_vno");
73
f.setAccessible(true);
74
if (f.getInt(kt) != KeyTabConstants.KRB5_KT_VNO) {
75
throw new Exception("kt_vno is " + f.getInt(kt));
76
}
77
}
78
}
79
80