changeset 7005:4e58dadf5ee8

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
author bchristi
date Tue, 28 Jan 2014 11:19:09 -0800
parents 3bb9483ca099
children 63c5c6443857
files make/common/Defs-macosx.gmk make/java/java/Makefile src/solaris/native/java/lang/java_props_macosx.c src/solaris/native/java/lang/java_props_macosx.h src/solaris/native/java/lang/java_props_md.c
diffstat 5 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/make/common/Defs-macosx.gmk	Fri Aug 02 15:30:11 2013 -0700
+++ b/make/common/Defs-macosx.gmk	Tue Jan 28 11:19:09 2014 -0800
@@ -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
 
 # Use unlimited select
 OTHER_CFLAGS += -D_DARWIN_UNLIMITED_SELECT
--- a/make/java/java/Makefile	Fri Aug 02 15:30:11 2013 -0700
+++ b/make/java/java/Makefile	Tue Jan 28 11:19:09 2014 -0800
@@ -102,6 +102,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
 
 #
@@ -222,6 +223,7 @@
 ifeq ($(PLATFORM), macosx)
 OTHER_LDLIBS += \
         -framework CoreFoundation \
+        -framework Foundation \
         -framework Security \
         -framework SystemConfiguration
 endif
--- a/src/solaris/native/java/lang/java_props_macosx.c	Fri Aug 02 15:30:11 2013 -0700
+++ b/src/solaris/native/java/lang/java_props_macosx.c	Tue Jan 28 11:19:09 2014 -0800
@@ -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"
 
@@ -262,9 +263,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/src/solaris/native/java/lang/java_props_macosx.h	Fri Aug 02 15:30:11 2013 -0700
+++ b/src/solaris/native/java/lang/java_props_macosx.h	Tue Jan 28 11:19:09 2014 -0800
@@ -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/src/solaris/native/java/lang/java_props_md.c	Fri Aug 02 15:30:11 2013 -0700
+++ b/src/solaris/native/java/lang/java_props_md.c	Tue Jan 28 11:19:09 2014 -0800
@@ -546,7 +546,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 */