Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/tools/KtabZero.java
38853 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import sun.security.krb5.internal.ktab.KeyTab;24import sun.security.krb5.internal.ktab.KeyTabConstants;2526import java.io.File;27import java.lang.reflect.Field;28import java.nio.file.Files;29import java.nio.file.Paths;3031/*32* @test33* @bug 801419634* @summary ktab creates a file with zero kt_vno35*/36public class KtabZero {3738static final String NAME = "k.tab";3940public static void main(String[] args) throws Exception {4142// 0. Non-existing keytab43Files.deleteIfExists(Paths.get(NAME));44check(true);4546// 1. Create with KeyTab47Files.deleteIfExists(Paths.get(NAME));48KeyTab.getInstance(NAME).save();49check(false);5051// 2. Create with the tool52Files.deleteIfExists(Paths.get(NAME));53try {54Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab");55ktab.getDeclaredMethod("main", String[].class).invoke(null,56(Object)(("-k " + NAME + " -a me@HERE pass").split(" ")));57} catch (ClassNotFoundException cnfe) {58// Only Windows has ktab tool59System.out.println("No ktab tool here. Ignored.");60return;61}62check(false);63}6465// Checks existence as well as kt-vno66static void check(boolean showBeMissing) throws Exception {67KeyTab kt = KeyTab.getInstance(NAME);68if (kt.isMissing() != showBeMissing) {69throw new Exception("isMissing is not " + showBeMissing);70}71Field f = KeyTab.class.getDeclaredField("kt_vno");72f.setAccessible(true);73if (f.getInt(kt) != KeyTabConstants.KRB5_KT_VNO) {74throw new Exception("kt_vno is " + f.getInt(kt));75}76}77}787980