5 #ifndef CVMFS_UID_MAP_H_
6 #define CVMFS_UID_MAP_H_
50 typedef typename std::map<key_type, value_type> map_type;
54 : valid_(true), has_default_value_(false), default_value_(T(0)) { }
61 void Set(
const T k,
const T v) { map_[k] = v; }
68 void SetDefault(
const T v) {
69 has_default_value_ =
true;
82 bool Read(
const std::string &path) {
83 valid_ = ReadFromFile(path);
92 bool Contains(
const T k)
const {
94 return map_.find(k) != map_.end();
102 T Map(
const T k)
const {
104 const typename map_type::const_iterator i = map_.find(k);
105 if (i != map_.end()) {
109 return (HasDefault()) ? default_value_ : k;
112 bool HasEffect()
const {
return (map_.size() != 0) || has_default_value_; }
114 bool IsEmpty()
const {
return map_.size() == 0; }
115 bool IsValid()
const {
return valid_; }
116 bool HasDefault()
const {
return has_default_value_; }
117 size_t RuleCount()
const {
return map_.size(); }
119 T GetDefault()
const {
120 assert(has_default_value_);
121 return default_value_;
123 const map_type &GetRuleMap()
const {
return map_; }
126 bool ReadFromFile(
const std::string &path) {
127 FILE *fmap = fopen(path.c_str(),
"r");
130 path.c_str(), errno);
137 unsigned int line_number = 0;
141 if (line.empty() || line[0] ==
'#') {
145 std::vector<std::string> components =
SplitString(line,
' ');
146 FilterEmptyStrings(&components);
147 if (components.size() != 2 || !int_sanitizer.
IsValid(components[1])
148 || (components[0] !=
"*" && !int_sanitizer.
IsValid(components[0]))) {
151 line_number, path.c_str());
156 if (components[0] ==
"*") {
169 void FilterEmptyStrings(std::vector<std::string> *vec)
const {
170 std::vector<std::string>::iterator i = vec->begin();
171 for (; i != vec->end();) {
172 i = (i->empty()) ? vec->erase(i) : i + 1;
180 bool has_default_value_;
184 typedef IntegerMap<uid_t> UidMap;
185 typedef IntegerMap<gid_t> GidMap;
187 #endif // CVMFS_UID_MAP_H_
string Trim(const string &raw, bool trim_newline)
static void Read(void *buf, size_t nbyte)
assert((mem||(size==0))&&"Out Of Memory")
bool GetLineFile(FILE *f, std::string *line)
vector< string > SplitString(const string &str, char delim)
uint64_t String2Uint64(const string &value)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)