1 ///
2 /// Access control for objects.
3 ///	@file		ownership.h - pianod
4 ///	@author		Perette Barella
5 ///	@date		2014-12-28
6 ///	@copyright	Copyright (c) 2014-2016 Devious Fish. All rights reserved.
7 ///
8 
9 #ifndef __pianod__ownership__
10 #define __pianod__ownership__
11 
12 #include <config.h>
13 
14 #include "fundamentals.h"
15 #include "lookup.h"
16 
17 /// Ownership where privilege is defined within the object.
18 class PrimaryOwnership : public Ownership {
19 private:
20     Type access = Type::DISOWNED;
21     User *owner = nullptr;
22 public:
23     PrimaryOwnership (void);
24     PrimaryOwnership (Type rule, User *owner = nullptr);
25     ~PrimaryOwnership (void);
26     void abandon (void);
27     void abandon (const User *user);
getOwner(void)28     User *getOwner (void) const { return owner; };
isOwned(void)29     inline bool isOwned (void) const { return owner != nullptr; };
30     const std::string &ownerName (void) const;
31     virtual bool isOwnedBy (const User *user) const override;
32     virtual bool hasPermission (const User *user, Action action) const override;
33 };
34 
35 
36 /// Ownership where privilege is regulated by some parent object.
37 class SubordinateOwnership : public Ownership {
38 protected:
39     virtual Ownership *parentOwner (void) const = 0;
40 public:
41     virtual bool isOwnedBy (const User *user) const override;
42     virtual bool hasPermission (const User *user, Action action) const override;
43 };
44 
45 
46 typedef const LookupTable<Ownership::Type> OwnershipLookup;
47 extern OwnershipLookup OWNERSHIP;
48 
49 
50 #endif // defined(__pianod__ownership__)
51