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