|  |  |  | @ -19,6 +19,7 @@ | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.*; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | /** | 
			
		
	
		
			
				
					|  |  |  |  |  * | 
			
		
	
		
			
				
					|  |  |  |  |  * @author Emil Ivov | 
			
		
	
		
			
				
					|  |  |  |  |  * @author Lyubomir Marinov | 
			
		
	
		
			
				
					|  |  |  |  |  */ | 
			
		
	
	
		
			
				
					|  |  |  | @ -110,13 +111,13 @@ public void stop(BundleContext 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. | 
			
		
	
		
			
				
					|  |  |  |  |      * Makes home folder and the configuration file readable and writable only | 
			
		
	
		
			
				
					|  |  |  |  |      * to the owner. | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param cs the <tt>ConfigurationService</tt> instance to check for home | 
			
		
	
		
			
				
					|  |  |  |  |      * folder and configuration file. | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     private static void fixPermissions( | 
			
		
	
		
			
				
					|  |  |  |  |         ConfigurationService configurationService) | 
			
		
	
		
			
				
					|  |  |  |  |     private static void fixPermissions(ConfigurationService cs) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         if(!OSUtils.IS_LINUX && !OSUtils.IS_MAC) | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -124,46 +125,50 @@ private static void fixPermissions( | 
			
		
	
		
			
				
					|  |  |  |  |         try | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             // let's check config file and config folder
 | 
			
		
	
		
			
				
					|  |  |  |  |             File homeFolder = new File( | 
			
		
	
		
			
				
					|  |  |  |  |                 configurationService.getScHomeDirLocation(), | 
			
		
	
		
			
				
					|  |  |  |  |                 configurationService.getScHomeDirName()); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             File homeFolder | 
			
		
	
		
			
				
					|  |  |  |  |                 = new File(cs.getScHomeDirLocation(), cs.getScHomeDirName()); | 
			
		
	
		
			
				
					|  |  |  |  |             CLibrary  libc = (CLibrary) Native.loadLibrary("c", CLibrary.class); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             libc.chmod(homeFolder.getAbsolutePath(), 0700); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             String fileName = configurationService.getConfigurationFilename(); | 
			
		
	
		
			
				
					|  |  |  |  |             String fileName = cs.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); | 
			
		
	
		
			
				
					|  |  |  |  |                     "Error creating c lib instance for fixing file permissions", | 
			
		
	
		
			
				
					|  |  |  |  |                     t); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (t instanceof InterruptedException) | 
			
		
	
		
			
				
					|  |  |  |  |                 Thread.currentThread().interrupt(); | 
			
		
	
		
			
				
					|  |  |  |  |             else if (t instanceof ThreadDeath) | 
			
		
	
		
			
				
					|  |  |  |  |                 throw (ThreadDeath) t; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * The jna interface to the c library and the chmod we use | 
			
		
	
		
			
				
					|  |  |  |  |      * to fix permissions of user files. | 
			
		
	
		
			
				
					|  |  |  |  |      * The JNA interface to the <tt>c</tt> library and the <tt>chmod</tt> | 
			
		
	
		
			
				
					|  |  |  |  |      * function we use to fix permissions of user files and folders. | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     public interface CLibrary | 
			
		
	
		
			
				
					|  |  |  |  |         extends Library | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         /** | 
			
		
	
		
			
				
					|  |  |  |  |          * Changes file permissions. | 
			
		
	
		
			
				
					|  |  |  |  |          * @param path the path to file or folder which permissions we will | 
			
		
	
		
			
				
					|  |  |  |  |          *             change. | 
			
		
	
		
			
				
					|  |  |  |  |          * | 
			
		
	
		
			
				
					|  |  |  |  |          * @param path the path to the file or folder the permissions of which | 
			
		
	
		
			
				
					|  |  |  |  |          * are to be changed. | 
			
		
	
		
			
				
					|  |  |  |  |          * @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. | 
			
		
	
		
			
				
					|  |  |  |  |          * @return <tt>0</tt> upon successful completion; otherwise, | 
			
		
	
		
			
				
					|  |  |  |  |          * <tt>-1</tt>. If <tt>-1</tt> is returned, no change to the file mode | 
			
		
	
		
			
				
					|  |  |  |  |          * occurs. | 
			
		
	
		
			
				
					|  |  |  |  |          */ | 
			
		
	
		
			
				
					|  |  |  |  |         public int chmod(String path, int mode); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |