@Override public int getEuid() throws NativeAccessException { try { return LIBC.geteuid(); } catch (Throwable exc) { throw new NativeAccessException("Failed to get Euid. " + exc.getLocalizedMessage()); } }
Darwin(NativeUtils nativeUtils) { this.nativeUtils = nativeUtils; try { for (final NativeProcess process : nativeUtils.getMacProcesses()) { try { super.processes.put(process.getPid(), new DarwinProcess(process)); } catch (NativeAccessException exc) { // We may have access permission, skip and get rest of the process logger.warn("Failed to fecth Native Mac Processes", exc.getLocalizedMessage()); } } } catch (NativeAccessException exc) { // Don't fail if the Native Mac access plugin is not installed. logger.warn("Failed to fecth Native Mac Processes", exc.getLocalizedMessage()); } }
if (exc.getMessage().contains("Native Windows Support plugin not installed")) { sendError("Java Native Access support plugin is not installed. It is required to create Windows Service", req, rsp); } else { StringWriter stWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stWriter); exc.printStackTrace(writer); sendError("Native Windows function isDotNetInstalled() failed. " + stWriter.toString(), req, rsp);
@Override protected UserDetails authenticate(String username, String password) throws AuthenticationException { try { Set<String> grps = NativeUtils.getInstance().pamAuthenticate(serviceName, username, password); List<GrantedAuthority> groups = new ArrayList<GrantedAuthority>(); for (String g : grps) { groups.add(new GrantedAuthorityImpl(g)); } groups.add(AUTHENTICATED_AUTHORITY); EnvVars.setHudsonUserEnvVar(username); return new User(username, "", true, true, true, true, groups); } catch (NativeAccessException exc) { throw new BadCredentialsException(exc.getMessage(), exc); } }
if (ze.getCode() == NativeAccessException.PERMISSION) {
@Override public boolean checkUnixGroup(String groupName) throws NativeAccessException { try { return CLibrary.libc.getgrnam(groupName) != null; } catch (Throwable exc) { throw new NativeAccessException("Failed to get Unix Group. " + exc.getLocalizedMessage()); } }
public boolean isRoot() { try { return NativeUtils.getInstance().getEuid() == 0; } catch (NativeAccessException exc) { LOGGER.log(Level.INFO, "Native Support to find EUID failed - {0}", exc.getLocalizedMessage()); return false; } }
private void ensureWindowsSupport(NativeFunction function) throws NativeAccessException { if (!hasWindowsSupport()) { throw new NativeAccessException("Native Windows Support plugin not installed"); } if (!nativeWindowsSupport.hasSupportFor(function)) { throw new NativeAccessException("Installed Native Windows Support plugin does not support " + function); } }
success = NativeUtils.getInstance().createSymlink(targetPathFile.getCanonicalPath(), symlinkFile); } catch (NativeAccessException exc) { errmsg = "Failed to create Symlink using Native Access. " + exc.getLocalizedMessage();
private void ensureMacSupport(NativeFunction function) throws NativeAccessException { if (!hasMacSupport()) { throw new NativeAccessException("Native Mac Support plugin not installed"); } if (!nativeMacSupport.hasSupportFor(function)) { throw new NativeAccessException("Installed Native Mac Support plugin does not support " + function); } }
private void ensureUnixSupport(NativeFunction function) throws NativeAccessException { if (!hasUnixSupport()) { throw new NativeAccessException("Native Unix Support plugin not installed"); } if (!nativeUnixSupport.hasSupportFor(function)) { throw new NativeAccessException("Installed Native Unix Support plugin does not support " + function); } }
private void ensureZfsSupport(NativeFunction function) throws NativeAccessException { if (!hasZfsSupport()) { throw new NativeAccessException("Native ZFS Support plugin not installed"); } if (!nativeZfsSupport.hasSupportFor(function)) { throw new NativeAccessException("Installed Native ZFS Support plugin does not support " + function); } }
@Override public boolean chown(File file, int uid, int gid) { try { return LIBC.chown(file.getPath(), uid, gid) == 0; } catch (Throwable ex) { throw new NativeAccessException("Failed to do chown. " + ex.getLocalizedMessage()); } }
@Override public int getEgid() throws NativeAccessException { try { return LIBC.getegid(); } catch (Throwable exc) { throw new NativeAccessException("Failed to get Egid. " + exc.getLocalizedMessage()); } }
@Override public String getProcessUser() throws NativeAccessException { try { return LIBC.getpwuid(getEuid()).pw_name; } catch (Throwable exc) { throw new NativeAccessException("Failed to get Process User. " + exc.getLocalizedMessage()); } }
@Override public int mode(File file) { try { return PosixAPI.get().stat(file.getPath()).mode(); } catch (Throwable ex) { throw new NativeAccessException("Failed to get File mode. " + ex.getLocalizedMessage()); } }
@Override public boolean chmod(File file, int mask) { try { return LIBC.chmod(file.getAbsolutePath(), mask) == 0; } catch (LinkageError e) { // if JNA is unavailable, fall back. // we still prefer to try JNA first as PosixAPI supports even smaller platforms. try { return PosixAPI.get().chmod(file.getAbsolutePath(), mask) == 0; } catch (Throwable ex) { throw new NativeAccessException("Failed to do chmod. " + ex.getLocalizedMessage()); } } }
@Override public Set<String> pamAuthenticate(String serviceName, String userName, String password) throws NativeAccessException { if (serviceName == null) { serviceName = "sshd"; // use sshd as the default } try { UnixUser unixUser = new PAM(serviceName).authenticate(userName, password); return unixUser.getGroups(); } catch (Throwable exc) { throw new NativeAccessException("Failed to do Pam Authentication. " + exc.getLocalizedMessage()); } }
@Override public NativeSystemMemory getSystemMemory() throws NativeAccessException { try { return new SystemMemoryImpl(MemoryMonitor.get().monitor()); } catch (Throwable exc) { throw new NativeAccessException("Failed to get System Memory. " + exc.getLocalizedMessage()); } }
@Override public boolean makeFileWritable(File file) { try { POSIX posix = PosixAPI.get(); String path = file.getAbsolutePath(); FileStat stat = posix.stat(path); return posix.chmod(path, stat.mode() | 0200) == 0; // u+w } catch (Throwable ex) { throw new NativeAccessException("Failed to make file writable. " + ex.getLocalizedMessage()); } }