This commit is contained in:
Mandy Chung 2009-01-20 16:16:35 -08:00
commit 5335a75b1c
5 changed files with 85 additions and 56 deletions

View File

@ -41,10 +41,11 @@ import java.security.PrivilegedExceptionAction;
* one machine to another may be routed differently, and may arrive in * one machine to another may be routed differently, and may arrive in
* any order. * any order.
* *
* <p>UDP broadcasts sends are always enabled on a DatagramSocket. * <p> Where possible, a newly constructed {@code DatagramSocket} has the
* In order to receive broadcast packets a DatagramSocket * {@link SocketOptions#SO_BROADCAST SO_BROADCAST} socket option enabled so as
* should be bound to the wildcard address. In some * to allow the transmission of broadcast datagrams. In order to receive
* implementations, broadcast packets may also be received when * broadcast packets a DatagramSocket should be bound to the wildcard address.
* In some implementations, broadcast packets may also be received when
* a DatagramSocket is bound to a more specific address. * a DatagramSocket is bound to a more specific address.
* <p> * <p>
* Example: * Example:
@ -1017,9 +1018,18 @@ class DatagramSocket implements java.io.Closeable {
/** /**
* Enable/disable SO_BROADCAST. * Enable/disable SO_BROADCAST.
* @param on whether or not to have broadcast turned on. *
* @exception SocketException if there is an error * <p> Some operating systems may require that the Java virtual machine be
* in the underlying protocol, such as an UDP error. * started with implementation specific privileges to enable this option or
* send broadcast datagrams.
*
* @param on
* whether or not to have broadcast turned on.
*
* @throws SocketException
* if there is an error in the underlying protocol, such as an UDP
* error.
*
* @since 1.4 * @since 1.4
* @see #getBroadcast() * @see #getBroadcast()
*/ */

View File

@ -427,7 +427,7 @@ public interface Collection<E> extends Iterable<E> {
* contract for the <tt>Object.hashCode</tt> method, programmers should * contract for the <tt>Object.hashCode</tt> method, programmers should
* take note that any class that overrides the <tt>Object.equals</tt> * take note that any class that overrides the <tt>Object.equals</tt>
* method must also override the <tt>Object.hashCode</tt> method in order * method must also override the <tt>Object.hashCode</tt> method in order
* to satisfy the general contract for the <tt>Object.hashCode</tt>method. * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
* In particular, <tt>c1.equals(c2)</tt> implies that * In particular, <tt>c1.equals(c2)</tt> implies that
* <tt>c1.hashCode()==c2.hashCode()</tt>. * <tt>c1.hashCode()==c2.hashCode()</tt>.
* *

View File

@ -32,7 +32,7 @@ import sun.misc.Unsafe;
* An instance of this class is used to generate a stream of * An instance of this class is used to generate a stream of
* pseudorandom numbers. The class uses a 48-bit seed, which is * pseudorandom numbers. The class uses a 48-bit seed, which is
* modified using a linear congruential formula. (See Donald Knuth, * modified using a linear congruential formula. (See Donald Knuth,
* <i>The Art of Computer Programming, Volume 3</i>, Section 3.2.1.) * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
* <p> * <p>
* If two instances of {@code Random} are created with the same * If two instances of {@code Random} are created with the same
* seed, and the same sequence of method calls is made for each, they * seed, and the same sequence of method calls is made for each, they

View File

@ -1,5 +1,5 @@
/* /*
* Portions Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * Portions Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -74,7 +74,7 @@ public class Config {
private String defaultRealm; // default kdc realm. private String defaultRealm; // default kdc realm.
// used for native interface // used for native interface
private static native String getWindowsDirectory(); private static native String getWindowsDirectory(boolean isSystem);
/** /**
@ -661,38 +661,37 @@ public class Config {
} }
/** /**
* Gets the default configuration file name. The file will be searched * Gets the default configuration file name. This method will never
* in a list of possible loations in the following order: * return null.
* 1. the location and file name defined by system property *
* "java.security.krb5.conf", * If the system property "java.security.krb5.conf" is defined, we'll
* 2. at Java home lib\security directory with "krb5.conf" name, * use its value, no matter if the file exists or not. Otherwise,
* 3. "krb5.ini" at Java home, * the file will be searched in a list of possible loations in the
* 4. at windows directory with the name of "krb5.ini" for Windows, * following order:
* /etc/krb5/krb5.conf for Solaris, /etc/krb5.conf for Linux. *
* 1. at Java home lib\security directory with "krb5.conf" name,
* 2. at windows directory with the name of "krb5.ini" for Windows,
* /etc/krb5/krb5.conf for Solaris, /etc/krb5.conf otherwise.
*
* Note: When the Terminal Service is started in Windows (from 2003),
* there are two kinds of Windows directories: A system one (say,
* C:\Windows), and a user-private one (say, C:\Users\Me\Windows).
* We will first look for krb5.ini in the user-private one. If not
* found, try the system one instead.
*/ */
private String getFileName() { private String getFileName() {
String name = String name =
java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
new sun.security.action. new sun.security.action.
GetPropertyAction("java.security.krb5.conf")); GetPropertyAction("java.security.krb5.conf"));
if (name != null) { if (name == null) {
boolean temp =
java.security.AccessController.doPrivileged(
new FileExistsAction(name));
if (temp)
return name;
} else {
name = java.security.AccessController.doPrivileged( name = java.security.AccessController.doPrivileged(
new sun.security.action. new sun.security.action.
GetPropertyAction("java.home")) + File.separator + GetPropertyAction("java.home")) + File.separator +
"lib" + File.separator + "security" + "lib" + File.separator + "security" +
File.separator + "krb5.conf"; File.separator + "krb5.conf";
boolean temp = if (!fileExists(name)) {
java.security.AccessController.doPrivileged( name = null;
new FileExistsAction(name));
if (temp) {
return name;
} else {
String osname = String osname =
java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("os.name")); new sun.security.action.GetPropertyAction("os.name"));
@ -703,19 +702,35 @@ public class Config {
// ignore exceptions // ignore exceptions
} }
if (Credentials.alreadyLoaded) { if (Credentials.alreadyLoaded) {
if ((name = getWindowsDirectory()) == null) { String path = getWindowsDirectory(false);
name = "c:\\winnt\\krb5.ini"; if (path != null) {
} else if (name.endsWith("\\")) { if (path.endsWith("\\")) {
name += "krb5.ini"; path = path + "krb5.ini";
} else { } else {
name += "\\krb5.ini"; path = path + "\\krb5.ini";
}
if (fileExists(path)) {
name = path;
}
} }
} else { if (name == null) {
path = getWindowsDirectory(true);
if (path != null) {
if (path.endsWith("\\")) {
path = path + "krb5.ini";
} else {
path = path + "\\krb5.ini";
}
name = path;
}
}
}
if (name == null) {
name = "c:\\winnt\\krb5.ini"; name = "c:\\winnt\\krb5.ini";
} }
} else if (osname.startsWith("SunOS")) { } else if (osname.startsWith("SunOS")) {
name = "/etc/krb5/krb5.conf"; name = "/etc/krb5/krb5.conf";
} else if (osname.startsWith("Linux")) { } else {
name = "/etc/krb5.conf"; name = "/etc/krb5.conf";
} }
} }
@ -1171,6 +1186,11 @@ public class Config {
return kdcs; return kdcs;
} }
private boolean fileExists(String name) {
return java.security.AccessController.doPrivileged(
new FileExistsAction(name));
}
static class FileExistsAction static class FileExistsAction
implements java.security.PrivilegedAction<Boolean> { implements java.security.PrivilegedAction<Boolean> {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,7 @@
* have any questions. * have any questions.
*/ */
#define UNICODE
#include <jni.h> #include <jni.h>
#include <windows.h> #include <windows.h>
#include <stdlib.h> #include <stdlib.h>
@ -30,22 +31,20 @@
/* /*
* Class: sun_security_krb5_Config * Class: sun_security_krb5_Config
* Method: getWindowsDirectory * Method: getWindowsDirectory
* Signature: ()Ljava/lang/String; * Signature: (Z)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_sun_security_krb5_Config_getWindowsDirectory( JNIEXPORT jstring JNICALL Java_sun_security_krb5_Config_getWindowsDirectory(
JNIEnv* env, jclass configClass) { JNIEnv* env, jclass configClass, jboolean isSystem) {
LPTSTR lpPath = NULL; TCHAR lpPath[MAX_PATH+1];
UINT uLength ; UINT len;
jstring path = NULL; if (isSystem) {
len = GetSystemWindowsDirectory(lpPath, MAX_PATH);
if (uLength = GetWindowsDirectory(lpPath, 0)) { } else {
lpPath = (LPTSTR)malloc(sizeof(TCHAR) * uLength); len = GetWindowsDirectory(lpPath, MAX_PATH);
if (lpPath != NULL) { }
if (GetWindowsDirectory(lpPath, uLength)) { if (len) {
path = (*env)->NewStringUTF(env, lpPath); return (*env)->NewString(env, lpPath, len);
} } else {
free(lpPath); return NULL;
}
} }
return path;
} }