transaction: Never return Transaction as error

While transaction does implement error, it's not a valid error
implementer because it may have bogous values since it's not thread-safe
and so we may read the result of Error() when it's into an invalid state

As per this never return it as an error, while always return the Status
unless when not available, where we still return pam.Error.
This commit is contained in:
Marco Trevisan (Treviño)
2023-10-11 12:16:59 +02:00
parent 911a346a00
commit adffdfbbdc
2 changed files with 22 additions and 19 deletions

View File

@@ -22,7 +22,6 @@ package pam
import "C"
import (
"errors"
"fmt"
"runtime"
"runtime/cgo"
@@ -146,8 +145,8 @@ func transactionFinalizer(t *Transaction) {
// Allows to call pam functions managing return status
func (t *Transaction) handlePamStatus(cStatus C.int) error {
t.lastStatus.Store(int32(cStatus))
if cStatus != success {
return t
if status := Error(cStatus); status != success {
return status
}
return nil
}
@@ -213,7 +212,7 @@ func start(service, user string, handler ConversationHandler, confDir string) (*
err = t.handlePamStatus(C.pam_start_confdir(s, u, t.conv, c, &t.handle))
}
if err != nil {
return nil, errors.Join(Error(t.lastStatus.Load()), err)
return nil, err
}
return t, nil
}
@@ -365,7 +364,7 @@ func (t *Transaction) GetEnvList() (map[string]string, error) {
p := C.pam_getenvlist(t.handle)
if p == nil {
t.lastStatus.Store(int32(ErrBuf))
return nil, t
return nil, ErrBuf
}
t.lastStatus.Store(success)
for q := p; *q != nil; q = next(q) {