00001
00002
00003
00004
00005 #ifndef DMLITE_CPP_UTILS_SECURITY_H_
00006 #define DMLITE_CPP_UTILS_SECURITY_H_
00007
00008 #include <stdint.h>
00009 #include <sys/stat.h>
00010 #include <string>
00011 #include <vector>
00012 #include "../authn.h"
00013 #include "../exceptions.h"
00014
00015 namespace dmlite {
00016
00017 static const std::string kGenericUser = "nouser";
00018
00019
00020 enum TokenResult {
00021 kTokenOK = 0,
00022 kTokenMalformed,
00023 kTokenInvalid,
00024 kTokenExpired,
00025 kTokenInvalidMode,
00026 kTokenInternalError
00027 };
00028
00029
00030 struct AclEntry {
00031
00032 static const uint8_t kUserObj = 1;
00033 static const uint8_t kUser = 2;
00034 static const uint8_t kGroupObj = 3;
00035 static const uint8_t kGroup = 4;
00036 static const uint8_t kMask = 5;
00037 static const uint8_t kOther = 6;
00038 static const uint8_t kDefault = 0x20;
00039
00040 uint8_t type;
00041 uint8_t perm;
00042 uint32_t id;
00043
00044
00045 bool operator == (const AclEntry&) const;
00046 bool operator != (const AclEntry&) const;
00047 bool operator < (const AclEntry&) const;
00048 bool operator > (const AclEntry&) const;
00049 };
00050
00051 struct Acl: public std::vector<AclEntry> {
00052 public:
00053 Acl() throw ();
00054
00055
00056 explicit Acl(const std::string&) throw ();
00057
00058
00059
00060
00061
00062
00063
00064 Acl(const Acl& parent, uid_t uid, gid_t gid, mode_t cmode, mode_t* fmode) throw ();
00065
00066
00067
00068 int has(uint8_t type) const throw ();
00069
00070 std::string serialize(void) const throw ();
00071 void validate (void) const ;
00072 };
00073
00074
00075
00076
00077
00078 bool hasGroup(const std::vector<GroupInfo>& groups, gid_t gid);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 int checkPermissions(const SecurityContext* context,
00089 const Acl& acl, const struct ::stat& stat,
00090 mode_t mode);
00091
00092
00093
00094
00095
00096 std::string voFromDn(const std::string& mapfile, const std::string& dn);
00097
00098
00099
00100
00101 std::string voFromRole(const std::string& role);
00102
00103
00104 std::string getCertificateSubject(const std::string& path);
00105
00106
00107
00108
00109
00110
00111
00112 std::string generateToken(const std::string& id, const std::string& pfn,
00113 const std::string& passwd, time_t lifetime,
00114 bool write = false);
00115
00116
00117
00118
00119
00120
00121
00122 TokenResult validateToken(const std::string& token, const std::string& id,
00123 const std::string& pfn, const std::string& passwd,
00124 bool write = false);
00125
00126 };
00127
00128 #endif // DMLITE_CPP_UTILS_SECURITY_H_