log.Printf("no protector to unlock: %s", err)
return nil
}
- policies := policiesUsingProtector(protector)
+ policies := policiesUsingProtector(protector, false)
if len(policies) == 0 {
log.Print("no policies to unlock")
return nil
// We don't stop provisioning polices on error, we try all of them.
for _, policy := range policies {
- if policy.IsProvisionedByTargetUser() {
- log.Printf("policy %s already provisioned by %v",
- policy.Descriptor(), handle.PamUser.Username)
- continue
- }
if err := policy.UnlockWithProtector(protector); err != nil {
log.Printf("unlocking policy %s: %s", policy.Descriptor(), err)
continue
log.Printf("nothing to lock: %s", err)
return needDropCaches, nil
}
- policies := policiesUsingProtector(protector)
+ policies := policiesUsingProtector(protector, true)
if len(policies) == 0 {
log.Print("no policies to lock")
return needDropCaches, nil
// We will try to deprovision all of the policies.
for _, policy := range policies {
- if !policy.IsProvisionedByTargetUser() {
- log.Printf("policy %s not provisioned by %v",
- policy.Descriptor(), handle.PamUser.Username)
- continue
- }
if policy.NeedsUserKeyring() {
needDropCaches = true
}
}
// policiesUsingProtector searches all the mountpoints for any policies
-// protected with the specified protector.
-func policiesUsingProtector(protector *actions.Protector) []*actions.Policy {
+// protected with the specified protector. If provisioned is true, then only
+// policies provisioned by the target user are returned; otherwise only policies
+// *not* provisioned by the target user are returned.
+func policiesUsingProtector(protector *actions.Protector, provisioned bool) []*actions.Policy {
mounts, err := filesystem.AllFilesystems()
if err != nil {
log.Print(err)
continue
}
- if policy.UsesProtector(protector) {
- policies = append(policies, policy)
+ if !policy.UsesProtector(protector) {
+ continue
+ }
+ if provisioned {
+ if !policy.IsProvisionedByTargetUser() {
+ log.Printf("policy %s not provisioned by %v",
+ policy.Descriptor(), ctx.TargetUser.Username)
+ continue
+ }
+ } else {
+ if policy.IsProvisionedByTargetUser() {
+ log.Printf("policy %s already provisioned by %v",
+ policy.Descriptor(), ctx.TargetUser.Username)
+ continue
+ }
}
+ policies = append(policies, policy)
}
}
return policies