Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unipermgen.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 */ 00006 00007 #ifndef __UNIPERMGEN_H 00008 #define __UNIPERMGEN_H 00009 00010 #include "unifiltergen.h" 00011 #include "wvstringtable.h" 00012 00013 /** 00014 * UniPermGen wraps a tree encoding Unix-style permissions, and provides an 00015 * API for setting and checking them. read permission allows you to read the 00016 * value of a key, write allows you to set it (duh). exec allows you to get 00017 * subkeys. You cannot iterate on a key unless you have exec permission. 00018 * (This is badly named, but it's inherited from Unix.) 00019 * 00020 * Permissions for 'key' are stored in the subkeys key/owner, key/group, 00021 * and key/user-read through key/world-write. owner and group store arbitrary 00022 * text strings, and the remainder are boolean values. 00023 * 00024 * UniPermGen cannot be created with a moniker due to all the extra methods. 00025 * Instead, just create one with new and mount it with UniConf::mountgen. (Of 00026 * course, in most cases it will be passed to a UniSecureGen's constructor 00027 * anyway.) 00028 */ 00029 class UniPermGen : public UniFilterGen 00030 { 00031 00032 public: 00033 UniPermGen(UniConfGen *_gen); 00034 UniPermGen(WvStringParm moniker); 00035 00036 enum Level { USER = 0, GROUP, WORLD }; 00037 static WvString level2str(Level l); 00038 00039 enum Type { READ = 0, WRITE, EXEC }; 00040 static WvString type2str(Type t); 00041 00042 struct Credentials 00043 { 00044 WvString user; 00045 mutable WvStringTable groups; 00046 // mutable because stupid WvHashTable has no const lookup methods 00047 00048 Credentials() : groups(7) { } 00049 }; 00050 00051 /** get and set the owner for a path */ 00052 void setowner(const UniConfKey &path, WvStringParm owner); 00053 WvString getowner(const UniConfKey &path); 00054 00055 /** get and set the group for a path */ 00056 void setgroup(const UniConfKey &path, WvStringParm group); 00057 WvString getgroup(const UniConfKey &path); 00058 00059 /** 00060 * Return true if a user with the given credentials is allowed to 00061 * read/write/exec the given path. 00062 */ 00063 bool getread(const UniConfKey &path, const Credentials &cred) 00064 { return getperm(path, cred, READ); } 00065 bool getwrite(const UniConfKey &path, const Credentials &cred) 00066 { return getperm(path, cred, WRITE); } 00067 bool getexec(const UniConfKey &path, const Credentials &cred) 00068 { return getperm(path, cred, EXEC); } 00069 00070 bool getperm(const UniConfKey &path, const Credentials &cred, Type type); 00071 00072 void setread(const UniConfKey &path, Level level, bool read) 00073 { setperm(path, level, READ, read); } 00074 void setwrite(const UniConfKey &path, Level level, bool write) 00075 { setperm(path, level, WRITE, write); } 00076 void setexec(const UniConfKey &path, Level level, bool exec) 00077 { setperm(path, level, EXEC, exec); } 00078 00079 void setperm(const UniConfKey &path, Level level, Type type, bool val); 00080 00081 /** 00082 * Set permissions for path using Unix style chmod (with the second form, 00083 * be sure to use octal) 00084 */ 00085 void chmod(const UniConfKey &path, unsigned int owner, unsigned int group, 00086 unsigned int world); 00087 void chmod(const UniConfKey &path, unsigned int mode); 00088 00089 private: 00090 00091 bool getoneperm(const UniConfKey &path, Level level, Type type); 00092 }; 00093 00094 00095 #endif // __UNIPERMGEN_H

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7