@@ -1662,7 +1662,7 @@ protected ForOpenJ9(Socket socket) {
1662
1662
public static VirtualMachine attach (String processId ) throws IOException {
1663
1663
return attach (processId , 5000 , Platform .isWindows ()
1664
1664
? new Dispatcher .ForJnaWindowsEnvironment ()
1665
- : new Dispatcher .ForJnaPosixEnvironment (15 , 100 , TimeUnit .MILLISECONDS ), ignoreUser );
1665
+ : new Dispatcher .ForJnaPosixEnvironment (15 , 100 , TimeUnit .MILLISECONDS ));
1666
1666
}
1667
1667
1668
1668
/**
@@ -1692,7 +1692,7 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
1692
1692
}
1693
1693
virtualMachines = new ArrayList <Properties >();
1694
1694
for (File aVmFolder : vmFolder ) {
1695
- if (aVmFolder .isDirectory () && isFileOwnedByUid ( dispatcher , aVmFolder , userId )) {
1695
+ if (aVmFolder .isDirectory () && ( userId == 0L || dispatcher . getOwnerIdOf ( aVmFolder ) == userId )) {
1696
1696
File attachInfo = new File (aVmFolder , "attachInfo" );
1697
1697
if (attachInfo .isFile ()) {
1698
1698
Properties virtualMachine = new Properties ();
@@ -1703,7 +1703,12 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
1703
1703
inputStream .close ();
1704
1704
}
1705
1705
int targetProcessId = Integer .parseInt (virtualMachine .getProperty ("processId" ));
1706
- long targetUserId = getUserId (virtualMachine );
1706
+ long targetUserId ;
1707
+ try {
1708
+ targetUserId = Long .parseLong (virtualMachine .getProperty ("userUid" ));
1709
+ } catch (NumberFormatException ignored ) {
1710
+ targetUserId = 0L ;
1711
+ }
1707
1712
if (userId != 0L && targetUserId == 0L ) {
1708
1713
targetUserId = dispatcher .getOwnerIdOf (attachInfo );
1709
1714
}
@@ -1750,13 +1755,18 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
1750
1755
key = Long .toHexString (SECURE_RANDOM .nextLong ());
1751
1756
}
1752
1757
File reply = new File (receiver , "replyInfo" );
1753
- long targetUserId = getUserId (target );
1758
+ long targetUserId ;
1759
+ try {
1760
+ targetUserId = Long .parseLong (target .getProperty ("userUid" ));
1761
+ } catch (NumberFormatException ignored ) {
1762
+ targetUserId = 0L ;
1763
+ }
1754
1764
try {
1755
1765
if (reply .createNewFile ()) {
1756
1766
dispatcher .setPermissions (reply , 0600 );
1757
1767
}
1758
- if (0 == userId && 0 != targetUserId ) {
1759
- dispatcher .chownFileToTargetUid (reply , targetUserId );
1768
+ if (userId == 0L && targetUserId != 0L ) {
1769
+ dispatcher .chownFileToUser (reply , targetUserId );
1760
1770
}
1761
1771
FileOutputStream outputStream = new FileOutputStream (reply );
1762
1772
try {
@@ -1839,31 +1849,6 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
1839
1849
}
1840
1850
}
1841
1851
1842
- /**
1843
- * Returns the userUid present in the virtualMachine properties file
1844
- * @param virtualMachine Properties of the J9 attachInfo file
1845
- * @return the userUid if it can be parsed, <code>0L</code> otherwise.
1846
- */
1847
- private static long getUserId (Properties virtualMachine ) {
1848
- long targetUserId ;
1849
- try {
1850
- targetUserId = Long .parseLong (virtualMachine .getProperty ("userUid" ));
1851
- } catch (NumberFormatException ignored ) {
1852
- targetUserId = 0L ;
1853
- }
1854
- return targetUserId ;
1855
- }
1856
-
1857
- /**
1858
- * Check if the file is owned by the UID. Note that UID 0 "owns" all files.
1859
- * @param aVmFolder File or directory
1860
- * @param userId user UID.
1861
- * @return true if the uid owns the file or uid == 0.
1862
- */
1863
- private static boolean isFileOwnedByUid (Dispatcher dispatcher , File aVmFolder , long userId ) {
1864
- return 0 == userId || dispatcher .getOwnerIdOf (aVmFolder ) == userId ;
1865
- }
1866
-
1867
1852
/**
1868
1853
* {@inheritDoc}
1869
1854
*/
@@ -2075,11 +2060,12 @@ public interface Dispatcher {
2075
2060
void decrementSemaphore (File directory , String name , boolean global , int count );
2076
2061
2077
2062
/**
2078
- * change the ownership of a file. Can be called only if this process is owned by root.
2079
- * @param path path to the file
2080
- * @param targetUserId effective userid
2063
+ * Changes the ownership of a file. Can be called only if this process is owned by root.
2064
+ *
2065
+ * @param file The path of the file to change ownership of.
2066
+ * @param userId The user that should own the file.
2081
2067
*/
2082
- void chownFileToTargetUid (File path , long targetUserId );
2068
+ void chownFileToUser (File file , long userId );
2083
2069
2084
2070
/**
2085
2071
* A connector implementation for a POSIX environment using JNA.
@@ -2221,9 +2207,8 @@ public void decrementSemaphore(File directory, String name, boolean global, int
2221
2207
/**
2222
2208
* {@inheritDoc}
2223
2209
*/
2224
- @ Override
2225
- public void chownFileToTargetUid (File file , long targetUserId ) {
2226
- library .chown (file .getAbsolutePath (), targetUserId );
2210
+ public void chownFileToUser (File file , long userId ) {
2211
+ library .chown (file .getAbsolutePath (), userId );
2227
2212
}
2228
2213
2229
2214
/**
@@ -2334,12 +2319,12 @@ protected interface PosixLibrary extends Library {
2334
2319
/**
2335
2320
* Runs the {@code chown} command.
2336
2321
*
2337
- * @param path The file path.
2338
- * @param uid The userid to set.
2322
+ * @param path The file path.
2323
+ * @param userId The user id to set.
2339
2324
* @return The return code.
2340
2325
* @throws LastErrorException If an error occurred.
2341
2326
*/
2342
- int chown (String path , long uid ) throws LastErrorException ;
2327
+ int chown (String path , long userId ) throws LastErrorException ;
2343
2328
2344
2329
/**
2345
2330
* Runs the {@code ftok} command.
@@ -2527,8 +2512,7 @@ public void decrementSemaphore(File directory, String name, boolean global, int
2527
2512
/**
2528
2513
* {@inheritDoc}
2529
2514
*/
2530
- @ Override
2531
- public void chownFileToTargetUid (File path , long targetUserId ) {
2515
+ public void chownFileToUser (File file , long userId ) {
2532
2516
/* do nothing */
2533
2517
}
2534
2518
0 commit comments