public FormValidation doTest() { try { String message = NativeUtils.getInstance().checkPamAuthentication(); if (message.startsWith("Error:")) { return FormValidation.error(message.replaceFirst("Error:", "")); } else { return FormValidation.ok(message); } } catch (NativeAccessException exc) { return FormValidation.error("Native Support for PAM Authentication not available."); } } }
@Override public GroupDetails loadGroupByGroupname(final String groupname) throws UsernameNotFoundException, DataAccessException { try { if (!NativeUtils.getInstance().checkUnixGroup(groupname)) { throw new UsernameNotFoundException("No such Unix group: " + groupname); } } catch (NativeAccessException exc) { throw new DataAccessException("Failed to find Unix Group", exc) { }; } return new GroupDetails() { @Override public String getName() { return groupname; } }; }
/** * Run chmod natively if we can, otherwise fall back to Ant. */ public static void chmod(File f, int mask, boolean tryNative) { if (Functions.isWindows()) { return; // noop } if (tryNative) { try { NativeUtils.getInstance().chmod(f, mask); } catch (NativeAccessException exc) { LOGGER.log(Level.WARNING, "Native function chmod failed ({0}). Using Ant''s chmod task instead.", NativeUtils.getInstance().getLastUnixError()); _chmodAnt(f, mask); } } else { _chmodAnt(f, mask); } }
PrintStream out = listener.getLogger(); int uid = nativeUtils.getEuid(); int gid = nativeUtils.getEgid(); final String userName = nativeUtils.getProcessUser(); NativeZfsFileSystem existing = nativeUtils.getZfsByMountPoint(home); return existing.getName(); List<NativeZfsFileSystem> roots = nativeUtils.getZfsRoots(); String name = computeHudsonFileSystemName(roots.get(0)); out.println("Creating " + name); hudson = nativeUtils.createZfs(name); hudson.setMountPoint(dir); hudson.mount(); if (nativeUtils.chown(dir, uid, gid)) { throw new IOException("Failed to chown " + dir);
/** * Do the Unix style chown (change Owner permission) on a File * * @param file * @param mask * @return true if the function executed successfully * @throws hudson.util.jna.Native.ExecutionError */ public boolean chown(File file, int uid, int gid) throws NativeAccessException { ensureUnixSupport(NativeFunction.CHOWN); return nativeUnixSupport.chown(file, uid, gid); }
success = NativeUtils.getInstance().createSymlink(targetPath, baseDir); } catch (NativeAccessException ex) { errmsg = "Native function mod failed" + NativeUtils.getInstance().getLastUnixError();
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { try { if (!NativeUtils.getInstance().checkUnixUser(username)) { throw new UsernameNotFoundException("No such Unix user: " + username); } } catch (NativeAccessException exc) { throw new DataAccessException("Failed to find Unix User", exc) { }; } // return some dummy instance return new User(username, "", true, true, true, true, new GrantedAuthority[]{AUTHENTICATED_AUTHORITY}); } };
public Void invoke(File f, VirtualChannel channel) throws IOException { try { NativeZfsFileSystem fs = nativeUtils.getZfsByMountPoint(f); if (fs != null) { return null; // already on ZFS } // nope. create a file system String fullName = rootDataset + '/' + name; listener.getLogger().println("Creating a ZFS file system " + fullName + " at " + f); fs = nativeUtils.createZfs(fullName); fs.setMountPoint(f); fs.mount(); } catch (NativeAccessException ex) { Logger.getLogger(ZFSProvisioner.class.getName()).log(Level.SEVERE, null, ex); } return null; } });
@Override public void verifyRestartable() throws RestartNotSupportedException { // see http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg00836.html and // http://factor-language.blogspot.com/2007/07/execve-returning-enotsup-on-mac-os-x.html // on Mac, execv fails with ENOTSUP if the caller is multi-threaded, resulting in an error like // the one described in http://www.nabble.com/Restarting-hudson-not-working-on-MacOS--to24641779.html if (Hudson.isDarwin()) { throw new RestartNotSupportedException("Restart is not supported on Mac OS X"); } else { try { if (!NativeUtils.getInstance().canRestartJavaProcess()) { throw new RestartNotSupportedException("Restart is not supported on this Platform"); } } catch (NativeAccessException exc) { throw new RestartNotSupportedException("Restart is not supported on this Platform"); } } } }
/** * Get the Native processes of a Mac System * * @return * @throws hudson.util.jna.Native.NativeExecutionException */ public List<NativeProcess> getMacProcesses() throws NativeAccessException { ensureMacSupport(NativeFunction.MAC_PROCESS); return nativeMacSupport.getMacProcesses(); }
/** * Get the effective User ID on a Unix System * * @return * @throws hudson.util.jna.Native.ExecutionError */ public int getEuid() throws NativeAccessException { ensureUnixSupport(NativeFunction.EUID); return nativeUnixSupport.getEuid(); }
/** * Get the Unix style mode (file permission) of a file * * @param file * @return * @throws hudson.util.jna.Native.ExecutionError */ public int mode(File file) throws NativeAccessException { ensureUnixSupport(NativeFunction.MODE); return nativeUnixSupport.mode(file); }
/** * Authenticate using Using Unix Pluggable Authentication Modules (PAM) * * @param userName * @param password * @return List<String> list of groups to which this user belongs * @throws hudson.util.jna.Native.NativeExecutionException */ public Set<String> pamAuthenticate(String serviceName, String userName, String password) throws NativeAccessException { ensureUnixSupport(NativeFunction.PAM); return nativeUnixSupport.pamAuthenticate(serviceName, userName, password); }
/** * Get the name of the user who started this Java process * * @return * @throws hudson.util.jna.Native.NativeExecutionException */ public String getProcessUser() throws NativeAccessException { ensureUnixSupport(NativeFunction.UNIX_USER); return nativeUnixSupport.getProcessUser(); }
/** * Make the file writable with native operation * * @param file * @return true if the operation is successful * @throws hudson.util.jna.Native.ExecutionError */ public boolean makeFileWritable(File file) throws NativeAccessException { ensureUnixSupport(NativeFunction.FILE_WRITABLE); return nativeUnixSupport.makeFileWritable(file); }
/** * Get the information about the System Memory * * @return * @throws hudson.util.jna.Native.ExecutionError */ public NativeSystemMemory getSystemMemory() throws NativeAccessException { ensureUnixSupport(NativeFunction.SYSTEM_MEMORY); return nativeUnixSupport.getSystemMemory(); }
/** * Check if PAM Authentication available in the machine where this program * runs * * @return Message corresponding to the availability of PAM * @throws hudson.util.jna.Native.NativeExecutionException */ public String checkPamAuthentication() throws NativeAccessException { ensureUnixSupport(NativeFunction.PAM); return nativeUnixSupport.checkPamAuthentication(); }
/** * Resolves symlink, if the given file is a symlink on a Unix System. * Otherwise return null. * * @param targetPath * @param file * @return String the resolved file path * @throws hudson.util.jna.Native.ExecutionError */ public String resolveSymlink(File file) throws NativeAccessException { ensureUnixSupport(NativeFunction.RESOLVE_LINK); return nativeUnixSupport.resolveSymlink(file); }
/** * Check if this Unix user exists on the machine where this program runs * * @param userName * @return * @throws hudson.util.jna.Native.NativeExecutionException */ public boolean checkUnixUser(String userName) throws NativeAccessException { ensureUnixSupport(NativeFunction.UNIX_USER); return nativeUnixSupport.checkUnixUser(userName); }
/** * Restart current Java process (JVM in which this application is running) * * @throws hudson.util.jna.Native.NativeExecutionException */ public void restartJavaProcess(Map<String, String> properties, boolean asDaemon) throws NativeAccessException { ensureUnixSupport(NativeFunction.JAVA_RESTART); nativeUnixSupport.restartJavaProcess(properties, asDaemon); }