jdk/src/share/classes/sun/security/krb5/Config.java
author jjg
Mon, 15 Aug 2011 11:48:20 -0700
changeset 10336 0bb1999251f8
parent 9499 f3115698a012
child 12047 320a714614e9
permissions -rw-r--r--
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror Reviewed-by: xuelei, mullan Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7977
diff changeset
     2
 * Copyright (c) 2000, 2011, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.UnknownHostException;
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
    45
import java.util.List;
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
    46
import sun.net.dns.ResolverConfiguration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.security.krb5.internal.crypto.EType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.security.krb5.internal.Krb5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * This class maintains key-value pairs of Kerberos configurable constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * from configuration file or from user specified system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class Config {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Only allow a single instance of Config.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Config singleton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Hashtable used to store configuration infomation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private Hashtable<String,Object> stanzaTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // these are used for hexdecimal calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int BASE16_0 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int BASE16_1 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final int BASE16_2 = 16 * 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final int BASE16_3 = 16 * 16 * 16;
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    74
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
     * 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
    77
     */
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    78
    private final String defaultRealm;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    79
    private final String defaultKDC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // used for native interface
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
    82
    private static native String getWindowsDirectory(boolean isSystem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Gets an instance of Config class. One and only one instance (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * singleton) is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @exception KrbException if error occurs when constructing a Config
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    90
     * 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
    91
     * java.security.krb5.kdc not specified, error reading configuration file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static synchronized Config getInstance() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (singleton == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            singleton = new Config();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return singleton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Refresh and reload the Configuration. This could involve,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * for example reading the Configuration file again or getting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * the java.security.krb5.* system properties again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @exception KrbException if error occurs when constructing a Config
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   106
     * 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
   107
     * java.security.krb5.kdc not specified, error reading configuration file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static synchronized void refresh() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        singleton = new Config();
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 6113
diff changeset
   112
        KdcComm.initStatic();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Private constructor - can not be instantiated externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private Config() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        /*
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   121
         * If either one system property is specified, we throw exception.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         */
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   123
        String tmp =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                new sun.security.action.GetPropertyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    ("java.security.krb5.kdc"));
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   127
        if (tmp != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   128
            // 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
   129
            defaultKDC = tmp.replace(':', ' ');
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   130
        } else {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   131
            defaultKDC = null;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   132
        }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   133
        defaultRealm =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                new sun.security.action.GetPropertyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    ("java.security.krb5.realm"));
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   137
        if ((defaultKDC == null && defaultRealm != null) ||
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   138
            (defaultRealm == null && defaultKDC != null)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                ("System property java.security.krb5.kdc and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                 "java.security.krb5.realm both must be set or " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                 "neither must be set.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   144
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   145
        // 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
   146
        try {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   147
            Vector<String> configFile;
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   148
            configFile = loadConfigFile();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   149
            stanzaTable = parseStanzaTable(configFile);
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents: 2587
diff changeset
   150
        } catch (IOException ioe) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   151
            // No krb5.conf, no problem. We'll use DNS or system property etc.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Gets the default int value for the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the default Integer, null is returned if no such name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * value are found in configuration file, or error occurs when parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * string to integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public int getDefaultIntValue(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        String result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        result = getDefault(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                value = parseIntValue(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    System.out.println("Exception in getting value of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                       name + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                       e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    System.out.println("Setting " + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                       " to minimum value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Gets the default int value for the specified name in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * section. <br>This method is quicker by using section name as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * search key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param sectio the name string of the section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the default Integer, null is returned if no such name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * value are found in configuration file, or error occurs when parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * string to integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public int getDefaultIntValue(String name, String section) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        String result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        int value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        result = getDefault(name, section);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                value = parseIntValue(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    System.out.println("Exception in getting value of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                       name +" in section " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                       section + " "  + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    System.out.println("Setting " + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                       " to minimum value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                value = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Gets the default string value for the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @return the default value, null is returned if it cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public String getDefault(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (stanzaTable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return getDefault(name, stanzaTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * This method does the real job to recursively search through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * stanzaTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param k the key string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param t stanzaTable or sub hashtable within it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return the value found in config file, returns null if no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * matched with the key is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   235
    private String getDefault(String k, Hashtable<String, Object> t) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        String result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (stanzaTable != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   239
            for (Enumeration<String> e = t.keys(); e.hasMoreElements(); ) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   240
                key = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                Object ob = t.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (ob instanceof Hashtable) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   243
                    @SuppressWarnings("unchecked") // Checked with an instanceof check
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   244
                    Hashtable<String, Object> table =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   245
                            (Hashtable<String, Object>)ob;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   246
                    result = getDefault(k, table);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                } else if (key.equalsIgnoreCase(k)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    if (ob instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        return (String)(t.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    } else if (ob instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        result = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                        int length = ((Vector)ob).size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                            if (i == length -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                result +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                    (String)(((Vector)ob).elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                result +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                    (String)(((Vector)ob).elementAt(i)) + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Gets the default string value for the specified name in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * specified section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <br>This method is quicker by using the section name as the search key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param section the name of the section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return the default value, null is returned if it cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   281
    // stanzaTable leads to a lot of unchecked casts since its value type is
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   282
    // STANZATABLE = String | Hashtable<String, STANZATABLE>
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   283
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public String getDefault(String name, String section) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        String stanzaName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        String result = null;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   287
        Hashtable<String, Object> subTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (stanzaTable != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   290
            for (Enumeration<String> e = stanzaTable.keys();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   291
                 e.hasMoreElements(); ) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   292
                stanzaName = e.nextElement();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   293
                subTable = (Hashtable<String, Object>)
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   294
                        stanzaTable.get(stanzaName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                if (stanzaName.equalsIgnoreCase(section)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    if (subTable.containsKey(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        return (String)(subTable.get(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                } else if (subTable.containsKey(section)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    Object ob = subTable.get(section);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    if (ob instanceof Hashtable) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   302
                        Hashtable<String, Object> temp =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   303
                                (Hashtable<String, Object>)ob;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        if (temp.containsKey(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                            Object object = temp.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                            if (object instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                result = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                int length = ((Vector)object).size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                    if (i == length - 1)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                        result +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                        (String)(((Vector)object).elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                        result +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                        (String)(((Vector)object).elementAt(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                                + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                result = (String)object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Gets the default boolean value for the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return the default boolean value, false is returned if it cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public boolean getDefaultBooleanValue(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        String val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (stanzaTable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            val = getDefault(name, stanzaTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (val != null && val.equalsIgnoreCase("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Gets the default boolean value for the specified name in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * specified section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <br>This method is quicker by using the section name as the search key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param name the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param section the name of the section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return the default boolean value, false is returned if it cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public boolean getDefaultBooleanValue(String name, String section) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        String val = getDefault(name, section);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (val != null && val.equalsIgnoreCase("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Parses a string to an integer. The convertible strings include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * string representations of positive integers, negative integers, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * hex decimal integers.  Valid inputs are, e.g., -1234, +1234,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * 0x40000.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @param input the String to be converted to an Integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @return an numeric value represented by the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @exception NumberFormationException if the String does not contain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * parsable integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private int parseIntValue(String input) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (input.startsWith("+")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            String temp = input.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return Integer.parseInt(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } else if (input.startsWith("0x")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            String temp = input.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            char[] chars = temp.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (chars.length > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                throw new NumberFormatException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                for (int i = 0; i < chars.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    int index = chars.length - i - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    switch (chars[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    case '0':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        value += 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    case '1':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        value += 1 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    case '2':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        value += 2 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    case '3':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                        value += 3 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        value += 4 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    case '5':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                        value += 5 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    case '6':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        value += 6 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    case '7':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        value += 7 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    case '8':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        value += 8 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        value += 9 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    case 'a':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    case 'A':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        value += 10 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    case 'b':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    case 'B':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        value += 11 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    case 'c':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        value += 12 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    case 'd':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        value += 13 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    case 'e':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        value += 14 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        value += 15 * getBase(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        throw new NumberFormatException("Invalid numerical format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if (value < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                throw new NumberFormatException("Data overflow.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            value = Integer.parseInt(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private int getBase(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        int result = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        switch (i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            result = BASE16_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            result = BASE16_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            result = BASE16_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            result = BASE16_3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            for (int j = 1; j < i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                result *= 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Finds the matching value in the hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private String find(String key1, String key2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        String result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if ((stanzaTable != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            ((result = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                (((Hashtable)(stanzaTable.get(key1))).get(key2))) != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Reads name/value pairs to the memory from the configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * file. The default location of the configuration file is in java home
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Configuration file contains information about the default realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * ticket parameters, location of the KDC and the admin server for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * known realms, etc. The file is divided into sections. Each section
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * contains one or more name/value pairs with one pair per line. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * typical file would be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * [libdefaults]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *          default_realm = EXAMPLE.COM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *          default_tgs_enctypes = des-cbc-md5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *          default_tkt_enctypes = des-cbc-md5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * [realms]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *          EXAMPLE.COM = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *                  kdc = kerberos.example.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *                  kdc = kerberos-1.example.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *                  admin_server = kerberos.example.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *          SAMPLE_COM = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *                  kdc = orange.sample.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *                  admin_server = orange.sample.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * [domain_realm]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *          blue.sample.com = TEST.SAMPLE.COM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *          .backup.com     = EXAMPLE.COM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    private Vector<String> loadConfigFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            final String fileName = getFileName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (!fileName.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                BufferedReader br = new BufferedReader(new InputStreamReader(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                new java.security.PrivilegedExceptionAction<FileInputStream> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                public FileInputStream run() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    return new FileInputStream(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                })));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                String Line;
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   538
                Vector<String> v = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                String previous = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                while ((Line = br.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    // ignore comments and blank line in the configuration file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    // Comments start with #.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    if (!(Line.startsWith("#") || Line.trim().isEmpty())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                        String current = Line.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        // In practice, a subsection might look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        //      EXAMPLE.COM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        //      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        //              kdc = kerberos.example.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        //              ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        //      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        // Before parsed into stanza table, it needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        // converted into formal style:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        //      EXAMPLE.COM = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        //              kdc = kerberos.example.com
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        //              ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        //      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        // So, if a line is "{", adhere to the previous line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        if (current.equals("{")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            if (previous == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                throw new IOException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                    "Config file should not start with \"{\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                            previous += " " + current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                            if (previous != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                v.addElement(previous);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                            previous = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                if (previous != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    v.addElement(previous);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                br.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        } catch (java.security.PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            throw (IOException)pe.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Parses stanza names and values from configuration file to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * stanzaTable (Hashtable). Hashtable key would be stanza names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * (libdefaults, realms, domain_realms, etc), and the hashtable value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * would be another hashtable which contains the key-value pairs under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * a stanza name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    private Hashtable<String,Object> parseStanzaTable(Vector<String> v) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw new KrbException("I/O error while reading" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        " configuration file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   599
        Hashtable<String,Object> table = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        for (int i = 0; i < v.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            String line = v.elementAt(i).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            if (line.equalsIgnoreCase("[realms]")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                for (int count = i + 1; count < v.size() + 1; count++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    // find the next stanza name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    if ((count == v.size()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                        (v.elementAt(count).startsWith("["))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        Hashtable<String,Hashtable<String,Vector<String>>> temp =
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   608
                            new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        temp = parseRealmField(v, i + 1, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                        table.put("realms", temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        i = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            } else if (line.equalsIgnoreCase("[capaths]")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                for (int count = i + 1; count < v.size() + 1; count++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    // find the next stanza name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    if ((count == v.size()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        (v.elementAt(count).startsWith("["))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        Hashtable<String,Hashtable<String,Vector<String>>> temp =
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   621
                            new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        temp = parseRealmField(v, i + 1, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        table.put("capaths", temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                        i = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            } else if (line.startsWith("[") && line.endsWith("]")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                String key = line.substring(1, line.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                for (int count = i + 1; count < v.size() + 1; count++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    // find the next stanza name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    if ((count == v.size()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        (v.elementAt(count).startsWith("["))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                        Hashtable<String,String> temp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                            parseField(v, i + 1, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        table.put(key, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        i = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   647
     * Gets the default configuration file name. This method will never
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   648
     * return null.
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   649
     *
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   650
     * If the system property "java.security.krb5.conf" is defined, we'll
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   651
     * use its value, no matter if the file exists or not. Otherwise,
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   652
     * the file will be searched in a list of possible loations in the
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   653
     * following order:
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   654
     *
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   655
     * 1. at Java home lib\security directory with "krb5.conf" name,
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   656
     * 2. at windows directory with the name of "krb5.ini" for Windows,
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   657
     * /etc/krb5/krb5.conf for Solaris, /etc/krb5.conf otherwise.
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   658
     *
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   659
     * 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
   660
     * 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
   661
     * 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
   662
     * 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
   663
     * found, try the system one instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    private String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        String name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                new sun.security.action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                GetPropertyAction("java.security.krb5.conf"));
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   670
        if (name == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            name = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                        new sun.security.action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                        GetPropertyAction("java.home")) + File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                "lib" + File.separator + "security" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                File.separator + "krb5.conf";
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   676
            if (!fileExists(name)) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   677
                name = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                String osname =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                        new sun.security.action.GetPropertyAction("os.name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                if (osname.startsWith("Windows")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                        Credentials.ensureLoaded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        // ignore exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    if (Credentials.alreadyLoaded) {
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   688
                        String path = getWindowsDirectory(false);
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   689
                        if (path != null) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   690
                            if (path.endsWith("\\")) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   691
                                path = path + "krb5.ini";
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   692
                            } else {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   693
                                path = path + "\\krb5.ini";
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   694
                            }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   695
                            if (fileExists(path)) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   696
                                name = path;
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   697
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                        }
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   699
                        if (name == null) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   700
                            path = getWindowsDirectory(true);
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   701
                            if (path != null) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   702
                                if (path.endsWith("\\")) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   703
                                    path = path + "krb5.ini";
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   704
                                } else {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   705
                                    path = path + "\\krb5.ini";
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   706
                                }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   707
                                name = path;
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   708
                            }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   709
                        }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   710
                    }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   711
                    if (name == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                        name = "c:\\winnt\\krb5.ini";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                } else if (osname.startsWith("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    name =  "/etc/krb5/krb5.conf";
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
   716
                } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    name =  "/etc/krb5.conf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            System.out.println("Config name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   727
    private static String trimmed(String s) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   728
        s = s.trim();
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   729
        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
   730
                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
   731
            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
   732
        }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   733
        return s;
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   734
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * Parses key-value pairs under a stanza name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    private Hashtable<String,String>  parseField(Vector<String> v, int start, int end) {
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   739
        Hashtable<String,String> table = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        for (int i = start; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            line = v.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            for (int j = 0; j < line.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                if (line.charAt(j) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    String key = (line.substring(0, j)).trim();
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   746
                    String value = trimmed(line.substring(j + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    table.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Parses key-value pairs under [realms].  The key would be the realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * name, the value would be another hashtable which contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * information for the realm given within a pair of braces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    private Hashtable<String,Hashtable<String,Vector<String>>> parseRealmField(Vector<String> v, int start, int end) {
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   761
        Hashtable<String,Hashtable<String,Vector<String>>> table = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        for (int i = start; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            line = v.elementAt(i).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (line.endsWith("{")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                String key = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                for (int j = 0; j < line.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    if (line.charAt(j) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        key = line.substring(0, j).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        // get the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                for (int k = i + 1; k < end; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    line = v.elementAt(k).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    for (int l = 0; l < line.length(); l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        if (line.charAt(l) == '}') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                            found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    if (found == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                        Hashtable<String,Vector<String>> temp = parseRealmFieldEx(v, i + 1, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                        table.put(key, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                        i = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * Parses key-value pairs within each braces under [realms].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    private Hashtable<String,Vector<String>> parseRealmFieldEx(Vector<String> v, int start, int end) {
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   801
        Hashtable<String,Vector<String>> table = new Hashtable<>();
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   802
        Vector<String> keyVector = new Vector<>();
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   803
        Vector<String> nameVector = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        String line = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        for (int i = start; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            line = v.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            for (int j = 0; j < line.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                if (line.charAt(j) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    int index;
1236
77c6416750aa 6740833: krb5.conf does not accept kdc=hostname (no spaces around =)
weijun
parents: 715
diff changeset
   811
                    key = line.substring(0, j).trim();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    if (! exists(key, keyVector)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                        keyVector.addElement(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                        nameVector = new Vector<String> ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                        nameVector = table.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    }
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
   818
                    nameVector.addElement(trimmed(line.substring(j + 1)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    table.put(key, nameVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Compares the key with the known keys to see if it exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   830
    private boolean exists(String key, Vector<String> v) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        boolean exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        for (int i = 0; i < v.size(); i++) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   833
            if (v.elementAt(i).equals(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                exists = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        return exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * For testing purpose. This method lists all information being parsed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * the configuration file to the hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    public void listTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        listTable(stanzaTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   848
    // stanzaTable leads to a lot of unchecked casts since its value type is
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   849
    // STANZATABLE = String | Hashtable<String, STANZATABLE>
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   850
    @SuppressWarnings("unchecked")
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   851
    private void listTable(Hashtable<String, Object> table) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   852
        Vector<String> v = new Vector<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (stanzaTable != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   855
            for (Enumeration<String> e = table.keys(); e.hasMoreElements(); ) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   856
                key = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                Object object = table.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                if (table == stanzaTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                    System.out.println("[" + key + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                if (object instanceof Hashtable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                    if (table != stanzaTable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                        System.out.println("\t" + key + " = {");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   864
                    listTable((Hashtable<String, Object>)object);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    if (table != stanzaTable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                        System.out.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                } else if (object instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    System.out.println("\t" + key + " = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                (String)table.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                } else if (object instanceof Vector) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   872
                    v = (Vector<String>)object;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    for (int i = 0; i < v.size(); i++) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   874
                        System.out.println("\t" + key + " = " + v.elementAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            System.out.println("Configuration file not found.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Returns the default encryption types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public int[] defaultEtype(String enctypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        String default_enctypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        default_enctypes = getDefault(enctypes, "libdefaults");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        String delim = " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        StringTokenizer st;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        int[] etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if (default_enctypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                System.out.println("Using builtin default etypes for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    enctypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            etype = EType.getBuiltInDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            for (int j = 0; j < default_enctypes.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                if (default_enctypes.substring(j, j + 1).equals(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    // only two delimiters are allowed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    // according to Kerberos DCE doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    delim = ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            st = new StringTokenizer(default_enctypes, delim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            int len = st.countTokens();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   910
            ArrayList<Integer> ls = new ArrayList<>(len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                type = getType(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                if ((type != -1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                    (EType.isSupported(type))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    ls.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
   919
            if (ls.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                        "no supported default etypes for " + enctypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                etype = new int[ls.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                for (int i = 0; i < etype.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    etype[i] = ls.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            System.out.print("default etypes for " + enctypes + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            for (int i = 0; i < etype.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                System.out.print(" " + etype[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            System.out.println(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        return etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * Get the etype and checksum value for the specified encryption and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * checksum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * This method converts the string representation of encryption type and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * checksum type to int value that can be later used by EType and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * Checksum classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public int getType(String input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        int result = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (input == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (input.startsWith("d") || (input.startsWith("D"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            if (input.equalsIgnoreCase("des-cbc-crc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                result = EncryptedData.ETYPE_DES_CBC_CRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            } else if (input.equalsIgnoreCase("des-cbc-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                result = EncryptedData.ETYPE_DES_CBC_MD5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            } else if (input.equalsIgnoreCase("des-mac")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                result = Checksum.CKSUMTYPE_DES_MAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            } else if (input.equalsIgnoreCase("des-mac-k")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                result = Checksum.CKSUMTYPE_DES_MAC_K;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            } else if (input.equalsIgnoreCase("des-cbc-md4")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                result = EncryptedData.ETYPE_DES_CBC_MD4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            } else if (input.equalsIgnoreCase("des3-cbc-sha1") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                input.equalsIgnoreCase("des3-hmac-sha1") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                input.equalsIgnoreCase("des3-cbc-sha1-kd") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                input.equalsIgnoreCase("des3-cbc-hmac-sha1-kd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                result = EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        } else if (input.startsWith("a") || (input.startsWith("A"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            // AES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            if (input.equalsIgnoreCase("aes128-cts") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                input.equalsIgnoreCase("aes128-cts-hmac-sha1-96")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                result = EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            } else if (input.equalsIgnoreCase("aes256-cts") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                input.equalsIgnoreCase("aes256-cts-hmac-sha1-96")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                result = EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            // ARCFOUR-HMAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            } else if (input.equalsIgnoreCase("arcfour-hmac") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                   input.equalsIgnoreCase("arcfour-hmac-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                result = EncryptedData.ETYPE_ARCFOUR_HMAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        // RC4-HMAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        } else if (input.equalsIgnoreCase("rc4-hmac")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            result = EncryptedData.ETYPE_ARCFOUR_HMAC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        } else if (input.equalsIgnoreCase("CRC32")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            result = Checksum.CKSUMTYPE_CRC32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        } else if (input.startsWith("r") || (input.startsWith("R"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            if (input.equalsIgnoreCase("rsa-md5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                result = Checksum.CKSUMTYPE_RSA_MD5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            } else if (input.equalsIgnoreCase("rsa-md5-des")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                result = Checksum.CKSUMTYPE_RSA_MD5_DES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        } else if (input.equalsIgnoreCase("hmac-sha1-des3-kd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            result = Checksum.CKSUMTYPE_HMAC_SHA1_DES3_KD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        } else if (input.equalsIgnoreCase("hmac-sha1-96-aes128")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            result = Checksum.CKSUMTYPE_HMAC_SHA1_96_AES128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        } else if (input.equalsIgnoreCase("hmac-sha1-96-aes256")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            result = Checksum.CKSUMTYPE_HMAC_SHA1_96_AES256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        } else if (input.equalsIgnoreCase("hmac-md5-rc4") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                input.equalsIgnoreCase("hmac-md5-arcfour") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                input.equalsIgnoreCase("hmac-md5-enc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            result = Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        } else if (input.equalsIgnoreCase("NULL")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            result = EncryptedData.ETYPE_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Resets the default kdc realm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * 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
  1020
     *
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1021
     * This method was useless. Kept here in case some class still calls it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    public void resetDefaultRealm(String realm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        if (DEBUG) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1025
            System.out.println(">>> Config try resetting default kdc " + realm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * Check to use addresses in tickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * use addresses if "no_addresses" or "noaddresses" is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    public boolean useAddresses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        boolean useAddr = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        // use addresses if "no_addresses" is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        String value = getDefault("no_addresses", "libdefaults");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        useAddr = (value != null && value.equalsIgnoreCase("false"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (useAddr == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            // use addresses if "noaddresses" is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            value = getDefault("noaddresses", "libdefaults");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            useAddr = (value != null && value.equalsIgnoreCase("false"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return useAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Check if need to use DNS to locate Kerberos services
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public boolean useDNS(String name) {
93
6266821dc652 6673164: dns_fallback parse error
weijun
parents: 2
diff changeset
  1050
        String value = getDefault(name, "libdefaults");
6266821dc652 6673164: dns_fallback parse error
weijun
parents: 2
diff changeset
  1051
        if (value == null) {
1946
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1052
            value = getDefault("dns_fallback", "libdefaults");
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1053
            if ("false".equalsIgnoreCase(value)) {
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1054
                return false;
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1055
            } else {
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1056
                return true;
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1057
            }
93
6266821dc652 6673164: dns_fallback parse error
weijun
parents: 2
diff changeset
  1058
        } else {
6266821dc652 6673164: dns_fallback parse error
weijun
parents: 2
diff changeset
  1059
            return value.equalsIgnoreCase("true");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * Check if need to use DNS to locate the KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    public boolean useDNS_KDC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        return useDNS("dns_lookup_kdc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * Check if need to use DNS to locate the Realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    public boolean useDNS_Realm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        return useDNS("dns_lookup_realm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * Gets default realm.
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1079
     * @throws KrbException where no realm can be located
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1080
     * @return the default realm, always non null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    public String getDefaultRealm() throws KrbException {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1083
        if (defaultRealm != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1084
            return defaultRealm;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1085
        }
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1086
        Exception cause = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        String realm = getDefault("default_realm", "libdefaults");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if ((realm == null) && useDNS_Realm()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            // use DNS to locate Kerberos realm
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1090
            try {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1091
                realm = getRealmFromDNS();
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1092
            } catch (KrbException ke) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1093
                cause = ke;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1094
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1095
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1096
        if (realm == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1097
            realm = java.security.AccessController.doPrivileged(
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1098
                    new java.security.PrivilegedAction<String>() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1099
                @Override
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1100
                public String run() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1101
                    String osname = System.getProperty("os.name");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1102
                    if (osname.startsWith("Windows")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1103
                        return System.getenv("USERDNSDOMAIN");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1104
                    }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1105
                    return null;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1106
                }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1107
            });
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1108
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1109
        if (realm == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1110
            KrbException ke = new KrbException("Cannot locate default realm");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1111
            if (cause != null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1112
                ke.initCause(cause);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1113
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1114
            throw ke;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        return realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * Returns a list of KDC's with each KDC separated by a space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     *
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1122
     * @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
  1123
     * @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
  1124
     * @return the list of KDCs separated by a space, always non null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    public String getKDCList(String realm) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (realm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            realm = getDefaultRealm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1130
        if (realm.equalsIgnoreCase(defaultRealm)) {
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
        Exception cause = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        String kdcs = getDefault("kdc", realm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        if ((kdcs == null) && useDNS_KDC()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            // use DNS to locate KDC
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1137
            try {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1138
                kdcs = getKDCFromDNS(realm);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1139
            } catch (KrbException ke) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1140
                cause = ke;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1141
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1142
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1143
        if (kdcs == null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1144
            kdcs = java.security.AccessController.doPrivileged(
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1145
                    new java.security.PrivilegedAction<String>() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1146
                @Override
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1147
                public String run() {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1148
                    String osname = System.getProperty("os.name");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1149
                    if (osname.startsWith("Windows")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1150
                        String logonServer = System.getenv("LOGONSERVER");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1151
                        if (logonServer != null
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1152
                                && logonServer.startsWith("\\\\")) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1153
                            logonServer = logonServer.substring(2);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1154
                        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1155
                        return logonServer;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1156
                    }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1157
                    return null;
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1158
                }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1159
            });
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1160
        }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1161
        if (kdcs == null) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1162
            if (defaultKDC != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1163
                return defaultKDC;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
  1164
            }
1947
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1165
            KrbException ke = new KrbException("Cannot locate KDC");
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1166
            if (cause != null) {
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1167
                ke.initCause(cause);
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1168
            }
316d79a73e74 6785456: Read Kerberos setting from Windows environment variables
weijun
parents: 1946
diff changeset
  1169
            throw ke;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        return kdcs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * Locate Kerberos realm using DNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @return the Kerberos realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    private String getRealmFromDNS() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        // use DNS to locate Kerberos realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        String realm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        String hostName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        try {
1946
2e6e15ca4d56 6552334: Enable DNS in Kerberos by default
weijun
parents: 1819
diff changeset
  1184
            hostName = InetAddress.getLocalHost().getCanonicalHostName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                "Unable to locate Kerberos realm: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            ke.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            throw (ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        // get the domain realm mapping from the configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        String mapRealm = PrincipalName.mapHostToRealm(hostName);
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1193
        if (mapRealm == null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1194
            // 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
  1195
            List<String> srchlist = ResolverConfiguration.open().searchlist();
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1196
            for (String domain: srchlist) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1197
                realm = checkRealm(domain);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1198
                if (realm != null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1199
                    break;
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1200
                }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1201
            }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1202
        } else {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1203
            realm = checkRealm(mapRealm);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1204
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1205
        if (realm == null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1206
            throw new KrbException(Krb5.KRB_ERR_GENERIC,
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1207
                                "Unable to locate Kerberos realm");
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1208
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1209
        return realm;
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1210
    }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1211
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1212
    /**
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1213
     * Check if the provided realm is the correct realm
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1214
     * @return the realm if correct, or null otherwise
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1215
     */
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1216
    private static String checkRealm(String mapRealm) {
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("getRealmFromDNS: trying " + mapRealm);
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1219
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        String[] records = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        String newRealm = mapRealm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        while ((records == null) && (newRealm != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            // locate DNS TXT record
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            records = KrbServiceLocator.getKerberosService(newRealm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            newRealm = Realm.parseRealmComponent(newRealm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            // if no DNS TXT records found, try again using sub-realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1228
        if (records != null) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1229
            for (int i = 0; i < records.length; i++) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1230
                if (records[i].equalsIgnoreCase(mapRealm)) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1231
                    return records[i];
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1232
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1235
        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Locate KDC using DNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @param realm the realm for which the master KDC is desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @return the KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    private String getKDCFromDNS(String realm) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        // use DNS to locate KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        String kdcs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        String[] srvs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        // locate DNS SRV record using UDP
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1249
        if (DEBUG) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1250
            System.out.println("getKDCFromDNS using UDP");
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1251
        }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1252
        srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        if (srvs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            // locate DNS SRV record using TCP
6113
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1255
            if (DEBUG) {
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1256
                System.out.println("getKDCFromDNS using UDP");
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1257
            }
6b79a63f1d4b 6969292: make DNS lookup for realm/kdc really work
weijun
parents: 5506
diff changeset
  1258
            srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        if (srvs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            // no DNS SRV records
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            throw new KrbException(Krb5.KRB_ERR_GENERIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                "Unable to locate KDC for realm " + realm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        for (int i = 0; i < srvs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            String value = srvs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            for (int j = 0; j < srvs[i].length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                // filter the KDC name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                if (value.charAt(j) == ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                    kdcs = (value.substring(0, j)).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        return kdcs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
1819
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1277
    private boolean fileExists(String name) {
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1278
        return java.security.AccessController.doPrivileged(
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1279
                                new FileExistsAction(name));
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1280
    }
be60e5317311 6793475: krb5.ini not found on some Windows
weijun
parents: 1236
diff changeset
  1281
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    static class FileExistsAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        implements java.security.PrivilegedAction<Boolean> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        public FileExistsAction(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            return new File(fileName).exists();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1296
    @Override
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1297
    public String toString() {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1298
        StringBuffer sb = new StringBuffer();
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1299
        toStringIndented("", stanzaTable, sb);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1300
        return sb.toString();
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1301
    }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1302
    private static void toStringIndented(String prefix, Object obj,
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1303
            StringBuffer sb) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1304
        if (obj instanceof String) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1305
            sb.append(prefix);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1306
            sb.append(obj);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1307
            sb.append('\n');
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1308
        } else if (obj instanceof Hashtable) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
  1309
            Hashtable<?, ?> tab = (Hashtable<?, ?>)obj;
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1310
            for (Object o: tab.keySet()) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1311
                sb.append(prefix);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1312
                sb.append(o);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1313
                sb.append(" = {\n");
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1314
                toStringIndented(prefix + "    ", tab.get(o), sb);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1315
                sb.append(prefix + "}\n");
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1316
            }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1317
        } else if (obj instanceof Vector) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9499
diff changeset
  1318
            Vector<?> v = (Vector<?>)obj;
2587
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1319
            for (Object o: v.toArray()) {
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1320
                toStringIndented(prefix + "    ", o, sb);
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1321
            }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1322
        }
42fa8d578501 6714845: Quotes in Kerberos configuration file are included in the values
weijun
parents: 1947
diff changeset
  1323
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
}