7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
authorbchristi
Fri, 13 Sep 2013 11:26:44 -0700
changeset 19857 d3a868255edb
parent 19856 5a74ef5d437a
child 19858 7c37f6ac403b
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx] Summary: On MacOS X set user.home to value of NSHomeDirectory() Reviewed-by: alanb, ddehaven, mduigou
jdk/make/common/Defs-macosx.gmk
jdk/make/java/java/Makefile
jdk/makefiles/CompileNativeLibraries.gmk
jdk/src/solaris/native/java/lang/java_props_macosx.c
jdk/src/solaris/native/java/lang/java_props_macosx.h
jdk/src/solaris/native/java/lang/java_props_md.c
--- a/jdk/make/common/Defs-macosx.gmk	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/make/common/Defs-macosx.gmk	Fri Sep 13 11:26:44 2013 -0700
@@ -397,12 +397,10 @@
   INCLUDE_SA = true
 endif
 
-ifdef CROSS_COMPILE_ARCH
-  # X11 headers are not under /usr/include
-  OTHER_CFLAGS += -I$(OPENWIN_HOME)/include
-  OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include
-  OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include
-endif
+# X11 headers are not under /usr/include
+OTHER_CFLAGS += -I$(OPENWIN_HOME)/include
+OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include
+OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include
 
 LIB_LOCATION ?= $(LIBDIR)
 
--- a/jdk/make/java/java/Makefile	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/make/java/java/Makefile	Fri Sep 13 11:26:44 2013 -0700
@@ -105,6 +105,7 @@
 		java/util/prefs/MacOSXPreferencesFactory.java
 
 CFLAGS_$(VARIANT)/java_props_md.o = -Os -x objective-c
+CFLAGS_$(VARIANT)/java_props_macosx.o = -Os -x objective-c
 endif
 
 #
--- a/jdk/makefiles/CompileNativeLibraries.gmk	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/makefiles/CompileNativeLibraries.gmk	Fri Sep 13 11:26:44 2013 -0700
@@ -211,6 +211,7 @@
 	LIBJAVA_EXCLUDE_FILES += java_props_macosx.c
 else
 	BUILD_LIBJAVA_java_props_md.c_CFLAGS:=-x objective-c
+        BUILD_LIBJAVA_java_props_macosx.c_CFLAGS:=-x objective-c
 endif
 
 ifeq ($(OPENJDK_TARGET_OS),windows)
@@ -252,6 +253,7 @@
 		LDFLAGS_SUFFIX_linux:=$(LIBDL) $(BUILD_LIBFDLIBM),\
 		LDFLAGS_SUFFIX_macosx:=-L$(JDK_OUTPUTDIR)/objs/ -lfdlibm \
                                          -framework CoreFoundation \
+                                         -framework Foundation \
                                          -framework Security -framework SystemConfiguration, \
 		LDFLAGS_SUFFIX_windows:=-export:winFileHandleOpen -export:handleLseek \
 					jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \
--- a/jdk/src/solaris/native/java/lang/java_props_macosx.c	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/src/solaris/native/java/lang/java_props_macosx.c	Fri Sep 13 11:26:44 2013 -0700
@@ -31,6 +31,7 @@
 #include <Security/AuthSession.h>
 #include <CoreFoundation/CoreFoundation.h>
 #include <SystemConfiguration/SystemConfiguration.h>
+#include <Foundation/Foundation.h>
 
 #include "java_props_macosx.h"
 
@@ -271,9 +272,20 @@
     return c_exception;
 }
 
+/*
+ * Method for fetching the user.home path and storing it in the property list.
+ * For signed .apps running in the Mac App Sandbox, user.home is set to the
+ * app's sandbox container.
+ */
+void setUserHome(java_props_t *sprops) {
+    if (sprops == NULL) { return; }
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    sprops->user_home = createUTF8CString((CFStringRef)NSHomeDirectory());
+    [pool drain];
+}
 
 /*
- * Method for fetching proxy info and storing it in the propery list.
+ * Method for fetching proxy info and storing it in the property list.
  */
 void setProxyProperties(java_props_t *sProps) {
     if (sProps == NULL) return;
--- a/jdk/src/solaris/native/java/lang/java_props_macosx.h	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/src/solaris/native/java/lang/java_props_macosx.h	Fri Sep 13 11:26:44 2013 -0700
@@ -27,6 +27,7 @@
 
 char *setupMacOSXLocale(int cat);
 void setOSNameAndVersion(java_props_t *sprops);
+void setUserHome(java_props_t *sprops);
 void setProxyProperties(java_props_t *sProps);
 
 enum PreferredToolkit_enum {
--- a/jdk/src/solaris/native/java/lang/java_props_md.c	Fri Sep 13 11:19:13 2013 -0700
+++ b/jdk/src/solaris/native/java/lang/java_props_md.c	Fri Sep 13 11:26:44 2013 -0700
@@ -591,7 +591,14 @@
     {
         struct passwd *pwent = getpwuid(getuid());
         sprops.user_name = pwent ? strdup(pwent->pw_name) : "?";
-        sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?";
+#ifdef MACOSX
+        setUserHome(&sprops);
+#else
+        sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL;
+#endif
+        if (sprops.user_home == NULL) {
+            sprops.user_home = "?";
+        }
     }
 
     /* User TIMEZONE */