Checks and fixes permissions of home folder and config file to be editable and writable only to the owner when using macosx or linux.

cusax-fix
Damian Minkov 13 years ago
parent f7f58da220
commit f2ae4c2e5d

@ -6,10 +6,14 @@
*/
package net.java.sip.communicator.impl.configuration;
import com.sun.jna.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.libjitsi.*;
import org.jitsi.util.*;
import org.osgi.framework.*;
import java.io.*;
/**
* @author Emil Ivov
* @author Lyubomir Marinov
@ -17,6 +21,13 @@
public class ConfigurationActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>ConfigurationActivator</tt> class
* for logging output.
*/
private static final Logger logger
= Logger.getLogger(ConfigurationActivator.class);
/**
* The <tt>BundleContext</tt> in which the configuration bundle has been
* started and has not been stopped yet.
@ -44,6 +55,8 @@ public void start(BundleContext bundleContext)
ConfigurationService.class.getName(),
configurationService,
null);
fixPermissions(configurationService);
}
}
@ -72,4 +85,63 @@ public static BundleContext getBundleContext()
{
return bundleContext;
}
/**
* Makes home folder and the configuration file readable and writable
* only to the owner.
* @param configurationService the config service instance to check
* for home folder and name.
*/
private static void fixPermissions(
ConfigurationService configurationService)
{
if(!OSUtils.IS_LINUX && !OSUtils.IS_MAC)
return;
try
{
// let's check config file and config folder
File homeFolder = new File(
configurationService.getScHomeDirLocation(),
configurationService.getScHomeDirName());
CLibrary libc = (CLibrary) Native.loadLibrary("c", CLibrary.class);
libc.chmod(homeFolder.getAbsolutePath(), 0700);
String fileName = configurationService.getConfigurationFilename();
if(fileName != null)
{
File cf = new File(homeFolder, fileName);
if(cf.exists())
{
libc.chmod(cf.getAbsolutePath(), 0600);
}
}
}
catch(Throwable t)
{
logger.error(
"Error creating c lib instance for fixing file permissions", t);
}
}
/**
* The jna interface to the c library and the chmod we use
* to fix permissions of user files.
*/
public interface CLibrary
extends Library
{
/**
* Changes file permissions.
* @param path the path to file or folder which permissions we will
* change.
* @param mode the mode operand
* @return 0 shall be returned upon successful completion;
* otherwise, -1 shall be returned. If -1 is returned,
* no change to the file mode occurs.
*/
public int chmod(String path, int mode);
}
}

@ -6,4 +6,6 @@ Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.jitsi.service.configuration,
org.jitsi.service.libjitsi,
org.jitsi.util,
com.sun.jna,
org.osgi.framework

Loading…
Cancel
Save