namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
-const std::string MDSCapMatch::MDS_AUTH_PATH_ROOT = "/";
-
template <typename Iterator>
struct MDSCapParser : qi::grammar<Iterator, MDSAuthCaps()>
{
qi::rule<Iterator, MDSAuthCaps()> mdscaps;
};
+void MDSCapMatch::normalize_path()
+{
+ // drop any leading /
+ while (path.length() && path[0] == '/') {
+ path = path.substr(1);
+ }
+
+ // drop dup //
+ // drop .
+ // drop ..
+}
+
bool MDSCapMatch::match(const std::string &target_path,
const int target_uid) const
{
if (i->match.match(inode_path, uid) &&
i->spec.allows(mask & (MAY_READ|MAY_EXECUTE), mask & MAY_WRITE)) {
// check unix permissions?
- if (i->match.uid != MDS_AUTH_UID_ANY) {
+ if (i->match.uid != MDSCapMatch::MDS_AUTH_UID_ANY) {
+ // use fcntl.h macros for the file mode:
+ // S_IRUSR S_IRGRP S_ROTH
+ // S_IWUSR S_IWGRP S_WOTH
+ // S_IXUSR S_IXGRP S_XOTH
// WRITE ME
ostream &operator<<(ostream &out, const MDSCapMatch &match)
{
- if (match.path != MDSCapMatch::MDS_AUTH_PATH_ROOT) {
- out << "path=\"" << match.path << "\"";
- }
- if (match.path != MDSCapMatch::MDS_AUTH_PATH_ROOT &&
- match.uid != MDSCapMatch::MDS_AUTH_UID_ANY) {
- out << " ";
+ if (match.path.length()) {
+ out << "path=\"/" << match.path << "\"";
+ if (match.uid != MDSCapMatch::MDS_AUTH_UID_ANY) {
+ out << " ";
+ }
}
if (match.uid != MDSCapMatch::MDS_AUTH_UID_ANY) {
out << "uid=" << match.uid;
// conditions before we are allowed to do it
struct MDSCapMatch {
static const int64_t MDS_AUTH_UID_ANY = -1;
- static const std::string MDS_AUTH_PATH_ROOT;
- int64_t uid; // Require UID to be equal to this, if !=MDS_AUTH_UID_ANY
+ int64_t uid; // Require UID to be equal to this, if !=MDS_AUTH_UID_ANY
std::vector<gid_t> gids; // Use these GIDs
- std::string path; // Require path to be child of this (may be "/" for any)
+ std::string path; // Require path to be child of this (may be "" or "/" for any)
- MDSCapMatch() : uid(MDS_AUTH_UID_ANY), path(MDS_AUTH_PATH_ROOT) {}
- MDSCapMatch(int64_t uid_, std::vector<gid_t>& gids_)
- : uid(uid_), gids(gids_), path(MDS_AUTH_PATH_ROOT) {}
- MDSCapMatch(std::string path_) : uid(MDS_AUTH_UID_ANY), path(path_) {}
+ MDSCapMatch() : uid(MDS_AUTH_UID_ANY) {}
+ MDSCapMatch(int64_t uid_, std::vector<gid_t>& gids_) : uid(uid_), gids(gids_) {}
+ MDSCapMatch(std::string path_)
+ : uid(MDS_AUTH_UID_ANY), path(path_) {
+ normalize_path();
+ }
MDSCapMatch(std::string path_, int64_t uid_, std::vector<gid_t>& gids_)
- : uid(uid_), gids(gids_), path(path_) {}
+ : uid(uid_), gids(gids_), path(path_) {
+ normalize_path();
+ }
+
+ void normalize_path();
bool is_match_all() const
{