Commit Graph

96 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
11daf4a88d transaction: Add ModuleTransaction type and ModuleHandler interface
This allows to easily define go-handlers for module operations.

We need to expose few more types externally so that it's possible to
create the module transaction handler and return specific transaction
errors
2023-12-01 19:59:59 +01:00
Marco Trevisan (Treviño)
bbc25e137c transaction: Add a transaction base type to define more transaction kinds
A pam handler can be used both by a module and by an Application, go-pam
is meant to be used in the application side right now, but it can be
easily changed to also create modules.

This is the prerequisite work to support this.
2023-12-01 19:59:59 +01:00
Michael Steinert
2bda45159c Update README for v2 2023-11-30 12:49:59 -06:00
Mike Steinert
30fb28f158 Merge pull request #21 from msteinert/v2
Update module version to v2
2023-11-30 12:47:56 -06:00
Michael Steinert
50ded1b0e7 Update module version to v2 2023-11-30 12:41:22 -06:00
Mike Steinert
6339228bcd Merge pull request #19 from msteinert/codecov
Another try at adding codecov
2023-11-29 21:59:13 -06:00
Michael Steinert
004c7008f4 Another try at adding codecov 2023-11-29 21:50:06 -06:00
Mike Steinert
fb46dfb9da Merge pull request #18 from msteinert/codecov
Add codecov configuration
2023-11-29 21:39:46 -06:00
Michael Steinert
64ad2183e8 Add codecov configuration 2023-11-29 21:36:53 -06:00
Mike Steinert
6bce85f6ba Merge pull request #17 from msteinert/update-example
Update example code to call Transaction.End
2023-11-29 21:17:23 -06:00
Michael Steinert
4537bb5583 Update example code to call Transaction.End 2023-11-29 21:14:45 -06:00
Mike Steinert
4ce1d8a7e0 Merge pull request #15 from 3v1n0/safer-transaction
Safer transaction: add End() method and don't use as error
2023-11-29 20:08:15 -06:00
Marco Trevisan (Treviño)
067f634acb transaction: Fix comment typo 2023-11-30 02:49:29 +01:00
Marco Trevisan (Treviño)
e6f817312a transaction: Skip some tests requiring confdir if not available 2023-11-30 02:49:29 +01:00
Marco Trevisan (Treviño)
01f62f11f7 transaction_test: Add tests checking the loaded services match 2023-11-30 02:49:29 +01:00
Marco Trevisan (Treviño)
31a452ad25 transaction: Add missing default PAM item types 2023-11-30 02:49:29 +01:00
Marco Trevisan (Treviño)
fe75bbaeee transaction: Mark Item, Flags and Style const values as Item, Flags and 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-30 02:49:29 +01:00
Marco Trevisan (Treviño)
c7ecbf20dc transaction: Add a test finalizer checking if transaction has ended
Check if a transaction is ended in in tests.
2023-11-30 02:49:29 +01:00
Marco Trevisan (Treviño)
c635cfc38a transaction: Add End() method and Remove Transaction finalizer
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
7162004668 transaction: Do not make Transaction to implement error interface anymore
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
adffdfbbdc 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.
2023-11-30 01:16:39 +01:00
Marco Trevisan (Treviño)
911a346a00 transaction: Use Atomic to store/load the status
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
3e4f7f5e4b transaction: Add an helper function to handle pam functions return status
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
a5f5ad6470 transaction: Return errors wrapping pam.Error values on failure
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
ea51cc0fe4 transaction: Add tests for all the possible Status (and error) values
Use pam_debug.so to generate pam configurations at test time and
check if the returned values expect the ones we want.
2023-11-30 01:16:39 +01:00
Marco Trevisan (Treviño)
6bb315c571 transaction: Add PAM Error types Go definitions
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-30 01:16:39 +01:00
Marco Trevisan (Treviño)
44c364e364 ci: Use golang-ci linter 2023-11-30 01:16:38 +01:00
Michael Steinert
a85a609bbe Run go fmt 2023-09-23 10:38:09 -05:00
Mike Steinert
2e7b8b76d5 Merge pull request #9 from 3v1n0/binary-protocol
transaction: Add support for Binary conversation
2023-09-22 09:16:15 -05:00
Marco Trevisan (Treviño)
b9265b1c6a transaction: Add support for Binary conversation
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-22 04:05:16 +02:00
Mike Steinert
08dbc65c91 Merge pull request #11 from msteinert/transaction
Transaction handler updates
2023-09-21 08:27:18 -05:00
Michael Steinert
b324e2b31b bugfix: Allocate after sanitizing inputs 2023-09-21 08:24:04 -05:00
Michael Steinert
df9e70a6d7 Format transaction.c with clang-format
To improve readability and encourage consistency in PRs.
2023-09-21 08:23:39 -05:00
Mike Steinert
d9b3ff918f Merge pull request #10 from msteinert/ci-matrix
Update CI configuration
2023-09-20 19:25:24 -05:00
Michael Steinert
736c9ebebe Update CI configuration 2023-09-20 19:22:43 -05:00
Mike Steinert
e0a2c7ba60 Merge pull request #8 from 3v1n0/simpler-callbacks
transaction: Use cgo.Handle to pass callback data to PAM
2023-09-20 08:54:38 -05:00
Mike Steinert
718a0b9deb Merge pull request #7 from 3v1n0/rootless-tests
tests: Add more tests on PAM conversations that can run as user
2023-09-20 08:46:09 -05:00
Marco Trevisan (Treviño)
78ffef4acd transaction: Use cgo.Handle to pass callback data to PAM
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
2023-09-19 20:06:38 +02:00
Marco Trevisan (Treviño)
a22a1abf3f transaction_test: Add root-less tests to check pam conversation
Use pam_succeed_if to make it implicitly ask for the user name and
verify that the provided one is correct.

This can safely run as user.
2023-09-19 18:46:25 +02:00
Marco Trevisan (Treviño)
1cab6e699c transaction_test: Add more authentication tests to run as user
So that it's possible also to verify an info text conversation
2023-09-19 18:46:25 +02:00
Marco Trevisan (Treviño)
ca3e79e605 transaction_test: Enable conf-dir tests without root
They don't require the `test` user nor being ran as root
2023-09-19 18:18:56 +02:00
Marco Trevisan (Treviño)
d0c0c8bf18 tests: Move services to a subdirectory
It makes it cleaner to handle, plus it allows adding more.

Also rename the `my-service` to something more self-explanatory.
2023-09-19 18:17:54 +02:00
Mike Steinert
5253f659f3 Merge pull request #6 from msteinert/deps
Update dependencies
2023-04-04 15:44:11 -05:00
Michael Steinert
2c8b026146 Update dependencies 2023-04-04 15:44:38 -05:00
Mike Steinert
313ea6f3ba Merge pull request #5 from didrocks/start_confdir
Allow to define confdir
2022-09-17 16:16:24 -05:00
Didier Roche
376af17c46 Integration test for confdir handling.
Add tests to cover StartConfDir with custom services path.
2022-09-16 08:50:03 +02:00
Didier Roche
bc958bdbd7 Allow to define confdir
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().
2022-09-16 08:09:26 +02:00
Michael Steinert
f401703daf Update CI build matrix 2022-08-03 16:07:21 -05:00
Michael Steinert
39406aafe4 Attempt to modernize the repo 2021-12-03 12:05:27 -06:00
Michael Steinert
e613721261 Update CI build matrix 2020-11-30 11:06:57 -06:00