1 21 package org.jsmtpd.tools.rights; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 36 public class UnixChown implements IChown { 37 private Log log = LogFactory.getLog(UnixChown.class); 38 39 public void chown(String file, String user) throws RightException { 40 String [] args = new String [3]; 41 args[0] = "chown"; 42 args[1] = user; 43 args[2] = file; 44 if (file.contains("..")) 45 throw new RightException("There is a .. in the file path."); 46 try { 47 Process child = Runtime.getRuntime().exec(args); 48 child.waitFor(); 49 int ret = child.exitValue(); 50 if (ret!=0) 51 throw new RightException ("Could not perform chown "+user+" "+file); 52 } catch (Exception e) { 53 throw new RightException (e); 54 } 55 log.debug("Performed chown "+user+" "+file); 56 } 57 58 public void recursiveChown(String file, String user) throws RightException { 59 String [] args = new String [4]; 60 args[0] = "chown"; 61 args[1] ="-R"; 62 args[2] = user; 63 args[3] = file; 64 if (file.contains("..")) 65 throw new RightException("There is a .. in the file path."); 66 try { 67 Process child = Runtime.getRuntime().exec(args); 68 child.waitFor(); 69 int ret = child.exitValue(); 70 if (ret!=0) 71 throw new RightException ("Could not perform chown "+user+" "+file); 72 } catch (Exception e) { 73 throw new RightException (e); 74 } 75 log.debug("Performed chown -R "+user+" "+file); 76 } 77 78 } 79 | Popular Tags |