Compare commits

...

406 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav d61017e615 Prepare to release Ximenia tomorrow. 2023-06-26 20:49:39 +02:00
Dag-Erling Smørgrav 41eb8b9f02 In openpam_subst(3), avoid incrementing past the end of the template.
My thanks to Robert Morris <rtm@lcs.mit.edu> for finding and reporting the bug.
2023-06-26 20:49:27 +02:00
Dag-Erling Smørgrav 7da86c0c62 Decrement optc when removing an option.
My thanks to Robert Morris <rtm@lcs.mit.edu> for finding and reporting the bug.
2023-06-26 20:24:42 +02:00
Dag-Erling Smørgrav 4b2e3c92df Remove unused variable. 2023-06-26 19:51:48 +02:00
Dag-Erling Smørgrav cc0d61260e Remove unnecessary log messages. 2021-10-22 17:21:48 +02:00
Dag-Erling Smørgrav f1871a7d9f Add unit tests for openpam_straddch(3). 2021-10-22 17:21:48 +02:00
Dag-Erling Smørgrav eed614622f Replace the coverage script with a Makefile target. 2021-10-22 17:21:48 +02:00
Dag-Erling Smørgrav 29e80880cc Whitespace cleanup. 2021-10-21 12:35:20 +02:00
Dag-Erling Smørgrav 64edbc294d Switch wiki markup from Trac to Gitea. 2021-10-21 11:45:46 +02:00
Dag-Erling Smørgrav 1d9c829c40 Switch to clang code coverage. 2021-10-20 18:47:01 +02:00
Dag-Erling Smørgrav ef5e67748c Drop mkpkgng in favor of a generated port Makefile. 2021-10-20 18:47:00 +02:00
Dag-Erling Smørgrav 05bd3febc0 Gitify. 2021-10-20 15:44:03 +02:00
Dag-Erling Smørgrav a967883b9c In openpam_ttyconv(3), wait to print the prompt until after we're ready
to accept input.  Otherwise, there is a small but non-zero chance that
input provided after the prompt appears is discarded when we flush the
tty buffer.

Submitted by:	Brooks Davis <brooks@freebsd.org>


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@948 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2020-11-19 05:41:15 +00:00
Dag-Erling Smørgrav e0e3406a78 Enable FALLBACK_TO_OTHER since we don't use (or need) a policy.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@946 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-22 12:38:53 +00:00
Dag-Erling Smørgrav 6bf8cb1753 Prepare to release Tabebuia on Sunday.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@945 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-22 09:52:46 +00:00
Dag-Erling Smørgrav bb68996306 Bump copyright years.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@944 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-22 09:49:12 +00:00
Dag-Erling Smørgrav 9bdf428c5a Fix an off-by-one bug in pam_getenv() which was inadvertantly
introduced when pam_getenv() was (needlessly) rewritten as part of
r913.  Rewrite pam_getenv() again (but correctly, this time) to reduce
the number of times we iterate over the same string.  Add a few unit
tests for pam_{get,put,set}env(), including one which would have
caught the bug.

Credit goes to Tim Creech <tcreech@tcreech.com> for discovering and
reporting the bug.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@943 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-20 13:23:51 +00:00
Dag-Erling Smørgrav 1dce53245b r940 relied on Cryb's own autoconf macros, which obviously aren't available unless Cryb itself is available, which is precisely what we're trying to figure out. Use plain pkg-config instead, as intended.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@942 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-20 13:19:01 +00:00
Dag-Erling Smørgrav 251dac8e4a We haven't needed libcrypto since the OATH code was removed.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@941 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-20 13:15:54 +00:00
Dag-Erling Smørgrav a501f2af85 Use pkg-config / pkgconf to locate libcryb-test.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@940 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2019-02-20 12:21:40 +00:00
Dag-Erling Smørgrav 9cd25f7e7d Switch from $Id$ to $OpenPAM$.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@938 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-30 21:34:42 +00:00
Dag-Erling Smørgrav d061313188 Markip nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@937 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-30 21:25:34 +00:00
Dag-Erling Smørgrav eefae6d5ef Rename release to Residacea.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@936 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-30 21:14:17 +00:00
Dag-Erling Smørgrav 919a1250d4 Bump copyright year.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@935 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 21:04:10 +00:00
Dag-Erling Smørgrav ddb34ad671 Prepare to release OpenPAM Reboulia on Sunday.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@934 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 20:53:18 +00:00
Dag-Erling Smørgrav 4876ee459d Add PAM_BAD_FEATURE and PAM_BAD_CONSTANT.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@933 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 20:43:55 +00:00
Dag-Erling Smørgrav 105d392c57 Add two more error codes for situations where we used PAM_SYMBOL_ERR.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@932 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 20:41:59 +00:00
Dag-Erling Smørgrav 29c7f93598 Introduce an array of error strings and use it wherever applicable.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@931 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 19:23:50 +00:00
Dag-Erling Smørgrav 0f7f351a10 Remove the NONNULL annotation since we reintroduced the NULL check.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@930 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 19:22:57 +00:00
Dag-Erling Smørgrav c87aee7c52 Add the new error codes and rewrite the error code handling to support
negated entries, e.g. in cases a() calls b() and b() can return code X
in certain situations, but a() ensures that this never happens.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@929 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 19:21:54 +00:00
Dag-Erling Smørgrav 07daaf4bb2 r927 should have said: introduce new error codes for situations where we
have long used the wrong ones because neither XSSO not Solaris defined
codes that fit the situation.  Also, the definition was missing.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@928 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 19:19:52 +00:00
Dag-Erling Smørgrav 3ebfd11150 Use the correct error code in some of the places where we have long used
the wrong one.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@927 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-04-26 19:15:30 +00:00
Dag-Erling Smørgrav e7f32a97b0 Adapt to newer versions of the Cryb test framework.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@926 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-03-23 13:42:56 +00:00
Dag-Erling Smørgrav 812256e9d1 Add missing #include.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@925 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-23 08:03:22 +00:00
Dag-Erling Smørgrav 25bcbd2652 Prepare to release OpenPAM Radula.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@923 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 19:31:16 +00:00
Dag-Erling Smørgrav a823b423ca Switch to using the cryb.to project's test framework.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@922 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 19:28:30 +00:00
Dag-Erling Smørgrav 890bea99e0 Update.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@921 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 18:10:30 +00:00
Dag-Erling Smørgrav 05afeb7a29 Document r918.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@920 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 18:06:43 +00:00
Dag-Erling Smørgrav f5a12fb24e Update the release notes to reflect that code flows from OpenPAM to
FreeBSD rather than the reverse.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@919 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 18:06:08 +00:00
Dag-Erling Smørgrav d9e44d146f Fix a bug that prevented the service name from being freed, thus
leaking a small amount of memory for every PAM session.

While there, eliminate an unnecessary variable.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@918 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-19 17:46:22 +00:00
Dag-Erling Smørgrav 2f340d61b5 Add a pair of scripts to facilitate running Bullseye Coverage and Coverity
Scan on the codebase.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@917 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-18 14:45:27 +00:00
Dag-Erling Smørgrav 82935b7d7a Downgrade the "unexpected EOF" message from ERROR to DEBUG.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@916 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-07 12:25:58 +00:00
Dag-Erling Smørgrav 1e09705bd7 Fix FREEV() when v is NULL.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@915 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-02-07 12:03:19 +00:00
Dag-Erling Smørgrav c5a320988e In pam_*env(3), set errno as the corresponding POSIX functions would.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@914 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-21 15:15:29 +00:00
Dag-Erling Smørgrav e936857588 Newer versions of clang take __nonnull__ annotations into account not only
when compiling code that calls the function, but also when compiling the
function itself.  This means that NULL checks in the function trigger
condition-always-false warnings.  We have a choice between disabling these
warnings, removing the __nonnull__ annotations, or removing the NULL checks.
We prefer to keep the annotations and warnings and remove the checks.  In
all cases, passing NULL to the function in question will result in a
segmentation fault, which is often easier to debug than an error return,
especially when most of these checks were for the PAM handle, which can only
be NULL if the caller ignored an error return from pam_start().


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@913 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-21 15:11:12 +00:00
Dag-Erling Smørgrav a18c87672e Postpone Radula until next Saturday.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@912 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-21 14:48:30 +00:00
Dag-Erling Smørgrav 23cdf95099 Correct markup for email addresses.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@910 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-21 12:22:08 +00:00
Dag-Erling Smørgrav 3112c53799 Remove experimental code that was accidentally committed in r908
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@909 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-20 08:13:20 +00:00
Dag-Erling Smørgrav adb7175c42 Prepare for releasing Radula on Saturday.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@908 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-18 10:11:57 +00:00
Dag-Erling Smørgrav c75883564d Move OATH development to a branch. OATH will soon disappear entirely
from this repository as Cryb takes over.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@907 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-18 09:39:01 +00:00
Dag-Erling Smørgrav 3699596d18 Correctly compare the return value from pam_get_item() to PAM_SUCCESS
instead of assuming (incorrectly) that it returns non-zero on success.
Bump dates as needed.

Reported by:	Patrick Bihan-Faou <patrick-fbsd@mindstep.com>


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@902 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2017-01-17 14:57:09 +00:00
Dag-Erling Smørgrav da26321ba8 Spell the GCC pragmas correctly.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@891 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-09-19 10:04:25 +00:00
Dag-Erling Smørgrav 26fbccde77 Bump dates if required on files modified in 2014 or later.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@890 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 16:22:09 +00:00
Dag-Erling Smørgrav b6605f9267 Add University of Oslo copyright and bump dates.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@889 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 16:21:28 +00:00
Dag-Erling Smørgrav aa6768d765 Fix props
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@888 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 16:19:57 +00:00
Dag-Erling Smørgrav c371da364c Note that the secret should also be percent-encoded.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@887 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 14:09:30 +00:00
Dag-Erling Smørgrav 4a77e993a9 Fix parsing of percent-encoded URIs.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@886 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 14:07:54 +00:00
Dag-Erling Smørgrav d040ae3d29 Add a man page for pam_oath(8) which I've had lying around for years.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@885 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 13:45:17 +00:00
Dag-Erling Smørgrav b1895baa2d Don't forget to generate the Makefile for pam_return(8).
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@884 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-11 13:44:33 +00:00
Dag-Erling Smørgrav ddfa63ca38 Disable coverage analysis of tests and test infrastructure.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@883 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 18:42:28 +00:00
Dag-Erling Smørgrav 41a50e0c57 Set an upper limit to the number of codes generated by the calc command.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@882 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 18:41:46 +00:00
Dag-Erling Smørgrav 9ff1a454ce Fix off-by-one bug: we forgot to account for the terminating NUL when
checking the length of the label.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@881 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 18:29:32 +00:00
Dag-Erling Smørgrav 310b5ee125 Partially revert r871 until a better solution can be found, as it only
works if the file already exists.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@880 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:52:39 +00:00
Dag-Erling Smørgrav a38c5db91b Fix rather embarassing #if nesting error in previous commit.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@879 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:43:56 +00:00
Dag-Erling Smørgrav f82c90afb6 Coverity Scan doesn't like the no-op default case, so hide it when
we're not instrumenting for coverage analysis.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@878 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:34:32 +00:00
Dag-Erling Smørgrav 4e92aa7e24 Plug potential memory leak reported by Coverity Scan. I'm not sure it
can actually ever occur, but the extra free() is harmless, provided we
make sure not to free() something we're still using.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@877 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:26:18 +00:00
Dag-Erling Smørgrav 5b83650c3d Don't forget to free the line we read from the key file.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@876 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:23:36 +00:00
Dag-Erling Smørgrav e89fab019e Fix NULL check in pam_oath_save_key() error-handling code, which
checked the wrong variable.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@875 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2016-01-09 17:22:34 +00:00
Dag-Erling Smørgrav d4aad88c97 Add a table-driven test which leverages the pam_return module to test
various code paths in openpam_dispatch().


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@874 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-12-01 19:40:01 +00:00
Dag-Erling Smørgrav 17c3fff539 For testing purposes, add a pam_return module which can be configured to
return any value, either by name (e.g. PAM_AUTH_ERR) or by number, even
if that number is out of range.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@873 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-12-01 19:38:01 +00:00
Dag-Erling Smørgrav f78c2be225 Add missing third clause.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@872 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-12-01 19:25:07 +00:00
Dag-Erling Smørgrav b3cd4386fa In t_fopen(), resolve the full path to the file before opening it.
In t_fprintf(), immediately flush the file after writing to it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@871 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-12-01 19:21:50 +00:00
Dag-Erling Smørgrav d30df17f67 Increase the TOTP window to ±2 timesteps.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@870 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-10-23 10:22:35 +00:00
Dag-Erling Smørgrav b149f4beed Fix uninitialized variable warning.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@869 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-10-23 10:19:21 +00:00
Dag-Erling Smørgrav 4a9cae719e Let the optional argument to the calc command be the total number of codes
to print, not the number of codes in addition to the current code.
Add a -n option which causes the calc command to print the counter or
timestamp in addition to the code.
Document the fact that the calc command does not work correctly for TOTP
keys with count > 1.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@868 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-10-23 09:41:16 +00:00
Dag-Erling Smørgrav 75781c2e7c Don't forget to distribute t_pam_conv.h
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@867 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-10-23 09:10:04 +00:00
Dag-Erling Smørgrav 37b1f12e58 Deconstify across the board to dodge -Wcast-qual until we convert to the far
superior cryb.to test framework.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@866 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-07-31 00:03:02 +00:00
Dag-Erling Smørgrav 4ee61ea341 intptr_t requires <stdint.h>
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@865 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-07-31 00:02:09 +00:00
Dag-Erling Smørgrav a1e8de164e ignore generated file
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@864 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-07-31 00:01:51 +00:00
Dag-Erling Smørgrav 38c6ca93b2 Start writing tests for openpam_dispatch(). The first is a regression test
for the bug fixed in r802.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@863 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-07-30 23:44:31 +00:00
Dag-Erling Smørgrav d84d7367fe Add a feature flag to control whether to fall back to the "other" policy
for chains that are still empty after the requested policy was loaded.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@862 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-07-30 23:42:38 +00:00
Dag-Erling Smørgrav 653950434c Fully fix the input overflow bug and add a test case for it.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@861 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-03-19 00:42:58 +00:00
Dag-Erling Smørgrav bf92462945 Include oath.man in the distribution tarball.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@860 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-03-19 00:21:23 +00:00
Dag-Erling Smørgrav 34ef29ccf8 ignore generated file
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@859 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-03-19 00:16:42 +00:00
Dag-Erling Smørgrav 737e1bef50 Increment by three, not one, after successfully decoding a character.
Add a boundary check.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@858 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-03-19 00:07:19 +00:00
Dag-Erling Smørgrav a1f83b0b30 Add unit tests for RFC 3986 percent encoding / decoding.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@857 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-03-19 00:06:32 +00:00
Dag-Erling Smørgrav ce014fab92 Silence all remaining qual-cast warnings except in the test suite.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@854 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-01-27 22:13:03 +00:00
Dag-Erling Smørgrav 563ac2d4bb Remove the pamgdb script, since "libtool exec gdb" does the same job better.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@853 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-01-15 17:20:49 +00:00
Dag-Erling Smørgrav 8a2e3ce9b6 BullseyeCoverage needs to know exactly which compiler we're using.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@852 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2015-01-15 17:18:03 +00:00
Dag-Erling Smørgrav 00fb76245a Silence an uninitialized variable warning from gcc, which does not realize
that the resynchronization loop will always run at least once.
Adjust the loop condition, which unintentionally ignored errors.
Remove a debugging message.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@851 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-15 17:11:36 +00:00
Dag-Erling Smørgrav 1cffa76b4f Track liboath:
- Use UINT_MAX to indicate an invalid response.
  - The meaning of the window parameter has changed slightly.
The calc command now accepts a count of codes to generate.
The resync command now fails if the key is not resynchronizable.
Clean up the usage message.
Document exit codes.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@850 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-15 17:00:59 +00:00
Dag-Erling Smørgrav cec8549503 Change the meaning of the window parameter to always indicate the number
of codes to check *in addition* to the current code.  Note that for TOTP,
the window goes in both directions; a window of 1 means to check the
current code plus the previous and next.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@849 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-15 16:42:31 +00:00
Dag-Erling Smørgrav e959d8c160 Consistently use UINT_MAX, not -1, to indicate an invalid response.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@848 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-15 16:12:29 +00:00
Dag-Erling Smørgrav 2f686b73cb Require the user to specify the OATH mode (HOTP or TOTP) when generating
a new key.

Allow resynchronizing with three keys instead of two, increasing the
resynchronization window from 100 keys to 1000 keys.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@847 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-11 14:06:59 +00:00
Dag-Erling Smørgrav c7a5aa489f Add an oath_mode(3) function which translates from mode names to numbers.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@846 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-11 13:58:15 +00:00
Dag-Erling Smørgrav e84c236ee9 Recognize enums and unions as well as structs.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@845 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-12-11 13:56:51 +00:00
Dag-Erling Smørgrav 8988b9122e The read-only option that was implemented in r841 was inaccessible
because the getopt(3) spec had not been updated to include it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@844 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-25 14:01:58 +00:00
Dag-Erling Smørgrav da2c1e7120 Fix a few cases where we incorrectly (and needlessly) cast away const
qualifiers.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@843 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-25 10:35:19 +00:00
Dag-Erling Smørgrav 753721df82 Implement HOTP resynchronization: the user provides two consecutive codes
from their token.  If the first code is found within the synchronization
window (currently hardcoded to 99) and the second is the next code in the
sequence, the counter is reset to one past the second code.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@842 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-12 17:30:38 +00:00
Dag-Erling Smørgrav d130c0ec09 Turn writeback mode on by default in oathkey(1).
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@841 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-12 16:21:15 +00:00
Dag-Erling Smørgrav fc5eeb8fd9 Trust configure to provide the correct source directory.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@840 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-07 16:44:26 +00:00
Dag-Erling Smørgrav f3fda3d07a Style nits
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@839 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-07 16:37:56 +00:00
Dag-Erling Smørgrav 4b2bc748fd Make sure we package symlinks as well as files, but don't package .la files.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@838 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-11-02 13:47:08 +00:00
Dag-Erling Smørgrav 273bae0b16 Oops - the line count is incremented by the line continuation, not by
the word that precedes it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@837 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-28 17:50:17 +00:00
Dag-Erling Smørgrav 16ae1d5b87 Further improve the line continuation tests.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@836 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-28 17:47:55 +00:00
Dag-Erling Smørgrav 1e3740645e Add a test case for line continuation within whitespace, similar to
the corresponding test in t_openpam_readword.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@835 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-28 13:48:00 +00:00
Dag-Erling Smørgrav ac54af0d69 Add configure options to build as much as possible using the system
libpam and / or liboath.  Doing so disables building the corresponding
library and its documentation, but still builts the corresponding tools
and modules and runs the unit tests.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@834 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-28 10:25:58 +00:00
Dag-Erling Smørgrav 385dfb33cb Use $() instead of @@ in Makefiles.
Don't build OATH man pages if --without-oath.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@833 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-28 09:03:41 +00:00
Dag-Erling Smørgrav 37baf24e77 Change manifest syntax from YAML to UCL to match recent versions of pkg.
Also, move the description out of the script.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@832 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-24 11:14:51 +00:00
Dag-Erling Smørgrav 7ce556ed8d Remove obsolete text.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@831 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-24 10:58:21 +00:00
Dag-Erling Smørgrav e6dc9378f7 staticize t_plan
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@830 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-24 08:49:47 +00:00
Dag-Erling Smørgrav e956efb61f Better tests for line continuation.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@828 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-23 08:25:08 +00:00
Dag-Erling Smørgrav 9c55e81bbb Add a calc command that prints the current code.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@827 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-22 10:03:14 +00:00
Dag-Erling Smørgrav e5b05552fc Remove unused variable.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@824 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-18 22:35:35 +00:00
Dag-Erling Smørgrav ce08052f96 Compare the return value from mmap() to MAP_FAILED, not NULL.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@823 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-16 13:44:34 +00:00
Dag-Erling Smørgrav 2c148271ae Avoid double-quoting function-like macros.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@821 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-09 14:45:32 +00:00
Dag-Erling Smørgrav 623d9e7b2f Small tweak to avoid marking up initialisms and acronyms like GCC, API
and PAM as code.  As a side effect, this simplifies the code for CVEs.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@820 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-09 14:34:03 +00:00
Dag-Erling Smørgrav 561cd87dbe Refactor. The only major change is that CVE numbers now link to the
corresponding NVD database entry.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@819 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-09 14:28:41 +00:00
Dag-Erling Smørgrav 8ad7aa9039 - Set the sameuser flag when a non-root user manipulates their own key.
- Rename the uri command to geturi (but retain backward compatibility).
- Add a getkey command that prints the key in hexadecimal.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@818 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-08 11:02:44 +00:00
Dag-Erling Smørgrav 37ff7929a0 Remove superfluous comments and blank lines.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@817 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-10-08 10:58:11 +00:00
Dag-Erling Smørgrav 5c8ea43402 Spell out option names
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@814 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-12 07:46:46 +00:00
Dag-Erling Smørgrav b94f9e7ce7 Gavin helped out with CVE-2014-3879
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@813 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-12 07:46:23 +00:00
Dag-Erling Smørgrav 6846134790 Push back one day.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@811 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-12 07:23:27 +00:00
Dag-Erling Smørgrav 1450290a72 typo
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@809 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 11:01:45 +00:00
Dag-Erling Smørgrav 95a55b95cf Prepare for releasing Ourouparia on Thursday.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@806 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 09:33:54 +00:00
Dag-Erling Smørgrav 2ae3b8b727 Include CVE numbers when available
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@805 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 09:13:00 +00:00
Dag-Erling Smørgrav 547794d58e Remove keywords from pure text files.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@804 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 09:11:31 +00:00
Dag-Erling Smørgrav 69b1a97268 Introduce strlset(), a memset() variant for strings where the actual
size of the buffer is not necessarily known, and which can replace the
"memset(str, 0, strlen(str))" idiom.  Use it to clear buffers which may
have contained authentication tokens.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@803 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 09:07:51 +00:00
Dag-Erling Smørgrav 131aba915f From NetBSD: require at least one service function to have succeeded.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@802 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-09 08:08:13 +00:00
Dag-Erling Smørgrav 548c44573c Belatedly document the addition of module search paths.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@800 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-09-08 12:42:29 +00:00
Dag-Erling Smørgrav 05630b94be Spell the name of the University of Oslo in English.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@799 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-07-10 17:16:48 +00:00
Dag-Erling Smørgrav 57429ccc0e Add missing cast.
Submitted by:	Jörg Sonnenberger <joerg@britannica.bec.de>


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@797 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-06-10 21:27:18 +00:00
Dag-Erling Smørgrav 7dbd5c38b7 In openpam_parse_chain():
1. Finish a comment which was meant to describe the four different
   termination conditions for the loop in openpam_parse_chain() but
   ended in mid-sentence.

2. Ensure that errno is consistently set to EINVAL if a syntax error
   is encountered in the policy file.

3. If openpam_load_module() fails because the module could not be
   loaded, set errno to ENOEXEC instead of ENOENT.  This closes a hole
   where a missing module or a typo in a module name would cause the
   corresponding chain to fail open.  Normally, if the policy exists
   but cannot be loaded, openpam_load_chain() will return an error,
   and openpam_configure() will discard any partially constructed
   chains.  However, openpam_load_chain() interprets ENOENT to mean
   that the policy was not found, so it does not immediately return an
   error, the partially-loaded chain is not discarded, and the policy
   is incorrectly considered to have been successfully loaded.

4. Ensure that errors encountered while parsing an included policy are
   correctly propagated to the original policy, and that ENOENT while
   processing an include directive is a hard error, not a soft error.

CVE-2014-3879


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@795 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-06-03 21:27:48 +00:00
Dag-Erling Smørgrav 1efe822057 For TOTP keys, we record when the key was last used. For HOTP keys,
however, we want to record the *next* allowed counter value.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@794 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-04-11 10:35:18 +00:00
Dag-Erling Smørgrav b61b6f9c74 Add a test for lines containing more words than will fit in
openpam_readword()'s initial allocation.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@793 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-17 14:27:03 +00:00
Dag-Erling Smørgrav e58f05403e Support line continuation in whitespace.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@792 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-17 14:11:41 +00:00
Dag-Erling Smørgrav 4614107c94 Missed one
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@791 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-17 14:10:33 +00:00
Dag-Erling Smørgrav f7e8328354 Additional tests for various end-of-line / end-of-file corner cases,
and for comments that aren't comments.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@790 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-17 14:08:31 +00:00
Dag-Erling Smørgrav 14d31b83e8 Fix headers
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@789 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-12 00:04:20 +00:00
Dag-Erling Smørgrav a4ff6191f7 I must have been drunk when I wrote this.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@788 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-12 00:03:53 +00:00
Dag-Erling Smørgrav 925436a04f Compress man pages before generating the manifest.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@787 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 15:43:17 +00:00
Dag-Erling Smørgrav 078ac6bb4a Move oath_key_from_file() into a separate source file and document it.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@786 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 15:37:55 +00:00
Dag-Erling Smørgrav 6722d714f5 Missing word
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@785 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 15:37:38 +00:00
Dag-Erling Smørgrav 38622bad18 Implement keyfile writeback.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@784 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 15:31:30 +00:00
Dag-Erling Smørgrav ebdefa45ca Fix buffer overflow in the b64complete test case by increasing the size
of the buffer used in tests.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@783 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 11:13:05 +00:00
Dag-Erling Smørgrav 7914208b2d Don't forget do distribute oath_impl.h.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@782 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 10:03:57 +00:00
Dag-Erling Smørgrav 9853f0d8d5 Generate man pages for oath_key_from_uri() and oath_uri_decode().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@781 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 09:59:01 +00:00
Dag-Erling Smørgrav 6243755aa2 Rudimentary key management tool.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@780 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-10 09:55:15 +00:00
Dag-Erling Smørgrav 5d59548018 When I changed the argument type from uint8_t * to char *, I forgot that
they were being used as array indices.  Cast them back to uint8_t.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@779 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 14:11:44 +00:00
Dag-Erling Smørgrav 6c087dd523 Add test vectors which encode to the complete alphabet.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@778 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 14:10:06 +00:00
Dag-Erling Smørgrav 2efb7c4b01 Support (but ignore, for now) the issuer parameter.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@777 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 13:08:14 +00:00
Dag-Erling Smørgrav 75a6073d2c Encoder:
- Return the desired length when the buffer is too small.

 - Annotate the switch so Bullseye doesn't complain about an uncovered
   default case.

Decoder:

 - The table approach was a good idea, but there was no way to tell the
   difference between a character that decodes as 0 and an invalid
   character.  Modify the tables so an invalid character is indicated
   by 0xff instead of 0x00.

 - Check that padding starts in a valid position.  Note that we still
   don't check for left-over bits.

 - The overflow test always failed, because we set *olen = len before
   comparing them.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@776 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 12:48:48 +00:00
