-
Notifications
You must be signed in to change notification settings - Fork 38
Safer transaction: add End() method and don't use as error #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
44c364e
ci: Use golang-ci linter
3v1n0 6bb315c
transaction: Add PAM Error types Go definitions
3v1n0 ea51cc0
transaction: Add tests for all the possible Status (and error) values
3v1n0 a5f5ad6
transaction: Return errors wrapping pam.Error values on failure
3v1n0 3e4f7f5
transaction: Add an helper function to handle pam functions return st…
3v1n0 911a346
transaction: Use Atomic to store/load the status
3v1n0 adffdfb
transaction: Never return Transaction as error
3v1n0 7162004
transaction: Do not make Transaction to implement error interface any…
3v1n0 c635cfc
transaction: Add End() method and Remove Transaction finalizer
3v1n0 c7ecbf2
transaction: Add a test finalizer checking if transaction has ended
3v1n0 fe75bba
transaction: Mark Item, Flags and Style const values as Item, Flags a…
3v1n0 31a452a
transaction: Add missing default PAM item types
3v1n0 01f62f1
transaction_test: Add tests checking the loaded services match
3v1n0 e6f8173
transaction: Skip some tests requiring confdir if not available
3v1n0 067f634
transaction: Fix comment typo
3v1n0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| on: [push, pull_request] | ||
| name: Lint | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| golangci: | ||
| name: lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '1.21' | ||
| cache: false | ||
| - name: Install PAM | ||
| run: sudo apt install -y libpam-dev | ||
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v3 | ||
| with: | ||
| version: v1.54 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # This is for linting. To run it, please use: | ||
| # golangci-lint run ${MODULE}/... [--fix] | ||
|
|
||
| linters: | ||
| # linters to run in addition to default ones | ||
| enable: | ||
| - dupl | ||
| - durationcheck | ||
| - errname | ||
| - errorlint | ||
| - exportloopref | ||
| - forbidigo | ||
| - forcetypeassert | ||
| - gci | ||
| - godot | ||
| - gofmt | ||
| - gosec | ||
| - misspell | ||
| - nakedret | ||
| - nolintlint | ||
| - revive | ||
| - thelper | ||
| - tparallel | ||
| - unconvert | ||
| - unparam | ||
| - whitespace | ||
|
|
||
| run: | ||
| timeout: 5m | ||
|
|
||
| # Get all linter issues, even if duplicated | ||
| issues: | ||
| exclude-use-default: false | ||
| max-issues-per-linter: 0 | ||
| max-same-issues: 0 | ||
| fix: false # we don’t want this in CI | ||
| exclude: | ||
| # EXC0001 errcheck: most errors are in defer calls, which are safe to ignore and idiomatic Go (would be good to only ignore defer ones though) | ||
| - 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv|w\.Stop). is not checked' | ||
| # EXC0008 gosec: duplicated of errcheck | ||
| - (G104|G307) | ||
| # EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' | ||
| - Potential file inclusion via variable | ||
| # We want named parameters even if unused, as they help better document the function | ||
| - unused-parameter | ||
| # Sometimes it is more readable it do a `if err:=a(); err != nil` tha simpy `return a()` | ||
| - if-return | ||
|
|
||
| nolintlint: | ||
| require-explanation: true | ||
| require-specific: true | ||
|
|
||
| linters-settings: | ||
| # Forbid the usage of deprecated ioutil and debug prints | ||
| forbidigo: | ||
| forbid: | ||
| - ioutil\. | ||
| - ^print.*$ | ||
| # Never have naked return ever | ||
| nakedret: | ||
| max-func-lines: 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package pam | ||
|
|
||
| /* | ||
| #include <security/pam_appl.h> | ||
| */ | ||
| import "C" | ||
|
|
||
| // Error is the Type for PAM Return types | ||
| type Error int | ||
|
|
||
| // Pam Return types | ||
| const ( | ||
| // OpenErr indicates a dlopen() failure when dynamically loading a | ||
| // service module. | ||
| ErrOpen Error = C.PAM_OPEN_ERR | ||
| // ErrSymbol indicates a symbol not found. | ||
| ErrSymbol Error = C.PAM_SYMBOL_ERR | ||
| // ErrService indicates a error in service module. | ||
| ErrService Error = C.PAM_SERVICE_ERR | ||
| // ErrSystem indicates a system error. | ||
| ErrSystem Error = C.PAM_SYSTEM_ERR | ||
| // ErrBuf indicates a memory buffer error. | ||
| ErrBuf Error = C.PAM_BUF_ERR | ||
| // ErrPermDenied indicates a permission denied. | ||
| ErrPermDenied Error = C.PAM_PERM_DENIED | ||
| // ErrAuth indicates a authentication failure. | ||
| ErrAuth Error = C.PAM_AUTH_ERR | ||
| // ErrCredInsufficient indicates a can not access authentication data due to | ||
| // insufficient credentials. | ||
| ErrCredInsufficient Error = C.PAM_CRED_INSUFFICIENT | ||
| // ErrAuthinfoUnavail indicates that the underlying authentication service | ||
| // can not retrieve authentication information. | ||
| ErrAuthinfoUnavail Error = C.PAM_AUTHINFO_UNAVAIL | ||
| // ErrUserUnknown indicates a user not known to the underlying authentication | ||
| // module. | ||
| ErrUserUnknown Error = C.PAM_USER_UNKNOWN | ||
| // ErrMaxtries indicates that an authentication service has maintained a retry | ||
| // count which has been reached. No further retries should be attempted. | ||
| ErrMaxtries Error = C.PAM_MAXTRIES | ||
| // ErrNewAuthtokReqd indicates a new authentication token required. This is | ||
| // normally returned if the machine security policies require that the | ||
| // password should be changed because the password is nil or it has aged. | ||
| ErrNewAuthtokReqd Error = C.PAM_NEW_AUTHTOK_REQD | ||
| // ErrAcctExpired indicates that an user account has expired. | ||
| ErrAcctExpired Error = C.PAM_ACCT_EXPIRED | ||
| // ErrSession indicates a can not make/remove an entry for the | ||
| // specified session. | ||
| ErrSession Error = C.PAM_SESSION_ERR | ||
| // ErrCredUnavail indicates that an underlying authentication service can not | ||
| // retrieve user credentials. | ||
| ErrCredUnavail Error = C.PAM_CRED_UNAVAIL | ||
| // ErrCredExpired indicates that an user credentials expired. | ||
| ErrCredExpired Error = C.PAM_CRED_EXPIRED | ||
| // ErrCred indicates a failure setting user credentials. | ||
| ErrCred Error = C.PAM_CRED_ERR | ||
| // ErrNoModuleData indicates a no module specific data is present. | ||
| ErrNoModuleData Error = C.PAM_NO_MODULE_DATA | ||
| // ErrConv indicates a conversation error. | ||
| ErrConv Error = C.PAM_CONV_ERR | ||
| // ErrAuthtokErr indicates an authentication token manipulation error. | ||
| ErrAuthtok Error = C.PAM_AUTHTOK_ERR | ||
| // ErrAuthtokRecoveryErr indicates an authentication information cannot | ||
| // be recovered. | ||
| ErrAuthtokRecovery Error = C.PAM_AUTHTOK_RECOVERY_ERR | ||
| // ErrAuthtokLockBusy indicates am authentication token lock busy. | ||
| ErrAuthtokLockBusy Error = C.PAM_AUTHTOK_LOCK_BUSY | ||
| // ErrAuthtokDisableAging indicates an authentication token aging disabled. | ||
| ErrAuthtokDisableAging Error = C.PAM_AUTHTOK_DISABLE_AGING | ||
| // ErrTryAgain indicates a preliminary check by password service. | ||
| ErrTryAgain Error = C.PAM_TRY_AGAIN | ||
| // ErrIgnore indicates to ignore underlying account module regardless of | ||
| // whether the control flag is required, optional, or sufficient. | ||
| ErrIgnore Error = C.PAM_IGNORE | ||
| // ErrAbort indicates a critical error (module fail now request). | ||
| ErrAbort Error = C.PAM_ABORT | ||
| // ErrAuthtokExpired indicates an user's authentication token has expired. | ||
| ErrAuthtokExpired Error = C.PAM_AUTHTOK_EXPIRED | ||
| // ErrModuleUnknown indicates a module is not known. | ||
| ErrModuleUnknown Error = C.PAM_MODULE_UNKNOWN | ||
| // ErrBadItem indicates a bad item passed to pam_*_item(). | ||
| ErrBadItem Error = C.PAM_BAD_ITEM | ||
| // ErrConvAgain indicates a conversation function is event driven and data | ||
| // is not available yet. | ||
| ErrConvAgain Error = C.PAM_CONV_AGAIN | ||
| // ErrIncomplete indicates to please call this function again to complete | ||
| // authentication stack. Before calling again, verify that conversation | ||
| // is completed. | ||
| ErrIncomplete Error = C.PAM_INCOMPLETE | ||
| ) | ||
|
|
||
| // Error returns the error message for the given status. | ||
| func (status Error) Error() string { | ||
| return C.GoString(C.pam_strerror(nil, C.int(status))) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.