Skip to content

Commit

Permalink
fix some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zunda-arrow committed Jun 1, 2024
1 parent ea5335b commit 7c07f6b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions login/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ func Authenticate(username string, password string, session config.Session, set_
ret := C.pam_start(serviceStr, usernameStr, &conv, &handle)

if ret != C.PAM_SUCCESS {
return errors.New("Could not start pam session.")
return errors.New("Could not start pam session: " + pamReason(ret))
}
}

{
ret := C.pam_authenticate(handle, 0)
if ret != C.PAM_SUCCESS {
return errors.New("Could not authenticate user.")
return errors.New("Could not authenticate user: " + pamReason(ret))
}
}

{
ret := C.pam_acct_mgmt(handle, 0)
if ret != C.PAM_SUCCESS {
return errors.New("Account is not valid.")
return errors.New("Account is not valid: " + pamReason(ret))
}
}

Expand All @@ -79,7 +79,7 @@ func Authenticate(username string, password string, session config.Session, set_
{
ret := C.pam_setcred(handle, C.PAM_ESTABLISH_CRED)
if ret != C.PAM_SUCCESS {
return errors.New("pam_setcred")
return errors.New("pam_setcred: " + pamReason(ret))
}
}

Expand All @@ -89,9 +89,8 @@ func Authenticate(username string, password string, session config.Session, set_
// Silenced to hide the distro's login message
ret := C.pam_open_session(handle, 1)
if ret != C.PAM_SUCCESS {
fmt.Println("There was an error opening the session." + pamReason(ret))
C.pam_setcred(handle, C.PAM_DELETE_CRED)
return errors.New("pam_open_session " + pamReason(ret))
return errors.New("pam_open_session: " + pamReason(ret))
}
fmt.Println("Session opened successfully.")
}
Expand Down

0 comments on commit 7c07f6b

Please sign in to comment.