2 * Copyright (c) 2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 #include "resources.h"
30 #include <security_utilities/cfutilities.h>
33 namespace CodeSigning
{
38 DirScanner(const char *path
);
39 DirScanner(string path
);
42 struct dirent
*getNext(); // gets the next item out of this DirScanner
43 bool initialized(); // returns false if the constructor failed to initialize the dirent
45 void unlink(const struct dirent
* ent
, int flags
);
46 bool isRegularFile(dirent
* dp
);
51 struct dirent entBuffer
;
59 DirValidator() : mRequireCount(0) { }
71 typedef std::string (^TargetPatternBuilder
)(const std::string
&name
, const std::string
&target
);
74 class Rule
: public ResourceBuilder::Rule
{
76 Rule(const std::string
&pattern
, uint32_t flags
, TargetPatternBuilder targetBlock
);
79 bool matchTarget(const char *path
, const char *target
) const;
82 TargetPatternBuilder mTargetBlock
;
84 void addRule(Rule
*rule
) { mRules
.push_back(rule
); }
88 FTS(const std::string
&path
, int options
= FTS_PHYSICAL
| FTS_COMFOLLOW
| FTS_NOCHDIR
);
91 operator ::FTS
* () const { return mFTS
; }
98 void allow(const std::string
&namePattern
, uint32_t flags
, TargetPatternBuilder targetBlock
= NULL
)
99 { addRule(new Rule(namePattern
, flags
, targetBlock
)); }
100 void require(const std::string
&namePattern
, uint32_t flags
, TargetPatternBuilder targetBlock
= NULL
)
101 { addRule(new Rule(namePattern
, flags
| required
, targetBlock
)); mRequireCount
++; }
103 void allow(const std::string
&namePattern
, uint32_t flags
, std::string targetPattern
)
104 { allow(namePattern
, flags
, ^ string (const std::string
&name
, const std::string
&target
) { return targetPattern
; }); }
105 void require(const std::string
&namePattern
, uint32_t flags
, std::string targetPattern
)
106 { require(namePattern
, flags
, ^ string (const std::string
&name
, const std::string
&target
) { return targetPattern
; }); }
108 void validate(const std::string
&root
, OSStatus error
);
111 Rule
* match(const char *relpath
, uint32_t flags
, bool executable
, const char *target
= NULL
);
114 typedef std::vector
<Rule
*> Rules
;
120 } // end namespace CodeSigning
121 } // end namespace Security
123 #endif // !_H_DIRSCANNER