Commit graph

247 commits

Author SHA1 Message Date
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 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 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 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 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 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 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 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 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 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 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 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 95ed7f5d0c Style / consistency
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@503 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-18 14:00:33 +00:00
Dag-Erling Smørgrav dd498bc7ad Use openpam_check_path_owner_perms()
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@502 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-18 13:59:22 +00:00
Dag-Erling Smørgrav 996a845863 Report an error if one of the modules in the chain does not implement
the requested primitive.  This is a significant change, but it should
only affect poorly-written PAM modules, and the alternative is a
potential fail-open situation.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@501 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-12-07 01:28:05 +00:00
Dag-Erling Smørgrav 229c006c86 Forgotten in previous commit: check the ownership and permissions of the
policy file.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@500 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-22 12:07:03 +00:00
Dag-Erling Smørgrav 1a4edb80d7 Factor out and improve the module ownership / permission check, and add
a similar (but race-proof) check for the policy file.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@499 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-22 11:51:50 +00:00
Dag-Erling Smørgrav b9f0b632da Validate the service name, closing an attack vector for programs like
kcheckpass that let the user specify which policy to apply.  See
<URL:http://c-skills.blogspot.com/2011/11/openpam-trickery.html>.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@497 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-21 16:25:49 +00:00
Dag-Erling Smørgrav 026c898ec5 Disallow changing the service name.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@496 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-21 16:20:45 +00:00
Dag-Erling Smørgrav d9f7580763 nit
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@494 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-20 02:58:34 +00:00
Dag-Erling Smørgrav d98f755c25 Refuse to load a module if it is owned by anyone else than root or the
arbitrator or it is writable by group or other.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@493 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-20 02:28:15 +00:00
Dag-Erling Smørgrav b011e58526 dst can't be const, you idiot.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@492 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-20 02:04:17 +00:00
Dag-Erling Smørgrav 6a92548403 Reorganize the headers and centralize the string tables.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@491 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-12 00:12:32 +00:00
Dag-Erling Smørgrav ff73a20a84 Add a strlcpy(3) implementation.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@490 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-11 03:04:46 +00:00
Dag-Erling Smørgrav e8522c7fcc Always create optv, even if there are no options.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@488 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-05 20:50:15 +00:00
Dag-Erling Smørgrav c86a681052 The count was never used, so ditch it and return plain PAM error codes
instead.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@487 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-05 20:00:46 +00:00
Dag-Erling Smørgrav ba7de9c9c6 Remove debugging code.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@484 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 16:47:26 +00:00
Dag-Erling Smørgrav 493804d19b Fix a couple of bugs in the option string reassembly code.
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@483 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 16:46:20 +00:00
Dag-Erling Smørgrav 6835696a2a Revert large parts of r478. I had forgotten that the module arguments
are actually passed to each service function in the classic (argc,
argv) form.  The only place where the compiler could have caught this
used a type cast, and it did not show up in testing either because all
of the modules I tested use openpam_get_option(3) instead of
manipulating argv directly.

The cleaned-up policy parsing code remains in place, but options are
once more stored as strings, pretty much the way they appear in the
policy file, except that quotes are stripped.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@482 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 16:33:02 +00:00
Dag-Erling Smørgrav c16faba34e The include directive expects a service name, not a filename.
While there, remember to check for trailing garbage.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@481 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 16:09:22 +00:00
Dag-Erling Smørgrav b373991f87 namespace violation mumble mumble
git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@479 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 15:40:15 +00:00
Dag-Erling Smørgrav 55f6a50684 Major overhaul of the policy parser to support quoted option values. As a
bonus, it should now be much easier to read and understand.

This also changes the way options are stored: they are now stored as a list
of { key, value } pairs rather than "key=value" strings.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@478 185d5e19-27fe-0310-9dcf-9bff6b9f3609
2011-11-03 15:39:18 +00:00