Dag-Erling Smørgrav d60017fe80 Additional tests (which also fail) for unexpected padding.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@775 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 12:04:56 +00:00
Dag-Erling Smørgrav 183cc6d511 The dummy constants have moved to oath_constants.h.
Add annotation macros for coverage analysis.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@774 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 11:51:08 +00:00
Dag-Erling Smørgrav c5265319ff Completely rewrite the test suite for the RFC 4648 encoding / decoding
functions and add many new tests, several of which fail.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@773 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 11:49:08 +00:00
Dag-Erling Smørgrav 01809a1b48 Switch from uint8_t to char.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@772 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-09 11:45:05 +00:00
Dag-Erling Smørgrav 17144e7a5f Replace base{32,64}_decode() with table-driven implementations. The new
code is less strict about padding, thus ensuring compatibility with
implementations which do not understand padding, such as MIME::Base32.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@771 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 17:54:58 +00:00
Dag-Erling Smørgrav 4645bc1762 Fix base{32,64}_decode(). The former handled padding incorrectly; the
latter was derived from the former, and had a couple of copy-paste bugs
in addition to the padding bug.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@770 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 12:35:47 +00:00
Dag-Erling Smørgrav 576e1e6b1c Add tests for base{32,64}_decode(). Both are broken.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@769 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 12:32:29 +00:00
Dag-Erling Smørgrav 56f7cf21f5 Make stdout line-buffered so verbose output is easier to read.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@768 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 12:31:31 +00:00
Dag-Erling Smørgrav 03207fcd61 oops, braino in previous commit.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@767 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 12:30:44 +00:00
Dag-Erling Smørgrav 3dab19018f props
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@766 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 12:29:36 +00:00
Dag-Erling Smørgrav 9f84c11072 props
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@765 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-03-06 09:29:06 +00:00
Dag-Erling Smørgrav 46df1b1050 Document the is_upper() bug.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@764 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-02-26 17:30:57 +00:00
Dag-Erling Smørgrav 5fadc4abb8 Credit Larry Baird for the is_upper() bug and sort the list.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@762 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-02-26 16:23:41 +00:00
Dag-Erling Smørgrav c7457cff15 Fix a bug in the is_upper() macro.
Submitted by:	Larry Baird <lab@gta.com>


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@761 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-02-26 16:23:22 +00:00
Dag-Erling Smørgrav 58921adbab Add complete coverage for the classification macros in openpam_ctype.h.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@760 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-02-26 16:22:32 +00:00
Dag-Erling Smørgrav 9e9207fd5d Add is_xdigit() predicate.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@759 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-24 13:44:34 +00:00
Dag-Erling Smørgrav 3d0d4da447 Factor out and document oath_key_from_uri().
Implement percent-decoding of the key label.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@758 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-23 20:19:54 +00:00
Dag-Erling Smørgrav aec3988b2f Bump copyright
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@757 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-23 20:17:41 +00:00
Dag-Erling Smørgrav 59313f56a4 Do not use oath_[ht]otp_match() as predicates - a non-zero return can
mean an error occurred.  We should probably switch to the standard
Unix idiom of returning 0 for success.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@756 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-22 15:13:56 +00:00
Dag-Erling Smørgrav e8cd86aade - The key length is in bytes, not bits, so the correct default is 20
and not 160 (which would actually overflow).  This should probably
  be a macro.
- Implement random key generation using OpenSSL's RAND_bytes(3).


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@755 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-22 15:12:15 +00:00
Dag-Erling Smørgrav 11a8c730d2 Enable OATH by default and tweak some option description strings.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@754 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-20 11:25:44 +00:00
Dag-Erling Smørgrav 9c592d628c Note that saving the keyfile updates a TOTP key's lastused parameter.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@753 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-20 10:48:39 +00:00
Dag-Erling Smørgrav aa338bce81 Add oath_key_create(3) which creates an OATH key from scratch.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@752 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-20 10:47:10 +00:00
Dag-Erling Smørgrav df95e0530d Credit Baptiste Daroussin for his various contributions, including but not
limited to r749.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@750 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-13 21:27:03 +00:00
Dag-Erling Smørgrav d68deb210c Update the way we extract the pkg version and ABI to match pkg 1.2.
Submitted by:	bapt@freebsd.org


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@749 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-13 21:26:25 +00:00
Dag-Erling Smørgrav d9f3164b53 The maximum number of messages in a single invocation conversation function
is called PAM_MAX_NUM_MSG, not PAM_NUM_MSG.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@748 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2014-01-13 21:23:05 +00:00
Dag-Erling Smørgrav e2375b0d73 typo
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@746 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-12-10 14:02:23 +00:00
Dag-Erling Smørgrav 7b4ce30d8e Currently, openpam_policy_path is a hardcoded array of short strings, and
filename is much larger than it needs to be.  However, this might not be
the case in the future.  To be safe, add a length check after strlcpy().
This should silence a Coverity warning about possible array overflow.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@745 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-21 23:22:48 +00:00
Dag-Erling Smørgrav cf0612ac98 I've always run aclocal before libtoolize, but the latter installs .m4
files, which requires regenerating aclocal.m4, so it should really be the
other way around.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@744 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-08 19:27:39 +00:00
Dag-Erling Smørgrav 914a5b3708 caught_signal should be static; gcc doesn't seem to mind, whereas some
clang versions (but not all) complain.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@742 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-07 19:25:57 +00:00
Dag-Erling Smørgrav 4dbe28d092 Sort the manifest.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@739 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-07 13:02:54 +00:00
Dag-Erling Smørgrav 2e6439e932 Prepare for OpenPAM Nummularia, which will be released later today from the
nooath branch.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@735 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-07 12:37:27 +00:00
Dag-Erling Smørgrav 8568521d18 It appears that "pkg create" works correctly, even though it complains
loudly about unresolved library dependencies.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@734 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-09-07 12:36:18 +00:00
Dag-Erling Smørgrav 3bc114befa It is entirely possible that pkg is present but not installed as a
package, or that the pkg binary in $PATH is not the one that was
installed (e.g. a development version in $HOME/bin/pkg).  Therefore,
use pkg -vv rather than pkg query to determine the pkg version.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@733 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-23 17:07:42 +00:00
Dag-Erling Smørgrav 7eacdef3fd This script is now sufficiently complex to merit a copyright statement
and a license.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@732 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-22 17:48:45 +00:00
Dag-Erling Smørgrav d4f3382050 various nits
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@731 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-22 15:10:16 +00:00
Dag-Erling Smørgrav ac8841d2bd Support storing the non-standard lastused parameter in a key URI.
Also fix some default values.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@730 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:32:54 +00:00
Dag-Erling Smørgrav 0446934acb Keep track of when a TOTP key was last used and prevent reuse of the same
sequence number.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@729 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:32:14 +00:00
Dag-Erling Smørgrav 2cc13d4b85 Allow digits in identifiers.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@728 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:28:24 +00:00
Dag-Erling Smørgrav e565eb6258 Document the key structure members a little better.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@727 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:15:21 +00:00
Dag-Erling Smørgrav 3b992508b8 Use a dummy bit in the key structure instead of relying on the label.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@726 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:14:02 +00:00
Dag-Erling Smørgrav 01d54c2924 Use the defined constant.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@725 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:10:31 +00:00
Dag-Erling Smørgrav df82cbb560 Change the label used for dummy keys to something OpenPAM-specific.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@724 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 15:08:40 +00:00
Dag-Erling Smørgrav d216fb463e RFC 6287 (OATH OCRA)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@723 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-21 12:39:13 +00:00
Dag-Erling Smørgrav 95539e42cf OATH roadmap.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@722 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-20 10:26:12 +00:00
Dag-Erling Smørgrav 84543123ea Desirable improvement / extension of openpam_log().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@721 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-20 10:21:39 +00:00
Dag-Erling Smørgrav 3b1c7851e6 repetitive
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@719 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:56:32 +00:00
Dag-Erling Smørgrav 56dd3d8d03 Improved dependency handling.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@718 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:54:21 +00:00
Dag-Erling Smørgrav 10e70f48b8 Ignore test output and logs.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@717 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:45:54 +00:00
Dag-Erling Smørgrav f69d77aaed liboath #include nits
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@716 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:37:29 +00:00
Dag-Erling Smørgrav 1b1f9c46e4 Start generating man pages for liboath.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@715 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:31:12 +00:00
Dag-Erling Smørgrav bcafac75c2 Insert joke about double-dating.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@713 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:11:04 +00:00
Dag-Erling Smørgrav 1f9f093691 Grr, gremlins slipped into gendoc.pl between testing and committing.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@712 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:09:27 +00:00
Dag-Erling Smørgrav 6b2927cfc5 Hardcode utf8 input encoding without messing around with environment
variables.

Stop pasting a (potentially incorrect) copyright statement and license
into generated files.  Instead, refer to the source, and if possible,
include the source revision number.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@711 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:04:50 +00:00
Dag-Erling Smørgrav fa62c8c348 Shorten hash dereferences wherever possible.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@710 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-19 15:01:44 +00:00
Dag-Erling Smørgrav 4264bfb000 Silence spurious warnings from aclocal.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@709 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-18 14:47:20 +00:00
Dag-Erling Smørgrav 90715a13d4 Extend the append-svn-revision-to-package-version logic to all
non-numeric branches, not just trunk.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@708 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-18 12:13:21 +00:00
Dag-Erling Smørgrav a03bbedb50 Increase the default synchronization window, and provide options to
control it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@707 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 13:45:55 +00:00
Dag-Erling Smørgrav b9ec47c689 Don't forget to install all the liboath headers.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@706 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 12:58:05 +00:00
Dag-Erling Smørgrav 0c4d5add5f Implement key saving, and change the outcome of failing to save the
key from a system error to a service error.

Note that currently, an error saving the key may destroy the original
keyfile.  This needs to be adressed.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@705 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 12:32:26 +00:00
Dag-Erling Smørgrav d34ad5ab09 liboath needs generic alloc() / free() facilities for key data;
oath_key_alloc() does the right thing, but oath_key_to_uri() doesn't.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@704 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 12:18:00 +00:00
Dag-Erling Smørgrav efa93c4a5f Don't log the text we read, it may contain sensitive information (such
as an OATH OTP key, since liboath uses openpam_readline() to read the
keyfile)


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@703 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 11:57:54 +00:00
Dag-Erling Smørgrav a02762c066 Update svn:ignore.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@702 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 10:28:48 +00:00
Dag-Erling Smørgrav b8ec0155ab - If @PACKAGE_VERSION@ is "trunk" and svnversion prints something
sensible, append the svn revision.
- Implement an ugly workaround for the shlib issue.
- Clean up and add comments.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@701 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-16 10:26:24 +00:00
Dag-Erling Smørgrav d3f359e2df Major cleanup.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@700 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 17:17:15 +00:00
Dag-Erling Smørgrav 929ddb1bc3 Fixed flipped condition.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@699 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 17:15:35 +00:00
Dag-Erling Smørgrav 0c34187244 Update.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@698 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 17:14:32 +00:00
Dag-Erling Smørgrav 880bd5c2d4 s/oath_dummy_key/oath_key_dummy/
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@697 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 16:24:28 +00:00
Dag-Erling Smørgrav fe081dbbfc Unfortunately, Linux doesn't have MAP_NOCORE.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@696 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 16:00:41 +00:00
Dag-Erling Smørgrav dfe04a59e4 svn:ignore the mkpkgng script.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@695 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 15:24:50 +00:00
Dag-Erling Smørgrav 88a91c2d02 Rename oath_dummy_key() to oath_key_dummy() and move it into its own file.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@694 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 15:23:58 +00:00
Dag-Erling Smørgrav 066e2b91ff Record the last successful use of a TOTP key. Also add commented-out
logic to prevent reuse of the same code or an earlier code within the
window, and make some minor type adjustments.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@693 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 15:21:31 +00:00
Dag-Erling Smørgrav b578b6a715 Add a script that creates a FreeBSD pkgng package. It does not currently
work as intended due to a bug in pkgng's shlib handling.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@692 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 14:01:04 +00:00
Dag-Erling Smørgrav efe4bec74a Remove --with-modules-dir now that we DTRT by default.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@691 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 13:59:33 +00:00
Dag-Erling Smørgrav 5847a34802 The --with-modules-dir configure option never quite worked, and became
even more badly broken when the dynamic loader was rewritten in March.
Reimplement it the way it was always meant to work (but never did):

If --with-modules-dir was specified, modules will be installed in that
directory and the dynamic loader will look for them there.  If it was
not specified, modules will be installed in libdir and the dynamic
loader will use the standard search path (/usr/lib:/usr/local/lib).  In
both cases, a policy file can still name a module by its full path.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@690 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-08-15 13:22:51 +00:00
Dag-Erling Smørgrav c9387115d9 Factor out oath_key_{alloc,free}() and implement wiring / locking.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@689 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-07-12 10:47:14 +00:00
Dag-Erling Smørgrav c05b6dd046 INFTIM is a BSDism; use -1 instead.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@688 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-07-11 16:40:08 +00:00
Dag-Erling Smørgrav 93d104bfd6 Reimplement, hopefully with marginally fewer bugs. There is an
unfortunate amount of code duplication between the tty and non-tty
paths, but the alternative is greatly increased complexity.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@687 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-07-11 16:37:25 +00:00
Dag-Erling Smørgrav 3a53d5117b Document that openpam_log(3) saves and restores errno(2).
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@686 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-07-11 16:36:02 +00:00
Dag-Erling Smørgrav 6950b99458 Add a command-line option that controls openpam_ttyconv_timeout.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@685 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-07-11 16:33:34 +00:00
Dag-Erling Smørgrav 3ab09a4f26 OPENPAM_DEBUG (--enable-debug) has a double action: it enables the
debugging macros, and sets the initial value of openpam_debug to 1.
This effectively gives the user a choice between no debugging at all,
or drowning in debugging messages from every part of the system.

Assuming that the primary use case for debugging is to allow admins to
troubleshoot their policies by adding the debug option to selected
pam.conf entries, remove the initialization of openpam_debug to 1.
This allows integrators to ship OpenPAM with OPENPAM_DEBUG defined
without spamming /var/log.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@684 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-04-14 15:44:32 +00:00
Dag-Erling Smørgrav a43b9256fc Log an error if open() failed for any other reason than ENOENT.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@683 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-04-14 14:49:59 +00:00
Dag-Erling Smørgrav 70d5d18643 Initialize has_ver and has_so to false, not true.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@682 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-04-14 14:48:29 +00:00
Dag-Erling Smørgrav 2fc7038ca4 Always restore errno before returning from openpam_log().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@681 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-04-14 14:36:05 +00:00
Dag-Erling Smørgrav 9f0aba7d25 Note need for loop detection
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@680 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-29 21:38:21 +00:00
Dag-Erling Smørgrav 9f6bdd74f4 Clean up and simplify dummy key handling.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@679 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-18 21:38:58 +00:00
Dag-Erling Smørgrav 7da9af6602 Set a reasonable, hard limit on label length. This removes the need for
a variable-length key structure (to accommodate a variable-length label)
and vastly simplifies key parsing.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@678 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-18 21:34:29 +00:00
Dag-Erling Smørgrav f3f8ccc9c3 An 80-byte key makes no sense, since HMAC hashes keys longer than 64
bytes.  Google Authenticator uses 20-byte keys.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@677 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-18 21:19:41 +00:00
Dag-Erling Smørgrav 496bd4632b - Add module options for specifying what to do if the user has no key
or if the key was unreadable or invalid.

- Fix inverted success / failure logic.

The module is now in a (barely) usable state.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@676 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-18 19:20:54 +00:00
Dag-Erling Smørgrav 2be62b5732 Document the changes to the module loading code.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@675 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 20:06:01 +00:00
Dag-Erling Smørgrav c1df418c6f comment nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@674 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 20:04:24 +00:00
Dag-Erling Smørgrav 422a3ccd39 - Mention quoting and add a cross-reference to openpam_readword(3),
which has a detailed explanation of how the file is parsed.

- Document the module search path.

- Warn against include loops.

- Briefly describe module options which affect libpam itself.

- Minor markup and formatting improvements.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@673 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 20:04:06 +00:00
Dag-Erling Smørgrav 794601a544 Make the .so suffix optional, so these three lines are now equivalent:
auth	required	pam_unix.so.2	try_first_pass
auth	required	pam_unix.so	try_first_pass
auth	required	pam_unix	try_first_pass


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@672 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 19:42:33 +00:00
Dag-Erling Smørgrav 4f9b0f6342 ...and there's more to come.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@671 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 19:37:00 +00:00
Dag-Erling Smørgrav d4ab77b35c Document the effect of module options (echo_pass, *_prompt etc)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@670 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 19:26:07 +00:00
Dag-Erling Smørgrav 30f65f8a44 Add a "maintained by" footer to ThinkSec-authored pages, like we do
for pam(3), openpam(3) and pam.conf(5).


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@669 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 19:21:55 +00:00
Dag-Erling Smørgrav bcebdf0ea8 Support tagged lists of module options.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@668 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 14:48:43 +00:00
Dag-Erling Smørgrav 32d5e093bd Remove unneeded #include
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@667 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 14:24:00 +00:00
Dag-Erling Smørgrav 3353ad06ce Add predicates for letters and digits.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@666 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 14:22:17 +00:00
Dag-Erling Smørgrav 2dd5f46e84 Add a few more verbose messages
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@665 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 12:46:51 +00:00
Dag-Erling Smørgrav 0f25be4e42 unbreak static linking
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@664 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-17 10:56:15 +00:00
Dag-Erling Smørgrav b501509854 update
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@663 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-11 16:34:01 +00:00
Dag-Erling Smørgrav 567ecaa2af Clean up the dynamic module loading code, and add support for the
module path which was added in r695.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@662 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-11 16:33:27 +00:00
Dag-Erling Smørgrav 2b8f7a6154 nit: the argument is a module name, which may or may not be a path.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@661 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-11 15:44:22 +00:00
Dag-Erling Smørgrav fe2e691204 Use dlfunc() if available; if not, fake it in terms of dlsym().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@660 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-11 15:08:52 +00:00
Dag-Erling Smørgrav 785bc19867 Move openpam_policy_path into openpam_constants.c, and add a corresponding
openpam_module_path.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@659 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-11 14:10:13 +00:00
Dag-Erling Smørgrav 429089e868 Add missing #include
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@658 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-06 22:59:15 +00:00
Dag-Erling Smørgrav 26d543d484 __unused is a FreeBSDism, use OPENPAM_UNUSED().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@657 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-06 22:59:05 +00:00
Dag-Erling Smørgrav efe65a2cab Add a macro for marking a variable or function argument as unused.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@656 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-06 22:58:45 +00:00
Dag-Erling Smørgrav 7bcd5bb700 Split up the liboath header files.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@655 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-06 14:10:09 +00:00
Dag-Erling Smørgrav 93a9982d45 Link with -lcrypto
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@654 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 19:03:59 +00:00
Dag-Erling Smørgrav 0ba869e872 Test cases for base 32 and 64 encoders
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@653 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 18:54:22 +00:00
Dag-Erling Smørgrav a810f26399 OpenSSL_add_all_algorithms() is actually a macro, and therefore
unsuitable for the purpose of locating libcrypto.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@652 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 18:40:37 +00:00
Dag-Erling Smørgrav 7ab83ce826 Support tests that require arguments
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@651 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 18:11:59 +00:00
Dag-Erling Smørgrav e6ad0c668c Update TODO list
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@650 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 17:58:43 +00:00
Dag-Erling Smørgrav 0da2f07cfb PAM_LOG_DEBUG -> PAM_LOG_LIBDEBUG
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@649 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 17:58:33 +00:00
Dag-Erling Smørgrav f6205baa20 prop sweep
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@648 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 17:54:27 +00:00
Dag-Erling Smørgrav d3b7a7843e Replace with useful content.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@647 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 17:49:55 +00:00
Dag-Erling Smørgrav a9a5497d3f Reorganize:
- move libpam into lib/libpam
 - move the OATH code into lib/liboath
 - move oath.h into include/security
 - update all pointers


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@646 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 17:49:06 +00:00
Dag-Erling Smørgrav 374a1769ca Relevant RFCs.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@645 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 16:56:27 +00:00
Dag-Erling Smørgrav bbcd45ace7 Add code to load a key and obtain and verify a response from the user.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@644 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 15:25:22 +00:00
Dag-Erling Smørgrav e39d0abb85 - Add a provisional API for computing the current HOTP or TOTP code.
- Add a provisional API for matching a user response.
- Add a provisional API for generating a dummy key.  When one of the
  matching functions recognizes a dummy key, it will go through the
  motions but never report a match.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@643 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 15:24:00 +00:00
Dag-Erling Smørgrav 2fe7fdd088 Move WITH_PAM_* up from the leaf Makefiles into the parent Makefile.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@642 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 10:27:29 +00:00
Dag-Erling Smørgrav a263be7c26 Fix encoder bugs: increment *olen rather than olen, and use the correct
mask for base64 (which was copy-pasted from the base32 code)


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@641 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-05 09:53:33 +00:00
Dag-Erling Smørgrav a9c6523c52 If setlogmask(3) is available, suppress logging during tests.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@640 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-04 10:38:45 +00:00
Dag-Erling Smørgrav 9187daa2ac Split up AC_CHECK_FUNCS.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@639 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-04 10:37:36 +00:00
Dag-Erling Smørgrav 2ec4f668a9 Add prototypes for the functions in oath_key.c.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@638 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 23:34:50 +00:00
Dag-Erling Smørgrav a1ee57dd24 Start preparing for the next release.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@637 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 23:28:04 +00:00
Dag-Erling Smørgrav f8a727ec0c Always use openpam_straddch(3) to bootstrap the string, even if we
have nothing to add to it.  This simplifies the code and fixes a bug
introduced in r553 where the first character in the string would
always be set to '\0', instead of only when bootstrapping.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@636 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 23:27:35 +00:00
Dag-Erling Smørgrav 75420a1e07 Simplify by using openpam_straddch(3) to bootstrap the string.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@635 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 23:23:58 +00:00
Dag-Erling Smørgrav 54d9167cea If ch == '\0', do not grow the string or advance the length counter,
but do allocate a string if there is none to begin with.  This makes
it possible to use openpam_straddch(3) to preallocate the string (if
necessary) instead of manually calling malloc(3) or calloc(3) and
initializing size and len.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@634 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 23:23:10 +00:00
Dag-Erling Smørgrav b21442245a Add test cases that mix quoted and unquoted text.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@633 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 22:57:21 +00:00
Dag-Erling Smørgrav 1a070e2544 Fix usage string
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@632 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 20:26:34 +00:00
Dag-Erling Smørgrav 08f35bc290 Style nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@631 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-03-03 19:41:24 +00:00
Dag-Erling Smørgrav ff9ea1145d PAM_SYSTEM_ERR is permissible here.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@630 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-28 20:13:56 +00:00
Dag-Erling Smørgrav 16a29af819 Fix svn:ignore property.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@629 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-28 12:51:25 +00:00
Dag-Erling Smørgrav 92d483a21a Implement URI encoding.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@628 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-28 12:12:53 +00:00
Dag-Erling Smørgrav 16e805fc4c After decoding a URI, check the result and set default values.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@627 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-28 12:11:45 +00:00
Dag-Erling Smørgrav 3d15ee7552 Implement otpauth URI parsing (untested)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@626 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-27 16:19:56 +00:00
Dag-Erling Smørgrav a37ffba3b8 Old patch: credit Ankita Pal, who uncovered a couple of issues while
porting OpenPAM to QNX.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@625 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-25 21:12:10 +00:00
Dag-Erling Smørgrav 772c94fdee Tweak the warning included in documentation for experimental features.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@624 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-25 21:11:38 +00:00
Dag-Erling Smørgrav 2546d3cf58 WIP: OATH module
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@623 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-25 07:24:51 +00:00
Dag-Erling Smørgrav 4978bcf862 Limit exported symbols to the PAM service functions.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@622 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-25 07:23:00 +00:00
Dag-Erling Smørgrav 515667a9c5 Add a default service name.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@621 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-25 07:13:35 +00:00
Dag-Erling Smørgrav f70250359e Use AM_CPPFLAGS instead of INCLUDES.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@620 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-24 18:51:10 +00:00
Dag-Erling Smørgrav e15ecfaa9c I seem to have inadvertantly used a non-standard variation of the BSD
license on code I wrote after the DARPA / NAI contract ended.  Change
all occurrences to the standard license.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@619 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2013-02-24 14:01:42 +00:00
Dag-Erling Smørgrav 35310aef5b Shared temp file handling code (should have been committed with r617)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@618 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-09-25 18:58:07 +00:00
Dag-Erling Smørgrav 9914cc8c45 Factor out temp file handling
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@617 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-09-18 11:35:13 +00:00
Dag-Erling Smørgrav 2b555bb3d3 Move our strlcat() and strlcpy() implementations into .c files.
Add asprintf() and vasprintf() for systems that don't have it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@616 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-08-07 15:18:16 +00:00
Dag-Erling Smørgrav 709f28793c Forgot to include openpam_cred.h in distribution.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@615 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-08-07 14:33:39 +00:00
Dag-Erling Smørgrav c0a7737a9b Forgot to set svn:keywords.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@614 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-08-07 14:31:06 +00:00
Dag-Erling Smørgrav 0869153c0b Define struct pam_saved_cred in a separate header.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@613 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-08-06 11:44:21 +00:00
Dag-Erling Smørgrav d4aebe2ae9 Fix a boneheaded error in the option copying loop that remained undetected
through months of testing only to show up within hours of release.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@611 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-05-26 22:57:11 +00:00
Dag-Erling Smørgrav 42f7e1bd47 Update for Micrampelis
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@609 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-05-26 13:57:45 +00:00
Dag-Erling Smørgrav 2a194a26ca set props
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@608 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-05-17 16:00:13 +00:00
Dag-Erling Smørgrav 78ab63e094 More code that inexplicably builds on one dev box but not on others.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@607 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-20 11:09:37 +00:00
Dag-Erling Smørgrav fe17647fb8 Name include guards consistently.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@606 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-20 11:06:38 +00:00
Dag-Erling Smørgrav 6d3ad38b26 Whitespace nit.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@605 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-20 11:05:10 +00:00
Dag-Erling Smørgrav fcce2d8609 Before committing r594, I shortened the names of certain features, but I
apparently didn't do it consistently.  For some reason, it built fine on
one of my dev machines, but nowhere else.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@604 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-20 11:04:05 +00:00
Dag-Erling Smørgrav 383544e1e9 Remove outdated checklist. There is a new one on the wiki:
http://www.openpam.org/wiki/Releases/Checklist


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@603 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-15 17:49:09 +00:00
Dag-Erling Smørgrav be8d8c6c7b Don't forget to distribute openpam_features.h.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@602 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-15 17:31:15 +00:00
Dag-Erling Smørgrav 56adeeabf3 umm, it's usually a good idea to test before committing.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@601 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 20:37:45 +00:00
Dag-Erling Smørgrav 7ca68ffaec Separate the code that opens and validates the policy file from the code
that searches for it.  If the service name contains a path separator
character, treat it is a relative or absolute path to the policy file.

