2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
9 #include "unifiltergen.h"
10 #include "wvstringtable.h"
13 * UniPermGen wraps a tree encoding Unix-style permissions, and provides an
14 * API for setting and checking them. read permission allows you to read the
15 * value of a key, write allows you to set it (duh). exec allows you to get
16 * subkeys. You cannot iterate on a key unless you have exec permission.
17 * (This is badly named, but it's inherited from Unix.)
19 * Permissions for 'key' are stored in the subkeys key/owner, key/group,
20 * and key/user-read through key/world-write. owner and group store arbitrary
21 * text strings, and the remainder are boolean values.
23 * If you want to use monikers, UniPermGen can only be via UniSecureGen (see
24 * unisecuregen.h) since it provides its own API beyond just UniConfGen.
26 class UniPermGen
: public UniFilterGen
29 UniPermGen(IUniConfGen
*_gen
);
30 UniPermGen(WvStringParm moniker
);
32 enum Level
{ USER
= 0, GROUP
, WORLD
};
33 static WvString
level2str(Level l
);
35 enum Type
{ READ
= 0, WRITE
, EXEC
};
36 static WvString
type2str(Type t
);
41 mutable WvStringTable groups
;
42 // mutable because stupid WvHashTable has no const lookup methods
44 Credentials() : groups(7) { }
47 /** get and set the owner for a path */
48 void setowner(const UniConfKey
&path
, WvStringParm owner
);
49 WvString
getowner(const UniConfKey
&path
);
51 /** get and set the group for a path */
52 void setgroup(const UniConfKey
&path
, WvStringParm group
);
53 WvString
getgroup(const UniConfKey
&path
);
56 * Return true if a user with the given credentials is allowed to
57 * read/write/exec the given path.
59 bool getread(const UniConfKey
&path
, const Credentials
&cred
)
60 { return getperm(path
, cred
, READ
); }
61 bool getwrite(const UniConfKey
&path
, const Credentials
&cred
)
62 { return getperm(path
, cred
, WRITE
); }
63 bool getexec(const UniConfKey
&path
, const Credentials
&cred
)
64 { return getperm(path
, cred
, EXEC
); }
66 bool getperm(const UniConfKey
&path
, const Credentials
&cred
, Type type
);
68 void setread(const UniConfKey
&path
, Level level
, bool read
)
69 { setperm(path
, level
, READ
, read
); }
70 void setwrite(const UniConfKey
&path
, Level level
, bool write
)
71 { setperm(path
, level
, WRITE
, write
); }
72 void setexec(const UniConfKey
&path
, Level level
, bool exec
)
73 { setperm(path
, level
, EXEC
, exec
); }
75 void setperm(const UniConfKey
&path
, Level level
, Type type
, bool val
);
78 * Set permissions for path using Unix style chmod (with the second form,
79 * be sure to use octal)
81 void chmod(const UniConfKey
&path
, unsigned int owner
, unsigned int group
,
83 void chmod(const UniConfKey
&path
, unsigned int mode
);
85 virtual void flush_buffers() { }
88 bool getoneperm(const UniConfKey
&path
, Level level
, Type type
);
92 #endif // __UNIPERMGEN_H