summaryrefslogtreecommitdiff
path: root/transaction.go
AgeCommit message (Collapse)Author
2024-01-19transaction: Ignore unused variable warningsMarco Trevisan (Treviño)
We may get some warnings when generating code as: warning: unused variable ‘_cgo_a’ This is something due to the fact we use `-Wall` that is not something golang upstream suggests. However, since this is the only warning we may have and it's not a super relevant one, we can ensure we ignore it.
2023-11-30transaction: Fix comment typoMarco Trevisan (Treviño)
2023-11-30transaction: Add missing default PAM item typesMarco Trevisan (Treviño)
2023-11-30transaction: Mark Item, Flags and Style const values as Item, Flags and ↵Marco Trevisan (Treviño)
Style types We redefined various PAM constant values for items, flags and style, but only few of them were marked as being Item's or Flag's. This caused go to just consider them as generic integers instead of the actual subtype.
2023-11-30transaction: Add a test finalizer checking if transaction has endedMarco Trevisan (Treviño)
Check if a transaction is ended in in tests.
2023-11-30transaction: Add End() method and Remove Transaction finalizerMarco Trevisan (Treviño)
A PAM transaction needs to be ended in order to release the associated resources, however this can't be sadly automated as the go finalizers run in goroutines and this could cause problems to modules that we load. In fact a module code may be called back during pam_end (to cleanup data for example) and the module code could not be thread safe. So let's make this more manual, but safer. The transaction status is still preserved in the transaction so end will be automatically called with the last-known status. Closes: #14
2023-11-30transaction: Do not make Transaction to implement error interface anymoreMarco Trevisan (Treviño)
As per previous commit, Transaction can't be used anymore as an error value, but we instead we always return the status code.
2023-11-30transaction: Never return Transaction as errorMarco Trevisan (Treviño)
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.
2023-11-30transaction: Use Atomic to store/load the statusMarco Trevisan (Treviño)
Transactions save the status of each operation in a status field, however such field could be written concurrently by various operations, so we need to be sure that: - We always return the status for the current operation - We store the status in a atomic way so that other actions won't create write races In general, in a multi-thread operation one should not rely on Transaction.Error() to get info about the last operation.
2023-11-30transaction: Add an helper function to handle pam functions return statusMarco Trevisan (Treviño)
All the pam functions return an integer with the status of the operation so instead of duplicating the same code everywhere, that is quite error prone, use an helper function. It would have been nice to make this more dynamic, but cgo doesn't allow us to do much magic here. This is enough though.
2023-11-30transaction: Return errors wrapping pam.Error values on failureMarco Trevisan (Treviño)
If the transaction fails during start, there's no way to get the error detail in a programmatic way, so let's wrap the pam.Error to allow more per-type checks.
2023-11-30transaction: Add PAM Error types Go definitionsMarco Trevisan (Treviño)
And use them instead of C ones. Given that we have strings for them we can easily implement error interfaces for it too.
2023-11-30ci: Use golang-ci linterMarco Trevisan (Treviño)
2023-09-22transaction: Add support for Binary conversationMarco Trevisan (Treviño)
PAM upports binary conversations using private protocols, this can be handled by C but it's not supported here because we implicitly convert all the messages to string, and this may lead to issues when this is not the case (as in binary protocol the pointer could contain zeros that the GoString conversion would consider them the end of the message). So, add another conversation handler implementation that allows to handle the binary protocol, whose function callback accepts a pointer to the struct (we can't use bytes as the length is unknown and may be defined in the header of the pointer itself). However since the binary prompt is not supported by all the platforms we need to do a compile-time check to disable it in case is used when not supported.
2023-09-19transaction: Use cgo.Handle to pass callback data to PAMMarco Trevisan (Treviño)
Go provides a nicer way to handle Go structs lifetime when they are passed to C now, so use this instead of a custom implementation that requires to store them in a map
2022-09-16Allow to define confdirDidier Roche
PAM has a pam_start_confdir() which allows to define the configuration directory where all services are located. This is useful to define your own service on tests in particular, so that you can control your stack and be independant of the host when running them. Allow defining this configuration directory, with a new StartConfDir function. Also, allow pre-checking for the API availability with CheckPamHasStartConfdir().
2015-12-04[ci skip] Update documentationMichael Steinert
2015-12-04Fix lintMichael Steinert
2015-12-04Remove dead codeMichael Steinert
2015-12-04Fix a memory leakMichael Steinert
2015-12-03Stop passing Go pointers to CMichael Steinert
2015-04-10Fix golint warningsMichael Steinert
2015-03-30Small documentation updatesMichael Steinert
2015-03-30This looks a bit betterMichael Steinert
2015-03-30Fix a silly bug and add test coverageMichael Steinert
2015-03-30Rework pam_getenvlist so it doesn't leakMichael Steinert
2015-03-29Add a test suiteMichael Steinert
2015-03-28Update interfaceMichael Steinert