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

unisecuregen.cc

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2002 Net Integration Technologies, Inc.
00004  * 
00005  * UniSecureGen is a UniConfGen for checking security on data 
00006  *
00007  */
00008 
00009 #include "unisecuregen.h"
00010 #include "wvmoniker.h"
00011 #include "wvstringlist.h"
00012 #include "wvtclstring.h"
00013 #include "wvlog.h"
00014 
00015 
00016 UniSecureGen::UniSecureGen(UniConfGen *_gen, UniPermGen *_perms) :
00017     UniFilterGen(_gen),
00018     perms(_perms)
00019 {
00020 }
00021 
00022 
00023 UniSecureGen::UniSecureGen(WvStringParm moniker, UniPermGen *_perms) :
00024     UniFilterGen(NULL)
00025 {
00026     UniConfGen *_gen = wvcreate<UniConfGen>(moniker);
00027     assert(_gen && "Moniker doesn't get us a generator!");
00028     setinner(_gen);
00029     perms = _perms;
00030 }
00031 
00032 
00033 void UniSecureGen::setcredentials(const UniPermGen::Credentials &_cred)
00034 {
00035     cred.user = _cred.user;
00036     cred.groups.zap();
00037     WvStringTable::Iter i(_cred.groups);
00038     for (i.rewind(); i.next(); )
00039         cred.groups.add(new WvString(*i), true);
00040 }
00041 
00042 
00043 void UniSecureGen::setcredentials(WvStringParm user, const WvStringList &groups)
00044 {
00045     cred.user = user;
00046     cred.groups.zap();
00047     WvStringList::Iter i(groups);
00048     for (i.rewind(); i.next(); )
00049         cred.groups.add(new WvString(*i), true);
00050 }
00051 
00052 
00053 WvString UniSecureGen::get(const UniConfKey &key)
00054 {
00055     if (findperm(key, UniPermGen::READ))
00056     {
00057         WvString val = UniFilterGen::get(key);
00058         return val;
00059     }
00060     return WvString::null;
00061 }
00062 
00063 
00064 bool UniSecureGen::exists(const UniConfKey &key)
00065 {
00066     if (findperm(key.removelast(), UniPermGen::EXEC))
00067         return UniFilterGen::exists(key);
00068     return false;
00069 }
00070 
00071 
00072 void UniSecureGen::set(const UniConfKey &key, WvStringParm value)
00073 {
00074     if (findperm(key, UniPermGen::WRITE))
00075         UniFilterGen::set(key, value);
00076 }
00077 
00078 
00079 bool UniSecureGen::haschildren(const UniConfKey &key)
00080 {
00081     if (findperm(key, UniPermGen::EXEC))
00082         return UniFilterGen::haschildren(key);
00083     return false;
00084 }
00085 
00086 
00087 UniConfGen::Iter *UniSecureGen::iterator(const UniConfKey &key)
00088 {
00089     if (findperm(key, UniPermGen::EXEC))
00090         return UniFilterGen::iterator(key);
00091     return new UniConfGen::NullIter();
00092 }
00093 
00094 
00095 void UniSecureGen::gencallback(const UniConfKey &key, WvStringParm value,
00096         void *userdata)
00097 {
00098     if (findperm(key, UniPermGen::READ))
00099         delta(key, value);
00100 }
00101 
00102 
00103 bool UniSecureGen::findperm(const UniConfKey &key, UniPermGen::Type type)
00104 {
00105     if (!drilldown(key))
00106         return false;
00107     else
00108         return perms->getperm(key, cred, type);
00109 }
00110 
00111 
00112 bool UniSecureGen::drilldown(const UniConfKey &key)
00113 {
00114     UniConfKey check;
00115     UniConfKey left = key;
00116 
00117     while (!left.isempty())
00118     {
00119         // check the exec perm
00120         if (!perms->getperm(check, cred, UniPermGen::EXEC))
00121             return false;
00122 
00123         // move the first segment of left to check
00124         // note that when left is empty, we exit the loop before checking the
00125         // last segment.  That's on purpose: the last segment is the 'file'
00126         // and we only need to check the 'directories'
00127         check.append(left.first());
00128         left = left.removefirst();
00129     }
00130     return true;
00131 }

Generated on Sat Mar 13 14:55:26 2004 for WvStreams by doxygen 1.3.6-20040222