This need to be documented either in pam.conf(5) or in pam_start(3) once
the feature mechanism is no longer experimental.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@600 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 16:11:39 +00:00
Dag-Erling Smørgrav aa1f7162f1 Use Sy instead of Em for deprecated / experimental notices.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@599 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 15:06:41 +00:00
Dag-Erling Smørgrav 1c59e86945 nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@598 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 15:04:43 +00:00
Dag-Erling Smørgrav 1ca33ae86f Add proper documentation.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@597 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 15:00:10 +00:00
Dag-Erling Smørgrav cf9114a400 Add support for marking a function as deprecated or experimental.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@596 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 14:52:40 +00:00
Dag-Erling Smørgrav d4b138c0e3 Add command-line options to disable module and policy checks.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@595 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 14:28:35 +00:00
Dag-Erling Smørgrav 312b5753a5 Add an experimental mechanism for enabling / disabling optional features.
Use it to control policy and module file checks.  The default settings
correspond to the current behavior: disallow path separators in policy
names, but allow them in module names; verify ownership and permissions
for both policy files and modules.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@594 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-14 14:18:41 +00:00
Dag-Erling Smørgrav b28d2d21ed Reorder: feature, enhance, bugfix
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@593 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 13:21:06 +00:00
Dag-Erling Smørgrav c23f34271d TODO list
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@592 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 13:19:51 +00:00
Dag-Erling Smørgrav 9b129a8850 ignore pamgdb
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@591 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 13:18:37 +00:00
Dag-Erling Smørgrav 2eb15b15cc Start preparing for the next release.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@590 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 12:57:57 +00:00
Dag-Erling Smørgrav 1f79315d9e Generate prettier wikitext.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@589 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 12:56:55 +00:00
Dag-Erling Smørgrav 4c8082f73d Markup nits
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@588 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 11:52:25 +00:00
Dag-Erling Smørgrav f0d658d97d Jason tipped me off about a memory leak in the previous iteration of
openpam_parse_chain().


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@587 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 11:12:10 +00:00
Dag-Erling Smørgrav d9ae0b5836 Consistently spell email addresses in lowercase.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@586 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-08 11:11:28 +00:00
Dag-Erling Smørgrav 8c5bc6cb91 An escaped newline within a single-quoted string is a literal newline,
but within a double-quoted string, it is a line continuation.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@585 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-07 22:49:12 +00:00
Dag-Erling Smørgrav 53544bd288 Add test cases for escaped whitespace within single- and double-quoted
strings.  This reveals a bug relating to line continuations within
double-quoted strings.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@584 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-07 22:47:16 +00:00
Dag-Erling Smørgrav 4c0e839be3 Add a gdb wrapper script that sets LD_LIBRARY_PATH and helps locate the
actual binary.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@583 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-07 18:56:13 +00:00
Dag-Erling Smørgrav c02ad56e43 Check the return value from asprintf().
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@582 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 23:23:35 +00:00
Dag-Erling Smørgrav 5cb6cd19f3 I've decided that the code, not the test, is correct in this case;
this is adequately documented in openpam_readlinev(3).


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@581 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 01:08:37 +00:00
Dag-Erling Smørgrav 364f3b0753 Clean up the code a bit and start adding cases with actual words.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@580 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 01:07:55 +00:00
Dag-Erling Smørgrav 3fdf34619c doc nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@579 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 01:06:17 +00:00
Dag-Erling Smørgrav 1db36adb17 As previously mentioned, move from 2-clause BSD to 3-clause BSD.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@578 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 00:45:59 +00:00
Dag-Erling Smørgrav cbfada51e9 Oops, re-add $(top_srcdir)/lib to VPATH, but under a less confusing
name.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@577 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-06 00:44:46 +00:00
Dag-Erling Smørgrav aa04edbebb Useful little script that updates the release name and version number
wherever they occur and bumps the date in man page.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@576 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:46:19 +00:00
Dag-Erling Smørgrav 37f6b5bcc9 Authorship; OpenPAM is no longer developed specifically "for the
FreeBSD project".


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@575 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:43:48 +00:00
Dag-Erling Smørgrav 487cc6afcb authorship and mdoc nits
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@574 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:42:39 +00:00
Dag-Erling Smørgrav 8435fe3eca authorship
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@573 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:42:14 +00:00
Dag-Erling Smørgrav 519086d0cb Include t.h in distribution.
Get libt.a from pwd, not srcdir.  Technically, it's in builddir, but
builddir is always equal to pwd.

List libt.a before libpam.la, in case we start using surrogates and
want to share them between tests.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@572 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:41:44 +00:00
Dag-Erling Smørgrav 3a0280a4cb Fix srcdir != pwd case (exercised by make distcheck)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@571 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:38:04 +00:00
Dag-Erling Smørgrav 03ef7cd64d include openpam_ctype.h in distribution
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@570 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 15:32:53 +00:00
Dag-Erling Smørgrav eea3231ee1 A single space before the section title is OK.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@569 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 14:38:07 +00:00
Dag-Erling Smørgrav 89e4f8a9e7 Fix authorship
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@568 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 14:35:53 +00:00
Dag-Erling Smørgrav 3cba749dfe Fix backslashes within single-quoted strings (no escape function)
Fix line continuation (newline is stripped, not quoted)
Further improve the documentation


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@567 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 14:32:51 +00:00
Dag-Erling Smørgrav 1a3013376f #include <stdio.h> when appropriate.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@566 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 14:30:41 +00:00
Dag-Erling Smørgrav 03c07732a6 Fix bugs in two escaped-quote tests.
Add more complex line-continuation tests.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@565 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 14:25:45 +00:00
Dag-Erling Smørgrav 8e1af43b32 Split all doubled-up quote tests in two (one for single quotes, one
for double quotes).  Add several more.  Also add a test of line
continuations (backslash-newline).  Several of these tests fail due to
discrepancies between openpam_readword() and POSIX quoting rules.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@564 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 13:58:01 +00:00
Dag-Erling Smørgrav 4ee06f968e Don't use \a as a test case for escaped letters, because people might
expect it to generate a BEL character, and I might at some point
decide to implement that.  Instead, use \z, which has no special
meaning in any C-like language I know of.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@563 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-05 12:20:18 +00:00
Dag-Erling Smørgrav 4063fef039 Start writing unit tests for openpam_readlinev(). One of them fails,
but I can't quite decide whether the code or the test is incorrect.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@562 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-03 20:13:38 +00:00
Dag-Erling Smørgrav ba1a5551d6 need config.h + missing printf() arguments + more tests
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@561 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 22:17:55 +00:00
Dag-Erling Smørgrav 73a3b34f32 Need config.h
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@560 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 22:06:24 +00:00
Dag-Erling Smørgrav b99998da9c Annotate t_verbose()
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@559 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 22:06:05 +00:00
Dag-Erling Smørgrav 28f7487e06 This was actually a bad idea, because the test might produce warning
or error messages that are shorter than what we printed.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@558 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 21:43:59 +00:00
Dag-Erling Smørgrav 94876a3695 whitespace nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@557 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 10:00:08 +00:00
Dag-Erling Smørgrav e9c697feb5 In verbose mode, output the number and name of each test to stderr
before running it.  End it with a carriage return so that any actual
output will overwrite it.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@556 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 09:59:53 +00:00
Dag-Erling Smørgrav 3a2fec89e2 Get rid of BSDisms
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@555 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 09:54:09 +00:00
Dag-Erling Smørgrav 31950458f5 Add strlcat() for non-BSD systems.
strlcpy() needs to be static.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@554 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-02 09:46:48 +00:00
Dag-Erling Smørgrav 3052dea7c0 Another bug uncovered by unit tests:
If the first character encountered is a quote, immediately allocate a
single byte.  This way, if the word we've started reading is actually
an empty quoted string ('' or ""), we correctly return an empty string
instead of NULL.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@553 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 21:04:44 +00:00
Dag-Erling Smørgrav 9a14604cd2 Start adding test cases involving quotes. The first two I could think of
both fail...


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@552 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 20:59:45 +00:00
Dag-Erling Smørgrav 81455d2603 Rename some tests, and test single and multiple whitespace separately.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@551 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 20:52:41 +00:00
Dag-Erling Smørgrav 49a4c1509e Fix a bug detected by the unit tests: to ensure consistent handling of
trailing whitespace, openpam_readword() should *always* push back the
last character read (which is a no-op in the EOF case).


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@550 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 20:45:19 +00:00
Dag-Erling Smørgrav d7708b3ae5 Always build and run the tests last so the results are more easily visible
in the scrollback or build log.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@549 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 20:38:30 +00:00
Dag-Erling Smørgrav 2baadb71ee Add a handful of unit tests for openpam_readword(3).
Note that one of them currently fails...


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@548 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 20:34:59 +00:00
Dag-Erling Smørgrav 96357f3c52 Add an openpam_straddch() function that appends a character to a
string, reallocating the string if necessary.

Add an openpam_readword() function that reads a single word from a
file according to the usual shell quoting rules.

Add an openpam_readlinev() function that uses openpam_readword() to
read an entire line and return a list of the words it contained.

Rewrite openpam_parse_chain() using openpam_readlinev(), which greatly
simplifies the code and ensures correct parsing of module option.

Thanks to Maëlle Lesage for pointing out the issue and writing an
early version of what became the main loop in openpam_readword().


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@547 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-04-01 15:01:21 +00:00
Dag-Erling Smørgrav 54b6b546dd Update year
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@546 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 23:13:20 +00:00
Dag-Erling Smørgrav 8121567cf6 More cases in which Fn should be used instead of Nm.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@545 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 23:12:54 +00:00
Dag-Erling Smørgrav d619fcb520 Through oversight, the PAM_LOG_LIBDEBUG case was left out in the
version of openpam_log() that's actually used.  Internal debugging
messages therefore went to the default case and were logged as errors,
spamming /var/log/messages and the console.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@544 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 22:47:15 +00:00
Dag-Erling Smørgrav e29b3b276f Even though I now prefer the 2-clause BSD license, for practical
reasons, it is easier to use the 3-clause BSD license even for new
additions to OpenPAM.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@543 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 22:11:34 +00:00
Dag-Erling Smørgrav 9857b1c9ea Add support for custom sections, including a custom RETURN VALUES
section which suppresses the auto-generated one.

Allow blank lines between list items.

If the name of a cross-referenced function is preceded by an
exclamation mark, leave it out of the SEE ALSO section.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@542 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 21:16:40 +00:00
Dag-Erling Smørgrav 10215cdd1e Only pull up punctuation which is followed by whitespace.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@541 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 21:15:44 +00:00
Dag-Erling Smørgrav 98687ed638 Use ".Fn foo" instead of ".Nm" for function names.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@540 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 20:53:50 +00:00
Dag-Erling Smørgrav f163a4b9df spelling
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@539 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 20:53:22 +00:00
Dag-Erling Smørgrav 103857f3c9 Short program that converts a PAM policy to C code that creates static
structures compatible with what openpam_configure() produces.
Always build but never install (for now)


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@538 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 17:04:29 +00:00
Dag-Erling Smørgrav 783a383e4b Save errno before calling asprintf(), since asprintf() may touch errno,
which will cause syslog() to log the wrong error message if the format
string contains %m.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@537 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 16:20:13 +00:00
Dag-Erling Smørgrav 74c787f664 Avoid underflow if *size == 0.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@536 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 15:34:19 +00:00
Dag-Erling Smørgrav 8e881dbdd7 Fix some embarassing typos introduced in the openpam_straddch() cleanup.
Move prototype from "opempam_impl.h" to <security/openpam.h>.
Generate openpam_straddch(3) man page.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@535 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 14:55:19 +00:00
Dag-Erling Smørgrav a7c9ef9a05 Additional return value hackery.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@534 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 14:49:30 +00:00
Dag-Erling Smørgrav be3bfed604 Clean up and document
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@533 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 14:25:43 +00:00
Dag-Erling Smørgrav b3a9a4792f Redundant #include
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@532 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 14:24:53 +00:00
Dag-Erling Smørgrav 2e479f3c12 Redundant #include
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@531 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 14:24:37 +00:00
Dag-Erling Smørgrav 7d5093463e Expand $Id$
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@530 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 13:44:51 +00:00
Dag-Erling Smørgrav aa8e257838 Ignore Emacs droppings
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@529 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-03-31 12:06:48 +00:00
Dag-Erling Smørgrav 42651f8d9b Add an internal function for appending a character to a dynamically
allocated string, expanding the string if necessary.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@528 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-02-26 03:34:46 +00:00
Dag-Erling Smørgrav 7d5d2733f5 Rename sigset to the_sigset to avoid shadowing sigset(3).
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@527 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-02-26 03:23:59 +00:00
Dag-Erling Smørgrav 0a4f5e9af7 Credit Don Lewis and Gleb Smirnoff for their assistance with tracking
down the recent openpam_configure() and openpam_dynamic() issues.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@526 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:47:45 +00:00
Dag-Erling Smørgrav cf0963e668 Improve error messages by logging the full path of the module we tried
to load rather than just the module name.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@525 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:45:09 +00:00
Dag-Erling Smørgrav c3d9f63b55 Fix a regression introduced by r487. The count was actually used to
determine whether to stop searching for a policy.  After r487,
multiple policies for the same service would be concatenated, whereas
the intention was that the one that came first in the policy path
should eclipse the others.

While there, take the time to reorganize the front end of the policy
loading code, both to clarify the logic and to produce better log
messages in case of errors.  The most important change is that
openpam_load_chain() now opens and vets the policy file before calling
openpam_parse_chain(), so it is better able to distinguish between
errors relating to the file itself and errors relating to its
contents.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@524 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:29:48 +00:00
Dag-Erling Smørgrav 88a6cda1a1 Reluctantly document PAM_LOG_LIBDEBUG.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@523 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:15:24 +00:00
Dag-Erling Smørgrav b616ada557 Add another log level, PAM_LOG_LIBDEBUG, with a negative priority. It
is currently equivalent to PAM_LOG_DEBUG, and is used only by the
library call tracing macros (ENTER*() and RETURN*()).  It should
eventually replace PAM_LOG_DEBUG throughout the library, except
perhaps for a few particularly interesting messages; PAM_LOG_DEBUG
will be reserved for modules.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@522 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:13:25 +00:00
Dag-Erling Smørgrav df3d585d08 Reduce log spam.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@521 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-11 00:03:18 +00:00
Dag-Erling Smørgrav 34c9fb6fd3 Only call dlerror() after dlsym() failed.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@520 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 23:57:31 +00:00
Dag-Erling Smørgrav 31e9142afc Verify that the target is a regular file.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@519 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 23:50:03 +00:00
Dag-Erling Smørgrav 407565fc1d The name of the default policy is (and always has been) "other", not
"default".


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@518 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 22:38:13 +00:00
Dag-Erling Smørgrav 255c7f6727 Detect fdlopen(3)
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@517 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 21:26:49 +00:00
Dag-Erling Smørgrav 8c2f4c74b7 Use fdlopen(3) if it is available.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@516 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 21:26:34 +00:00
Dag-Erling Smørgrav 8f8a8584fc Correct usage string
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@515 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 21:22:57 +00:00
Dag-Erling Smørgrav ca0b4cb0c7 Generate Trac-compatible wiki text for each release from HISTORY.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@514 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 21:16:05 +00:00
Dag-Erling Smørgrav fb9c3dcdf5 Normalize whitespace
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@513 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-10 21:05:42 +00:00
Dag-Erling Smørgrav 41bb288744 The only place RETURNP() is used returns a non-const pointer.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@511 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2012-01-09 13:25:09 +00:00
Dag-Erling Smørgrav 596b3af085 Use a different default prompt if PAM_RHOST != PAM_HOST.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@510 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-31 13:14:23 +00:00
Dag-Erling Smørgrav 8ec4a16273 Don't log an error message if the file does not exist.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@509 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-22 17:18:53 +00:00
Dag-Erling Smørgrav 8372b71ce1 Add Matthias Drochner - I wish I'd remembered to do so before I rolled
Lycopsida.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@508 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-18 17:07:53 +00:00
166 changed files with 7440 additions and 2017 deletions

30
.gitignore vendored Normal file
View File

@ -0,0 +1,30 @@
/aclocal.m4
/autom4te.cache
/compile
/config.guess
/config.h.in
/config.h
/config.log
/config.status
/config.sub
/configure
/cov
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
/stamp-h1
/test-driver
*~
.deps
.libs
*.a
*.la
*.lo
*.log
*.o
*.pc
*.profraw
Makefile
Makefile.in

View File

@ -1,30 +0,0 @@
Release checklist
=================
0) Find a code name for the release
1) Update configure.ac and include/security/openpam_version.h
2) Read through the diffs from the last release, and update the change
log.
3) Update the release notes.
4) If any files have been added, update the manifest.
5) Run dist.sh to generate a tarball.
6) Unpack the tarball somewhere safe and build everything.
7) Fix any problems.
8) Submit.
9) Re-run dist.sh to roll the actual release.
A) Publish the tarball on SourceForge.
B) Update the website.
$Id$

25
CREDITS
View File

@ -1,4 +1,6 @@
_Ἀπόδοτε οὖν τὰ Καίσαρος Καίσαρι καὶ τὰ τοῦ Θεοῦ τῷ Θεῷ_
The OpenPAM library was developed for the FreeBSD Project by ThinkSec AS
and Network Associates Laboratories, the Security Research Division of
Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
@ -13,29 +15,42 @@ directly or indirectly, with patches, criticism, suggestions, or
ideas:
Andrew Morgan <morgan@transmeta.com>
Ankita Pal <pal.ankita.ankita@gmail.com>
Baptiste Daroussin <bapt@freebsd.org>
Brian Fundakowski Feldman <green@freebsd.org>
Brooks Davis <brooks@freebsd.org>
Christos Zoulas <christos@netbsd.org>
Daniel Richard G. <skunk@iskunk.org>
Darren J. Moffat <Darren.Moffat@sun.com>
Darren J. Moffat <darren.moffat@sun.com>
Dimitry Andric <dim@freebsd.org>
Dmitry V. Levin <ldv@altlinux.org>
Don Lewis <truckman@freebsd.org>
Emmanuel Dreyfus <manu@netbsd.org>
Eric Melville <eric@freebsd.org>
Gary Winiger <Gary.Winiger@sun.com>
Espen Grøndahl <espegro@usit.uio.no>
Gary Winiger <gary.winiger@sun.com>
Gavin Atkinson <gavin@freebsd.org>
Gleb Smirnoff <glebius@freebsd.org>
Hubert Feyrer <hubert@feyrer.de>
Jason Evans <jasone@freebsd.org>
Joe Marcus Clarke <marcus@freebsd.org>
Juli Mallett <jmallett@freebsd.org>
Jörg Sonnenberger <joerg@britannica.bec.de>
Juli Mallett <jmallett@freebsd.org>
Larry Baird <lab@gta.com>
Maëlle Lesage <lesage.maelle@gmail.com>
Mark Murray <markm@freebsd.org>
Matthias Drochner <drochner@netbsd.org>
Mike Petullo <mike@flyn.org>
Mikhail Teterin <mi@aldan.algebra.com>
Mikko Työläjärvi <mbsd@pacbell.net>
Nick Hibma <nick@van-laarhoven.org>
Patrick Bihan-Faou <patrick-fbsd@mindstep.com>
Robert Morris <rtm@lcs.mit.edu>
Robert Watson <rwatson@freebsd.org>
Ruslan Ermilov <ru@freebsd.org>
Sebastian Krahmer <sebastian.krahmer@gmail.com>
Solar Designer <solar@openwall.com>
Takanori Saneto <sanewo@ba2.so-net.ne.jp>
Tim Creech <tcreech@tcreech.com>
Wojciech A. Koszek <wkoszek@freebsd.org>
Yar Tikhiy <yar@freebsd.org>
$Id$

165
HISTORY
View File

@ -1,3 +1,156 @@
OpenPAM Ximenia 2023-06-27
- BUGFIX: Fix race condition in openpam_ttyconv(3) when used with
expect scripts.
- BUGFIX: In openpam_set_option(3), when removing an option, properly
decrement the option count.
- BUGFIX: In openpam_subst(3), avoid incrementing past the end of the
template.
============================================================================
OpenPAM Tabebuia 2019-02-24
- BUGFIX: Fix off-by-one bug in pam_getenv(3) which was introduced in
OpenPAM Radula.
- ENHANCE: Add unit tests for pam_{get,put,set}env(3).
============================================================================
OpenPAM Resedacea 2017-04-30
- BUGFIX: Reinstore the NULL check in pam_end(3) which was removed in
OpenPAM Radula, as it breaks common error-handling constructs.
- BUGFIX: Return PAM_SYMBOL_ERR instead of PAM_SYSTEM_ERR from the
dispatcher when the required service function could not be found.
- ENHANCE: Introduce the PAM_BAD_HANDLE error code for when pamh is
NULL in API functions that have a NULL check.
- ENHANCE: Introduce the PAM_BAD_ITEM, PAM_BAD_FEATURE and
PAM_BAD_CONSTANT error codes for situations where we previously
incorrectly used PAM_SYMBOL_ERR to denote that an invalid constant
had been passed to an API function.
- ENHANCE: Improve the RETURN VALUES section in API man pages,
especially for functions that cannot fail, which were incorrectly
documented as returning -1 on failure.
============================================================================
OpenPAM Radula 2017-02-19
- BUGFIX: Fix an inverted test which prevented pam_get_authtok(3) and
pam_get_user(3) from using application-provided custom prompts.
- BUGFIX: Plug a memory leak in pam_set_item(3).
- BUGFIX: Plug a potential memory leak in openpam_readlinev(3).
- BUGFIX: In openpam_readword(3), support line continuations within
whitespace.
- ENHANCE: Add a feature flag to control fallback to "other" policy.
- ENHANCE: Add a pam_return(8) module which returns an arbitrary
code specified in the module options.
- ENHANCE: More and better unit tests.
============================================================================
OpenPAM Ourouparia 2014-09-12
- ENHANCE: When executing a chain, require at least one service
function to succeed. This mitigates fail-open scenarios caused by
misconfigurations or missing modules.
- ENHANCE: Make sure to overwrite buffers which may have contained an
authentication token when they're no longer needed.
- BUGFIX: Under certain circumstances, specifying a non-existent
module (or misspelling the name of a module) in a policy could
result in a fail-open scenario. (CVE-2014-3879)
- FEATURE: Add a search path for modules. This was implemented in
Nummularia but inadvertently left out of the release notes.
- BUGFIX: The is_upper() predicate only accepted the letter A as an
upper-case character instead of the entire A-Z range. As a result,
service and module names containing upper-case letters other than A
would be rejected.
============================================================================
OpenPAM Nummularia 2013-09-07
- ENHANCE: Rewrite the dynamic loader to improve readability and
reliability. Modules can now be listed without the ".so" suffix in
the policy file; OpenPAM will automatically add it, just like it
will automatically add the version number if required.
- ENHANCE: Allow openpam_straddch(3) to be called without a character
so it can be used to preallocate a string.
- ENHANCE: Improve portability by adding simple asprintf(3) and
vasprintf(3) implementations for platforms that don't have them.
- ENHANCE: Move the libpam sources into a separate subdirectory.
- ENHANCE: Substantial documentation improvements.
- BUGFIX: When openpam_readword(3) encountered an opening quote, it
would set the first byte in the buffer to '\0', discarding all
existing text and, unless the buffer was empty to begin with, all
subsequent text as well. This went unnoticed because none of the
unit tests for quoted strings had any text preceding the opening
quote.
- BUGFIX: make --with-modules-dir work the way it was meant to work
(but never did).
============================================================================
OpenPAM Micrampelis 2012-05-26
- FEATURE: Add an openpam_readword(3) function which reads the next
word from an input stream, applying shell quoting and escaping
rules. Add numerous unit tests for openpam_readword(3).
- FEATURE: Add an openpam_readlinev(3) function which uses the
openpam_readword(3) function to read words from an input stream one
at a time until it reaches an unquoted, unescaped newline, and
returns an array of those words. Add several unit tests for
openpam_readlinev(3).
- FEATURE: Add a PAM_HOST item which pam_start(3) initializes to the
machine's hostname. This was implemented in Lycopsida but
inadvertantly left out of the release notes.
- FEATURE: In pam_get_authtok(3), if neither the application nor the
module have specified a prompt and PAM_HOST and PAM_RHOST are both
defined but not equal, use a different default prompt that includes
PAM_USER and PAM_HOST.
- ENHANCE: Rewrite the policy parser to used openpam_readlinev(),
which greatly simplifies the code.
- ENHANCE: The previous implementation of the policy parser relied on
the openpam_readline(3) function, which (by design) munges
whitespace and understands neither quotes nor backslash escapes.
As a result of the aforementioned rewrite, whitespace, quotes and
backslash escapes in policy files are now handled in a consistent
and predictable manner.
- ENHANCE: On platforms that have it, use fdlopen(3) to load modules.
This closes the race between the ownership / permission check and
the dlopen(3) call.
- ENHANCE: Reduce the amount of pointless error messages generated
while searching for a module.
- ENHANCE: Numerous documentation improvements, both in content and
formatting.
- BUGFIX: A patch incorporated in Lycopsida inadvertantly changed
OpenPAM's behavior when several policies exist for the same
service, from ignoring all but the first to concatenating them all.
Revert to the original behavior.
- BUGFIX: Plug a memory leak in the policy parser.
============================================================================
OpenPAM Lycopsida 2011-12-18
- ENHANCE: removed static build autodetection, which didn't work
@ -22,7 +175,7 @@ OpenPAM Lycopsida 2011-12-18
module before loading it.
- ENHANCE: added / improved input validation in many cases, including
the policy file and some function arguments.
the policy file and some function arguments. (CVE-2011-4122)
============================================================================
OpenPAM Hydrangea 2007-12-21
@ -269,7 +422,7 @@ OpenPAM Cinchona 2002-04-08
- ENHANCE: Add openpam_free_data(), a generic cleanup function for
pam_set_data() consumers.
============================================================================
OpenPAM Centaury 2002-03-14
OpenPAM Centaury 2002-03-14
- BUGFIX: Add missing #include <string.h> to openpam_log.c.
@ -308,7 +461,7 @@ OpenPAM Celandine 2002-03-05
module with the same version number as the library itself to one
with no version number at all.
============================================================================
OpenPAM Cantaloupe 2002-02-22
OpenPAM Cantaloupe 2002-02-22
- BUGFIX: The proper use of PAM_SYMBOL_ERR is to indicate an invalid
argument to pam_[gs]et_item(3), not to indicate dlsym(3) failures.
@ -338,7 +491,7 @@ OpenPAM Cantaloupe 2002-02-22
- ENHANCE: openpam_get_authtok() now respects the echo_pass,
try_first_pass, and use_first_pass options.
============================================================================
OpenPAM Caliopsis 2002-02-13
OpenPAM Caliopsis 2002-02-13
Fixed a number of bugs in the previous release, including:
- a number of bugs in and related to pam_[gs]et_item(3)
@ -349,8 +502,6 @@ Fixed a number of bugs in the previous release, including:
- missing 'continue' in openpam_dispatch.c caused successes to be
counted as failures
============================================================================
OpenPAM Calamite 2002-02-09
OpenPAM Calamite 2002-02-09
First (beta) release.
============================================================================
$Id$

View File

@ -54,5 +54,3 @@
directory:
# make install
$Id$

View File

@ -1,6 +1,6 @@
Copyright (c) 2002-2003 Networks Associates Technology, Inc.
Copyright (c) 2004-2011 Dag-Erling Smørgrav
Copyright (c) 2004-2023 Dag-Erling Smørgrav
All rights reserved.
This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,5 +31,3 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
$Id$

View File

@ -1,13 +1,13 @@
# $Id$
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = lib bin modules include
SUBDIRS = misc include lib bin modules
if WITH_DOC
SUBDIRS += doc
endif
SUBDIRS += t
EXTRA_DIST = \
CREDITS \
HISTORY \
@ -17,3 +17,32 @@ EXTRA_DIST = \
RELNOTES \
autogen.sh \
misc/gendoc.pl
if WITH_CODE_COVERAGE
covdir = @abs_top_builddir@/cov
coverage: coverage-clean all coverage-prepare coverage-run coverage-report
coverage-clean:
-rm -rf "${covdir}"
coverage-prepare:
mkdir "${covdir}"
if CLANG_CODE_COVERAGE
profdata = ${covdir}/@PACKAGE@.profdata
# hardcoding libpam.so here is horrible, need to find a better solution
coverage-run:
LLVM_PROFILE_FILE="${covdir}/@PACKAGE@.%p.raw" \
${MAKE} -C "@abs_top_builddir@" check
coverage-report:
llvm-profdata@clang_ver@ merge \
--sparse "${covdir}/@PACKAGE@".*.raw -o "${profdata}"
llvm-cov@clang_ver@ show \
--format=html --tab-size=8 \
--output-dir="${covdir}" \
--instr-profile="${profdata}" \
--object "@abs_top_builddir@/lib/libpam/.libs/libpam.so"
@echo "coverage report: file://${covdir}/index.html"
endif
else
coverage:
echo "code coverage is not enabled." >&2
false
endif

