From c7bdaa5539e796e6507b08ff0f87e5c955fb451f Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sat, 14 Jan 2017 17:12:15 +0100 Subject: Use Java 7 instead of JNA to update home dir permissions --- .../impl/configuration/ConfigurationActivator.java | 46 ++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/net/java/sip/communicator/impl/configuration/ConfigurationActivator.java b/src/net/java/sip/communicator/impl/configuration/ConfigurationActivator.java index a019c13..a77b2f5 100644 --- a/src/net/java/sip/communicator/impl/configuration/ConfigurationActivator.java +++ b/src/net/java/sip/communicator/impl/configuration/ConfigurationActivator.java @@ -28,6 +28,9 @@ import org.jitsi.util.*; import org.osgi.framework.*; import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; /** * @@ -138,17 +141,30 @@ public class ConfigurationActivator // let's check config file and config folder File homeFolder = new File(cs.getScHomeDirLocation(), cs.getScHomeDirName()); - CLibrary libc = (CLibrary) Native.loadLibrary("c", CLibrary.class); - - libc.chmod(homeFolder.getAbsolutePath(), 0700); + Set perms = + new HashSet() + {{ + add(PosixFilePermission.OWNER_READ); + add(PosixFilePermission.OWNER_WRITE); + add(PosixFilePermission.OWNER_EXECUTE); + }}; + Files.setPosixFilePermissions( + Paths.get(homeFolder.getAbsolutePath()), perms); String fileName = cs.getConfigurationFilename(); - if(fileName != null) { File cf = new File(homeFolder, fileName); if(cf.exists()) - libc.chmod(cf.getAbsolutePath(), 0600); + { + perms = new HashSet() + {{ + add(PosixFilePermission.OWNER_READ); + add(PosixFilePermission.OWNER_WRITE); + }}; + Files.setPosixFilePermissions( + Paths.get(cf.getAbsolutePath()), perms); + } } } catch(Throwable t) @@ -163,24 +179,4 @@ public class ConfigurationActivator throw (ThreadDeath) t; } } - - /** - * The JNA interface to the c library and the chmod - * function we use to fix permissions of user files and folders. - */ - public interface CLibrary - extends Library - { - /** - * Changes file permissions. - * - * @param path the path to the file or folder the permissions of which - * are to be changed. - * @param mode the mode operand - * @return 0 upon successful completion; otherwise, - * -1. If -1 is returned, no change to the file mode - * occurs. - */ - public int chmod(String path, int mode); - } } -- cgit v1.1