8 #include "unipermgen.h" 10 #include "wvmoniker.h" 11 #include "wvstringlist.h" 14 #include "wvlinkerhack.h" 30 assert(gen &&
"Moniker doesn't get us a generator!");
37 inner()->set(
WvString(
"%s/owner", path), owner);
53 inner()->set(
WvString(
"%s/group", path), group);
66 void UniPermGen::setperm(
const UniConfKey &path, Level level,
69 inner()->set(
WvString(
"%s/%s-%s", path, level2str(level),
70 type2str(type)), val);
81 if (!!owner && cred.user == owner) level = USER;
82 else if (!!group && cred.groups[group]) level = GROUP;
85 bool perm = getoneperm(path, level, type);
96 bool UniPermGen::getoneperm(
const UniConfKey &path, Level level, Type type)
98 int val =
str2int(inner()->
get(
WvString(
"%s/%s-%s", path, level2str(level),
99 type2str(type))), -1);
107 case READ:
return false;
108 case WRITE:
return false;
109 case EXEC:
return false;
113 return getoneperm(path.
removelast(), level, type);
120 unsigned int user,
unsigned int group,
123 static const int r = 4;
124 static const int w = 2;
125 static const int x = 1;
127 setperm(path, USER, READ, (user & r));
128 setperm(path, USER, WRITE, (user & w));
129 setperm(path, USER, EXEC, (user & x));
131 setperm(path, GROUP, READ, (group & r));
132 setperm(path, GROUP, WRITE, (group & w));
133 setperm(path, GROUP, EXEC, (group & x));
135 setperm(path, WORLD, READ, (world & r));
136 setperm(path, WORLD, WRITE, (world & w));
137 setperm(path, WORLD, EXEC, (world & x));
143 unsigned int user = (mode & 0700) >> 6;
144 unsigned int group = (mode & 0070) >> 3;
145 unsigned int world = (mode & 0007);
147 chmod(path, user, group, world);
151 WvString UniPermGen::level2str(Level level)
155 case USER:
return "user";
156 case GROUP:
return "group";
157 case WORLD:
return "world";
159 assert(
false &&
"Something in the Level enum wasn't covered");
160 return WvString::null;
164 WvString UniPermGen::type2str(Type type)
168 case READ:
return "read";
169 case WRITE:
return "write";
170 case EXEC:
return "exec";
172 assert(
false &&
"Something in the Type enum wasn't covered");
173 return WvString::null;
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
bool isempty() const
Returns true if this path has zero segments (also known as root).
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Functions to handle "tcl-style" strings and lists.
An abstract data container that backs a UniConf tree.
void setowner(const UniConfKey &path, WvStringParm owner)
get and set the owner for a path
void setgroup(const UniConfKey &path, WvStringParm group)
get and set the group for a path
UniConfKey removelast(int n=1) const
Returns the path formed by removing the last n segments of this path.
virtual int str2int(WvStringParm s, int defvalue) const
Converts a string to an integer.
A UniConfGen that delegates all requests to an inner generator.
void chmod(const UniConfKey &path, unsigned int owner, unsigned int group, unsigned int world)
Set permissions for path using Unix style chmod (with the second form, be sure to use octal) ...
WvString is an implementation of a simple and efficient printable-string class.
UniPermGen wraps a tree encoding Unix-style permissions, and provides an API for setting and checking...