17
README
View File

@ -7,21 +7,4 @@ implementations disagree, OpenPAM tries to remain compatible with
Solaris, at the expense of XSSO conformance and Linux-PAM
compatibility.
These are some of OpenPAM's features:
- Implements the complete PAM API as described in the original PAM
paper and in OSF-RFC 86.0; this corresponds to the full XSSO API
except for mappings and secondary authentication. Also
implements some extensions found in Solaris 9.
- Extends the API with several useful and time-saving functions.
- Performs strict checking of return values from service modules.
- Reads configuration from /etc/pam.d/, /etc/pam.conf,
/usr/local/etc/pam.d/ and /usr/local/etc/pam.conf, in that order;
this will be made configurable in a future release.
Please direct bug reports and inquiries to <des@des.no>.
$Id$

View File

@ -1,24 +1,21 @@
Release notes for OpenPAM Lycopsida
===================================
Release notes for OpenPAM Ximenia
=================================
This release corresponds to the code used in FreeBSD HEAD as of the
release date, and is also expected to work on almost any POSIX-like
platform that has GNU autotools, GNU make and the GNU compiler suite
installed.
OpenPAM is developed primarily on FreeBSD, but is expected to work on
almost any POSIX-like platform that has GNU autotools, GNU make and
the GNU compiler suite installed.
The library itself is complete. Documentation exists in the form of
man pages for the library functions. These man pages are generated by
a Perl script from specially marked-up comments in the source files
themselves, which minimizes the chance that any of them should be out
of date.
The OpenPAM distribution consists of the following components:
The distribution also includes three sample modules (pam_deny,
pam_permit and pam_unix) and a sample application (su). These are not
intended for actual use, but rather to serve as examples for module or
application developers. It also includes a command-line application
(pamtest) which can be used to test policies and modules.
- The PAM library itself, with complete API documentation.
- Sample modules (pam_permit, pam_deny and pam_unix) and a sample
application (su) which demonstrate how to use the PAM library.
- A test application (pamtest) which can be used to test policies and
modules.
- Unit tests for limited portions of the library.
Please direct bug reports and inquiries to <des@des.no>.
$Id$

9
TODO Normal file
View File

@ -0,0 +1,9 @@
- Fix try_first_pass / use_first_pass (pam_get_authtok() code &
documentation are slightly incorrect, OpenPAM's pam_unix(8) is
incorrect, all FreeBSD modules are broken)
- Add loop detection to openpam_load_chain().
- Complete unit tests for openpam_dispatch().
- Stop using PAM_SYMBOL_ERR incorrectly.

View File

@ -1,7 +1,4 @@
#!/bin/sh
#
# $Id$
#
set -ex
@ -15,7 +12,8 @@ export CONFIG_SHELL=/bin/sh
--with-pam-unix \
--with-pamtest \
--with-su \
--with-modules-dir=/usr/lib \
--enable-debug \
--enable-developer-warnings \
--enable-werror \
--enable-code-coverage \
"$@"

View File

@ -1,10 +1,7 @@
#!/bin/sh
#
# $Id$
#
aclocal
libtoolize --copy --force
aclocal -I m4
autoheader
automake -a -c --foreign
automake --add-missing --copy --foreign
autoconf

View File

@ -1,6 +1,4 @@
# $Id$
SUBDIRS =
SUBDIRS = openpam_dump_policy
if WITH_PAMTEST
SUBDIRS += pamtest

1
bin/openpam_dump_policy/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/openpam_dump_policy

View File

@ -0,0 +1,9 @@
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libpam
noinst_PROGRAMS = openpam_dump_policy
openpam_dump_policy_SOURCES = openpam_dump_policy.c
if WITH_SYSTEM_LIBPAM
openpam_dump_policy_LDADD = $(SYSTEM_LIBPAM)
else
openpam_dump_policy_LDADD = $(top_builddir)/lib/libpam/libpam.la
endif

View File

@ -0,0 +1,200 @@
/*-
* Copyright (c) 2011-2014 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_asprintf.h"
static char *
openpam_chain_name(const char *service, pam_facility_t fclt)
{
const char *facility = pam_facility_name[fclt];
char *name;
if (asprintf(&name, "pam_%s_%s", service, facility) == -1)
return (NULL);
return (name);
}
static char *
openpam_facility_index_name(pam_facility_t fclt)
{
const char *facility = pam_facility_name[fclt];
char *name, *p;
if (asprintf(&name, "PAM_%s", facility) == -1)
return (NULL);
for (p = name + 4; *p; ++p)
*p = toupper((unsigned char)*p);
return (name);
}
int
openpam_dump_chain(const char *name, pam_chain_t *chain)
{
char *modname, **opt, *p;
int i;
for (i = 0; chain != NULL; ++i, chain = chain->next) {
/* declare the module's struct pam_module */
modname = strrchr(chain->module->path, '/');
modname = strdup(modname ? modname : chain->module->path);
if (modname == NULL)
return (PAM_BUF_ERR);
for (p = modname; *p && *p != '.'; ++p)
/* nothing */ ;
*p = '\0';
printf("extern struct pam_module %s_pam_module;\n", modname);
/* module arguments */
printf("static char *%s_%d_optv[] = {\n", name, i);
for (opt = chain->optv; *opt; ++opt) {
printf("\t\"");
for (p = *opt; *p; ++p) {
if (isprint((unsigned char)*p) && *p != '"')
printf("%c", *p);
else
printf("\\x%02x", (unsigned char)*p);
}
printf("\",\n");
}
printf("\tNULL,\n");
printf("};\n");
/* next module in chain */
if (chain->next != NULL)
printf("static pam_chain_t %s_%d;\n", name, i + 1);
/* chain entry */
printf("static pam_chain_t %s_%d = {\n", name, i);
printf("\t.module = &%s_pam_module,\n", modname);
printf("\t.flag = 0x%08x,\n", chain->flag);
printf("\t.optc = %d,\n", chain->optc);
printf("\t.optv = %s_%d_optv,\n", name, i);
if (chain->next)
printf("\t.next = &%s_%d,\n", name, i + 1);
else
printf("\t.next = NULL,\n");
printf("};\n");
free(modname);
}
return (PAM_SUCCESS);
}
int
openpam_dump_policy(const char *service)
{
pam_handle_t *pamh;
char *name;
int fclt, ret;
if ((pamh = calloc(1, sizeof *pamh)) == NULL)
return (PAM_BUF_ERR);
if ((ret = openpam_configure(pamh, service)) != PAM_SUCCESS)
return (ret);
for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) {
if (pamh->chains[fclt] != NULL) {
if ((name = openpam_chain_name(service, fclt)) == NULL)
return (PAM_BUF_ERR);
ret = openpam_dump_chain(name, pamh->chains[fclt]);
free(name);
if (ret != PAM_SUCCESS)
return (ret);
}
}
printf("static pam_policy_t pam_%s_policy = {\n", service);
printf("\t.service = \"%s\",\n", service);
printf("\t.chains = {\n");
for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) {
if ((name = openpam_facility_index_name(fclt)) == NULL)
return (PAM_BUF_ERR);
printf("\t\t[%s] = ", name);
free(name);
if (pamh->chains[fclt] != NULL) {
if ((name = openpam_chain_name(service, fclt)) == NULL)
return (PAM_BUF_ERR);
printf("&%s_0,\n", name);
free(name);
} else {
printf("NULL,\n");
}
}
printf("\t},\n");
printf("};\n");
free(pamh);
return (PAM_SUCCESS);
}
static void
usage(void)
{
fprintf(stderr, "usage: openpam_dump_policy [-d] policy ...\n");
exit(1);
}
int
main(int argc, char *argv[])
{
int i, opt;
while ((opt = getopt(argc, argv, "d")) != -1)
switch (opt) {
case 'd':
openpam_debug = 1;
break;
default:
usage();
}
argc -= optind;
argv += optind;
if (argc < 1)
usage();
printf("#include <security/pam_appl.h>\n");
printf("#include \"openpam_impl.h\"\n");
for (i = 0; i < argc; ++i)
openpam_dump_policy(argv[i]);
printf("pam_policy_t *pam_embedded_policies[] = {\n");
for (i = 0; i < argc; ++i)
printf("\t&pam_%s_policy,\n", argv[i]);
printf("\tNULL,\n");
printf("};\n");
exit(0);
}

1
bin/pamtest/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/pamtest

View File

@ -1,9 +1,11 @@
# $Id$
INCLUDES = -I$(top_srcdir)/include
AM_CPPFLAGS = -I$(top_srcdir)/include
bin_PROGRAMS = pamtest
pamtest_SOURCES = pamtest.c
pamtest_LDADD = $(top_builddir)/lib/libpam.la
if WITH_SYSTEM_LIBPAM
pamtest_LDADD = $(SYSTEM_LIBPAM)
else
pamtest_LDADD = $(top_builddir)/lib/libpam/libpam.la
endif
dist_man1_MANS = pamtest.1

View File

@ -1,5 +1,5 @@
.\"-
.\" Copyright (c) 2011 Dag-Erling Smørgrav
.\" Copyright (c) 2011-2017 Dag-Erling Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -10,6 +10,9 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,19 +26,18 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\"
.Dd November 2, 2011
.Dd July 11, 2013
.Dt PAMTEST 1
.Os
.Sh NAME
.Nm pamtest
.Nd PAM policy tester
.Sh SYNOPSYS
.Sh SYNOPSIS
.Nm
.Op Fl dksv
.Op Fl dkMPsv
.Op Fl H Ar rhost
.Op Fl h Ar host
.Op Fl T Ar timeout
.Op Fl t Ar tty
.Op Fl U Ar ruser
.Op Fl u Ar user
@ -116,6 +118,11 @@ The default is to use the result of calling
.Xr gethostname 3 .
.It Fl k
Keep going even if one of the commands fails.
.It Fl M
Disable path, ownership and permission checks on module files.
.It Fl P
Disable service name validation and path, ownership and permission
checks on policy files.
.It Fl s
Set the
.Dv PAM_SILENT
@ -128,6 +135,9 @@ flag when calling the
and
.Xr pam_close_session 3
primitives.
.It Fl T Ar timeout
Set the conversation timeout (in seconds) for
.Xr openpam_ttyconv 3 .
.It Fl t Ar tty
Specify the name of the tty.
The default is to use the result of calling
@ -149,14 +159,14 @@ policy:
pamtest -v system auth account change setcred open close unsetcred
.Ed
.Sh SEE ALSO
.Xr openpam 3
.Xr pam 3
.Xr openpam 3 ,
.Xr pam 3 ,
.Xr pam.conf 5
.Sh AUTHORS
The
.Nm
utility and this manual page were written by
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .
.Sh BUGS
The
.Nm

View File

