/** * Performs an early disposal of the object, instead of letting this GC-ed. * Since PAM may hold on to native resources that don't put pressure on Java GC, * doing this is a good idea. * * <p> * This method is called by {@link #finalize()}, too, so it's not required * to call this method explicitly, however. */ public void dispose() { if(pht!=null) { libpam.pam_end(pht,ret); pht=null; } }
/** * Authenticate the user with a password. * * @return * Upon a successful authentication, return information about the user. * @throws PAMException * If the authentication fails. */ public UnixUser authenticate(String username, String password) throws PAMException { this.password = password; try { check(libpam.pam_set_item(pht,PAM_USER,username),"pam_set_item failed"); check(libpam.pam_authenticate(pht,0),"pam_authenticate failed"); check(libpam.pam_setcred(pht,0),"pam_setcred failed"); // several different error code seem to be used to represent authentication failures check(libpam.pam_acct_mgmt(pht,0),"pam_acct_mgmt failed"); PointerByReference r = new PointerByReference(); check(libpam.pam_get_item(pht,PAM_USER,r),"pam_get_item failed"); String userName = r.getValue().getString(0); passwd pwd = libc.getpwnam(userName); if(pwd==null) throw new PAMException("Authentication succeeded but no user information is available"); return new UnixUser(userName,pwd); } finally { this.password = null; } }
/** * Authenticate the user with a password. * * @return * Upon a successful authentication, return information about the user. * @throws PAMException * If the authentication fails. */ public UnixUser authenticate(String username, String password) throws PAMException { this.password = password; try { check(libpam.pam_set_item(pht,PAM_USER,username),"pam_set_item failed"); check(libpam.pam_authenticate(pht,0),"pam_authenticate failed"); // several different error code seem to be used to represent authentication failures // check(libpam.pam_acct_mgmt(pht,0),"pam_acct_mgmt failed"); PointerByReference r = new PointerByReference(); check(libpam.pam_get_item(pht,PAM_USER,r),"pam_get_item failed"); String userName = r.getValue().getString(0); passwd pwd = libc.getpwnam(userName); if(pwd==null) throw new PAMException("Authentication succeeded but no user information is available"); return new UnixUser(userName,pwd); } finally { this.password = null; } }
private void check(int ret, String msg) throws PAMException { this.ret = ret; if(ret!=0) { if(pht!=null) throw new PAMException(msg+" : "+libpam.pam_strerror(pht,ret)); else throw new PAMException(msg); } }
check(libpam.pam_start(serviceName,null,conv,phtr), "pam_start failed"); pht = new pam_handle_t(phtr.getValue());
/** * Authenticate the user with a password. * * @return * Upon a successful authentication, return information about the user. * @throws PAMException * If the authentication fails. */ public UnixUser authenticate(String username, String password) throws PAMException { this.password = password; try { check(libpam.pam_set_item(pht,PAM_USER,username),"pam_set_item failed"); check(libpam.pam_authenticate(pht,0),"pam_authenticate failed"); check(libpam.pam_setcred(pht,0),"pam_setcred failed"); // several different error code seem to be used to represent authentication failures // check(libpam.pam_acct_mgmt(pht,0),"pam_acct_mgmt failed"); PointerByReference r = new PointerByReference(); check(libpam.pam_get_item(pht,PAM_USER,r),"pam_get_item failed"); String userName = r.getValue().getString(0); Passwd pwd = libc.getpwnam(userName); if(pwd==null) throw new PAMException("Authentication succeeded but no user information is available"); return new UnixUser(userName,pwd); } finally { this.password = null; } }
private void check(int ret, String msg) throws PAMException { this.ret = ret; if(ret!=0) { if(pht!=null) throw new PAMException(msg+" : "+libpam.pam_strerror(pht,ret)); else throw new PAMException(msg); } }
check(libpam.pam_start(serviceName,null,conv,phtr), "pam_start failed"); pht = new pam_handle_t(phtr.getValue());
private void check(int ret, String msg) throws PAMException { this.ret = ret; if(ret!=0) { if(pht!=null) throw new PAMException(msg+" : "+libpam.pam_strerror(pht,ret)); else throw new PAMException(msg); } }
/** * Performs an early disposal of the object, instead of letting this GC-ed. * Since PAM may hold on to native resources that don't put pressure on Java GC, * doing this is a good idea. * * <p> * This method is called by {@link #finalize()}, too, so it's not required * to call this method explicitly, however. */ public void dispose() { if(pht!=null) { libpam.pam_end(pht,ret); pht=null; } }
check(libpam.pam_start(serviceName,null,conv,phtr), "pam_start failed"); pht = new pam_handle_t(phtr.getValue());
/** * Performs an early disposal of the object, instead of letting this GC-ed. * Since PAM may hold on to native resources that don't put pressure on Java GC, * doing this is a good idea. * * <p> * This method is called by {@link #finalize()}, too, so it's not required * to call this method explicitly, however. */ public void dispose() { if(pht!=null) { libpam.pam_end(pht,ret); pht=null; } }