jdk/src/share/classes/sun/security/krb5/Config.java
author weijun
Fri, 20 Jun 2014 10:27:10 +0800
changeset 25151 7a670121602e
parent 23716 33cc4db6209b
permissions -rw-r--r--
8029994: Support "include" and "includedir" in krb5.conf Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.security.krb5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    34
import java.io.FilePermission;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    35
import java.nio.file.DirectoryStream;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    36
import java.nio.file.Files;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    37
import java.nio.file.Paths;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    38
import java.nio.file.Path;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
    39
import java.security.PrivilegedAction;
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
    40
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.UnknownHostException;
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
    44
import java.security.AccessController;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
    45
import java.security.PrivilegedExceptionAction;
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
    46
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
    47
import sun.net.dns.ResolverConfiguration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.security.krb5.internal.crypto.EType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.security.krb5.internal.Krb5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This class maintains key-value pairs of Kerberos configurable constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * from configuration file or from user specified system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class Config {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Only allow a single instance of Config.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Config singleton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /*
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20175
diff changeset
    64
     * Hashtable used to store configuration information.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
    66
    private Hashtable<String,Object> stanzaTable = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // these are used for hexdecimal calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int BASE16_0 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final int BASE16_1 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final int BASE16_2 = 16 * 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int BASE16_3 = 16 * 16 * 16;
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    75
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    76
    /**
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    77
     * Specified by system properties. Must be both null or non-null.
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    78
     */
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    79
    private final String defaultRealm;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    80
    private final String defaultKDC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // used for native interface
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
    83
    private static native String getWindowsDirectory(boolean isSystem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Gets an instance of Config class. One and only one instance (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * singleton) is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @exception KrbException if error occurs when constructing a Config
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    91
     * instance. Possible causes would be either of java.security.krb5.realm or
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    92
     * java.security.krb5.kdc not specified, error reading configuration file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static synchronized Config getInstance() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (singleton == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            singleton = new Config();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return singleton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Refresh and reload the Configuration. This could involve,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * for example reading the Configuration file again or getting
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   104
     * the java.security.krb5.* system properties again. This method
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   105
     * also tries its best to update static fields in other classes
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   106
     * that depend on the configuration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @exception KrbException if error occurs when constructing a Config
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   109
     * instance. Possible causes would be either of java.security.krb5.realm or
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   110
     * java.security.krb5.kdc not specified, error reading configuration file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static synchronized void refresh() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        singleton = new Config();
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 6113
diff changeset
   115
        KdcComm.initStatic();
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   116
        EType.initStatic();
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   117
        Checksum.initStatic();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   121
    private static boolean isMacosLionOrBetter() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   122
        // split the "10.x.y" version number
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   123
        String osname = getProperty("os.name");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   124
        if (!osname.contains("OS X")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   125
            return false;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   126
        }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   127
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   128
        String osVersion = getProperty("os.version");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   129
        String[] fragments = osVersion.split("\\.");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   130
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   131
        // sanity check the "10." part of the version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   132
        if (!fragments[0].equals("10")) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   133
        if (fragments.length < 2) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   134
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   135
        // check if Mac OS X 10.7(.y)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   136
        try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   137
            int minorVers = Integer.parseInt(fragments[1]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   138
            if (minorVers >= 7) return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   139
        } catch (NumberFormatException e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   140
            // was not an integer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   141
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   142
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   143
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   144
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Private constructor - can not be instantiated externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private Config() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /*
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   151
         * If either one system property is specified, we throw exception.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         */
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   153
        String tmp = getProperty("java.security.krb5.kdc");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   154
        if (tmp != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   155
            // The user can specify a list of kdc hosts separated by ":"
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   156
            defaultKDC = tmp.replace(':', ' ');
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   157
        } else {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   158
            defaultKDC = null;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   159
        }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   160
        defaultRealm = getProperty("java.security.krb5.realm");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   161
        if ((defaultKDC == null && defaultRealm != null) ||
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   162
            (defaultRealm == null && defaultKDC != null)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                ("System property java.security.krb5.kdc and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                 "java.security.krb5.realm both must be set or " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                 "neither must be set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   168
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   169
        // Always read the Kerberos configuration file
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   170
        try {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   171
            List<String> configFile;
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   172
            String fileName = getJavaFileName();
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   173
            if (fileName != null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   174
                configFile = loadConfigFile(fileName);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   175
                stanzaTable = parseStanzaTable(configFile);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   176
                if (DEBUG) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   177
                    System.out.println("Loaded from Java config");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   178
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   179
            } else {
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   180
                boolean found = false;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   181
                if (isMacosLionOrBetter()) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   182
                    try {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   183
                        stanzaTable = SCDynamicStoreConfig.getConfig();
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   184
                        if (DEBUG) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   185
                            System.out.println("Loaded from SCDynamicStoreConfig");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   186
                        }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   187
                        found = true;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   188
                    } catch (IOException ioe) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   189
                        // OK. Will go on with file
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   190
                    }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   191
                }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   192
                if (!found) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   193
                    fileName = getNativeFileName();
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   194
                    configFile = loadConfigFile(fileName);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   195
                    stanzaTable = parseStanzaTable(configFile);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   196
                    if (DEBUG) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   197
                        System.out.println("Loaded from native config");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   198
                    }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   199
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   200
            }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   201
        } catch (IOException ioe) {
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   202
            if (DEBUG) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   203
                System.out.println("Exception thrown in loading config:");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   204
                ioe.printStackTrace(System.out);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   205
            }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   206
            throw new KrbException("krb5.conf loading failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   211
     * Gets the last-defined string value for the specified keys.
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   212
     * @param keys the keys, as an array from section name, sub-section names
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   213
     * (if any), to value name.
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   214
     * @return the value. When there are multiple values for the same key,
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   215
     * returns the first one. {@code null} is returned if not all the keys are
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   216
     * defined. For example, {@code get("libdefaults", "forwardable")} will
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   217
     * return null if "forwardable" is not defined in [libdefaults], and
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   218
     * {@code get("realms", "R", "kdc")} will return null if "R" is not
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   219
     * defined in [realms] or "kdc" is not defined for "R".
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   220
     * @throws IllegalArgumentException if any of the keys is illegal, either
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   221
     * because a key not the last one is not a (sub)section name or the last
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   222
     * key is still a section name. For example, {@code get("libdefaults")}
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   223
     * throws this exception because [libdefaults] is a section name instead of
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   224
     * a value name, and {@code get("libdefaults", "forwardable", "tail")}
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   225
     * also throws this exception because "forwardable" is already a value name
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   226
     * and has no sub-key at all (given "forwardable" is defined, otherwise,
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   227
     * this method has no knowledge if it's a value name or a section name),
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   228
     */
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   229
    public String get(String... keys) {
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   230
        Vector<String> v = getString0(keys);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   231
        if (v == null) return null;
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   232
        return v.firstElement();
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   233
    }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   234
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   235
    /**
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   236
     * Gets the boolean value for the specified keys. Returns TRUE if the
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   237
     * string value is "yes", or "true", FALSE if "no", or "false", or null
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   238
     * if otherwise or not defined. The comparision is case-insensitive.
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   239
     *
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   240
     * @param keys the keys, see {@link #get(String...)}
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   241
     * @return the boolean value, or null if there is no value defined or the
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   242
     * value does not look like a boolean value.
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   243
     * @throws IllegalArgumentException see {@link #get(String...)}
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   244
     */
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   245
    public Boolean getBooleanObject(String... keys) {
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   246
        String s = get(keys);
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   247
        if (s == null) {
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   248
            return null;
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   249
        }
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   250
        switch (s.toLowerCase(Locale.US)) {
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   251
            case "yes": case "true":
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   252
                return Boolean.TRUE;
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   253
            case "no": case "false":
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   254
                return Boolean.FALSE;
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   255
            default:
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   256
                return null;
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   257
        }
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   258
    }
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   259
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   260
    /**
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   261
     * Gets all values for the specified keys.
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   262
     * @throws IllegalArgumentException if any of the keys is illegal
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   263
     *         (See {@link #get})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   265
    public String getAll(String... keys) {
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   266
        Vector<String> v = getString0(keys);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   267
        if (v == null) return null;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   268
        StringBuilder sb = new StringBuilder();
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   269
        boolean first = true;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   270
        for (String s: v) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   271
            if (first) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   272
                sb.append(s);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   273
                first = false;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   274
            } else {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   275
                sb.append(' ').append(s);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   276
            }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   277
        }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   278
        return sb.toString();
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   279
    }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   280
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   281
    /**
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   282
     * Returns true if keys exists, can be final string(s) or a sub-section
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   283
     * @throws IllegalArgumentException if any of the keys is illegal
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   284
     *         (See {@link #get})
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   285
     */
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   286
    public boolean exists(String... keys) {
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   287
        return get0(keys) != null;
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   288
    }
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   289
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   290
    // Returns final string value(s) for given keys.
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   291
    @SuppressWarnings("unchecked")
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   292
    private Vector<String> getString0(String... keys) {
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   293
        try {
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   294
            return (Vector<String>)get0(keys);
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   295
        } catch (ClassCastException cce) {
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   296
            throw new IllegalArgumentException(cce);
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   297
        }
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   298
    }
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   299
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   300
    // Internal method. Returns the value for keys, which can be a sub-section
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   301
    // (as a Hashtable) or final string value(s) (as a Vector). This is the
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   302
    // only method (except for toString) that reads stanzaTable directly.
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   303
    @SuppressWarnings("unchecked")
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   304
    private Object get0(String... keys) {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   305
        Object current = stanzaTable;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   306
        try {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   307
            for (String key: keys) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   308
                current = ((Hashtable<String,Object>)current).get(key);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   309
                if (current == null) return null;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   310
            }
20175
a65ad0a49e3c 8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents: 18168
diff changeset
   311
            return current;
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   312
        } catch (ClassCastException cce) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   313
            throw new IllegalArgumentException(cce);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   314
        }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   315
    }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   316
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   317
    /**
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   318
     * Gets the int value for the specified keys.
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   319
     * @param keys the keys
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   320
     * @return the int value, Integer.MIN_VALUE is returned if it cannot be
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   321
     * found or the value is not a legal integer.
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   322
     * @throw IllegalArgumentException if any of the keys is illegal
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   323
     * @see #get(java.lang.String[])
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   324
     */
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   325
    public int getIntValue(String... keys) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   326
        String result = get(keys);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        int value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                value = parseIntValue(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    System.out.println("Exception in getting value of " +
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   334
                                       Arrays.toString(keys) + " " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                       e.getMessage());
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   336
                    System.out.println("Setting " + Arrays.toString(keys) +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                       " to minimum value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Parses a string to an integer. The convertible strings include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * string representations of positive integers, negative integers, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * hex decimal integers.  Valid inputs are, e.g., -1234, +1234,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * 0x40000.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param input the String to be converted to an Integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return an numeric value represented by the string
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
   353
     * @exception NumberFormatException if the String does not contain a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * parsable integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private int parseIntValue(String input) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (input.startsWith("+")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            String temp = input.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return Integer.parseInt(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        } else if (input.startsWith("0x")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            String temp = input.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            char[] chars = temp.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (chars.length > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                throw new NumberFormatException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                for (int i = 0; i < chars.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    int index = chars.length - i - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    switch (chars[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    case '0':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        value += 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    case '1':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        value += 1 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    case '2':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        value += 2 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    case '3':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        value += 3 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        value += 4 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    case '5':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        value += 5 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    case '6':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        value += 6 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    case '7':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                        value += 7 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    case '8':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        value += 8 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        value += 9 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    case 'a':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    case 'A':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        value += 10 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    case 'b':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    case 'B':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        value += 11 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    case 'c':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        value += 12 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    case 'd':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        value += 13 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    case 'e':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        value += 14 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        value += 15 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        throw new NumberFormatException("Invalid numerical format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (value < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                throw new NumberFormatException("Data overflow.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            value = Integer.parseInt(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private int getBase(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int result = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        switch (i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            result = BASE16_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            result = BASE16_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            result = BASE16_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            result = BASE16_3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            for (int j = 1; j < i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                result *= 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   462
     * Reads the lines of the configuration file. All include and includedir
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   463
     * directives are resolved by calling this method recursively.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   465
     * @param file the krb5.conf file, must be absolute
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   466
     * @param content the lines. Comment and empty lines are removed,
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   467
     *                all lines trimmed, include and includedir
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   468
     *                directives resolved, unknown directives ignored
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   469
     * @param dups a set of Paths to check for possible infinite loop
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   470
     * @throws IOException if there is an I/O error
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   471
     */
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   472
    private static Void readConfigFileLines(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   473
            Path file, List<String> content, Set<Path> dups)
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   474
            throws IOException {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   475
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   476
        if (DEBUG) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   477
            System.out.println("Loading krb5 profile at " + file);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   478
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   479
        if (!file.isAbsolute()) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   480
            throw new IOException("Profile path not absolute");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   481
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   482
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   483
        if (!dups.add(file)) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   484
            throw new IOException("Profile path included more than once");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   485
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   486
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   487
        List<String> lines = Files.readAllLines(file);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   488
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   489
        boolean inDirectives = true;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   490
        for (String line: lines) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   491
            line = line.trim();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   492
            if (line.isEmpty() || line.startsWith("#")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   493
                continue;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   494
            }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   495
            if (inDirectives) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   496
                if (line.charAt(0) == '[') {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   497
                    inDirectives = false;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   498
                    content.add(line);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   499
                } else if (line.startsWith("includedir ")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   500
                    Path dir = Paths.get(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   501
                            line.substring("includedir ".length()).trim());
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   502
                    try (DirectoryStream<Path> files =
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   503
                                 Files.newDirectoryStream(dir)) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   504
                        for (Path p: files) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   505
                            if (Files.isDirectory(p)) continue;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   506
                            String name = p.getFileName().toString();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   507
                            if (name.matches("[a-zA-Z0-9_-]+")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   508
                                // if dir is absolute, so is p
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   509
                                readConfigFileLines(p, content, dups);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   510
                            }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   511
                        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   512
                    }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   513
                } else if (line.startsWith("include ")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   514
                    readConfigFileLines(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   515
                            Paths.get(line.substring("include ".length()).trim()),
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   516
                            content, dups);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   517
                } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   518
                    // Unsupported directives
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   519
                    if (DEBUG) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   520
                        System.out.println("Unknown directive: " + line);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   521
                    }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   522
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   523
            } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   524
                content.add(line);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   525
            }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   526
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   527
        return null;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   528
    }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   529
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   530
    /**
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   531
     * Reads the configuration file and return normalized lines.
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   532
     * If the original file is:
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   533
     *
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   534
     *     [realms]
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   535
     *     EXAMPLE.COM =
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   536
     *     {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   537
     *         kdc = kerberos.example.com
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   538
     *         ...
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   539
     *     }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   540
     *     ...
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   541
     *
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   542
     * The result will be (no indentations):
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   543
     *
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   544
     *     {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   545
     *         realms = {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   546
     *             EXAMPLE.COM = {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   547
     *                 kdc = kerberos.example.com
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   548
     *                 ...
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   549
     *             }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   550
     *         }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   551
     *         ...
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   552
     *     }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   553
     *
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   554
     * @param fileName the configuration file
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   555
     * @return normalized lines
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   557
    private List<String> loadConfigFile(final String fileName)
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   558
            throws IOException, KrbException {
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   559
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   560
        List<String> result = new ArrayList<>();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   561
        List<String> raw = new ArrayList<>();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   562
        Set<Path> dupsCheck = new HashSet<>();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   563
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        try {
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   565
            Path fullp = AccessController.doPrivileged((PrivilegedAction<Path>)
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   566
                        () -> Paths.get(fileName).toAbsolutePath(),
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   567
                    null,
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   568
                    new PropertyPermission("user.dir", "read"));
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   569
            AccessController.doPrivileged(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   570
                    new PrivilegedExceptionAction<Void>() {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   571
                        @Override
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   572
                        public Void run() throws IOException {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   573
                            Path path = Paths.get(fileName);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   574
                            if (!Files.exists(path)) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   575
                                // This is OK. There are other ways to get
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   576
                                // Kerberos 5 settings
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   577
                                return null;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   578
                            } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   579
                                return readConfigFileLines(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   580
                                        fullp, raw, dupsCheck);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   581
                            }
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   582
                        }
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   583
                    },
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   584
                    null,
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   585
                    // include/includedir can go anywhere
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   586
                    new FilePermission("<<ALL FILES>>", "read"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        } catch (java.security.PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            throw (IOException)pe.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   590
        String previous = null;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   591
        for (String line: raw) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   592
            if (line.startsWith("[")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   593
                if (!line.endsWith("]")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   594
                    throw new KrbException("Illegal config content:"
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   595
                            + line);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   596
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   597
                if (previous != null) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   598
                    result.add(previous);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   599
                    result.add("}");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   600
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   601
                String title = line.substring(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   602
                        1, line.length()-1).trim();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   603
                if (title.isEmpty()) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   604
                    throw new KrbException("Illegal config content:"
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   605
                            + line);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   606
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   607
                previous = title + " = {";
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   608
            } else if (line.startsWith("{")) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   609
                if (previous == null) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   610
                    throw new KrbException(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   611
                        "Config file should not start with \"{\"");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   612
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   613
                previous += " {";
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   614
                if (line.length() > 1) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   615
                    // { and content on the same line
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   616
                    result.add(previous);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   617
                    previous = line.substring(1).trim();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   618
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   619
            } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   620
                if (previous == null) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   621
                    // This won't happen, because before a section
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   622
                    // all directives have been resolved
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   623
                    throw new KrbException(
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   624
                        "Config file must starts with a section");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   625
                }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   626
                result.add(previous);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   627
                previous = line;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   628
            }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   629
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   630
        if (previous != null) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   631
            result.add(previous);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   632
            result.add("}");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   633
        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   634
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   638
     * Parses the input lines to a hashtable. The key would be section names
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   639
     * (libdefaults, realms, domain_realms, etc), and the value would be
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   640
     * another hashtable which contains the key-value pairs inside the section.
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   641
     * The value of this sub-hashtable can be another hashtable containing
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   642
     * another sub-sub-section or a non-empty vector of strings for final values
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   643
     * (even if there is only one value defined).
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   644
     * <p>
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   645
     * For top-level sections with duplicates names, their contents are merged.
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   646
     * For sub-sections the former overwrites the latter. For final values,
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   647
     * they are stored in a vector in their appearing order. Please note these
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   648
     * values must appear in the same sub-section. Otherwise, the sub-section
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   649
     * appears first should have already overridden the others.
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   650
     * <p>
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   651
     * As a corner case, if the same name is used as both a section name and a
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   652
     * value name, the first appearance decides the type. That is to say, if the
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   653
     * first one is for a section, all latter appearances are ignored. If it's
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   654
     * a value, latter appearances as sections are ignored, but those as values
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   655
     * are added to the vector.
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   656
     * <p>
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   657
     * The behavior described above is compatible to other krb5 implementations
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   658
     * but it's not decumented publicly anywhere. the best practice is not to
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   659
     * assume any kind of override functionality and only specify values for
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   660
     * a particular key in one place.
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   661
     *
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   662
     * @param v the normalized input as return by loadConfigFile
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   663
     * @throws KrbException if there is a file format error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   665
    @SuppressWarnings("unchecked")
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   666
    private Hashtable<String,Object> parseStanzaTable(List<String> v)
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   667
            throws KrbException {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   668
        Hashtable<String,Object> current = stanzaTable;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   669
        for (String line: v) {
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   670
            // There are only 3 kinds of lines
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   671
            // 1. a = b
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   672
            // 2. a = {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   673
            // 3. }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   674
            if (line.equals("}")) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   675
                // Go back to parent, see below
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   676
                current = (Hashtable<String,Object>)current.remove(" PARENT ");
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   677
                if (current == null) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   678
                    throw new KrbException("Unmatched close brace");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                }
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   680
            } else {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   681
                int pos = line.indexOf('=');
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   682
                if (pos < 0) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   683
                    throw new KrbException("Illegal config content:" + line);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                }
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   685
                String key = line.substring(0, pos).trim();
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   686
                String value = unquote(line.substring(pos + 1));
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   687
                if (value.equals("{")) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   688
                    Hashtable<String,Object> subTable;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   689
                    if (current == stanzaTable) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   690
                        key = key.toLowerCase(Locale.US);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    }
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   692
                    // When there are dup names for sections
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   693
                    if (current.containsKey(key)) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   694
                        if (current == stanzaTable) {   // top-level, merge
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   695
                            // The value at top-level must be another Hashtable
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   696
                            subTable = (Hashtable<String,Object>)current.get(key);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   697
                        } else {                        // otherwise, ignored
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   698
                            // read and ignore it (do not put into current)
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   699
                            subTable = new Hashtable<>();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   700
                        }
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   701
                    } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   702
                        subTable = new Hashtable<>();
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   703
                        current.put(key, subTable);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   704
                    }
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   705
                    // A special entry for its parent. Put whitespaces around,
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   706
                    // so will never be confused with a normal key
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   707
                    subTable.put(" PARENT ", current);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   708
                    current = subTable;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   709
                } else {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   710
                    Vector<String> values;
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   711
                    if (current.containsKey(key)) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   712
                        Object obj = current.get(key);
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   713
                        if (obj instanceof Vector) {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   714
                            // String values are merged
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   715
                            values = (Vector<String>)obj;
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   716
                            values.add(value);
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   717
                        } else {
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   718
                            // If a key shows as section first and then a value,
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   719
                            // ignore the value.
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   720
                        }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   721
                    } else {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   722
                        values = new Vector<String>();
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   723
                        values.add(value);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   724
                        current.put(key, values);
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   725
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   729
        if (current != stanzaTable) {
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   730
            throw new KrbException("Not closed");
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   731
        }
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   732
        return current;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   736
     * Gets the default Java configuration file name.
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   737
     *
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   738
     * If the system property "java.security.krb5.conf" is defined, we'll
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   739
     * use its value, no matter if the file exists or not. Otherwise, we
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   740
     * will look at $JAVA_HOME/lib/security directory with "krb5.conf" name,
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   741
     * and return it if the file exists.
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   742
     *
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   743
     * The method returns null if it cannot find a Java config file.
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   744
     */
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   745
    private String getJavaFileName() {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   746
        String name = getProperty("java.security.krb5.conf");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   747
        if (name == null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   748
            name = getProperty("java.home") + File.separator +
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   749
                                "lib" + File.separator + "security" +
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   750
                                File.separator + "krb5.conf";
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   751
            if (!fileExists(name)) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   752
                name = null;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   753
            }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   754
        }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   755
        if (DEBUG) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   756
            System.out.println("Java config name: " + name);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   757
        }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   758
        return name;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   759
    }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   760
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   761
    /**
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   762
     * Gets the default native configuration file name.
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   763
     *
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   764
     * Depending on the OS type, the method returns the default native
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   765
     * kerberos config file name, which is at windows directory with
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   766
     * the name of "krb5.ini" for Windows, /etc/krb5/krb5.conf for Solaris,
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   767
     * /etc/krb5.conf otherwise. Mac OSX X has a different file name.
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   768
     *
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   769
     * Note: When the Terminal Service is started in Windows (from 2003),
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   770
     * there are two kinds of Windows directories: A system one (say,
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   771
     * C:\Windows), and a user-private one (say, C:\Users\Me\Windows).
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   772
     * We will first look for krb5.ini in the user-private one. If not
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   773
     * found, try the system one instead.
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   774
     *
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   775
     * This method will always return a non-null non-empty file name,
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   776
     * even if that file does not exist.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   778
    private String getNativeFileName() {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   779
        String name = null;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   780
        String osname = getProperty("os.name");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   781
        if (osname.startsWith("Windows")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   782
            try {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   783
                Credentials.ensureLoaded();
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   784
            } catch (Exception e) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   785
                // ignore exceptions
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   786
            }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   787
            if (Credentials.alreadyLoaded) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   788
                String path = getWindowsDirectory(false);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   789
                if (path != null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   790
                    if (path.endsWith("\\")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   791
                        path = path + "krb5.ini";
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   792
                    } else {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   793
                        path = path + "\\krb5.ini";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   795
                    if (fileExists(path)) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   796
                        name = path;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   797
                    }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   798
                }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   799
                if (name == null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   800
                    path = getWindowsDirectory(true);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   801
                    if (path != null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   802
                        if (path.endsWith("\\")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   803
                            path = path + "krb5.ini";
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   804
                        } else {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   805
                            path = path + "\\krb5.ini";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                        }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   807
                        name = path;
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   808
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   811
            if (name == null) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   812
                name = "c:\\winnt\\krb5.ini";
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   813
            }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   814
        } else if (osname.startsWith("SunOS")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   815
            name =  "/etc/krb5/krb5.conf";
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   816
        } else if (osname.contains("OS X")) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   817
            name = findMacosConfigFile();
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   818
        } else {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   819
            name =  "/etc/krb5.conf";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if (DEBUG) {
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   822
            System.out.println("Native config name: " + name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   827
    private static String getProperty(String property) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   828
        return java.security.AccessController.doPrivileged(
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   829
                new sun.security.action.GetPropertyAction(property));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   830
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   831
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   832
    private String findMacosConfigFile() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   833
        String userHome = getProperty("user.home");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   834
        final String PREF_FILE = "/Library/Preferences/edu.mit.Kerberos";
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   835
        String userPrefs = userHome + PREF_FILE;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   836
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   837
        if (fileExists(userPrefs)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   838
            return userPrefs;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   839
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   840
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   841
        if (fileExists(PREF_FILE)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   842
            return PREF_FILE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   843
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   844
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
   845
        return "/etc/krb5.conf";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   846
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10336
diff changeset
   847
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23716
diff changeset
   848
    private static String unquote(String s) {
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   849
        s = s.trim();
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   850
        if (s.isEmpty()) return s;
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   851
        if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   852
                s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\'') {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   853
            s = s.substring(1, s.length()-1).trim();
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   854
        }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   855
        return s;
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   856
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * For testing purpose. This method lists all information being parsed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * the configuration file to the hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public void listTable() {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   863
        System.out.println(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   867
     * Returns all etypes specified in krb5.conf for the given configName,
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   868
     * or all the builtin defaults. This result is always non-empty.
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   869
     * If no etypes are found, an exception is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   871
    public int[] defaultEtype(String configName) throws KrbException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        String default_enctypes;
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   873
        default_enctypes = get("libdefaults", configName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        int[] etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        if (default_enctypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                System.out.println("Using builtin default etypes for " +
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   878
                    configName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            etype = EType.getBuiltInDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        } else {
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   882
            String delim = " ";
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   883
            StringTokenizer st;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            for (int j = 0; j < default_enctypes.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                if (default_enctypes.substring(j, j + 1).equals(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                    // only two delimiters are allowed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    // according to Kerberos DCE doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    delim = ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            st = new StringTokenizer(default_enctypes, delim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            int len = st.countTokens();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   894
            ArrayList<Integer> ls = new ArrayList<>(len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            for (int i = 0; i < len; i++) {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   897
                type = Config.getType(st.nextToken());
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   898
                if (type != -1 && EType.isSupported(type)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    ls.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   902
            if (ls.isEmpty()) {
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   903
                throw new KrbException("no supported default etypes for "
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   904
                        + configName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                etype = new int[ls.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                for (int i = 0; i < etype.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    etype[i] = ls.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (DEBUG) {
18168
f47169155ea0 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679
weijun
parents: 14515
diff changeset
   914
            System.out.print("default etypes for " + configName + ":");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            for (int i = 0; i < etype.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                System.out.print(" " + etype[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            System.out.println(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        return etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * Get the etype and checksum value for the specified encryption and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * checksum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * This method converts the string representation of encryption type and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * checksum type to int value that can be later used by EType and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Checksum classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
   934
    public static int getType(String input) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        int result = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (input == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (input.startsWith("d") || (input.startsWith("D"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            if (input.equalsIgnoreCase("des-cbc-crc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                result = EncryptedData.ETYPE_DES_CBC_CRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            } else if (input.equalsIgnoreCase("des-cbc-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                result = EncryptedData.ETYPE_DES_CBC_MD5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            } else if (input.equalsIgnoreCase("des-mac")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                result = Checksum.CKSUMTYPE_DES_MAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            } else if (input.equalsIgnoreCase("des-mac-k")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                result = Checksum.CKSUMTYPE_DES_MAC_K;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            } else if (input.equalsIgnoreCase("des-cbc-md4")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                result = EncryptedData.ETYPE_DES_CBC_MD4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            } else if (input.equalsIgnoreCase("des3-cbc-sha1") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                input.equalsIgnoreCase("des3-hmac-sha1") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                input.equalsIgnoreCase("des3-cbc-sha1-kd") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                input.equalsIgnoreCase("des3-cbc-hmac-sha1-kd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                result = EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        } else if (input.startsWith("a") || (input.startsWith("A"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            // AES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (input.equalsIgnoreCase("aes128-cts") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                input.equalsIgnoreCase("aes128-cts-hmac-sha1-96")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                result = EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            } else if (input.equalsIgnoreCase("aes256-cts") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                input.equalsIgnoreCase("aes256-cts-hmac-sha1-96")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                result = EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            // ARCFOUR-HMAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            } else if (input.equalsIgnoreCase("arcfour-hmac") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                   input.equalsIgnoreCase("arcfour-hmac-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                result = EncryptedData.ETYPE_ARCFOUR_HMAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        // RC4-HMAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else if (input.equalsIgnoreCase("rc4-hmac")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            result = EncryptedData.ETYPE_ARCFOUR_HMAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        } else if (input.equalsIgnoreCase("CRC32")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            result = Checksum.CKSUMTYPE_CRC32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        } else if (input.startsWith("r") || (input.startsWith("R"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (input.equalsIgnoreCase("rsa-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                result = Checksum.CKSUMTYPE_RSA_MD5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            } else if (input.equalsIgnoreCase("rsa-md5-des")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                result = Checksum.CKSUMTYPE_RSA_MD5_DES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        } else if (input.equalsIgnoreCase("hmac-sha1-des3-kd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            result = Checksum.CKSUMTYPE_HMAC_SHA1_DES3_KD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        } else if (input.equalsIgnoreCase("hmac-sha1-96-aes128")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            result = Checksum.CKSUMTYPE_HMAC_SHA1_96_AES128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        } else if (input.equalsIgnoreCase("hmac-sha1-96-aes256")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            result = Checksum.CKSUMTYPE_HMAC_SHA1_96_AES256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        } else if (input.equalsIgnoreCase("hmac-md5-rc4") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                input.equalsIgnoreCase("hmac-md5-arcfour") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                input.equalsIgnoreCase("hmac-md5-enc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            result = Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        } else if (input.equalsIgnoreCase("NULL")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            result = EncryptedData.ETYPE_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * Resets the default kdc realm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * We do not need to synchronize these methods since assignments are atomic
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1000
     *
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1001
     * This method was useless. Kept here in case some class still calls it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    public void resetDefaultRealm(String realm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        if (DEBUG) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1005
            System.out.println(">>> Config try resetting default kdc " + realm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * Check to use addresses in tickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * use addresses if "no_addresses" or "noaddresses" is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    public boolean useAddresses() {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1014
        return getBooleanObject("libdefaults", "no_addresses") == Boolean.FALSE ||
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1015
                getBooleanObject("libdefaults", "noaddresses") == Boolean.FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1019
     * Check if need to use DNS to locate Kerberos services for name. If not
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1020
     * defined, check dns_fallback, whose default value is true.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
  1022
    private boolean useDNS(String name) {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1023
        Boolean value = getBooleanObject("libdefaults", name);
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1024
        if (value != null) {
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1025
            return value.booleanValue();
93
6266821dc652 6673164: dns_fallback parse error
weijun
parents: 2
diff changeset
  1026
        } else {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 23336
diff changeset
  1027
            return getBooleanObject("libdefaults", "dns_fallback") != Boolean.FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Check if need to use DNS to locate the KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
  1034
    private boolean useDNS_KDC() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        return useDNS("dns_lookup_kdc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * Check if need to use DNS to locate the Realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
  1041
    private boolean useDNS_Realm() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        return useDNS("dns_lookup_realm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * Gets default realm.
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1047
     * @throws KrbException where no realm can be located
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1048
     * @return the default realm, always non null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    public String getDefaultRealm() throws KrbException {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1051
        if (defaultRealm != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1052
            return defaultRealm;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1053
        }
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1054
        Exception cause = null;
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
  1055
        String realm = get("libdefaults", "default_realm");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        if ((realm == null) && useDNS_Realm()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            // use DNS to locate Kerberos realm
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1058
            try {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1059
                realm = getRealmFromDNS();
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1060
            } catch (KrbException ke) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1061
                cause = ke;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1062
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1063
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1064
        if (realm == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1065
            realm = java.security.AccessController.doPrivileged(
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1066
                    new java.security.PrivilegedAction<String>() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1067
                @Override
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1068
                public String run() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1069
                    String osname = System.getProperty("os.name");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1070
                    if (osname.startsWith("Windows")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1071
                        return System.getenv("USERDNSDOMAIN");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1072
                    }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1073
                    return null;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1074
                }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1075
            });
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1076
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1077
        if (realm == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1078
            KrbException ke = new KrbException("Cannot locate default realm");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1079
            if (cause != null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1080
                ke.initCause(cause);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1081
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1082
            throw ke;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        return realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * Returns a list of KDC's with each KDC separated by a space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1090
     * @param realm the realm for which the KDC list is desired
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1091
     * @throws KrbException if there's no way to find KDC for the realm
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1092
     * @return the list of KDCs separated by a space, always non null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    public String getKDCList(String realm) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        if (realm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            realm = getDefaultRealm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1098
        if (realm.equalsIgnoreCase(defaultRealm)) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1099
            return defaultKDC;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1100
        }
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1101
        Exception cause = null;
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 13658
diff changeset
  1102
        String kdcs = getAll("realms", realm, "kdc");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        if ((kdcs == null) && useDNS_KDC()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            // use DNS to locate KDC
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1105
            try {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1106
                kdcs = getKDCFromDNS(realm);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1107
            } catch (KrbException ke) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1108
                cause = ke;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1109
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1110
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1111
        if (kdcs == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1112
            kdcs = java.security.AccessController.doPrivileged(
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1113
                    new java.security.PrivilegedAction<String>() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1114
                @Override
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1115
                public String run() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1116
                    String osname = System.getProperty("os.name");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1117
                    if (osname.startsWith("Windows")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1118
                        String logonServer = System.getenv("LOGONSERVER");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1119
                        if (logonServer != null
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1120
                                && logonServer.startsWith("\\\\")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1121
                            logonServer = logonServer.substring(2);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1122
                        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1123
                        return logonServer;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1124
                    }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1125
                    return null;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1126
                }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1127
            });
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1128
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1129
        if (kdcs == null) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1130
            if (defaultKDC != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1131
                return defaultKDC;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1132
            }
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1133
            KrbException ke = new KrbException("Cannot locate KDC");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1134
            if (cause != null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1135
                ke.initCause(cause);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1136
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1137
            throw ke;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        return kdcs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * Locate Kerberos realm using DNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @return the Kerberos realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    private String getRealmFromDNS() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        // use DNS to locate Kerberos realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        String realm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        String hostName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        try {
1946
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1152
            hostName = InetAddress.getLocalHost().getCanonicalHostName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                "Unable to locate Kerberos realm: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            ke.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            throw (ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        // get the domain realm mapping from the configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        String mapRealm = PrincipalName.mapHostToRealm(hostName);
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1161
        if (mapRealm == null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1162
            // No match. Try search and/or domain in /etc/resolv.conf
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1163
            List<String> srchlist = ResolverConfiguration.open().searchlist();
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1164
            for (String domain: srchlist) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1165
                realm = checkRealm(domain);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1166
                if (realm != null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1167
                    break;
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1168
                }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1169
            }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1170
        } else {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1171
            realm = checkRealm(mapRealm);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1172
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1173
        if (realm == null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1174
            throw new KrbException(Krb5.KRB_ERR_GENERIC,
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1175
                                "Unable to locate Kerberos realm");
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1176
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1177
        return realm;
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1178
    }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1179
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1180
    /**
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1181
     * Check if the provided realm is the correct realm
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1182
     * @return the realm if correct, or null otherwise
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1183
     */
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1184
    private static String checkRealm(String mapRealm) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1185
        if (DEBUG) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1186
            System.out.println("getRealmFromDNS: trying " + mapRealm);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1187
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        String[] records = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        String newRealm = mapRealm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        while ((records == null) && (newRealm != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            // locate DNS TXT record
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            records = KrbServiceLocator.getKerberosService(newRealm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            newRealm = Realm.parseRealmComponent(newRealm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            // if no DNS TXT records found, try again using sub-realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1196
        if (records != null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1197
            for (int i = 0; i < records.length; i++) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1198
                if (records[i].equalsIgnoreCase(mapRealm)) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1199
                    return records[i];
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1200
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1203
        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * Locate KDC using DNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @param realm the realm for which the master KDC is desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @return the KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    private String getKDCFromDNS(String realm) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        // use DNS to locate KDC
14515
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1214
        String kdcs = "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        String[] srvs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        // locate DNS SRV record using UDP
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1217
        if (DEBUG) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1218
            System.out.println("getKDCFromDNS using UDP");
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1219
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1220
        srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        if (srvs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            // locate DNS SRV record using TCP
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1223
            if (DEBUG) {
14515
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1224
                System.out.println("getKDCFromDNS using TCP");
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1225
            }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1226
            srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        if (srvs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            // no DNS SRV records
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            throw new KrbException(Krb5.KRB_ERR_GENERIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                "Unable to locate KDC for realm " + realm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
14515
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1233
        if (srvs.length == 0) {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1234
            return null;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1235
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        for (int i = 0; i < srvs.length; i++) {
14515
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1237
            kdcs += srvs[i].trim() + " ";
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1238
        }
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1239
        kdcs = kdcs.trim();
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1240
        if (kdcs.equals("")) {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents: 14327
diff changeset
  1241
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        return kdcs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1246
    private boolean fileExists(String name) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1247
        return java.security.AccessController.doPrivileged(
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1248
                                new FileExistsAction(name));
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1249
    }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    static class FileExistsAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        implements java.security.PrivilegedAction<Boolean> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        public FileExistsAction(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            return new File(fileName).exists();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1265
    // Shows the content of the Config object for debug purpose.
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1266
    //
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1267
    // {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1268
    //      libdefaults = {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1269
    //          default_realm = R
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1270
    //      }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1271
    //      realms = {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1272
    //          R = {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1273
    //              kdc = [k1,k2]
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1274
    //          }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1275
    //      }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1276
    // }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1277
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1278
    @Override
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1279
    public String toString() {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1280
        StringBuffer sb = new StringBuffer();
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1281
        toStringInternal("", stanzaTable, sb);
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1282
        return sb.toString();
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1283
    }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1284
    private static void toStringInternal(String prefix, Object obj,
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1285
            StringBuffer sb) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1286
        if (obj instanceof String) {
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1287
            // A string value, just print it
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1288
            sb.append(obj).append('\n');
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1289
        } else if (obj instanceof Hashtable) {
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1290
            // A table, start a new sub-section...
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
  1291
            Hashtable<?, ?> tab = (Hashtable<?, ?>)obj;
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1292
            sb.append("{\n");
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1293
            for (Object o: tab.keySet()) {
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1294
                // ...indent, print "key = ", and
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1295
                sb.append(prefix).append("    ").append(o).append(" = ");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1296
                // ...go recursively into value
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1297
                toStringInternal(prefix + "    ", tab.get(o), sb);
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1298
            }
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1299
            sb.append(prefix).append("}\n");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1300
        } else if (obj instanceof Vector) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1301
            // A vector of strings, print them inside [ and ]
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1302
            Vector<?> v = (Vector<?>)obj;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1303
            sb.append("[");
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1304
            boolean first = true;
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1305
            for (Object o: v.toArray()) {
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1306
                if (!first) sb.append(",");
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1307
                sb.append(o);
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1308
                first = false;
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1309
            }
13658
730a11bef766 7184815: [macosx] Need to read Kerberos config in files
weijun
parents: 12538
diff changeset
  1310
            sb.append("]\n");
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1311
        }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1312
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
}