@ -6,11 +6,13 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,8 +25,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -32,6 +32,7 @@
#endif
#include <err.h>
#include <limits.h>
#include <pwd.h>
#include <stdarg.h>
#include <stdio.h>
@ -113,6 +114,7 @@ pt_authenticate(int flags)
int pame;
flags |= silent;
pt_verbose("pam_authenticate()");
if ((pame = pam_authenticate(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_authenticate()");
return (pame);
@ -127,6 +129,7 @@ pt_acct_mgmt(int flags)
int pame;
flags |= silent;
pt_verbose("pam_acct_mgmt()");
if ((pame = pam_acct_mgmt(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_acct_mgmt()");
return (pame);
@ -141,6 +144,7 @@ pt_chauthtok(int flags)
int pame;
flags |= silent;
pt_verbose("pam_chauthtok()");
if ((pame = pam_chauthtok(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_chauthtok()");
return (pame);
@ -155,6 +159,7 @@ pt_setcred(int flags)
int pame;
flags |= silent;
pt_verbose("pam_setcred()");
if ((pame = pam_setcred(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_setcred()");
return (pame);
@ -169,6 +174,7 @@ pt_open_session(int flags)
int pame;
flags |= silent;
pt_verbose("pam_open_session()");
if ((pame = pam_open_session(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_open_session()");
return (pame);
@ -183,6 +189,7 @@ pt_close_session(int flags)
int pame;
flags |= silent;
pt_verbose("pam_close_session()");
if ((pame = pam_close_session(pamh, flags)) != PAM_SUCCESS)
pt_error(pame, "pam_close_session()");
return (pame);
@ -261,11 +268,29 @@ static void
usage(void)
{
fprintf(stderr, "usage: pamtest [-dksv] %s\n",
"[-H rhost] [-h host] [-t tty] [-U ruser] [-u user] service");
fprintf(stderr, "usage: pamtest %s service command ...\n",
"[-dkMPsv] [-H rhost] [-h host] [-t tty] [-U ruser] [-u user]");
exit(1);
}
/*
* Handle an option that takes an int argument and can be used only once
*/
static void
opt_num_once(int opt, long *num, const char *arg)
{
char *end;
long l;
l = strtol(arg, &end, 0);
if (end == optarg || *end != '\0') {
fprintf(stderr,
"The -%c option expects a numeric argument\n", opt);
usage();
}
*num = l;
}
/*
* Handle an option that takes a string argument and can be used only once
*/
@ -293,11 +318,12 @@ main(int argc, char *argv[])
const char *user = NULL;
const char *service = NULL;
const char *tty = NULL;
long timeout = 0;
int keepatit = 0;
int pame;
int opt;
while ((opt = getopt(argc, argv, "dH:h:kst:U:u:v")) != -1)
while ((opt = getopt(argc, argv, "dH:h:kMPsT:t:U:u:v")) != -1)
switch (opt) {
case 'd':
openpam_debug++;
@ -311,9 +337,26 @@ main(int argc, char *argv[])
case 'k':
keepatit = 1;
break;
case 'M':
openpam_set_feature(OPENPAM_RESTRICT_MODULE_NAME, 0);
openpam_set_feature(OPENPAM_VERIFY_MODULE_FILE, 0);
break;
case 'P':
openpam_set_feature(OPENPAM_RESTRICT_SERVICE_NAME, 0);
openpam_set_feature(OPENPAM_VERIFY_POLICY_FILE, 0);
break;
case 's':
silent = PAM_SILENT;
break;
case 'T':
opt_num_once(opt, &timeout, optarg);
if (timeout < 0 || timeout > INT_MAX) {
fprintf(stderr,
"Invalid conversation timeout\n");
usage();
}
openpam_ttyconv_timeout = (int)timeout;
break;
case 't':
opt_str_once(opt, &tty, optarg);
break;
@ -341,6 +384,8 @@ main(int argc, char *argv[])
++argv;
/* defaults */
if (service == NULL)
service = "pamtest";
if (rhost == NULL) {
if (gethostname(hostname, sizeof(hostname)) == -1)
err(1, "gethostname()");

1
bin/su/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/su

View File

@ -1,9 +1,11 @@
# $Id$
INCLUDES = -I$(top_srcdir)/include
AM_CPPFLAGS = -I$(top_srcdir)/include
bin_PROGRAMS = su
su_SOURCES = su.c
su_LDADD = $(top_builddir)/lib/libpam.la
if WITH_SYSTEM_LIBPAM
su_LDADD = $(SYSTEM_LIBPAM)
else
su_LDADD = $(top_builddir)/lib/libpam/libpam.la
endif
dist_man1_MANS = su.1

View File

@ -1,5 +1,5 @@
.\"-
.\" Copyright (c) 2011 Dag-Erling Smørgrav
.\" Copyright (c) 2011-2017 Dag-Erling Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -10,6 +10,9 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,15 +26,13 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\"
.Dd November 2, 2011
.Dt SU 1
.Os
.Sh NAME
.Nm su
.Nd switch user identity
.Sh SYNOPSYS
.Sh SYNOPSIS
.Nm
.Op Ar login Op Ar ...
.Sh DESCRIPTION
@ -53,10 +54,10 @@ The
utility is provided with the OpenPAM library as a sample application
and should not be used in production systems.
.Sh SEE ALSO
.Xr openpam 3
.Xr openpam 3 ,
.Xr pam 3
.Sh AUTHORS
The
.Nm
utility and this manual page were written by
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -1,27 +1,29 @@
dnl $Id$
AC_PREREQ([2.62])
AC_REVISION([$Id$])
AC_INIT([OpenPAM], [trunk], [des@des.no])
AC_CONFIG_SRCDIR([lib/pam_start.c])
AC_PREREQ([2.69])
AC_INIT([OpenPAM], [trunk], [des@des.no], [openpam], [https://openpam.org/])
AC_CONFIG_SRCDIR([lib/libpam/pam_start.c])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AM_CONFIG_HEADER([config.h])
# C compiler and features
AC_LANG(C)
AC_PROG_CC
AC_PROG_CC([clang gcc cc])
AC_PROG_CC_STDC
AC_PROG_CPP
AC_PROG_CXX([clang++ g++ c++])
AC_GNU_SOURCE
AC_C_CONST
AC_C_RESTRICT
AC_C_VOLATILE
AX_COMPILER_VENDOR
# libtool
LT_PREREQ([2.2.6])
LT_INIT([disable-static dlopen])
# pkg-config
AX_PROG_PKG_CONFIG
# other programs
AC_PROG_INSTALL
@ -31,31 +33,29 @@ AC_DEFINE_UNQUOTED(LIB_MAJ, $LIB_MAJ, [OpenPAM library major number])
AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug],
[turn debugging on by default]),
AC_DEFINE(OPENPAM_DEBUG, 1, [Turn debugging on by default]))
[turn debugging macros on]),
AC_DEFINE(OPENPAM_DEBUG, 1, [Turn debugging macros on]))
AC_ARG_ENABLE([unversioned-modules],
AC_HELP_STRING([--disable-unversioned-modules],
[support loading of unversioned modules]),
[support loading of unversioned modules]),
[AS_IF([test x"$enableval" = x"no"], [
AC_DEFINE(DISABLE_UNVERSIONED_MODULES,
1,
[Whether loading unversioned modules support is disabled])
AC_DEFINE(DISABLE_UNVERSIONED_MODULES,
1,
[Whether loading unversioned modules support is disabled])
])])
AC_ARG_WITH([modules-dir],
AC_HELP_STRING([--with-modules-dir=DIR],
[OpenPAM modules directory]),
[OpenPAM modules directory]),
[AS_IF([test x"$withval" != x"no"], [
OPENPAM_MODULES_DIR="$withval"
], [
OPENPAM_MODULES_DIR="$libdir"
])],
[OPENPAM_MODULES_DIR="$libdir"])
AC_DEFINE_UNQUOTED(OPENPAM_MODULES_DIR,
"${OPENPAM_MODULES_DIR%/}/",
[OpenPAM modules directory])
OPENPAM_MODULES_DIR="$withval"
AC_DEFINE_UNQUOTED(OPENPAM_MODULES_DIR,
"${OPENPAM_MODULES_DIR%/}",
[OpenPAM modules directory])
])])
AC_SUBST(OPENPAM_MODULES_DIR)
AM_CONDITIONAL([CUSTOM_MODULES_DIR], [test x"$OPENPAM_MODULES_DIR" != x""])
AC_ARG_WITH([doc],
AC_HELP_STRING([--without-doc], [do not build documentation]),
@ -64,26 +64,36 @@ AC_ARG_WITH([doc],
AM_CONDITIONAL([WITH_DOC], [test x"$with_doc" = x"yes"])
AC_ARG_WITH([pam-unix],
AC_HELP_STRING([--with-pam-unix], [compile sample pam_unix(8) implementation]),
AC_HELP_STRING([--with-pam-unix], [build sample pam_unix(8) module]),
[],
[with_pam_unix=no])
AM_CONDITIONAL([WITH_PAM_UNIX], [test x"$with_pam_unix" = x"yes"])
AC_ARG_WITH(pamtest,
AC_HELP_STRING([--with-pamtest], [compile test application]),
AC_HELP_STRING([--with-pamtest], [build test application]),
[],
[with_pamtest=no])
AM_CONDITIONAL([WITH_PAMTEST], [test x"$with_pamtest" = x"yes"])
AC_ARG_WITH(su,
AC_HELP_STRING([--with-su], [compile sample su(1) implementation]),
AC_HELP_STRING([--with-su], [build sample su(1) implementation]),
[],
[with_su=no])
AM_CONDITIONAL([WITH_SU], [test x"$with_su" = x"yes"])
AC_ARG_WITH(system-libpam,
AC_HELP_STRING([--with-system-libpam], [use system libpam]),
[],
[with_system_libpam=no])
AM_CONDITIONAL([WITH_SYSTEM_LIBPAM], [test x"$with_system_libpam" = x"yes"])
AC_CHECK_HEADERS([crypt.h])
AC_CHECK_FUNCS([fpurge strlcmp strlcpy])
AC_CHECK_FUNCS([asprintf vasprintf])
AC_CHECK_FUNCS([dlfunc fdlopen])
AC_CHECK_FUNCS([fpurge])
AC_CHECK_FUNCS([setlogmask])
AC_CHECK_FUNCS([strlcat strlcmp strlcpy strlset])
saved_LIBS="${LIBS}"
LIBS=""
@ -94,14 +104,19 @@ AC_SUBST(DL_LIBS)
saved_LIBS="${LIBS}"
LIBS=""
AC_CHECK_LIB([crypt], [crypt])
CRYPT_LIBS="${LIBS}"
AC_CHECK_LIB([pam], [pam_start])
SYSTEM_LIBPAM="${LIBS}"
LIBS="${saved_LIBS}"
AC_SUBST(CRYPT_LIBS)
AC_SUBST(SYSTEM_LIBPAM)
AX_PKG_CONFIG_CHECK([cryb-test],
[AC_MSG_NOTICE([Cryb test framework found, unit tests enabled.])],
[AC_MSG_WARN([Cryb test framework not found, unit tests disabled.])])
AM_CONDITIONAL([WITH_TEST], [test x"$CRYB_TEST_LIBS" != x""])
AC_ARG_ENABLE([developer-warnings],
AS_HELP_STRING([--enable-developer-warnings], [enable strict warnings (default is NO)]),
[CFLAGS="${CFLAGS} -Wall -Wextra"])
[CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual"])
AC_ARG_ENABLE([debugging-symbols],
AS_HELP_STRING([--enable-debugging-symbols], [enable debugging symbols (default is NO)]),
[CFLAGS="${CFLAGS} -O0 -g -fno-inline"])
@ -109,19 +124,47 @@ AC_ARG_ENABLE([werror],
AS_HELP_STRING([--enable-werror], [use -Werror (default is NO)]),
[CFLAGS="${CFLAGS} -Werror"])
AC_ARG_ENABLE([code-coverage],
AS_HELP_STRING([--enable-code-coverage],
[enable code coverage]))
AS_IF([test x"$enable_code_coverage" = x"yes"], [
AM_COND_IF([WITH_TEST], [
AS_IF([test x"$ax_cv_c_compiler_vendor" = x"clang"], [
CFLAGS="${CFLAGS} -fprofile-instr-generate -fcoverage-mapping"
clang_code_coverage="yes"
AC_SUBST([clang_ver], [${CC#clang}])
], [
AC_MSG_ERROR([code coverage is only supported with clang])
])
AC_DEFINE([WITH_CODE_COVERAGE], [1], [Define to 1 if code coverage is enabled])
AC_MSG_NOTICE([code coverage enabled])
], [
AC_MSG_ERROR([code coverage requires unit tests])
])
])
AM_CONDITIONAL([WITH_CODE_COVERAGE], [test x"$enable_code_coverage" = x"yes"])
AM_CONDITIONAL([CLANG_CODE_COVERAGE], [test x"$clang_code_coverage" = x"yes"])
AC_CONFIG_FILES([
Makefile
bin/Makefile
bin/openpam_dump_policy/Makefile
bin/pamtest/Makefile
bin/su/Makefile
doc/Makefile
doc/man/Makefile
freebsd/Makefile
include/Makefile
include/security/Makefile
lib/Makefile
lib/libpam/Makefile
misc/Makefile
modules/Makefile
modules/pam_unix/Makefile
modules/pam_deny/Makefile
modules/pam_permit/Makefile
doc/Makefile
doc/man/Makefile
Makefile
modules/pam_return/Makefile
modules/pam_unix/Makefile
t/Makefile
])
AC_CONFIG_FILES([misc/coverity.sh],[chmod +x misc/coverity.sh])
AC_OUTPUT

View File

@ -1,3 +1 @@
# $Id$
SUBDIRS = man

2
doc/man/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/*.3
!/pam_conv.3

View File

@ -1,9 +1,7 @@
# $Id$
NULL =
# Standard PAM API
PMAN = \
PAM_MAN = \
pam_acct_mgmt.3 \
pam_authenticate.3 \
pam_chauthtok.3 \
@ -24,7 +22,7 @@ PMAN = \
$(NULL)
# Standard module API
MMAN = \
MOD_MAN = \
pam_sm_acct_mgmt.3 \
pam_sm_authenticate.3 \
pam_sm_chauthtok.3 \
@ -34,16 +32,21 @@ MMAN = \
$(NULL)
# OpenPAM extensions
OMAN = \
OPENPAM_MAN = \
openpam_borrow_cred.3 \
openpam_free_data.3 \
openpam_free_envlist.3 \
openpam_get_feature.3 \
openpam_get_option.3 \
openpam_log.3 \
openpam_nullconv.3 \
openpam_readline.3 \
openpam_readlinev.3 \
openpam_readword.3 \
openpam_restore_cred.3 \
openpam_set_feature.3 \
openpam_set_option.3 \
openpam_straddch.3 \
openpam_subst.3 \
openpam_ttyconv.3 \
pam_error.3 \
@ -58,27 +61,35 @@ OMAN = \
EXTRA_DIST = openpam.man pam.man
ALLCMAN = $(PMAN) $(MMAN) $(OMAN)
if !WITH_SYSTEM_LIBPAM
PAMCMAN = $(PAM_MAN) $(MOD_MAN) $(OPENPAM_MAN)
PAMXMAN = openpam.3 pam.3
endif
dist_man3_MANS = $(ALLCMAN) openpam.3 pam.3 pam_conv.3
ALLCMAN = $(PAMCMAN)
GENMAN = $(ALLCMAN) $(PAMXMAN)
dist_man3_MANS = $(GENMAN) pam_conv.3
dist_man5_MANS = pam.conf.5
CLEANFILES = $(ALLCMAN) openpam.3 pam.3
CLEANFILES = $(GENMAN)
GENDOC = $(top_srcdir)/misc/gendoc.pl
SRCDIR = $(top_srcdir)/lib
LIBPAMSRCDIR = $(top_srcdir)/lib/libpam
VPATH = $(SRCDIR)
VPATH = $(LIBPAMSRCDIR) $(srcdir)
SUFFIXES = .3
.c.3: $(GENDOC)
perl -w $(GENDOC) $<
perl -w $(GENDOC) $< || rm $@
openpam.3: $(OMAN) $(GENDOC) openpam.man
perl -w $(GENDOC) -o $(abs_srcdir)/$(OMAN) <$(srcdir)/openpam.man
openpam.3: $(OPENPAM_MAN) $(GENDOC) $(srcdir)/openpam.man
perl -w $(GENDOC) -o $(OPENPAM_MAN) <$(srcdir)/openpam.man || rm $@
pam.3: $(PMAN) $(GENDOC) pam.man
perl -w $(GENDOC) -p $(abs_srcdir)/$(PMAN) <$(srcdir)/pam.man
pam.3: $(PAM_MAN) $(GENDOC) $(srcdir)/pam.man
perl -w $(GENDOC) -p $(PAM_MAN) <$(srcdir)/pam.man || rm $@
$(GENMAN): $(GENDOC)

View File

@ -1,6 +1,3 @@
.\"
.\" $Id$
.\"
.Sh DESCRIPTION
These functions are OpenPAM extensions to the PAM API.
Those named

View File

@ -1,5 +1,5 @@
.\"-
.\" Copyright (c) 2005-2011 Dag-Erling Smørgrav
.\" Copyright (c) 2005-2017 Dag-Erling Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -26,9 +26,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\"
.Dd November 3, 2011
.Dd March 17, 2013
.Dt PAM.CONF 5
.Os
.Sh NAME
@ -50,7 +48,7 @@ decreasing order of preference:
.Pp
If none of these locations contains a policy for the given service,
the
.Dv default
.Dq Dv other
policy is used instead, if it exists.
.Pp
Entries in per-service policy files must be of one of the two forms
@ -65,15 +63,16 @@ Entries in
policy files are of the same form, but are prefixed by an additional
field specifying the name of the service they apply to.
.Pp
In both types of policy files, blank lines are ignored, as is anything
to the right of a
In both cases, blank lines and comments introduced by a
.Ql #
sign.
sign are ignored, and the normal shell quoting rules apply.
The precise details of how the file is tokenized are described in
.Xr openpam_readword 3 .
.Pp
The
.Ar facility
field specifies the facility the entry applies to, and is one of:
.Bl -tag -width ".Cm password"
.Bl -tag -width 12n
.It Cm auth
Authentication functions
.Po
@ -99,7 +98,7 @@ The
field determines how the result returned by the module affects the
flow of control through (and the final result of) the rest of the
chain, and is one of:
.Bl -tag -width ".Cm sufficient"
.Bl -tag -width 12n
.It Cm required
If this module succeeds, the result of the chain will be success
unless a later module fails.
@ -141,16 +140,18 @@ phase of
.Pp
The
.Ar module-path
field specifies the name, or optionally the full path, of the module
to call.
field specifies the name or full path of the module to call.
If only the name is specified, the PAM library will search for it in
the following locations:
.Bl -enum
.It
.Pa /usr/lib
.It
.Pa /usr/local/lib
.El
.Pp
The remaining fields are passed as arguments to the module if and when
it is invoked.
As a special case, if an argument is of the form ``name=value'' and
the right-hand side is surrounded by single or double quotes, any
whitespace between the quote characters will be considered part of the
same argument rather than a separator between this argument and the
next.
The remaining fields, if any, are passed unmodified to the module if
and when it is invoked.
.Pp
The
.Cm include
@ -161,6 +162,37 @@ This allows one to define system-wide policies which are then included
into service-specific policies.
The system-wide policy can then be modified without having to also
modify each and every service-specific policy.
.Pp
.Bf -symbolic
Take care not to introduce loops when using
.Cm include
rules, as there is currently no loop detection in place.
.Ef
.Sh MODULE OPTIONS
Some PAM library functions may alter their behavior when called by a
service module if certain module options were specified, regardless of
whether the module itself accords them any importance.
One such option is
.Cm debug ,
which causes the dispatcher to enable debugging messages before
calling each service function, and disable them afterwards (unless
they were already enabled).
Other special options include:
.Bl -tag -width 12n
.It Cm authtok_prompt Ns = Ns Ar prompt , Cm oldauthtok_prompt Ns = Ns Ar prompt , Cm user_prompt Ns = Ns Ar prompt
These options can be used to override the prompts used by
.Xr pam_get_authtok 3
and
.Xr pam_get_user 3 .
.It Cm echo_pass
This option controls whether
.Xr pam_get_authtok 3
will allow the user to see what they are typing.
.It Cm try_first_pass , Cm use_first_pass
These options control
.Xr pam_get_authtok 3 Ns 's
use of cached authentication tokens.
.El
.Sh SEE ALSO
.Xr pam 3
.Sh STANDARDS
@ -177,5 +209,5 @@ DARPA/SPAWAR contract N66001-01-C-8035
.Pq Dq CBOSS ,
as part of the DARPA CHATS research program.
.Pp
This manual page was written by
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
The OpenPAM library is maintained by
.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .

View File

@ -1,6 +1,3 @@
.\"
.\" $Id$
.\"
.Sh DESCRIPTION
The Pluggable Authentication Modules (PAM) library abstracts a number
of common authentication-related operations and provides a framework

View File

@ -1,6 +1,6 @@
.\"-
.\" Copyright (c) 2002-2003 Networks Associates Technology, Inc.
.\" Copyright (c) 2004-2011 Dag-Erling Smørgrav
.\" Copyright (c) 2004-2017 Dag-Erling Smørgrav
.\" All rights reserved.
.\"
.\" This software was developed for the FreeBSD Project by ThinkSec AS and
@ -32,8 +32,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\"
.Dd June 16, 2005
.Dt PAM_CONV 3
.Os
@ -76,7 +74,7 @@ item.
.Pp
The conversation function's first argument specifies the number of
messages (up to
.Dv PAM_NUM_MSG )
.Dv PAM_MAX_NUM_MSG )
to process.
The second argument is a pointer to an array of pointers to
.Vt pam_message
@ -181,3 +179,6 @@ the Security Research Division of Network Associates, Inc.\& under
DARPA/SPAWAR contract N66001-01-C-8035
.Pq Dq CBOSS ,
as part of the DARPA CHATS research program.
.Pp
The OpenPAM library is maintained by
.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .

View File

@ -1,5 +1,3 @@
$Id$
Errata in XSSO, chapter 5:
p. 25: the first member of struct pam_response is named "resp", not

2
freebsd/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
!/Makefile.in
/work

33
freebsd/Makefile.in Normal file
View File

@ -0,0 +1,33 @@
# $FreeBSD: portlint$
PORTNAME= @PACKAGE_TARNAME@
PORTVERSION= @PACKAGE_VERSION@
CATEGORIES= security devel
MASTER_SITES= #
DISTFILES= #
MAINTAINER= @PACKAGE_BUGREPORT@
COMMENT= BSD-licensed implementation of Pluggable Authentication Modules
LICENSE= BSD3CLAUSE
USES= gmake libtool pkgconfig
USE_LDCONFIG= yes
GNU_CONFIGURE= yes
INSTALL_TARGET= install-strip
TEST_TARGET= check
DESCR= ${WRKDIR}/pkg-descr
do-extract:
(cd @abs_top_srcdir@ && \
${GMAKE} distdir && ${MV} ${PKGNAME} ${WRKDIR})
(${CAT} ${WRKSRC}/README && ${ECHO} && \
${ECHO} "WWW: @PACKAGE_URL@") >${DESCR}
post-stage:
(cd ${STAGEDIR} && \
${FIND} -s . -type f -or -type l | cut -c 2- | \
${SED} -E '/\/man\//s/([0-9])$$/\1.gz/') >>${TMPPLIST}
.include <bsd.port.mk>

View File

@ -1,3 +1 @@
# $Id$
SUBDIRS = security

View File

@ -1,8 +1,6 @@
# $Id$
securitydir = $(includedir)/security
openpamdir = $(includedir)/security
openpam_HEADERS = \
security_HEADERS = \
openpam.h \
openpam_attr.h \
openpam_version.h \

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2015 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_OPENPAM_H_INCLUDED
@ -157,12 +155,50 @@ openpam_readline(FILE *_f,
int *_lineno,
size_t *_lenp)
OPENPAM_NONNULL((1));
char **
openpam_readlinev(FILE *_f,
int *_lineno,
int *_lenp)
OPENPAM_NONNULL((1));
char *
openpam_readword(FILE *_f,
int *_lineno,
size_t *_lenp)
OPENPAM_NONNULL((1));
#endif
int
openpam_straddch(char **_str,
size_t *_sizep,
size_t *_lenp,
int ch)
OPENPAM_NONNULL((1));
/*
* Enable / disable optional features
*/
enum {
OPENPAM_RESTRICT_SERVICE_NAME,
OPENPAM_VERIFY_POLICY_FILE,
OPENPAM_RESTRICT_MODULE_NAME,
OPENPAM_VERIFY_MODULE_FILE,
OPENPAM_FALLBACK_TO_OTHER,
OPENPAM_NUM_FEATURES
};
int
openpam_set_feature(int _feature, int _onoff);
int
openpam_get_feature(int _feature, int *_onoff);
/*
* Log levels
*/
enum {
PAM_LOG_LIBDEBUG = -1,
PAM_LOG_DEBUG,
PAM_LOG_VERBOSE,
PAM_LOG_NOTICE,
@ -196,8 +232,8 @@ _openpam_log(int _level,
void
openpam_log(int _level,
const char *_format,
...)
OPENPAM_FORMAT ((__printf__, 2, 3))
...)
OPENPAM_FORMAT ((__printf__, 2, 3))
OPENPAM_NONNULL((2));
#endif

View File

@ -1,9 +1,5 @@
/*
* $Id$
*/
#ifndef SECURITY_PAM_ATTRIBUTES_H_INCLUDED
#define SECURITY_PAM_ATTRIBUTES_H_INCLUDED
#ifndef SECURITY_OPENPAM_ATTR_H_INCLUDED
#define SECURITY_OPENPAM_ATTR_H_INCLUDED
/* GCC attributes */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__STRICT_ANSI__)
@ -25,4 +21,10 @@
# define OPENPAM_NONNULL(params)
#endif
#endif /* !SECURITY_PAM_ATTRIBUTES_H_INCLUDED */
#if OPENPAM_GNUC_PREREQ(2,7)
# define OPENPAM_UNUSED(var) var __attribute__((__unused__))
#else
# define OPENPAM_UNUSED(var) var
#endif
#endif /* !SECURITY_OPENPAM_ATTR_H_INCLUDED */

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2023 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,15 +31,13 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_OPENPAM_VERSION_H_INCLUDED
#define SECURITY_OPENPAM_VERSION_H_INCLUDED
#define OPENPAM
#define OPENPAM_VERSION 20111218
#define OPENPAM_RELEASE "Lycopsida"
#define OPENPAM_VERSION 20230627
#define OPENPAM_RELEASE "Ximenia"
#endif /* !SECURITY_OPENPAM_VERSION_H_INCLUDED */

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_PAM_APPL_H_INCLUDED

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_PAM_CONSTANTS_H_INCLUDED
@ -78,6 +76,10 @@ enum {
PAM_TRY_AGAIN = 27,
PAM_MODULE_UNKNOWN = 28,
PAM_DOMAIN_UNKNOWN = 29,
PAM_BAD_HANDLE = 30, /* OpenPAM extension */
PAM_BAD_ITEM = 31, /* OpenPAM extension */
PAM_BAD_FEATURE = 32, /* OpenPAM extension */
PAM_BAD_CONSTANT = 33, /* OpenPAM extension */
PAM_NUM_ERRORS /* OpenPAM extension */
};

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_PAM_MODULES_H_INCLUDED

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef SECURITY_PAM_TYPES_H_INCLUDED

View File

@ -1,83 +1,5 @@
# $Id$
SUBDIRS =
NULL =
INCLUDES = -I$(top_srcdir)/include
lib_LTLIBRARIES = libpam.la
noinst_HEADERS = \
openpam_constants.h \
openpam_debug.h \
openpam_impl.h \
openpam_strlcmp.h \
openpam_strlcpy.h
libpam_la_SOURCES = \
openpam_borrow_cred.c \
openpam_check_owner_perms.c \
openpam_configure.c \
openpam_constants.c \
openpam_dispatch.c \
openpam_dynamic.c \
openpam_findenv.c \
openpam_free_data.c \
openpam_free_envlist.c \
openpam_get_option.c \
openpam_load.c \
openpam_log.c \
openpam_nullconv.c \
openpam_readline.c \
openpam_restore_cred.c \
openpam_set_option.c \
openpam_static.c \
openpam_subst.c \
openpam_ttyconv.c \
pam_acct_mgmt.c \
pam_authenticate.c \
pam_chauthtok.c \
pam_close_session.c \
pam_end.c \
pam_error.c \
pam_get_authtok.c \
pam_get_data.c \
pam_get_item.c \
pam_get_user.c \
pam_getenv.c \
pam_getenvlist.c \
pam_info.c \
pam_open_session.c \
pam_prompt.c \
pam_putenv.c \
pam_set_data.c \
pam_set_item.c \
pam_setcred.c \
pam_setenv.c \
pam_start.c \
pam_strerror.c \
pam_verror.c \
pam_vinfo.c \
pam_vprompt.c \
$(NULL)
libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@
libpam_la_LIBADD = @DL_LIBS@
EXTRA_DIST = \
pam_authenticate_secondary.c \
pam_get_mapped_authtok.c \
pam_get_mapped_username.c \
pam_set_mapped_authtok.c \
pam_set_mapped_username.c \
\
pam_sm_acct_mgmt.c \
pam_sm_authenticate.c \
pam_sm_authenticate_secondary.c \
pam_sm_chauthtok.c \
pam_sm_close_session.c \
pam_sm_get_mapped_authtok.c \
pam_sm_get_mapped_username.c \
pam_sm_open_session.c \
pam_sm_set_mapped_authtok.c \
pam_sm_set_mapped_username.c \
pam_sm_setcred.c
if !WITH_SYSTEM_LIBPAM
SUBDIRS += libpam
endif

100
lib/libpam/Makefile.am Normal file
View File

@ -0,0 +1,100 @@
NULL =
AM_CPPFLAGS = -I$(top_srcdir)/include
lib_LTLIBRARIES = libpam.la
noinst_HEADERS = \
openpam_asprintf.h \
openpam_constants.h \
openpam_cred.h \
openpam_ctype.h \
openpam_debug.h \
openpam_dlfunc.h \
openpam_features.h \
openpam_impl.h \
openpam_strlcat.h \
openpam_strlcmp.h \
openpam_strlcpy.h \
openpam_strlset.h \
openpam_vasprintf.h
libpam_la_SOURCES = \
openpam_asprintf.c \
openpam_borrow_cred.c \
openpam_check_owner_perms.c \
openpam_configure.c \
openpam_constants.c \
openpam_dispatch.c \
openpam_dynamic.c \
openpam_features.c \
openpam_findenv.c \
openpam_free_data.c \
openpam_free_envlist.c \
openpam_get_feature.c \
openpam_get_option.c \
openpam_load.c \
openpam_log.c \
openpam_nullconv.c \
openpam_readline.c \
openpam_readlinev.c \
openpam_readword.c \
openpam_restore_cred.c \
openpam_set_option.c \
openpam_set_feature.c \
openpam_static.c \
openpam_straddch.c \
openpam_strlcat.c \
openpam_strlcpy.c \
openpam_strlset.c \
openpam_subst.c \
openpam_vasprintf.c \
openpam_ttyconv.c \
pam_acct_mgmt.c \
pam_authenticate.c \
pam_chauthtok.c \
pam_close_session.c \
pam_end.c \
pam_error.c \
pam_get_authtok.c \
pam_get_data.c \
pam_get_item.c \
pam_get_user.c \
pam_getenv.c \
pam_getenvlist.c \
pam_info.c \
pam_open_session.c \
pam_prompt.c \
pam_putenv.c \
pam_set_data.c \
pam_set_item.c \
pam_setcred.c \
pam_setenv.c \
pam_start.c \
pam_strerror.c \
pam_verror.c \
pam_vinfo.c \
pam_vprompt.c \
$(NULL)
libpam_la_LDFLAGS = -no-undefined -version-info $(LIB_MAJ)
libpam_la_LIBADD = $(DL_LIBS)
EXTRA_DIST = \
pam_authenticate_secondary.c \
pam_get_mapped_authtok.c \
pam_get_mapped_username.c \
pam_set_mapped_authtok.c \
pam_set_mapped_username.c \
\
pam_sm_acct_mgmt.c \
pam_sm_authenticate.c \
pam_sm_authenticate_secondary.c \
pam_sm_chauthtok.c \
pam_sm_close_session.c \
pam_sm_get_mapped_authtok.c \
pam_sm_get_mapped_username.c \
pam_sm_open_session.c \
pam_sm_set_mapped_authtok.c \
pam_sm_set_mapped_username.c \
pam_sm_setcred.c

View File

@ -0,0 +1,55 @@
/*-
* Copyright (c) 2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_ASPRINTF
#include <stdarg.h>
#include <stdio.h>
#include "openpam_asprintf.h"
#include "openpam_vasprintf.h"
/* like sprintf(3), but allocates memory for the result. */
int
openpam_asprintf(char **str, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = vasprintf(str, fmt, ap);
va_end(ap);
return (ret);
}
#endif

View File

@ -0,0 +1,39 @@
/*-
* Copyright (c) 2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_ASPRINTF_H_INCLUDED
#define OPENPAM_ASPRINTF_H_INCLUDED
#ifndef HAVE_ASPRINTF
int openpam_asprintf(char **, const char *, ...);
#undef asprintf
#define asprintf(arg, ...) openpam_asprintf(arg, __VA_ARGS__)
#endif
#endif

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -50,6 +48,7 @@
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_cred.h"
/*
* OpenPAM extension
@ -68,12 +67,12 @@ openpam_borrow_cred(pam_handle_t *pamh,
ENTERI(pwd->pw_uid);
r = pam_get_data(pamh, PAM_SAVED_CRED, &scredp);
if (r == PAM_SUCCESS && scredp != NULL) {
openpam_log(PAM_LOG_DEBUG,
openpam_log(PAM_LOG_LIBDEBUG,
"already operating under borrowed credentials");
RETURNC(PAM_SYSTEM_ERR);
}
if (geteuid() != 0 && geteuid() != pwd->pw_uid) {
openpam_log(PAM_LOG_DEBUG, "called with non-zero euid: %d",
openpam_log(PAM_LOG_LIBDEBUG, "called with non-zero euid: %d",
(int)geteuid());
RETURNC(PAM_PERM_DENIED);
}

View File

@ -6,11 +6,13 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,8 +25,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -67,6 +67,12 @@ openpam_check_desc_owner_perms(const char *name, int fd)
errno = serrno;
return (-1);
}
if (!S_ISREG(sb.st_mode)) {
openpam_log(PAM_LOG_ERROR,
"%s: not a regular file", name);
errno = EINVAL;
return (-1);
}
if ((sb.st_uid != root && sb.st_uid != arbitrator) ||
(sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
openpam_log(PAM_LOG_ERROR,
@ -84,7 +90,7 @@ openpam_check_desc_owner_perms(const char *name, int fd)
* up to it are owned by either root or the arbitrator and that they are
* not writable by group or other.
*
* Note that openpam_check_file_owner_perms() should be used instead if
* Note that openpam_check_desc_owner_perms() should be used instead if
* possible to avoid a race between the ownership / permission check and
* the actual open().
*/
@ -95,8 +101,9 @@ openpam_check_path_owner_perms(const char *path)
uid_t root, arbitrator;
char pathbuf[PATH_MAX];
struct stat sb;
int len, serrno;
int len, serrno, tip;
tip = 1;
root = 0;
arbitrator = geteuid();
if (realpath(path, pathbuf) == NULL)
@ -104,9 +111,17 @@ openpam_check_path_owner_perms(const char *path)
len = strlen(pathbuf);
while (len > 0) {
if (stat(pathbuf, &sb) != 0) {
serrno = errno;
openpam_log(PAM_LOG_ERROR, "%s: %m", pathbuf);
errno = serrno;
if (errno != ENOENT) {
serrno = errno;
openpam_log(PAM_LOG_ERROR, "%s: %m", pathbuf);
errno = serrno;
}
return (-1);
}
if (tip && !S_ISREG(sb.st_mode)) {
openpam_log(PAM_LOG_ERROR,
"%s: not a regular file", pathbuf);
errno = EINVAL;
return (-1);
}
if ((sb.st_uid != root && sb.st_uid != arbitrator) ||
@ -118,6 +133,7 @@ openpam_check_path_owner_perms(const char *path)
}
while (--len > 0 && pathbuf[len] != '/')
pathbuf[len] = '\0';
tip = 0;
}
return (0);
}

View File

@ -0,0 +1,486 @@
/*-
* Copyright (c) 2001-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2015 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
* Network Associates Laboratories, the Security Research Division of
* Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
* ("CBOSS"), as part of the DARPA CHATS research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_ctype.h"
#include "openpam_strlcat.h"
#include "openpam_strlcpy.h"
static int openpam_load_chain(pam_handle_t *, const char *, pam_facility_t);
/*
* Validate a service name.
*
* Returns a non-zero value if the argument points to a NUL-terminated
* string consisting entirely of characters in the POSIX portable filename
* character set, excluding the path separator character.
*/
static int
valid_service_name(const char *name)
{
const char *p;
if (OPENPAM_FEATURE(RESTRICT_SERVICE_NAME)) {
/* path separator not allowed */
for (p = name; *p != '\0'; ++p)
if (!is_pfcs(*p))
return (0);
} else {
/* path separator allowed */
for (p = name; *p != '\0'; ++p)
if (!is_pfcs(*p) && *p != '/')
return (0);
}
return (1);
}
/*
* Parse the facility name.
*
* Returns the corresponding pam_facility_t value, or -1 if the argument
* is not a valid facility name.
*/
static pam_facility_t
parse_facility_name(const char *name)
{
int i;
for (i = 0; i < PAM_NUM_FACILITIES; ++i)
if (strcmp(pam_facility_name[i], name) == 0)
return (i);
return ((pam_facility_t)-1);
}
/*
* Parse the control flag.
*
* Returns the corresponding pam_control_t value, or -1 if the argument is
* not a valid control flag name.
*/
static pam_control_t
parse_control_flag(const char *name)
{
int i;
for (i = 0; i < PAM_NUM_CONTROL_FLAGS; ++i)
if (strcmp(pam_control_flag_name[i], name) == 0)
return (i);
return ((pam_control_t)-1);
}
/*
* Validate a file name.
*
* Returns a non-zero value if the argument points to a NUL-terminated
* string consisting entirely of characters in the POSIX portable filename
* character set, including the path separator character.
*/
static int
valid_module_name(const char *name)
{
const char *p;
if (OPENPAM_FEATURE(RESTRICT_MODULE_NAME)) {
/* path separator not allowed */
for (p = name; *p != '\0'; ++p)
if (!is_pfcs(*p))
return (0);
} else {
/* path separator allowed */
for (p = name; *p != '\0'; ++p)
if (!is_pfcs(*p) && *p != '/')
return (0);
}
return (1);
}
typedef enum { pam_conf_style, pam_d_style } openpam_style_t;
/*
* Extracts given chains from a policy file.
*
* Returns the number of policy entries which were found for the specified
* service and facility, or -1 if a system error occurred or a syntax
* error was encountered.
*/
static int
openpam_parse_chain(pam_handle_t *pamh,
const char *service,
pam_facility_t facility,
FILE *f,
const char *filename,
openpam_style_t style)
{
pam_chain_t *this, **next;
pam_facility_t fclt;
pam_control_t ctlf;
char *name, *servicename, *modulename;
int count, lineno, ret, serrno;
char **wordv, *word;
int i, wordc;
count = 0;
this = NULL;
name = NULL;
lineno = 0;
wordc = 0;
wordv = NULL;
while ((wordv = openpam_readlinev(f, &lineno, &wordc)) != NULL) {
/* blank line? */
if (wordc == 0) {
FREEV(wordc, wordv);
continue;
}
i = 0;
/* check service name if necessary */
if (style == pam_conf_style &&
strcmp(wordv[i++], service) != 0) {
FREEV(wordc, wordv);
continue;
}
/* check facility name */
if ((word = wordv[i++]) == NULL ||
(fclt = parse_facility_name(word)) == (pam_facility_t)-1) {
openpam_log(PAM_LOG_ERROR,
"%s(%d): missing or invalid facility",
filename, lineno);
errno = EINVAL;
goto fail;
}
if (facility != fclt && facility != PAM_FACILITY_ANY) {
FREEV(wordc, wordv);
continue;
}
/* check for "include" */
if ((word = wordv[i++]) != NULL &&
strcmp(word, "include") == 0) {
if ((servicename = wordv[i++]) == NULL ||
!valid_service_name(servicename)) {
openpam_log(PAM_LOG_ERROR,
"%s(%d): missing or invalid service name",
filename, lineno);
errno = EINVAL;
goto fail;
}
if (wordv[i] != NULL) {
openpam_log(PAM_LOG_ERROR,
"%s(%d): garbage at end of line",
filename, lineno);
errno = EINVAL;
goto fail;
}
ret = openpam_load_chain(pamh, servicename, fclt);
FREEV(wordc, wordv);
if (ret < 0) {
/*
* Bogus errno, but this ensures that the
* outer loop does not just ignore the
* error and keep searching.
*/
if (errno == ENOENT)
errno = EINVAL;
goto fail;
}
continue;
}
/* get control flag */
if (word == NULL || /* same word we compared to "include" */
(ctlf = parse_control_flag(word)) == (pam_control_t)-1) {
openpam_log(PAM_LOG_ERROR,
"%s(%d): missing or invalid control flag",
filename, lineno);
errno = EINVAL;
goto fail;
}
/* get module name */
if ((modulename = wordv[i++]) == NULL ||
!valid_module_name(modulename)) {
openpam_log(PAM_LOG_ERROR,
"%s(%d): missing or invalid module name",
filename, lineno);
errno = EINVAL;
goto fail;
}
/* allocate new entry */
if ((this = calloc(1, sizeof *this)) == NULL)
goto syserr;
this->flag = ctlf;
/* load module */
if ((this->module = openpam_load_module(modulename)) == NULL) {
if (errno == ENOENT)
errno = ENOEXEC;
goto fail;
}
/*
* The remaining items in wordv are the module's
* arguments. We could set this->optv = wordv + i, but
* then free(this->optv) wouldn't work. Instead, we free
* the words we've already consumed, shift the rest up,
* and clear the tail end of the array.
*/
this->optc = wordc - i;
for (i = 0; i < wordc - this->optc; ++i) {
FREE(wordv[i]);
}
for (i = 0; i < this->optc; ++i) {
wordv[i] = wordv[wordc - this->optc + i];
wordv[wordc - this->optc + i] = NULL;
}
this->optv = wordv;
wordv = NULL;
wordc = 0;
/* hook it up */
for (next = &pamh->chains[fclt]; *next != NULL;
next = &(*next)->next)
/* nothing */ ;
*next = this;
this = NULL;
++count;
}
/*
* The loop ended because openpam_readword() returned NULL, which
* can happen for four different reasons: an I/O error (ferror(f)
* is true), a memory allocation failure (ferror(f) is false,
* feof(f) is false, errno is non-zero), the file ended with an
* unterminated quote or backslash escape (ferror(f) is false,
* feof(f) is true, errno is non-zero), or the end of the file was
* reached without error (ferror(f) is false, feof(f) is true,
* errno is zero).
*/
if (ferror(f) || errno != 0)
goto syserr;
if (!feof(f))
goto fail;
fclose(f);
return (count);
syserr:
serrno = errno;
openpam_log(PAM_LOG_ERROR, "%s: %m", filename);
errno = serrno;
/* fall through */
fail:
serrno = errno;
if (this && this->optc && this->optv)
FREEV(this->optc, this->optv);
FREE(this);
FREEV(wordc, wordv);
FREE(wordv);
FREE(name);
fclose(f);
errno = serrno;
return (-1);
}
/*
* Read the specified chains from the specified file.
*
* Returns 0 if the file exists but does not contain any matching lines.
*
* Returns -1 and sets errno to ENOENT if the file does not exist.
*
* Returns -1 and sets errno to some other non-zero value if the file
* exists but is unsafe or unreadable, or an I/O error occurs.
*/
static int
openpam_load_file(pam_handle_t *pamh,
const char *service,
pam_facility_t facility,
const char *filename,
openpam_style_t style)
{
FILE *f;
int ret, serrno;
/* attempt to open the file */
if ((f = fopen(filename, "r")) == NULL) {
serrno = errno;
openpam_log(errno == ENOENT ? PAM_LOG_DEBUG : PAM_LOG_ERROR,
"%s: %m", filename);
errno = serrno;
RETURNN(-1);
} else {
openpam_log(PAM_LOG_DEBUG, "found %s", filename);
}
/* verify type, ownership and permissions */
if (OPENPAM_FEATURE(VERIFY_POLICY_FILE) &&
openpam_check_desc_owner_perms(filename, fileno(f)) != 0) {
/* already logged the cause */
serrno = errno;
fclose(f);
errno = serrno;
RETURNN(-1);
}
/* parse the file */
ret = openpam_parse_chain(pamh, service, facility,
f, filename, style);
RETURNN(ret);
}
/*
* Locates the policy file for a given service and reads the given chains
* from it.
*
* Returns the number of policy entries which were found for the specified
* service and facility, or -1 if a system error occurred or a syntax
* error was encountered.
*/
static int
openpam_load_chain(pam_handle_t *pamh,
const char *service,
pam_facility_t facility)
{
const char *p, **path;
char filename[PATH_MAX];
size_t len;
openpam_style_t style;
int ret;
ENTERS(facility < 0 ? "any" : pam_facility_name[facility]);
/* either absolute or relative to cwd */
if (strchr(service, '/') != NULL) {
if ((p = strrchr(service, '.')) != NULL && strcmp(p, ".conf") == 0)
style = pam_conf_style;
else
style = pam_d_style;
ret = openpam_load_file(pamh, service, facility,
service, style);
RETURNN(ret);
}
/* search standard locations */
for (path = openpam_policy_path; *path != NULL; ++path) {
/* construct filename */
len = strlcpy(filename, *path, sizeof filename);
if (len >= sizeof filename) {
errno = ENAMETOOLONG;
RETURNN(-1);
}
if (filename[len - 1] == '/') {
len = strlcat(filename, service, sizeof filename);
if (len >= sizeof filename) {
errno = ENAMETOOLONG;
RETURNN(-1);
}
style = pam_d_style;
} else {
style = pam_conf_style;
}
ret = openpam_load_file(pamh, service, facility,
filename, style);
/* success */
if (ret > 0)
RETURNN(ret);
/* the file exists, but an error occurred */
if (ret == -1 && errno != ENOENT)
RETURNN(ret);
/* in pam.d style, an empty file counts as a hit */
if (ret == 0 && style == pam_d_style)
RETURNN(ret);
}
/* no hit */
errno = ENOENT;
RETURNN(-1);
}
/*
* OpenPAM internal
*
* Configure a service
*/
int
openpam_configure(pam_handle_t *pamh,
const char *service)
{
pam_facility_t fclt;
int serrno;
ENTERS(service);
if (!valid_service_name(service)) {
openpam_log(PAM_LOG_ERROR, "invalid service name");
RETURNC(PAM_SYSTEM_ERR);
}
if (openpam_load_chain(pamh, service, PAM_FACILITY_ANY) < 0) {
if (errno != ENOENT)
goto load_err;
}
for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) {
if (pamh->chains[fclt] != NULL)
continue;
if (OPENPAM_FEATURE(FALLBACK_TO_OTHER)) {
if (openpam_load_chain(pamh, PAM_OTHER, fclt) < 0)
goto load_err;
}
}
RETURNC(PAM_SUCCESS);
load_err:
serrno = errno;
openpam_clear_chains(pamh->chains);
errno = serrno;
RETURNC(PAM_SYSTEM_ERR);
}
/*
* NODOC
*
* Error codes:
* PAM_SYSTEM_ERR
*/

View File

@ -0,0 +1,183 @@
/*-
* Copyright (c) 2001-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
* Network Associates Laboratories, the Security Research Division of
* Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
* ("CBOSS"), as part of the DARPA CHATS research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <security/pam_appl.h>
#include "openpam_impl.h"
const char *pam_err_name[PAM_NUM_ERRORS] = {
[PAM_SUCCESS] = "PAM_SUCCESS",
[PAM_OPEN_ERR] = "PAM_OPEN_ERR",
[PAM_SYMBOL_ERR] = "PAM_SYMBOL_ERR",
[PAM_SERVICE_ERR] = "PAM_SERVICE_ERR",
[PAM_SYSTEM_ERR] = "PAM_SYSTEM_ERR",
[PAM_BUF_ERR] = "PAM_BUF_ERR",
[PAM_CONV_ERR] = "PAM_CONV_ERR",
[PAM_PERM_DENIED] = "PAM_PERM_DENIED",
[PAM_MAXTRIES] = "PAM_MAXTRIES",
[PAM_AUTH_ERR] = "PAM_AUTH_ERR",
[PAM_NEW_AUTHTOK_REQD] = "PAM_NEW_AUTHTOK_REQD",
[PAM_CRED_INSUFFICIENT] = "PAM_CRED_INSUFFICIENT",
[PAM_AUTHINFO_UNAVAIL] = "PAM_AUTHINFO_UNAVAIL",
[PAM_USER_UNKNOWN] = "PAM_USER_UNKNOWN",
[PAM_CRED_UNAVAIL] = "PAM_CRED_UNAVAIL",
[PAM_CRED_EXPIRED] = "PAM_CRED_EXPIRED",
[PAM_CRED_ERR] = "PAM_CRED_ERR",
[PAM_ACCT_EXPIRED] = "PAM_ACCT_EXPIRED",
[PAM_AUTHTOK_EXPIRED] = "PAM_AUTHTOK_EXPIRED",
[PAM_SESSION_ERR] = "PAM_SESSION_ERR",
[PAM_AUTHTOK_ERR] = "PAM_AUTHTOK_ERR",
[PAM_AUTHTOK_RECOVERY_ERR] = "PAM_AUTHTOK_RECOVERY_ERR",
[PAM_AUTHTOK_LOCK_BUSY] = "PAM_AUTHTOK_LOCK_BUSY",
[PAM_AUTHTOK_DISABLE_AGING] = "PAM_AUTHTOK_DISABLE_AGING",
[PAM_NO_MODULE_DATA] = "PAM_NO_MODULE_DATA",
[PAM_IGNORE] = "PAM_IGNORE",
[PAM_ABORT] = "PAM_ABORT",
[PAM_TRY_AGAIN] = "PAM_TRY_AGAIN",
[PAM_MODULE_UNKNOWN] = "PAM_MODULE_UNKNOWN",
[PAM_DOMAIN_UNKNOWN] = "PAM_DOMAIN_UNKNOWN",
[PAM_BAD_HANDLE] = "PAM_BAD_HANDLE",
[PAM_BAD_ITEM] = "PAM_BAD_ITEM",
[PAM_BAD_FEATURE] = "PAM_BAD_FEATURE",
[PAM_BAD_CONSTANT] = "PAM_BAD_CONSTANT",
};
const char *pam_err_text[PAM_NUM_ERRORS] = {
[PAM_SUCCESS] = "Success",
[PAM_OPEN_ERR] = "Failed to load module",
[PAM_SYMBOL_ERR] = "Invalid symbol",
[PAM_SERVICE_ERR] = "Error in service module",
[PAM_SYSTEM_ERR] = "System error",
[PAM_BUF_ERR] = "Memory buffer error",
[PAM_CONV_ERR] = "Conversation failure",
[PAM_PERM_DENIED] = "Permission denied",
[PAM_MAXTRIES] = "Maximum number of tries exceeded",
[PAM_AUTH_ERR] = "Authentication error",
[PAM_NEW_AUTHTOK_REQD] = "New authentication token required",
[PAM_CRED_INSUFFICIENT] = "Insufficient credentials",
[PAM_AUTHINFO_UNAVAIL] = "Authentication information is unavailable",
[PAM_USER_UNKNOWN] = "Unknown user",
[PAM_CRED_UNAVAIL] = "Failed to retrieve user credentials",
[PAM_CRED_EXPIRED] = "User credentials have expired",
[PAM_CRED_ERR] = "Failed to set user credentials",
[PAM_ACCT_EXPIRED] = "User account has expired",
[PAM_AUTHTOK_EXPIRED] = "Password has expired",
[PAM_SESSION_ERR] = "Session failure",
[PAM_AUTHTOK_ERR] = "Authentication token failure",
[PAM_AUTHTOK_RECOVERY_ERR] = "Failed to recover old authentication token",
[PAM_AUTHTOK_LOCK_BUSY] = "Authentication token lock busy",
[PAM_AUTHTOK_DISABLE_AGING] = "Authentication token aging disabled",
[PAM_NO_MODULE_DATA] = "Module data not found",
[PAM_IGNORE] = "Ignore this module",
[PAM_ABORT] = "General failure",
[PAM_TRY_AGAIN] = "Try again",
[PAM_MODULE_UNKNOWN] = "Unknown module type",
[PAM_DOMAIN_UNKNOWN] = "Unknown authentication domain",
[PAM_BAD_HANDLE] = "Invalid PAM handle",
[PAM_BAD_ITEM] = "Unrecognized or restricted item",
[PAM_BAD_FEATURE] = "Unrecognized or restricted feature",
[PAM_BAD_CONSTANT] = "Invalid constant",
};
const char *pam_item_name[PAM_NUM_ITEMS] = {
[PAM_SERVICE] = "PAM_SERVICE",
[PAM_USER] = "PAM_USER",
[PAM_TTY] = "PAM_TTY",
[PAM_RHOST] = "PAM_RHOST",
[PAM_CONV] = "PAM_CONV",
[PAM_AUTHTOK] = "PAM_AUTHTOK",
[PAM_OLDAUTHTOK] = "PAM_OLDAUTHTOK",
[PAM_RUSER] = "PAM_RUSER",
[PAM_USER_PROMPT] = "PAM_USER_PROMPT",
[PAM_REPOSITORY] = "PAM_REPOSITORY",
[PAM_AUTHTOK_PROMPT] = "PAM_AUTHTOK_PROMPT",
[PAM_OLDAUTHTOK_PROMPT] = "PAM_OLDAUTHTOK_PROMPT",
[PAM_HOST] = "PAM_HOST",
};
const char *pam_facility_name[PAM_NUM_FACILITIES] = {
[PAM_ACCOUNT] = "account",
[PAM_AUTH] = "auth",
[PAM_PASSWORD] = "password",
[PAM_SESSION] = "session",
};
const char *pam_control_flag_name[PAM_NUM_CONTROL_FLAGS] = {
[PAM_BINDING] = "binding",
[PAM_OPTIONAL] = "optional",
[PAM_REQUIRED] = "required",
[PAM_REQUISITE] = "requisite",
[PAM_SUFFICIENT] = "sufficient",
};
const char *pam_func_name[PAM_NUM_PRIMITIVES] = {
[PAM_SM_AUTHENTICATE] = "pam_authenticate",
[PAM_SM_SETCRED] = "pam_setcred",
[PAM_SM_ACCT_MGMT] = "pam_acct_mgmt",
[PAM_SM_OPEN_SESSION] = "pam_open_session",
[PAM_SM_CLOSE_SESSION] = "pam_close_session",
[PAM_SM_CHAUTHTOK] = "pam_chauthtok"
};
const char *pam_sm_func_name[PAM_NUM_PRIMITIVES] = {
[PAM_SM_AUTHENTICATE] = "pam_sm_authenticate",
[PAM_SM_SETCRED] = "pam_sm_setcred",
[PAM_SM_ACCT_MGMT] = "pam_sm_acct_mgmt",
[PAM_SM_OPEN_SESSION] = "pam_sm_open_session",
[PAM_SM_CLOSE_SESSION] = "pam_sm_close_session",
[PAM_SM_CHAUTHTOK] = "pam_sm_chauthtok"
};
const char *openpam_policy_path[] = {
"/etc/pam.d/",
"/etc/pam.conf",
"/usr/local/etc/pam.d/",
"/usr/local/etc/pam.conf",
NULL
};
const char *openpam_module_path[] = {
#ifdef OPENPAM_MODULES_DIRECTORY
OPENPAM_MODULES_DIRECTORY,
#else
"/usr/lib",
"/usr/local/lib",
#endif
NULL
};

View File

@ -1,16 +1,18 @@
/*-
* Copyright (c) 2011 Dag-Erling Smørgrav
* Copyright (c) 2011-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,18 +25,20 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef OPENPAM_CONSTANTS_INCLUDED
#define OPENPAM_CONSTANTS_INCLUDED
#ifndef OPENPAM_CONSTANTS_H_INCLUDED
#define OPENPAM_CONSTANTS_H_INCLUDED
extern const char *pam_err_name[PAM_NUM_ERRORS];
extern const char *pam_err_text[PAM_NUM_ERRORS];
extern const char *pam_item_name[PAM_NUM_ITEMS];
extern const char *pam_facility_name[PAM_NUM_FACILITIES];
extern const char *pam_control_flag_name[PAM_NUM_CONTROL_FLAGS];
extern const char *pam_func_name[PAM_NUM_PRIMITIVES];
extern const char *pam_sm_func_name[PAM_NUM_PRIMITIVES];
extern const char *openpam_policy_path[];
extern const char *openpam_module_path[];
#endif

View File

@ -31,97 +31,20 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#ifndef OPENPAM_CRED_H_INCLUDED
#define OPENPAM_CRED_H_INCLUDED
/*
* Saved credentials
*/
#define PAM_SAVED_CRED "pam_saved_cred"
struct pam_saved_cred {
uid_t euid;
gid_t egid;
gid_t groups[NGROUPS_MAX];
int ngroups;
};
#endif
#include <security/pam_appl.h>
#include "openpam_impl.h"
const char *pam_err_name[PAM_NUM_ERRORS] = {
"PAM_SUCCESS",
"PAM_OPEN_ERR",
"PAM_SYMBOL_ERR",
"PAM_SERVICE_ERR",
"PAM_SYSTEM_ERR",
"PAM_BUF_ERR",
"PAM_CONV_ERR",
"PAM_PERM_DENIED",
"PAM_MAXTRIES",
"PAM_AUTH_ERR",
"PAM_NEW_AUTHTOK_REQD",
"PAM_CRED_INSUFFICIENT",
"PAM_AUTHINFO_UNAVAIL",
"PAM_USER_UNKNOWN",
"PAM_CRED_UNAVAIL",
"PAM_CRED_EXPIRED",
"PAM_CRED_ERR",
"PAM_ACCT_EXPIRED",
"PAM_AUTHTOK_EXPIRED",
"PAM_SESSION_ERR",
"PAM_AUTHTOK_ERR",
"PAM_AUTHTOK_RECOVERY_ERR",
"PAM_AUTHTOK_LOCK_BUSY",
"PAM_AUTHTOK_DISABLE_AGING",
"PAM_NO_MODULE_DATA",
"PAM_IGNORE",
"PAM_ABORT",
"PAM_TRY_AGAIN",
"PAM_MODULE_UNKNOWN",
"PAM_DOMAIN_UNKNOWN"
};
const char *pam_item_name[PAM_NUM_ITEMS] = {
"(NO ITEM)",
"PAM_SERVICE",
"PAM_USER",
"PAM_TTY",
"PAM_RHOST",
"PAM_CONV",
"PAM_AUTHTOK",
"PAM_OLDAUTHTOK",
"PAM_RUSER",
"PAM_USER_PROMPT",
"PAM_REPOSITORY",
"PAM_AUTHTOK_PROMPT",
"PAM_OLDAUTHTOK_PROMPT",
"PAM_HOST",
};
const char *pam_facility_name[PAM_NUM_FACILITIES] = {
[PAM_ACCOUNT] = "account",
[PAM_AUTH] = "auth",
[PAM_PASSWORD] = "password",
[PAM_SESSION] = "session",
};
const char *pam_control_flag_name[PAM_NUM_CONTROL_FLAGS] = {
[PAM_BINDING] = "binding",
[PAM_OPTIONAL] = "optional",
[PAM_REQUIRED] = "required",
[PAM_REQUISITE] = "requisite",
[PAM_SUFFICIENT] = "sufficient",
};
const char *pam_func_name[PAM_NUM_PRIMITIVES] = {
"pam_authenticate",
"pam_setcred",
"pam_acct_mgmt",
"pam_open_session",
"pam_close_session",
"pam_chauthtok"
};
const char *pam_sm_func_name[PAM_NUM_PRIMITIVES] = {
"pam_sm_authenticate",
"pam_sm_setcred",
"pam_sm_acct_mgmt",
"pam_sm_open_session",
"pam_sm_close_session",
"pam_sm_chauthtok"
};

View File

@ -0,0 +1,95 @@
/*-
* Copyright (c) 2012-2014 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_CTYPE_H_INCLUDED
#define OPENPAM_CTYPE_H_INCLUDED
/*
* Evaluates to non-zero if the argument is a digit.
*/
#define is_digit(ch) \
(ch >= '0' && ch <= '9')
/*
* Evaluates to non-zero if the argument is a hex digit.
*/
#define is_xdigit(ch) \
((ch >= '0' && ch <= '9') || \
(ch >= 'a' && ch <= 'f') || \
(ch >= 'A' && ch <= 'F'))
/*
* Evaluates to non-zero if the argument is an uppercase letter.
*/
#define is_upper(ch) \
(ch >= 'A' && ch <= 'Z')
/*
* Evaluates to non-zero if the argument is a lowercase letter.
*/
#define is_lower(ch) \
(ch >= 'a' && ch <= 'z')
/*
* Evaluates to non-zero if the argument is a letter.
*/
#define is_letter(ch) \
(is_upper(ch) || is_lower(ch))
/*
* Evaluates to non-zero if the argument is a linear whitespace character.
* For the purposes of this macro, the definition of linear whitespace is
* extended to include the form feed and carraige return characters.
*/
#define is_lws(ch) \
(ch == ' ' || ch == '\t' || ch == '\f' || ch == '\r')
/*
* Evaluates to non-zero if the argument is a whitespace character.
*/
#define is_ws(ch) \
(is_lws(ch) || ch == '\n')
/*
* Evaluates to non-zero if the argument is a printable ASCII character.
* Assumes that the execution character set is a superset of ASCII.
*/
#define is_p(ch) \
(ch >= '!' && ch <= '~')
/*
* Returns non-zero if the argument belongs to the POSIX Portable Filename
* Character Set. Assumes that the execution character set is a superset
* of ASCII.
*/
#define is_pfcs(ch) \
(is_digit(ch) || is_letter(ch) || \
ch == '.' || ch == '_' || ch == '-')
#endif

View File

@ -31,61 +31,67 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef OPENPAM_DEBUG_INCLUDED
#define OPENPAM_DEBUG_INCLUDED
#ifndef OPENPAM_DEBUG_H_INCLUDED
#define OPENPAM_DEBUG_H_INCLUDED
#ifdef OPENPAM_DEBUG
#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering")
#define ENTER() openpam_log(PAM_LOG_LIBDEBUG, "entering")
#define ENTERI(i) do { \
int i_ = (i); \
if (i_ > 0 && i_ < PAM_NUM_ITEMS) \
openpam_log(PAM_LOG_DEBUG, "entering: %s", pam_item_name[i_]); \
openpam_log(PAM_LOG_LIBDEBUG, "entering: %s", pam_item_name[i_]); \
else \
openpam_log(PAM_LOG_DEBUG, "entering: %d", i_); \
openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", i_); \
} while (0)
#define ENTERN(n) do { \
int n_ = (n); \
openpam_log(PAM_LOG_DEBUG, "entering: %d", n_); \
openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", n_); \
} while (0)
#define ENTERS(s) do { \
const char *s_ = (s); \
if (s_ == NULL) \
openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \
openpam_log(PAM_LOG_LIBDEBUG, "entering: NULL"); \
else \
openpam_log(PAM_LOG_DEBUG, "entering: '%s'", s_); \
openpam_log(PAM_LOG_LIBDEBUG, "entering: '%s'", s_); \
} while (0)
#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning")
#define ENTERF(f) do { \
int f_ = (f); \
if (f_ >= 0 && f_ <= OPENPAM_NUM_FEATURES) \
openpam_log(PAM_LOG_LIBDEBUG, "entering: %s", \
openpam_features[f_].name); \
else \
openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", f_); \
} while (0)
#define RETURNV() openpam_log(PAM_LOG_LIBDEBUG, "returning")
#define RETURNC(c) do { \
int c_ = (c); \
if (c_ >= 0 && c_ < PAM_NUM_ERRORS) \
openpam_log(PAM_LOG_DEBUG, "returning %s", pam_err_name[c_]); \
openpam_log(PAM_LOG_LIBDEBUG, "returning %s", pam_err_name[c_]); \
else \
openpam_log(PAM_LOG_DEBUG, "returning %d!", c_); \
openpam_log(PAM_LOG_LIBDEBUG, "returning %d!", c_); \
return (c_); \
} while (0)
#define RETURNN(n) do { \
int n_ = (n); \
openpam_log(PAM_LOG_DEBUG, "returning %d", n_); \
openpam_log(PAM_LOG_LIBDEBUG, "returning %d", n_); \
return (n_); \
} while (0)
#define RETURNP(p) do { \
const void *p_ = (p); \
void *p_ = (p); \
if (p_ == NULL) \
openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
openpam_log(PAM_LOG_LIBDEBUG, "returning NULL"); \
else \
openpam_log(PAM_LOG_DEBUG, "returning %p", p_); \
openpam_log(PAM_LOG_LIBDEBUG, "returning %p", p_); \
return (p_); \
} while (0)
#define RETURNS(s) do { \
const char *s_ = (s); \
if (s_ == NULL) \
openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
openpam_log(PAM_LOG_LIBDEBUG, "returning NULL"); \
else \
openpam_log(PAM_LOG_DEBUG, "returning '%s'", s_); \
openpam_log(PAM_LOG_LIBDEBUG, "returning '%s'", s_); \
return (s_); \
} while (0)
#else
@ -93,6 +99,7 @@
#define ENTERI(i)
#define ENTERN(n)
#define ENTERS(s)
#define ENTERF(f)
#define RETURNV() return
#define RETURNC(c) return (c)
#define RETURNN(n) return (n)

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -41,6 +39,8 @@
#include <sys/param.h>
#include <stdint.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
@ -63,12 +63,10 @@ openpam_dispatch(pam_handle_t *pamh,
int flags)
{
pam_chain_t *chain;
int err, fail, r;
int err, fail, nsuccess, r;
int debug;
ENTER();
if (pamh == NULL)
RETURNC(PAM_SYSTEM_ERR);
/* prevent recursion */
if (pamh->current != NULL) {
@ -101,23 +99,25 @@ openpam_dispatch(pam_handle_t *pamh,
}
/* execute */
for (err = fail = 0; chain != NULL; chain = chain->next) {
err = PAM_SUCCESS;
fail = nsuccess = 0;
for (; chain != NULL; chain = chain->next) {
if (chain->module->func[primitive] == NULL) {
openpam_log(PAM_LOG_ERROR, "%s: no %s()",
chain->module->path, pam_sm_func_name[primitive]);
r = PAM_SYSTEM_ERR;
r = PAM_SYMBOL_ERR;
} else {
pamh->primitive = primitive;
pamh->current = chain;
debug = (openpam_get_option(pamh, "debug") != NULL);
if (debug)
++openpam_debug;
openpam_log(PAM_LOG_DEBUG, "calling %s() in %s",
openpam_log(PAM_LOG_LIBDEBUG, "calling %s() in %s",
pam_sm_func_name[primitive], chain->module->path);
r = (chain->module->func[primitive])(pamh, flags,
chain->optc, (const char **)chain->optv);
chain->optc, (const char **)(intptr_t)chain->optv);
pamh->current = NULL;
openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s",
openpam_log(PAM_LOG_LIBDEBUG, "%s: %s(): %s",
chain->module->path, pam_sm_func_name[primitive],
pam_strerror(pamh, r));
if (debug)
@ -127,6 +127,7 @@ openpam_dispatch(pam_handle_t *pamh,
if (r == PAM_IGNORE)
continue;
if (r == PAM_SUCCESS) {
++nsuccess;
/*
* For pam_setcred() and pam_chauthtok() with the
* PAM_PRELIM_CHECK flag, treat "sufficient" as
@ -148,11 +149,11 @@ openpam_dispatch(pam_handle_t *pamh,
* fail. If a required module fails, record the
* return code from the first required module to fail.
*/
if (err == 0)
if (err == PAM_SUCCESS)
err = r;
if ((chain->flag == PAM_REQUIRED ||
chain->flag == PAM_BINDING) && !fail) {
openpam_log(PAM_LOG_DEBUG, "required module failed");
openpam_log(PAM_LOG_LIBDEBUG, "required module failed");
fail = 1;
err = r;
}
@ -162,7 +163,7 @@ openpam_dispatch(pam_handle_t *pamh,
* immediately.
*/
if (chain->flag == PAM_REQUISITE) {
openpam_log(PAM_LOG_DEBUG, "requisite module failed");
openpam_log(PAM_LOG_LIBDEBUG, "requisite module failed");
fail = 1;
break;
}
@ -170,6 +171,18 @@ openpam_dispatch(pam_handle_t *pamh,
if (!fail && err != PAM_NEW_AUTHTOK_REQD)
err = PAM_SUCCESS;
/*
* Require the chain to be non-empty, and at least one module
* in the chain to be successful, so that we don't fail open.
*/
if (err == PAM_SUCCESS && nsuccess < 1) {
openpam_log(PAM_LOG_ERROR,
"all modules were unsuccessful for %s()",
pam_sm_func_name[primitive]);
err = PAM_SYSTEM_ERR;
}
RETURNC(err);
}
@ -179,6 +192,7 @@ openpam_check_error_code(int primitive, int r)
{
/* common error codes */
if (r == PAM_SUCCESS ||
r == PAM_SYSTEM_ERR ||
r == PAM_SERVICE_ERR ||
r == PAM_BUF_ERR ||
r == PAM_CONV_ERR ||

View File

@ -0,0 +1,44 @@
/*-
* Copyright (c) 2013 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_DLFCN_H_INCLUDED
#define OPENPAM_DLFCN_H_INCLUDED
#ifndef HAVE_DLFUNC
typedef void (*dlfunc_t)();
static inline dlfunc_t
dlfunc(void *handle, const char *symbol)
{
return ((dlfunc_t)dlsym(handle, symbol));
}
#endif
#endif

View File

@ -0,0 +1,260 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
* Network Associates Laboratories, the Security Research Division of
* Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
* ("CBOSS"), as part of the DARPA CHATS research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/param.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_asprintf.h"
#include "openpam_ctype.h"
#include "openpam_dlfunc.h"
#ifndef RTLD_NOW
#define RTLD_NOW RTLD_LAZY
#endif
/*
* OpenPAM internal
*
* Perform sanity checks and attempt to load a module
*/
#ifdef HAVE_FDLOPEN
static void *
try_dlopen(const char *modfn)
{
void *dlh;
int fd;
openpam_log(PAM_LOG_LIBDEBUG, "dlopen(%s)", modfn);
if ((fd = open(modfn, O_RDONLY)) < 0) {
if (errno != ENOENT)
openpam_log(PAM_LOG_ERROR, "%s: %m", modfn);
return (NULL);
}
if (OPENPAM_FEATURE(VERIFY_MODULE_FILE) &&
openpam_check_desc_owner_perms(modfn, fd) != 0) {
close(fd);
return (NULL);
}
if ((dlh = fdlopen(fd, RTLD_NOW)) == NULL) {
openpam_log(PAM_LOG_ERROR, "%s: %s", modfn, dlerror());
close(fd);
errno = 0;
return (NULL);
}
close(fd);
return (dlh);
}
#else
static void *
try_dlopen(const char *modfn)
{
int check_module_file;
void *dlh;
openpam_log(PAM_LOG_LIBDEBUG, "dlopen(%s)", modfn);
openpam_get_feature(OPENPAM_VERIFY_MODULE_FILE,
&check_module_file);
if (check_module_file &&
openpam_check_path_owner_perms(modfn) != 0)
return (NULL);
if ((dlh = dlopen(modfn, RTLD_NOW)) == NULL) {
openpam_log(PAM_LOG_ERROR, "%s: %s", modfn, dlerror());
errno = 0;
return (NULL);
}
return (dlh);
}
#endif
/*
* Try to load a module from the suggested location.
*/
static pam_module_t *
try_module(const char *modpath)
{
const pam_module_t *dlmodule;
pam_module_t *module;
int i, serrno;
if ((module = calloc(1, sizeof *module)) == NULL ||
(module->path = strdup(modpath)) == NULL ||
(module->dlh = try_dlopen(modpath)) == NULL)
goto err;
dlmodule = dlsym(module->dlh, "_pam_module");
for (i = 0; i < PAM_NUM_PRIMITIVES; ++i) {
if (dlmodule) {
module->func[i] = dlmodule->func[i];
} else {
module->func[i] = (pam_func_t)dlfunc(module->dlh,
pam_sm_func_name[i]);
/*
* This openpam_log() call is a major source of
* log spam, and the cases that matter are caught
* and logged in openpam_dispatch(). This would
* be less problematic if dlerror() returned an
* error code so we could log an error only when
* dlfunc() failed for a reason other than "no
* such symbol".
*/
#if 0
if (module->func[i] == NULL)
openpam_log(PAM_LOG_LIBDEBUG, "%s: %s(): %s",
modpath, pam_sm_func_name[i], dlerror());
#endif
}
}
return (module);
err:
serrno = errno;
if (module != NULL) {
if (module->dlh != NULL)
dlclose(module->dlh);
if (module->path != NULL)
FREE(module->path);
FREE(module);
}
errno = serrno;
if (serrno != 0 && serrno != ENOENT)
openpam_log(PAM_LOG_ERROR, "%s: %m", modpath);
errno = serrno;
return (NULL);
}
/*
* OpenPAM internal
*
* Locate a dynamically linked module
*/
pam_module_t *
openpam_dynamic(const char *modname)
{
pam_module_t *module;
char modpath[PATH_MAX];
const char **path, *p;
int has_so, has_ver;
int dot, len;
/*
* Simple case: module name contains path separator(s)
*/
if (strchr(modname, '/') != NULL) {
/*
* Absolute paths are not allowed if RESTRICT_MODULE_NAME
* is in effect (default off). Relative paths are never
* allowed.
*/
if (OPENPAM_FEATURE(RESTRICT_MODULE_NAME) ||
modname[0] != '/') {
openpam_log(PAM_LOG_ERROR,
"invalid module name: %s", modname);
return (NULL);
}
return (try_module(modname));
}
/*
* Check for .so and version sufixes
*/
p = strchr(modname, '\0');
has_ver = has_so = 0;
while (is_digit(*p))
--p;
if (*p == '.' && *++p != '\0') {
/* found a numeric suffix */
has_ver = 1;
/* assume that .so is either present or unneeded */
has_so = 1;
} else if (*p == '\0' && p >= modname + sizeof PAM_SOEXT &&
strcmp(p - sizeof PAM_SOEXT + 1, PAM_SOEXT) == 0) {
/* found .so suffix */
has_so = 1;
}
/*
* Complicated case: search for the module in the usual places.
*/
for (path = openpam_module_path; *path != NULL; ++path) {
/*
* Assemble the full path, including the version suffix. Take
* note of where the suffix begins so we can cut it off later.
*/
if (has_ver)
len = snprintf(modpath, sizeof modpath, "%s/%s%n",
*path, modname, &dot);
else if (has_so)
len = snprintf(modpath, sizeof modpath, "%s/%s%n.%d",
*path, modname, &dot, LIB_MAJ);
else
len = snprintf(modpath, sizeof modpath, "%s/%s%s%n.%d",
*path, modname, PAM_SOEXT, &dot, LIB_MAJ);
/* check for overflow */
if (len < 0 || (unsigned int)len >= sizeof modpath) {
errno = ENOENT;
continue;
}
/* try the versioned path */
if ((module = try_module(modpath)) != NULL)
return (module);
if (errno == ENOENT && modpath[dot] != '\0') {
/* no luck, try the unversioned path */
modpath[dot] = '\0';
if ((module = try_module(modpath)) != NULL)
return (module);
}
}
/* :( */
return (NULL);
}
/*
* NOPARSE
*/

View File

@ -0,0 +1,71 @@
/*-
* Copyright (c) 2012-2015 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <security/pam_appl.h>
#include "openpam_impl.h"
#define STRUCT_OPENPAM_FEATURE(name, descr, dflt) \
[OPENPAM_##name] = { \
"OPENPAM_" #name, \
descr, \
dflt \
}
struct openpam_feature openpam_features[OPENPAM_NUM_FEATURES] = {
STRUCT_OPENPAM_FEATURE(
RESTRICT_SERVICE_NAME,
"Disallow path separators in service names",
1
),
STRUCT_OPENPAM_FEATURE(
VERIFY_POLICY_FILE,
"Verify ownership and permissions of policy files",
1
),
STRUCT_OPENPAM_FEATURE(
RESTRICT_MODULE_NAME,
"Disallow path separators in module names",
0
),
STRUCT_OPENPAM_FEATURE(
VERIFY_MODULE_FILE,
"Verify ownership and permissions of module files",
1
),
STRUCT_OPENPAM_FEATURE(
FALLBACK_TO_OTHER,
"Fall back to \"other\" policy for empty chains",
1
),
};

View File

@ -0,0 +1,45 @@
/*-
* Copyright (c) 2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_FEATURES_H_INCLUDED
#define OPENPAM_FEATURES_H_INCLUDED
struct openpam_feature {
const char *name;
const char *desc;
int onoff;
};
extern struct openpam_feature openpam_features[OPENPAM_NUM_FEATURES];
/* shortcut for internal use */
#define OPENPAM_FEATURE(f) \
openpam_features[OPENPAM_##f].onoff
#endif

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,14 +31,13 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <string.h>
#include <security/pam_appl.h>
@ -59,12 +58,11 @@ openpam_findenv(pam_handle_t *pamh,
int i;
ENTER();
if (pamh == NULL)
RETURNN(-1);
for (i = 0; i < pamh->env_count; ++i)
if (strncmp(pamh->env[i], name, len) == 0 &&
pamh->env[i][len] == '=')
RETURNN(i);
errno = ENOENT;
RETURNN(-1);
}

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -6,8 +6,7 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
@ -24,8 +23,6 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -0,0 +1,96 @@
/*-
* Copyright (c) 2012-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <security/pam_appl.h>
#include <security/openpam.h>
#include "openpam_impl.h"
/*
* OpenPAM extension
*
* Query the state of an optional feature.
*/
int
openpam_get_feature(int feature, int *onoff)
{
ENTERF(feature);
if (feature < 0 || feature >= OPENPAM_NUM_FEATURES)
RETURNC(PAM_BAD_FEATURE);
*onoff = openpam_features[feature].onoff;
RETURNC(PAM_SUCCESS);
}
/*
* Error codes:
*
* PAM_BAD_FEATURE
*/
/**
* EXPERIMENTAL
*
* The =openpam_get_feature function stores the current state of the
* specified feature in the variable pointed to by its =onoff argument.
*
* The following features are recognized:
*
* =OPENPAM_RESTRICT_SERVICE_NAME:
* Disallow path separators in service names.
* This feature is enabled by default.
* Disabling it allows the application to specify the path to
* the desired policy file directly.
*
* =OPENPAM_VERIFY_POLICY_FILE:
* Verify the ownership and permissions of the policy file
* and the path leading up to it.
* This feature is enabled by default.
*
* =OPENPAM_RESTRICT_MODULE_NAME:
* Disallow path separators in module names.
* This feature is disabled by default.
* Enabling it prevents the use of modules in non-standard
* locations.
*
* =OPENPAM_VERIFY_MODULE_FILE:
* Verify the ownership and permissions of each loadable
* module and the path leading up to it.
* This feature is enabled by default.
*
*
* >openpam_set_feature
*
* AUTHOR DES
*/

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -44,7 +42,6 @@
#include <string.h>
#include <security/pam_appl.h>
#include <security/openpam.h>
#include "openpam_impl.h"

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef OPENPAM_IMPL_H_INCLUDED
@ -122,19 +120,6 @@ struct pam_handle {
int env_size;
};
#ifdef NGROUPS_MAX
/*
* Saved credentials
*/
#define PAM_SAVED_CRED "pam_saved_cred"
struct pam_saved_cred {
uid_t euid;
gid_t egid;
gid_t groups[NGROUPS_MAX];
int ngroups;
};
#endif
/*
* Default policy
*/
@ -143,23 +128,46 @@ struct pam_saved_cred {
/*
* Internal functions
*/
int openpam_configure(pam_handle_t *, const char *);
int openpam_dispatch(pam_handle_t *, int, int);
int openpam_findenv(pam_handle_t *, const char *, size_t);
pam_module_t *openpam_load_module(const char *);
void openpam_clear_chains(pam_chain_t **);
int openpam_configure(pam_handle_t *, const char *)
OPENPAM_NONNULL((1));
int openpam_dispatch(pam_handle_t *, int, int)
OPENPAM_NONNULL((1));
int openpam_findenv(pam_handle_t *, const char *, size_t)
OPENPAM_NONNULL((1,2));
pam_module_t *openpam_load_module(const char *)
OPENPAM_NONNULL((1));
void openpam_clear_chains(pam_chain_t **)
OPENPAM_NONNULL((1));
int openpam_check_desc_owner_perms(const char *, int);
int openpam_check_path_owner_perms(const char *);
int openpam_check_desc_owner_perms(const char *, int)
OPENPAM_NONNULL((1));
int openpam_check_path_owner_perms(const char *)
OPENPAM_NONNULL((1));
#ifdef OPENPAM_STATIC_MODULES
pam_module_t *openpam_static(const char *);
pam_module_t *openpam_static(const char *)
OPENPAM_NONNULL((1));
#endif
pam_module_t *openpam_dynamic(const char *);
pam_module_t *openpam_dynamic(const char *)
OPENPAM_NONNULL((1));
#define FREE(p) do { free((p)); (p) = NULL; } while (0)
#define FREE(p) \
do { \
free(p); \
(p) = NULL; \
} while (0)
#define FREEV(c, v) \
do { \
if ((v) != NULL) { \
while ((c)-- > 0) \
FREE((v)[(c)]); \
FREE(v); \
} \
} while (0)
#include "openpam_constants.h"
#include "openpam_debug.h"
#include "openpam_features.h"
#endif

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2013 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -52,24 +50,24 @@
*/
pam_module_t *
openpam_load_module(const char *path)
openpam_load_module(const char *modulename)
{
pam_module_t *module;
module = openpam_dynamic(path);
module = openpam_dynamic(modulename);
openpam_log(PAM_LOG_DEBUG, "%s dynamic %s",
(module == NULL) ? "no" : "using", path);
(module == NULL) ? "no" : "using", modulename);
#ifdef OPENPAM_STATIC_MODULES
/* look for a static module */
if (module == NULL && strchr(path, '/') == NULL) {
module = openpam_static(path);
if (module == NULL && strchr(modulename, '/') == NULL) {
module = openpam_static(modulename);
openpam_log(PAM_LOG_DEBUG, "%s static %s",
(module == NULL) ? "no" : "using", path);
(module == NULL) ? "no" : "using", modulename);
}
#endif
if (module == NULL) {
openpam_log(PAM_LOG_ERROR, "no %s found", path);
openpam_log(PAM_LOG_ERROR, "no %s found", modulename);
return (NULL);
}
return (module);
@ -84,6 +82,7 @@ openpam_load_module(const char *path)
static void
openpam_release_module(pam_module_t *module)
{
if (module == NULL)
return;
if (module->dlh == NULL)
@ -104,13 +103,12 @@ openpam_release_module(pam_module_t *module)
static void
openpam_destroy_chain(pam_chain_t *chain)
{
if (chain == NULL)
return;
openpam_destroy_chain(chain->next);
chain->next = NULL;
while (chain->optc--)
FREE(chain->optv[chain->optc]);
FREE(chain->optv);
FREEV(chain->optc, chain->optv);
openpam_release_module(chain->module);
chain->module = NULL;
FREE(chain);

View File

@ -31,30 +31,24 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_asprintf.h"
#ifdef OPENPAM_DEBUG
int openpam_debug = 1;
#else
int openpam_debug = 0;
#endif
#if !defined(openpam_log)
@ -69,8 +63,10 @@ openpam_log(int level, const char *fmt, ...)
{
va_list ap;
int priority;
int serrno;
switch (level) {
case PAM_LOG_LIBDEBUG:
case PAM_LOG_DEBUG:
if (!openpam_debug)
return;
@ -87,9 +83,11 @@ openpam_log(int level, const char *fmt, ...)
priority = LOG_ERR;
break;
}
serrno = errno;
va_start(ap, fmt);
vsyslog(priority, fmt, ap);
va_end(ap);
errno = serrno;
}
#else
@ -100,8 +98,10 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
va_list ap;
char *format;
int priority;
int serrno;
switch (level) {
case PAM_LOG_LIBDEBUG:
case PAM_LOG_DEBUG:
if (!openpam_debug)
return;
@ -118,14 +118,18 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
priority = LOG_ERR;
break;
}
serrno = errno;
va_start(ap, fmt);
if (asprintf(&format, "in %s(): %s", func, fmt) > 0) {
errno = serrno;
vsyslog(priority, format, ap);
FREE(format);
} else {
errno = serrno;
vsyslog(priority, fmt, ap);
}
va_end(ap);
errno = serrno;
}
#endif
@ -137,6 +141,9 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
* The =level argument indicates the importance of the message.
* The following levels are defined:
*
* =PAM_LOG_LIBDEBUG:
* Debugging messages.
* For internal use only.
* =PAM_LOG_DEBUG:
* Debugging messages.
* These messages are normally not logged unless the global
@ -159,4 +166,6 @@ _openpam_log(int level, const char *func, const char *fmt, ...)
*
* The remaining arguments are a =printf format string and the
* corresponding arguments.
*
* The =openpam_log function does not modify the value of :errno.
*/

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -31,19 +31,17 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#define MIN_LINE_LENGTH 128
@ -61,22 +59,9 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp)
size_t len, size;
int ch;
if ((line = malloc(MIN_LINE_LENGTH)) == NULL)
line = NULL;
if (openpam_straddch(&line, &size, &len, 0) != 0)
return (NULL);
size = MIN_LINE_LENGTH;
len = 0;
#define line_putch(ch) do { \
if (len >= size - 1) { \
char *tmp = realloc(line, size *= 2); \
if (tmp == NULL) \
goto fail; \
line = tmp; \
} \
line[len++] = ch; \
line[len] = '\0'; \
} while (0)
for (;;) {
ch = fgetc(f);
/* strip comment */
@ -105,22 +90,10 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp)
/* done */
break;
}
/* whitespace */
if (isspace(ch)) {
/* ignore leading whitespace */
/* collapse linear whitespace */
if (len > 0 && line[len - 1] != ' ')
line_putch(' ');
continue;
}
/* anything else */
line_putch(ch);
if (openpam_straddch(&line, &size, &len, ch) != 0)
goto fail;
}
/* remove trailing whitespace */
while (len > 0 && isspace((unsigned char)line[len - 1]))
--len;
line[len] = '\0';
if (len == 0)
goto fail;
if (lenp != NULL)
@ -132,16 +105,18 @@ fail:
}
/**
* DEPRECATED openpam_readlinev
*
* The =openpam_readline function reads a line from a file, and returns it
* in a NUL-terminated buffer allocated with =malloc.
* in a NUL-terminated buffer allocated with =!malloc.
*
* The =openpam_readline function performs a certain amount of processing
* on the data it reads:
*
* - Comments (introduced by a hash sign) are stripped, as is leading and
* trailing whitespace.
* - Any amount of linear whitespace is collapsed to a single space.
* - Comments (introduced by a hash sign) are stripped.
*
* - Blank lines are ignored.
*
* - If a line ends in a backslash, the backslash is stripped and the
* next line is appended.
*
@ -152,5 +127,8 @@ fail:
* terminating NUL character) is stored in the variable it points to.
*
* The caller is responsible for releasing the returned buffer by passing
* it to =free.
* it to =!free.
*
* >openpam_readlinev
* >openpam_readword
*/

View File

@ -0,0 +1,153 @@
/*-
* Copyright (c) 2012-2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#define MIN_WORDV_SIZE 32
/*
* OpenPAM extension
*
* Read a line from a file and split it into words.
*/
char **
openpam_readlinev(FILE *f, int *lineno, int *lenp)
{
char *word, **wordv, **tmp;
size_t wordlen, wordvsize;
int ch, serrno, wordvlen;
wordvsize = MIN_WORDV_SIZE;
wordvlen = 0;
if ((wordv = malloc(wordvsize * sizeof *wordv)) == NULL) {
errno = ENOMEM;
return (NULL);
}
wordv[wordvlen] = NULL;
while ((word = openpam_readword(f, lineno, &wordlen)) != NULL) {
if ((unsigned int)wordvlen + 1 >= wordvsize) {
/* need to expand the array */
wordvsize *= 2;
tmp = realloc(wordv, wordvsize * sizeof *wordv);
if (tmp == NULL) {
errno = ENOMEM;
break;
}
wordv = tmp;
}
/* insert our word */
wordv[wordvlen++] = word;
wordv[wordvlen] = NULL;
word = NULL;
}
if (errno != 0) {
/* I/O error or out of memory */
serrno = errno;
while (wordvlen--)
free(wordv[wordvlen]);
free(wordv);
free(word);
errno = serrno;
return (NULL);
}
/* assert(!ferror(f)) */
ch = fgetc(f);
/* assert(ch == EOF || ch == '\n') */
if (ch == EOF && wordvlen == 0) {
free(wordv);
return (NULL);
}
if (ch == '\n' && lineno != NULL)
++*lineno;
if (lenp != NULL)
*lenp = wordvlen;
return (wordv);
}
/**
* The =openpam_readlinev function reads a line from a file, splits it
* into words according to the rules described in the =openpam_readword
* manual page, and returns a list of those words.
*
* If =lineno is not =NULL, the integer variable it points to is
* incremented every time a newline character is read.
* This includes quoted or escaped newline characters and the newline
* character at the end of the line.
*
* If =lenp is not =NULL, the number of words on the line is stored in the
* variable to which it points.
*
* RETURN VALUES
*
* If successful, the =openpam_readlinev function returns a pointer to a
* dynamically allocated array of pointers to individual dynamically
* allocated NUL-terminated strings, each containing a single word, in the
* order in which they were encountered on the line.
* The array is terminated by a =NULL pointer.
*
* The caller is responsible for freeing both the array and the individual
* strings by passing each of them to =!free.
*
* If the end of the line was reached before any words were read,
* =openpam_readlinev returns a pointer to a dynamically allocated array
* containing a single =NULL pointer.
*
* The =openpam_readlinev function can fail and return =NULL for one of
* four reasons:
*
* - The end of the file was reached before any words were read; :errno is
* zero, =!ferror returns zero, and =!feof returns a non-zero value.
*
* - The end of the file was reached while a quote or backslash escape
* was in effect; :errno is set to =EINVAL, =!ferror returns zero, and
* =!feof returns a non-zero value.
*
* - An error occurred while reading from the file; :errno is non-zero,
* =!ferror returns a non-zero value and =!feof returns zero.
*
* - A =!malloc or =!realloc call failed; :errno is set to =ENOMEM,
* =!ferror returns a non-zero value, and =!feof may or may not return
* a non-zero value.
*
* >openpam_readline
* >openpam_readword
*
* AUTHOR DES
*/

View File

@ -0,0 +1,214 @@
/*-
* Copyright (c) 2012-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_ctype.h"
#define MIN_WORD_SIZE 32
/*
* OpenPAM extension
*
* Read a word from a file, respecting shell quoting rules.
*/
char *
openpam_readword(FILE *f, int *lineno, size_t *lenp)
{
char *word;
size_t size, len;
int ch, escape, quote;
int serrno;
errno = 0;
/* skip initial whitespace */
escape = quote = 0;
while ((ch = getc(f)) != EOF) {
if (ch == '\n') {
/* either EOL or line continuation */
if (!escape)
break;
if (lineno != NULL)
++*lineno;
escape = 0;
} else if (escape) {
/* escaped something else */
break;
} else if (ch == '#') {
/* comment: until EOL, no continuation */
while ((ch = getc(f)) != EOF)
if (ch == '\n')
break;
break;
} else if (ch == '\\') {
escape = 1;
} else if (!is_ws(ch)) {
break;
}
}
if (ch == EOF)
return (NULL);
ungetc(ch, f);
if (ch == '\n')
return (NULL);
word = NULL;
size = len = 0;
while ((ch = fgetc(f)) != EOF && (!is_ws(ch) || quote || escape)) {
if (ch == '\\' && !escape && quote != '\'') {
/* escape next character */
escape = ch;
} else if ((ch == '\'' || ch == '"') && !quote && !escape) {
/* begin quote */
quote = ch;
/* edge case: empty quoted string */
if (openpam_straddch(&word, &size, &len, 0) != 0)
return (NULL);
} else if (ch == quote && !escape) {
/* end quote */
quote = 0;
} else if (ch == '\n' && escape) {
/* line continuation */
escape = 0;
} else {
if (escape && quote && ch != '\\' && ch != quote &&
openpam_straddch(&word, &size, &len, '\\') != 0) {
free(word);
errno = ENOMEM;
return (NULL);
}
if (openpam_straddch(&word, &size, &len, ch) != 0) {
free(word);
errno = ENOMEM;
return (NULL);
}
escape = 0;
}
if (lineno != NULL && ch == '\n')
++*lineno;
}
if (ch == EOF && ferror(f)) {
serrno = errno;
free(word);
errno = serrno;
return (NULL);
}
if (ch == EOF && (escape || quote)) {
/* Missing escaped character or closing quote. */
free(word);
errno = EINVAL;
return (NULL);
}
ungetc(ch, f);
if (lenp != NULL)
*lenp = len;
return (word);
}
/**
* The =openpam_readword function reads the next word from a file, and
* returns it in a NUL-terminated buffer allocated with =!malloc.
*
* A word is a sequence of non-whitespace characters.
* However, whitespace characters can be included in a word if quoted or
* escaped according to the following rules:
*
* - An unescaped single or double quote introduces a quoted string,
* which ends when the same quote character is encountered a second
* time.
* The quotes themselves are stripped.
*
* - Within a single- or double-quoted string, all whitespace characters,
* including the newline character, are preserved as-is.
*
* - Outside a quoted string, a backslash escapes the next character,
* which is preserved as-is, unless that character is a newline, in
* which case it is discarded and reading continues at the beginning of
* the next line as if the backslash and newline had not been there.
* In all cases, the backslash itself is discarded.
*
* - Within a single-quoted string, double quotes and backslashes are
* preserved as-is.
*
* - Within a double-quoted string, a single quote is preserved as-is,
* and a backslash is preserved as-is unless used to escape a double
* quote.
*
* In addition, if the first non-whitespace character on the line is a
* hash character (#), the rest of the line is discarded.
* If a hash character occurs within a word, however, it is preserved
* as-is.
* A backslash at the end of a comment does cause line continuation.
*
* If =lineno is not =NULL, the integer variable it points to is
* incremented every time a quoted or escaped newline character is read.
*
* If =lenp is not =NULL, the length of the word (after quotes and
* backslashes have been removed) is stored in the variable it points to.
*
* RETURN VALUES
*
* If successful, the =openpam_readword function returns a pointer to a
* dynamically allocated NUL-terminated string containing the first word
* encountered on the line.
*
* The caller is responsible for releasing the returned buffer by passing
* it to =!free.
*
* If =openpam_readword reaches the end of the line or file before any
* characters are copied to the word, it returns =NULL. In the former
* case, the newline is pushed back to the file.
*
* If =openpam_readword reaches the end of the file while a quote or
* backslash escape is in effect, it sets :errno to =EINVAL and returns
* =NULL.
*
* IMPLEMENTATION NOTES
*
* The parsing rules are intended to be equivalent to the normal POSIX
* shell quoting rules.
* Any discrepancy is a bug and should be reported to the author along
* with sample input that can be used to reproduce the error.
*
* >openpam_readline
* >openpam_readlinev
*
* AUTHOR DES
*/

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -50,6 +48,7 @@
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_cred.h"
/*
* OpenPAM extension

View File

@ -0,0 +1,72 @@
/*-
* Copyright (c) 2012-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <security/pam_appl.h>
#include <security/openpam.h>
#include "openpam_impl.h"
/*
* OpenPAM extension
*
* Enable or disable an optional feature.
*/
int
openpam_set_feature(int feature, int onoff)
{
ENTERF(feature);
if (feature < 0 || feature >= OPENPAM_NUM_FEATURES)
RETURNC(PAM_BAD_FEATURE);
openpam_features[feature].onoff = onoff;
RETURNC(PAM_SUCCESS);
}
/*
* Error codes:
*
* PAM_BAD_FEATURE
*/
/**
* EXPERIMENTAL
*
* The =openpam_set_feature function sets the state of the specified
* feature to the value specified by the =onoff argument.
* See =openpam_get_feature for a list of recognized features.
*
* >openpam_get_feature
*
* AUTHOR DES
*/

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2023 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -46,9 +44,9 @@
#include <string.h>
#include <security/pam_appl.h>
#include <security/openpam.h>
#include "openpam_impl.h"
#include "openpam_asprintf.h"
/*
* OpenPAM extension
@ -85,6 +83,7 @@ openpam_set_option(pam_handle_t *pamh,
for (free(cur->optv[i]); i < cur->optc; ++i)
cur->optv[i] = cur->optv[i + 1];
cur->optv[i] = NULL;
--cur->optc;
RETURNC(PAM_SUCCESS);
}
if (asprintf(&opt, "%.*s=%s", (int)len, option, value) < 0)

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -0,0 +1,113 @@
/*-
* Copyright (c) 2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <stdlib.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#define MIN_STR_SIZE 32
/*
* OpenPAM extension
*
* Add a character to a string, expanding the buffer if needed.
*/
int
openpam_straddch(char **str, size_t *size, size_t *len, int ch)
{
size_t tmpsize;
char *tmpstr;
if (*str == NULL) {
/* initial allocation */
tmpsize = MIN_STR_SIZE;
if ((tmpstr = malloc(tmpsize)) == NULL) {
errno = ENOMEM;
return (-1);
}
*str = tmpstr;
*size = tmpsize;
*len = 0;
} else if (ch != 0 && *len + 1 >= *size) {
/* additional space required */
tmpsize = *size * 2;
if ((tmpstr = realloc(*str, tmpsize)) == NULL) {
errno = ENOMEM;
return (-1);
}
*size = tmpsize;
*str = tmpstr;
}
if (ch != 0) {
(*str)[*len] = ch;
++*len;
}
(*str)[*len] = '\0';
return (0);
}
/**
* The =openpam_straddch function appends a character to a dynamically
* allocated NUL-terminated buffer, reallocating the buffer as needed.
*
* The =str argument points to a variable containing either a pointer to
* an existing buffer or =NULL.
* If the value of the variable pointed to by =str is =NULL, a new buffer
* is allocated.
*
* The =size and =len argument point to variables used to hold the size
* of the buffer and the length of the string it contains, respectively.
*
* The final argument, =ch, is the character that should be appended to
* the string. If =ch is 0, nothing is appended, but a new buffer is
* still allocated if =str is NULL. This can be used to "bootstrap" the
* string.
*
* If a new buffer is allocated or an existing buffer is reallocated to
* make room for the additional character, =str and =size are updated
* accordingly.
*
* The =openpam_straddch function ensures that the buffer is always
* NUL-terminated.
*
* If the =openpam_straddch function is successful, it increments the
* integer variable pointed to by =len (unless =ch was 0) and returns 0.
* Otherwise, it leaves the variables pointed to by =str, =size and =len
* unmodified, sets :errno to =ENOMEM and returns -1.
*
* AUTHOR DES
*/

View File

@ -0,0 +1,56 @@
/*-
* Copyright (c) 2011-2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_STRLCAT
#include <stddef.h>
#include "openpam_strlcat.h"
/* like strcat(3), but always NUL-terminates; returns strlen(src) */
size_t
openpam_strlcat(char *dst, const char *src, size_t size)
{
size_t len;
for (len = 0; *dst && size > 1; ++len, --size)
dst++;
for (; *src && size > 1; ++len, --size)
*dst++ = *src++;
*dst = '\0';
while (*src)
++len, ++src;
return (len);
}
#endif

View File

@ -0,0 +1,39 @@
/*-
* Copyright (c) 2011 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_STRLCAT_H_INCLUDED
#define OPENPAM_STRLCAT_H_INCLUDED
#ifndef HAVE_STRLCAT
size_t openpam_strlcat(char *, const char *, size_t);
#undef strlcat
#define strlcat(arg, ...) openpam_strlcat(arg, __VA_ARGS__)
#endif
#endif

View File

@ -6,11 +6,13 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,8 +25,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef OPENPAM_STRLCMP_H_INCLUDED

View File

@ -0,0 +1,54 @@
/*-
* Copyright (c) 2011-2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_STRLCPY
#include <stddef.h>
#include "openpam_strlcpy.h"
/* like strcpy(3), but always NUL-terminates; returns strlen(src) */
size_t
openpam_strlcpy(char *dst, const char *src, size_t size)
{
size_t len;
for (len = 0; *src && size > 1; ++len, --size)
*dst++ = *src++;
*dst = '\0';
while (*src)
++len, ++src;
return (len);
}
#endif

View File

@ -6,11 +6,13 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,27 +25,15 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef OPENPAM_STRLCPY_H_INCLUDED
#define OPENPAM_STRLCPY_H_INCLUDED
#ifndef HAVE_STRLCPY
/* like strcpy(3), but always NUL-terminates; returns strlen(src) */
size_t
strlcpy(char *dst, const char *src, size_t size)
{
size_t len;
for (len = 0; *src && size > 1; ++len, --size)
*dst++ = *src++;
*dst = '\0';
while (*src)
++len, ++src;
return (len);
}
size_t openpam_strlcpy(char *, const char *, size_t);
#undef strlcpy
#define strlcpy(arg, ...) openpam_strlcpy(arg, __VA_ARGS__)
#endif
#endif

View File

@ -0,0 +1,56 @@
/*-
* Copyright (c) 2014 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_STRLSET
#include <stddef.h>
#include "openpam_strlset.h"
/*
* like memset(3), but stops at the first NUL byte and NUL-terminates the
* result. Returns the number of bytes that were written, not including
* the terminating NUL.
*/
size_t
openpam_strlset(char *str, int ch, size_t size)
{
size_t len;
for (len = 0; *str && size > 1; ++len, --size)
*str++ = ch;
*str = '\0';
return (++len);
}
#endif

View File

@ -0,0 +1,39 @@
/*-
* Copyright (c) 2014 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_STRLSET_H_INCLUDED
#define OPENPAM_STRLSET_H_INCLUDED
#ifndef HAVE_STRLSET
size_t openpam_strlset(char *, int, size_t);
#undef strlset
#define strlset(arg, ...) openpam_strlset(arg, __VA_ARGS__)
#endif
#endif

View File

@ -1,16 +1,18 @@
/*-
* Copyright (c) 2011 Dag-Erling Smørgrav
* Copyright (c) 2011-2023 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -23,8 +25,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -104,7 +104,8 @@ openpam_subst(const pam_handle_t *pamh,
subst_char('%');
subst_char(*template);
}
++template;
if (*template)
++template;
} else {
subst_char(*template++);
}

View File

@ -0,0 +1,400 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2014 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
* Network Associates Laboratories, the Security Research Division of
* Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
* ("CBOSS"), as part of the DARPA CHATS research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <security/pam_appl.h>
#include "openpam_impl.h"
#include "openpam_strlset.h"
int openpam_ttyconv_timeout = 0;
static volatile sig_atomic_t caught_signal;
/*
* Handle incoming signals during tty conversation
*/
static void
catch_signal(int signo)
{
switch (signo) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
caught_signal = signo;
break;
}
}
/*
* Accept a response from the user on a tty
*/
static int
prompt_tty(int ifd, int ofd, const char *message, char *response, int echo)
{
struct sigaction action;
struct sigaction saction_sigint, saction_sigquit, saction_sigterm;
struct termios tcattr;
struct timeval now, target, remaining;
int remaining_ms;
tcflag_t slflag;
struct pollfd pfd;
int serrno;
int pos, ret;
char ch;
/* turn echo off if requested */
slflag = 0; /* prevent bogus uninitialized variable warning */
if (!echo) {
if (tcgetattr(ifd, &tcattr) != 0) {
openpam_log(PAM_LOG_ERROR, "tcgetattr(): %m");
return (-1);
}
slflag = tcattr.c_lflag;
tcattr.c_lflag &= ~ECHO;
if (tcsetattr(ifd, TCSAFLUSH, &tcattr) != 0) {
openpam_log(PAM_LOG_ERROR, "tcsetattr(): %m");
return (-1);
}
}
/* write prompt */
if (write(ofd, message, strlen(message)) < 0) {
openpam_log(PAM_LOG_ERROR, "write(): %m");
return (-1);
}
/* install signal handlers */
caught_signal = 0;
action.sa_handler = &catch_signal;
action.sa_flags = 0;
sigfillset(&action.sa_mask);
sigaction(SIGINT, &action, &saction_sigint);
sigaction(SIGQUIT, &action, &saction_sigquit);
sigaction(SIGTERM, &action, &saction_sigterm);
/* compute timeout */
if (openpam_ttyconv_timeout > 0) {
(void)gettimeofday(&now, NULL);
remaining.tv_sec = openpam_ttyconv_timeout;
remaining.tv_usec = 0;
timeradd(&now, &remaining, &target);
} else {
/* prevent bogus uninitialized variable warning */
now.tv_sec = now.tv_usec = 0;
remaining.tv_sec = remaining.tv_usec = 0;
target.tv_sec = target.tv_usec = 0;
}
/* input loop */
pos = 0;
ret = -1;
serrno = 0;
while (!caught_signal) {
pfd.fd = ifd;
pfd.events = POLLIN;
pfd.revents = 0;
if (openpam_ttyconv_timeout > 0) {
gettimeofday(&now, NULL);
if (timercmp(&now, &target, >))
break;
timersub(&target, &now, &remaining);
remaining_ms = remaining.tv_sec * 1000 +
remaining.tv_usec / 1000;
} else {
remaining_ms = -1;
}
if ((ret = poll(&pfd, 1, remaining_ms)) < 0) {
serrno = errno;
if (errno == EINTR)
continue;
openpam_log(PAM_LOG_ERROR, "poll(): %m");
break;
} else if (ret == 0) {
/* timeout */
write(ofd, " timed out", 10);
openpam_log(PAM_LOG_NOTICE, "timed out");
break;
}
if ((ret = read(ifd, &ch, 1)) < 0) {
serrno = errno;
openpam_log(PAM_LOG_ERROR, "read(): %m");
break;
} else if (ret == 0 || ch == '\n') {
response[pos] = '\0';
ret = pos;
break;
}
if (pos + 1 < PAM_MAX_RESP_SIZE)
response[pos++] = ch;
/* overflow is discarded */
}
/* restore tty state */
if (!echo) {
tcattr.c_lflag = slflag;
if (tcsetattr(ifd, 0, &tcattr) != 0) {
/* treat as non-fatal, since we have our answer */
openpam_log(PAM_LOG_NOTICE, "tcsetattr(): %m");
}
}
/* restore signal handlers and re-post caught signal*/
sigaction(SIGINT, &saction_sigint, NULL);
sigaction(SIGQUIT, &saction_sigquit, NULL);
sigaction(SIGTERM, &saction_sigterm, NULL);
if (caught_signal != 0) {
openpam_log(PAM_LOG_ERROR, "caught signal %d",
(int)caught_signal);
raise((int)caught_signal);
/* if raise() had no effect... */
serrno = EINTR;
ret = -1;
}
/* done */
write(ofd, "\n", 1);
errno = serrno;
return (ret);
}
/*
* Accept a response from the user on a non-tty stdin.
*/
static int
prompt_notty(const char *message, char *response)
{
struct timeval now, target, remaining;
int remaining_ms;
struct pollfd pfd;
int ch, pos, ret;
/* show prompt */
fputs(message, stdout);
fflush(stdout);
/* compute timeout */
if (openpam_ttyconv_timeout > 0) {
(void)gettimeofday(&now, NULL);
remaining.tv_sec = openpam_ttyconv_timeout;
remaining.tv_usec = 0;
timeradd(&now, &remaining, &target);
} else {
/* prevent bogus uninitialized variable warning */
now.tv_sec = now.tv_usec = 0;
remaining.tv_sec = remaining.tv_usec = 0;
target.tv_sec = target.tv_usec = 0;
}
/* input loop */
pos = 0;
for (;;) {
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
pfd.revents = 0;
if (openpam_ttyconv_timeout > 0) {
gettimeofday(&now, NULL);
if (timercmp(&now, &target, >))
break;
timersub(&target, &now, &remaining);
remaining_ms = remaining.tv_sec * 1000 +
remaining.tv_usec / 1000;
} else {
remaining_ms = -1;
}
if ((ret = poll(&pfd, 1, remaining_ms)) < 0) {
/* interrupt is ok, everything else -> bail */
if (errno == EINTR)
continue;
perror("\nopenpam_ttyconv");
return (-1);
} else if (ret == 0) {
/* timeout */
break;
} else {
/* input */
if ((ch = getchar()) == EOF && ferror(stdin)) {
perror("\nopenpam_ttyconv");
return (-1);
}
if (ch == EOF || ch == '\n') {
response[pos] = '\0';
return (pos);
}
if (pos + 1 < PAM_MAX_RESP_SIZE)
response[pos++] = ch;
/* overflow is discarded */
}
}
fputs("\nopenpam_ttyconv: timeout\n", stderr);
return (-1);
}
/*
* Determine whether stdin is a tty; if not, try to open the tty; in
* either case, call the appropriate method.
*/
static int
prompt(const char *message, char *response, int echo)
{
int ifd, ofd, ret;
if (isatty(STDIN_FILENO)) {
fflush(stdout);
#ifdef HAVE_FPURGE
fpurge(stdin);
#endif
ifd = STDIN_FILENO;
ofd = STDOUT_FILENO;
} else {
if ((ifd = open("/dev/tty", O_RDWR)) < 0)
/* no way to prevent echo */
return (prompt_notty(message, response));
ofd = ifd;
}
ret = prompt_tty(ifd, ofd, message, response, echo);
if (ifd != STDIN_FILENO)
close(ifd);
return (ret);
}
/*
* OpenPAM extension
*
* Simple tty-based conversation function
*/
int
openpam_ttyconv(int n,
const struct pam_message **msg,
struct pam_response **resp,
void *data)
{
char respbuf[PAM_MAX_RESP_SIZE];
struct pam_response *aresp;
int i;
ENTER();
(void)data;
if (n <= 0 || n > PAM_MAX_NUM_MSG)
RETURNC(PAM_CONV_ERR);
if ((aresp = calloc(n, sizeof *aresp)) == NULL)
RETURNC(PAM_BUF_ERR);
for (i = 0; i < n; ++i) {
aresp[i].resp_retcode = 0;
aresp[i].resp = NULL;
switch (msg[i]->msg_style) {
case PAM_PROMPT_ECHO_OFF:
if (prompt(msg[i]->msg, respbuf, 0) < 0 ||
(aresp[i].resp = strdup(respbuf)) == NULL)
goto fail;
break;
case PAM_PROMPT_ECHO_ON:
if (prompt(msg[i]->msg, respbuf, 1) < 0 ||
(aresp[i].resp = strdup(respbuf)) == NULL)
goto fail;
break;
case PAM_ERROR_MSG:
fputs(msg[i]->msg, stderr);
if (strlen(msg[i]->msg) > 0 &&
msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n')
fputc('\n', stderr);
break;
case PAM_TEXT_INFO:
fputs(msg[i]->msg, stdout);
if (strlen(msg[i]->msg) > 0 &&
msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n')
fputc('\n', stdout);
break;
default:
goto fail;
}
}
*resp = aresp;
memset(respbuf, 0, sizeof respbuf);
RETURNC(PAM_SUCCESS);
fail:
for (i = 0; i < n; ++i) {
if (aresp[i].resp != NULL) {
strlset(aresp[i].resp, 0, PAM_MAX_RESP_SIZE);
FREE(aresp[i].resp);
}
}
memset(aresp, 0, n * sizeof *aresp);
FREE(aresp);
*resp = NULL;
memset(respbuf, 0, sizeof respbuf);
RETURNC(PAM_CONV_ERR);
}
/*
* Error codes:
*
* PAM_SYSTEM_ERR
* PAM_BUF_ERR
* PAM_CONV_ERR
*/
/**
* The =openpam_ttyconv function is a standard conversation function
* suitable for use on TTY devices.
* It should be adequate for the needs of most text-based interactive
* programs.
*
* The =openpam_ttyconv function allows the application to specify a
* timeout for user input by setting the global integer variable
* :openpam_ttyconv_timeout to the length of the timeout in seconds.
*
* >openpam_nullconv
* >pam_prompt
* >pam_vprompt
*/

View File

@ -0,0 +1,58 @@
/*-
* Copyright (c) 2011-2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_VASPRINTF
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "openpam_vasprintf.h"
/* like vsprintf(3), but allocates memory for the result. */
int
openpam_vasprintf(char **str, const char *fmt, va_list ap)
{
va_list apcopy;
int len, ret;
va_copy(apcopy, ap);
len = vsnprintf(NULL, 0, fmt, ap);
if ((*str = malloc(len + 1)) == NULL)
return (-1);
ret = vsnprintf(*str, len + 1, fmt, apcopy);
va_end(apcopy);
return (ret);
}
#endif

View File

@ -0,0 +1,39 @@
/*-
* Copyright (c) 2012 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef OPENPAM_VASPRINTF_H_INCLUDED
#define OPENPAM_VASPRINTF_H_INCLUDED
#ifndef HAVE_VASPRINTF
int openpam_vasprintf(char **, const char *, va_list);
#undef vasprintf
#define vasprintf(arg, ...) openpam_vasprintf(arg, __VA_ARGS__)
#endif
#endif

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -60,7 +58,7 @@ pam_authenticate(pam_handle_t *pamh,
ENTER();
if (flags & ~(PAM_SILENT|PAM_DISALLOW_NULL_AUTHTOK))
RETURNC(PAM_SYMBOL_ERR);
RETURNC(PAM_BAD_CONSTANT);
r = openpam_dispatch(pamh, PAM_SM_AUTHENTICATE, flags);
pam_set_item(pamh, PAM_AUTHTOK, NULL);
RETURNC(r);
@ -72,7 +70,7 @@ pam_authenticate(pam_handle_t *pamh,
* =openpam_dispatch
* =pam_sm_authenticate
* !PAM_IGNORE
* PAM_SYMBOL_ERR
* PAM_BAD_CONSTANT
*/
/**
@ -92,5 +90,5 @@ pam_authenticate(pam_handle_t *pamh,
* Fail if the user's authentication token is null.
*
* If any other bits are set, =pam_authenticate will return
* =PAM_SYMBOL_ERR.
* =PAM_BAD_CONSTANT.
*/

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -60,7 +58,7 @@ pam_chauthtok(pam_handle_t *pamh,
ENTER();
if (flags & ~(PAM_SILENT|PAM_CHANGE_EXPIRED_AUTHTOK))
RETURNC(PAM_SYMBOL_ERR);
RETURNC(PAM_BAD_CONSTANT);
r = openpam_dispatch(pamh, PAM_SM_CHAUTHTOK,
flags | PAM_PRELIM_CHECK);
if (r == PAM_SUCCESS)
@ -77,7 +75,7 @@ pam_chauthtok(pam_handle_t *pamh,
* =openpam_dispatch
* =pam_sm_chauthtok
* !PAM_IGNORE
* PAM_SYMBOL_ERR
* PAM_BAD_CONSTANT
*/
/**
@ -93,5 +91,5 @@ pam_chauthtok(pam_handle_t *pamh,
* =PAM_CHANGE_EXPIRED_AUTHTOK:
* Change only those authentication tokens that have expired.
*
* If any other bits are set, =pam_chauthtok will return =PAM_SYMBOL_ERR.
* If any other bits are set, =pam_chauthtok will return =PAM_BAD_CONSTANT.
*/

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -60,7 +58,7 @@ pam_close_session(pam_handle_t *pamh,
ENTER();
if (flags & ~(PAM_SILENT))
RETURNC(PAM_SYMBOL_ERR);
RETURNC(PAM_BAD_CONSTANT);
r = openpam_dispatch(pamh, PAM_SM_CLOSE_SESSION, flags);
RETURNC(r);
}
@ -71,7 +69,7 @@ pam_close_session(pam_handle_t *pamh,
* =openpam_dispatch
* =pam_sm_close_session
* !PAM_IGNORE
* PAM_SYMBOL_ERR
* PAM_BAD_CONSTANT
*/
/**
@ -85,5 +83,5 @@ pam_close_session(pam_handle_t *pamh,
* Do not emit any messages.
*
* If any other bits are set, =pam_close_session will return
* =PAM_SYMBOL_ERR.
* =PAM_BAD_CONSTANT.
*/

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -61,7 +59,7 @@ pam_end(pam_handle_t *pamh,
ENTER();
if (pamh == NULL)
RETURNC(PAM_SYSTEM_ERR);
RETURNC(PAM_BAD_HANDLE);
/* clear module data */
while ((dp = pamh->module_data) != NULL) {
@ -94,7 +92,7 @@ pam_end(pam_handle_t *pamh,
/*
* Error codes:
*
* PAM_SYSTEM_ERR
* PAM_BAD_HANDLE
*/
/**

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -48,8 +46,10 @@
#include <security/openpam.h>
#include "openpam_impl.h"
#include "openpam_strlset.h"
static const char authtok_prompt[] = "Password:";
static const char authtok_prompt_remote[] = "Password for %u@%h:";
static const char oldauthtok_prompt[] = "Old Password:";
static const char newauthtok_prompt[] = "New Password:";
@ -69,12 +69,11 @@ pam_get_authtok(pam_handle_t *pamh,
size_t prompt_size;
const void *oldauthtok, *prevauthtok, *promptp;
const char *prompt_option, *default_prompt;
const void *lhost, *rhost;
char *resp, *resp2;
int pitem, r, style, twice;
ENTER();
if (pamh == NULL || authtok == NULL)
RETURNC(PAM_SYSTEM_ERR);
*authtok = NULL;
twice = 0;
switch (item) {
@ -82,6 +81,14 @@ pam_get_authtok(pam_handle_t *pamh,
pitem = PAM_AUTHTOK_PROMPT;
prompt_option = "authtok_prompt";
default_prompt = authtok_prompt;
r = pam_get_item(pamh, PAM_RHOST, &rhost);
if (r == PAM_SUCCESS && rhost != NULL) {
r = pam_get_item(pamh, PAM_HOST, &lhost);
if (r == PAM_SUCCESS && lhost != NULL) {
if (strcmp(rhost, lhost) != 0)
default_prompt = authtok_prompt_remote;
}
}
r = pam_get_item(pamh, PAM_OLDAUTHTOK, &oldauthtok);
if (r == PAM_SUCCESS && oldauthtok != NULL) {
default_prompt = newauthtok_prompt;
@ -95,7 +102,7 @@ pam_get_authtok(pam_handle_t *pamh,
twice = 0;
break;
default:
RETURNC(PAM_SYMBOL_ERR);
RETURNC(PAM_BAD_CONSTANT);
}
if (openpam_get_option(pamh, "try_first_pass") ||
openpam_get_option(pamh, "use_first_pass")) {
@ -103,17 +110,19 @@ pam_get_authtok(pam_handle_t *pamh,
if (r == PAM_SUCCESS && prevauthtok != NULL) {
*authtok = prevauthtok;
RETURNC(PAM_SUCCESS);
}
else if (openpam_get_option(pamh, "use_first_pass"))
} else if (openpam_get_option(pamh, "use_first_pass")) {
RETURNC(r == PAM_SUCCESS ? PAM_AUTH_ERR : r);
}
}
/* pam policy overrides the module's choice */
if ((promptp = openpam_get_option(pamh, prompt_option)) != NULL)
prompt = promptp;
/* no prompt provided, see if there is one tucked away somewhere */
if (prompt == NULL)
if (pam_get_item(pamh, pitem, &promptp) && promptp != NULL)
if (prompt == NULL) {
r = pam_get_item(pamh, pitem, &promptp);
if (r == PAM_SUCCESS && promptp != NULL)
prompt = promptp;
}
/* fall back to hardcoded default */
if (prompt == NULL)
prompt = default_prompt;
@ -130,16 +139,21 @@ pam_get_authtok(pam_handle_t *pamh,
if (twice) {
r = pam_prompt(pamh, style, &resp2, "Retype %s", prompt);
if (r != PAM_SUCCESS) {
strlset(resp, 0, PAM_MAX_RESP_SIZE);
FREE(resp);
RETURNC(r);
}
if (strcmp(resp, resp2) != 0)
if (strcmp(resp, resp2) != 0) {
strlset(resp, 0, PAM_MAX_RESP_SIZE);
FREE(resp);
}
strlset(resp2, 0, PAM_MAX_RESP_SIZE);
FREE(resp2);
}
if (resp == NULL)
RETURNC(PAM_TRY_AGAIN);
r = pam_set_item(pamh, item, resp);
strlset(resp, 0, PAM_MAX_RESP_SIZE);
FREE(resp);
if (r != PAM_SUCCESS)
RETURNC(r);
@ -154,14 +168,17 @@ pam_get_authtok(pam_handle_t *pamh,
* =pam_prompt
* =pam_set_item
* !PAM_SYMBOL_ERR
* PAM_BAD_CONSTANT
* PAM_TRY_AGAIN
*/
/**
* The =pam_get_authtok function returns the cached authentication token,
* or prompts the user if no token is currently cached.
* The =pam_get_authtok function either prompts the user for an
* authentication token or retrieves a cached authentication token,
* depending on circumstances.
* Either way, a pointer to the authentication token is stored in the
* location pointed to by the =authtok argument.
* location pointed to by the =authtok argument, and the corresponding PAM
* item is updated.
*
* The =item argument must have one of the following values:
*
@ -176,20 +193,47 @@ pam_get_authtok(pam_handle_t *pamh,
* If it is =NULL, the =PAM_AUTHTOK_PROMPT or =PAM_OLDAUTHTOK_PROMPT item,
* as appropriate, will be used.
* If that item is also =NULL, a hardcoded default prompt will be used.
* Either way, the prompt is expanded using =openpam_subst before it is
* passed to the conversation function.
*
* If =pam_get_authtok is called from a module and the ;authtok_prompt /
* ;oldauthtok_prompt option is set in the policy file, the value of that
* option takes precedence over both the =prompt argument and the
* =PAM_AUTHTOK_PROMPT / =PAM_OLDAUTHTOK_PROMPT item.
* Additionally, when =pam_get_authtok is called from a service module,
* the prompt may be affected by module options as described below.
* The prompt is then expanded using =openpam_subst before it is passed to
* the conversation function.
*
* If =item is set to =PAM_AUTHTOK and there is a non-null =PAM_OLDAUTHTOK
* item, =pam_get_authtok will ask the user to confirm the new token by
* retyping it.
* If there is a mismatch, =pam_get_authtok will return =PAM_TRY_AGAIN.
*
* MODULE OPTIONS
*
* When called by a service module, =pam_get_authtok will recognize the
* following module options:
*
* ;authtok_prompt:
* Prompt to use when =item is set to =PAM_AUTHTOK.
* This option overrides both the =prompt argument and the
* =PAM_AUTHTOK_PROMPT item.
* ;echo_pass:
* If the application's conversation function allows it, this
* lets the user see what they are typing.
* This should only be used for non-reusable authentication
* tokens.
* ;oldauthtok_prompt:
* Prompt to use when =item is set to =PAM_OLDAUTHTOK.
* This option overrides both the =prompt argument and the
* =PAM_OLDAUTHTOK_PROMPT item.
* ;try_first_pass:
* If the requested item is non-null, return it without
* prompting the user.
* Typically, the service module will verify the token, and
* if it does not match, clear the item before calling
* =pam_get_authtok a second time.
* ;use_first_pass:
* Do not prompt the user at all; just return the cached
* value, or =PAM_AUTH_ERR if there is none.
*
* >pam_conv
* >pam_get_item
* >pam_get_user
* >openpam_get_option
* >openpam_subst
*/

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -60,8 +58,6 @@ pam_get_data(const pam_handle_t *pamh,
pam_data_t *dp;
ENTERS(module_data_name);
if (pamh == NULL)
RETURNC(PAM_SYSTEM_ERR);
for (dp = pamh->module_data; dp != NULL; dp = dp->next) {
if (strcmp(dp->name, module_data_name) == 0) {
*data = (void *)dp->data;
@ -74,7 +70,6 @@ pam_get_data(const pam_handle_t *pamh,
/*
* Error codes:
*
* PAM_SYSTEM_ERR
* PAM_NO_MODULE_DATA
*/

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 2002-2003 Networks Associates Technology, Inc.
* Copyright (c) 2004-2011 Dag-Erling Smørgrav
* Copyright (c) 2004-2017 Dag-Erling Smørgrav
* All rights reserved.
*
* This software was developed for the FreeBSD Project by ThinkSec AS and
@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
@ -59,8 +57,6 @@ pam_get_item(const pam_handle_t *pamh,
{
ENTERI(item_type);
if (pamh == NULL)
RETURNC(PAM_SYSTEM_ERR);
switch (item_type) {
case PAM_SERVICE:
case PAM_USER:
@ -78,15 +74,14 @@ pam_get_item(const pam_handle_t *pamh,
*item = pamh->item[item_type];
RETURNC(PAM_SUCCESS);
default:
RETURNC(PAM_SYMBOL_ERR);
RETURNC(PAM_BAD_ITEM);
}
}
/*
* Error codes:
*
* PAM_SYMBOL_ERR
* PAM_SYSTEM_ERR
* PAM_BAD_ITEM
*/
/**

View File

@ -31,8 +31,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H

Some files were not shown because too many files have changed in this diff Show More