From f3f1d2f98de26e8180c56d87aaad0e4e98fb4e47 Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Wed, 19 Jul 2017 15:40:35 -0700 Subject: Various small nits a helper functions for PAM --- actions/policy.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/policy.go b/actions/policy.go index bf1f593..461f8cc 100644 --- a/actions/policy.go +++ b/actions/policy.go @@ -278,13 +278,19 @@ func (policy *Policy) Lock() error { return err } +// UsesProtector returns if the policy is protected with the protector +func (policy *Policy) UsesProtector(protector *Protector) bool { + _, ok := policy.findWrappedKeyIndex(protector.Descriptor()) + return ok +} + // AddProtector updates the data that is wrapping the Policy Key so that the // provided Protector is now protecting the specified Policy. If an error is // returned, no data has been changed. If the policy and protector are on // different filesystems, a link will be created between them. The policy and // protector must both be unlocked. func (policy *Policy) AddProtector(protector *Protector) error { - if _, ok := policy.findWrappedKeyIndex(protector.Descriptor()); ok { + if policy.UsesProtector(protector) { return ErrAlreadyProtected } if policy.key == nil || protector.key == nil { -- cgit v1.2.3