Skip to content

Commit

Permalink
Make pam_fscrypt.so support the unlock_only option
Browse files Browse the repository at this point in the history
Now that it's been requested by users, bring back the "unlock_only"
option, which was originally proposed as part of
#281 but was dropped in the final
version of that pull request.

Resolves #357
  • Loading branch information
ebiggers committed Oct 19, 2022
1 parent 5d9198f commit 79edab3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,15 @@ after `pam_unix.so` in `/etc/pam.d/common-session` or similar, but before
which starts processes that access the user's home directory during their
session.

To make `pam_fscrypt.so` print debugging messages to the system log, add the
`debug` option. All hook types accept this option.
`pam_fscrypt.so` accepts several options:

* `debug`: print additional debug messages to the syslog. All hook types accept
this option.

* `unlock_only`: only unlock directories (at log-in); don't also lock them (at
log-out). This is only relevant for the "session" hook. Note that in
`fscrypt` v0.2.9 and earlier, unlock-only was the default behavior, and
`lock_policies` needed to be specified to enable locking.

### Allowing `fscrypt` to check your login passphrase

Expand Down
29 changes: 17 additions & 12 deletions pam_fscrypt/pam_fscrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ const (
debugFlag = "debug"

// This option is accepted for compatibility with existing config files,
// but now we lock policies unconditionally and this option is a no-op.
// but now we lock policies by default and this option is a no-op.
lockPoliciesFlag = "lock_policies"

// Only unlock directories, don't lock them.
unlockOnlyFlag = "unlock_only"

// This option is accepted for compatibility with existing config files,
// but it no longer does anything. pam_fscrypt now drops caches if and
// only if it is needed. (Usually it is not needed anymore, as the
Expand Down Expand Up @@ -279,19 +282,21 @@ func CloseSession(handle *pam.Handle, args map[string]bool) error {
// Don't automatically drop privileges, since we may need them to
// deprovision policies or to drop caches.

log.Print("locking policies protected with login protector")
needDropCaches, errLock := lockLoginPolicies(handle)

var errCache error
if needDropCaches {
log.Print("dropping appropriate filesystem caches at session close")
errCache = security.DropFilesystemCache()
}
if !args[unlockOnlyFlag] {
log.Print("locking policies protected with login protector")
needDropCaches, errLock := lockLoginPolicies(handle)

if errLock != nil {
return errLock
var errCache error
if needDropCaches {
log.Print("dropping appropriate filesystem caches at session close")
errCache = security.DropFilesystemCache()
}
if errLock != nil {
return errLock
}
return errCache
}
return errCache
return nil
}

// lockLoginPolicies deprovisions all policy keys that are protected by the
Expand Down

0 comments on commit 79edab3

Please sign in to comment.