check if the cSploit user can create executable files inside a directory. @param dir directory to check @return true if can execute files into dir, false otherwise
(String dir)
| 137 | * @return true if can execute files into {@code dir}, false otherwise |
| 138 | */ |
| 139 | private boolean user(String dir) { |
| 140 | String tmpname; |
| 141 | File tmpfile = null; |
| 142 | |
| 143 | if(dir==null) |
| 144 | return false; |
| 145 | |
| 146 | tmpfile = new File(dir); |
| 147 | |
| 148 | try { |
| 149 | if(!tmpfile.exists()) |
| 150 | tmpfile.mkdirs(); |
| 151 | |
| 152 | do { |
| 153 | tmpname = UUID.randomUUID().toString(); |
| 154 | } while((tmpfile = new File(dir, tmpname)).exists()); |
| 155 | |
| 156 | tmpfile.createNewFile(); |
| 157 | |
| 158 | return (tmpfile.canExecute() || tmpfile.setExecutable(true, false)); |
| 159 | |
| 160 | } catch (IOException e) { |
| 161 | Logger.warning(String.format("cannot create files over '%s'",dir)); |
| 162 | } finally { |
| 163 | if(tmpfile!=null && tmpfile.exists()) |
| 164 | tmpfile.delete(); |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * check if we can execute binaries in {@code dir} |
no test coverage detected