Loading src/admin.cpp +10 −38 Changes for src/admin.cpp: 10 added lines, 38 removed lines. Original line number Diff line number Diff line Loading @@ -1540,23 +1540,7 @@ namespace authdb { } }; if(gpodat){ GpoData::Allow allow; allow.count=0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if( strcmp(curdispo->getKey(),"name")==0 && strcmp(curdispo->getValue(),"gpoingroup")==0 ){ ++allow.count; } } } allow.uid = new uuid_t[allow.count]; std::vector<uuid> allow; size_t i = 0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); Loading @@ -1578,9 +1562,10 @@ namespace authdb { else gpodat->setGpoValue(true); }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){ if(uuid_parse_range(curformdat->Value.data(),curformdat->Value.data()+curformdat->Value.size(), allow.uid[i++])!=0) uuid gal; if(uuid_parse_range(curformdat->Value.data(),curformdat->Value.data()+curformdat->Value.size(),gal.value)!=0) throw AuthBackendError("wrong uid in gpolist!"); allow.emplace_back(gal); } } } Loading Loading @@ -1708,27 +1693,12 @@ namespace authdb { size_t gppos=sizeof(authdb::AuthHeader); gpo.info(*backend,gpodat,gppos); GpoData::Allow allow; std::vector<uuid> allow; if(GPOForm.getBoundary()){ gpo.remove(*backend,gpid); allow.count=0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if( strcmp(curdispo->getKey(),"name")==0 && strcmp(curdispo->getValue(),"gpoingroup")==0 ){ ++allow.count; } } } allow.uid = new uuid_t[allow.count]; size_t i = 0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); Loading @@ -1747,10 +1717,12 @@ namespace authdb { else gpodat.setGpoValue(true); }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){ uuid gal; if(uuid_parse_range(curformdat->Value.data(), curformdat->Value.data()+curformdat->Value.size(), allow.uid[i++])!=0) gal.value)!=0) throw AuthBackendError("wrong uid in gpolist!"); allow.emplace_back(gal); } } } Loading Loading @@ -1839,8 +1811,8 @@ namespace authdb { opt.insertChild(&optname); bool found=false; for(size_t i = 0; i < allow.count; ++i){ if( uuid_compare(cur->uuid,allow.uid[i])==0 ){ for(const uuid &al : allow ){ if( al==cur->uuid ){ found=true; groupel->appendChild(&opt); break; Loading src/authdb.cpp +3 −7 Changes for src/authdb.cpp: 3 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -140,10 +140,8 @@ namespace authdb { group.create(_AdminBackend,&gdat); class Gpo gpo; GpoData::Allow gallow; gallow.uid=new uuid_t[1]; uuid_copy(gallow.uid[0],admingid); gallow.count=1; std::vector<uuid> gallow; gallow.emplace_back(admingid); size_t i=0; try { while(gpo_default[i][0]){ Loading @@ -162,8 +160,6 @@ namespace authdb { std::cerr << e.what() << std::endl; } delete[] gallow.uid; libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; Loading @@ -188,7 +184,7 @@ namespace authdb { } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ // AuthBackendLock admlock(_AdminBackend); AuthBackendLock admlock(_AdminBackend); if(curreq->getRequestURL().compare(0,10,"/authdb.js",10)==0){ libhttppp::HttpResponse rep; rep.setState(HTTP200); Loading src/gpo.cpp +16 −34 Changes for src/gpo.cpp: 16 added lines, 34 removed lines. Original line number Diff line number Diff line Loading @@ -58,37 +58,37 @@ bool authdb::GpoData::getGpoValue(){ this,&_GpoDefault,"gpodefault"); } void authdb::GpoData::setAllowed(Allow &allowed){ size_t uidsize=(sizeof(uuid_t)*allowed.count); char *data=new char[uidsize+sizeof(size_t)]; memset(data,0,uidsize+sizeof(size_t)); std::copy(&allowed.count,&allowed.count+sizeof(size_t),data); for(size_t i=0; i<allowed.count; ++i){ void authdb::GpoData::setAllowed(std::vector<uuid> &allowed){ char *data=new char[allowed.size()]; memset(data,0,allowed.size()); size_t asize=allowed.size(); std::copy(&asize,&asize+sizeof(size_t),data); size_t num=0; for(uuid allow : allowed){ std::copy( reinterpret_cast<char*>(&allowed.uid[i]), reinterpret_cast<char*>(&allowed.uid[i])+sizeof(uuid_t), data+((sizeof(uuid_t)*i)+sizeof(size_t)) reinterpret_cast<const char*>(&allow), reinterpret_cast<const char*>(&allow+sizeof(uuid)), data+((sizeof(uuid)*num++)+sizeof(size_t)) ); } setAuthData<const char>(DataType::PolicyData,StorageType::BinaryStorage,this,&_Allowed,"gpoallowed",data,uidsize+sizeof(size_t)); setAuthData<const char>(DataType::PolicyData,StorageType::BinaryStorage,this,&_Allowed,"gpoallowed",data,asize); delete[] data; } void authdb::GpoData::getAlowed(Allow &allowed){ void authdb::GpoData::getAlowed(std::vector<uuid> &allowed){ try{ getAuthData<char>(DataType::PolicyData,StorageType::BinaryStorage, this,&_Allowed,"gpoallowed"); }catch(...){ return; } size_t asize=0; std::copy(_Allowed->data,_Allowed->data+sizeof(size_t),&asize); std::copy(_Allowed->data,_Allowed->data+sizeof(size_t),&allowed.count); allowed.uid=new uuid_t[allowed.count]; uuid_t *start = reinterpret_cast<uuid_t*>(_Allowed->data+sizeof(size_t)); for(size_t i =0; i<allowed.count; ++i){ uuid_copy(allowed.uid[i],*start+(i*sizeof(uuid_t))); for(size_t i =sizeof(size_t); i<asize; i+=sizeof(uuid)){ allowed.emplace_back(_Allowed->data+i); } } Loading @@ -112,24 +112,6 @@ authdb::GpoData::GpoData(const GpoData& src) : AuthData(src){ authdb::GpoData::~GpoData(){ } authdb::GpoData::Allow::Allow(){ count=0; uid=nullptr; } authdb::GpoData::Allow::Allow(const char* src, size_t srclen) : Allow(){ std::copy(src,src+sizeof(size_t),&count); uid=new uuid_t[count]; size_t ipos=0; for(size_t i =sizeof(size_t); i<srclen; i+=sizeof(uuid_t)){ std::copy(src+i,src+(i+sizeof(uuid_t)),uid[ipos++]); } } authdb::GpoData::Allow::~Allow(){ } bool authdb::Gpo::exits(AuthBackend& backend, uuid gpid, const char* name, int& ret){ std::shared_ptr<authdb::AuthData::Record> cur=std::make_shared<AuthData::Record>(); Loading src/gpo.h +3 −9 Changes for src/gpo.h: 3 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <vector> #include <uuid/uuid.h> #include "authdb.h" Loading @@ -49,16 +50,9 @@ namespace authdb { void setGpoValue(const bool dest); bool getGpoValue(); struct Allow { Allow(); Allow(const char *src,size_t srclen); ~Allow(); size_t count; uuid_t *uid; }; public: void setAllowed(Allow &allowed); void getAlowed(Allow &allowed); void setAllowed(std::vector<uuid> &allowed); void getAlowed(std::vector<uuid> &allowed); private: AuthData::Record* _Name; AuthData::Record* _Desc; Loading src/session.cpp +7 −7 Changes for src/session.cpp: 7 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,10 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid SessionData::GPOResult *gpores=&_lastData->_GPOResult; Gpo gpo; std::shared_ptr<class GpoData> gpodat=std::make_shared<class GpoData>(cur->uuid); std::vector<uuid> allow; rd=sizeof(authdb::AuthHeader); while(rd<end){ Loading @@ -246,8 +250,6 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid rd=backend.getPos()+cur->datasize; if(cur->type == PolicyData && strcmp(cur->fieldname,"gponame")==0){ Gpo gpo; std::shared_ptr<class GpoData> gpodat=std::make_shared<class GpoData>(cur->uuid); size_t upos=sizeof(authdb::AuthHeader); gpo.info(backend,*gpodat,upos); if(!gpores->GPOId.empty()){ Loading @@ -257,17 +259,15 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid gpores->GPOId=cur->uuid; gpores->GPORes=gpodat->getGpoValue(); GpoData::Allow allow; gpodat->getAlowed(allow); for(size_t i =0; i< allow.count; ++i){ for(const uuid &al : allow){ for(uuid member : _lastData->_members){ if(member==allow.uid[i]){ if(member==al){ gpores->GPORes=gpodat->getGpoValue() ? false : true; } } } delete[] allow.uid; } } return _lastData; Loading Loading
src/admin.cpp +10 −38 Changes for src/admin.cpp: 10 added lines, 38 removed lines. Original line number Diff line number Diff line Loading @@ -1540,23 +1540,7 @@ namespace authdb { } }; if(gpodat){ GpoData::Allow allow; allow.count=0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if( strcmp(curdispo->getKey(),"name")==0 && strcmp(curdispo->getValue(),"gpoingroup")==0 ){ ++allow.count; } } } allow.uid = new uuid_t[allow.count]; std::vector<uuid> allow; size_t i = 0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); Loading @@ -1578,9 +1562,10 @@ namespace authdb { else gpodat->setGpoValue(true); }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){ if(uuid_parse_range(curformdat->Value.data(),curformdat->Value.data()+curformdat->Value.size(), allow.uid[i++])!=0) uuid gal; if(uuid_parse_range(curformdat->Value.data(),curformdat->Value.data()+curformdat->Value.size(),gal.value)!=0) throw AuthBackendError("wrong uid in gpolist!"); allow.emplace_back(gal); } } } Loading Loading @@ -1708,27 +1693,12 @@ namespace authdb { size_t gppos=sizeof(authdb::AuthHeader); gpo.info(*backend,gpodat,gppos); GpoData::Allow allow; std::vector<uuid> allow; if(GPOForm.getBoundary()){ gpo.remove(*backend,gpid); allow.count=0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if( strcmp(curdispo->getKey(),"name")==0 && strcmp(curdispo->getValue(),"gpoingroup")==0 ){ ++allow.count; } } } allow.uid = new uuid_t[allow.count]; size_t i = 0; for (libhttppp::HttpForm::MultipartForm::Data* curformdat = GPOForm.MultipartFormData.getFormData(); Loading @@ -1747,10 +1717,12 @@ namespace authdb { else gpodat.setGpoValue(true); }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){ uuid gal; if(uuid_parse_range(curformdat->Value.data(), curformdat->Value.data()+curformdat->Value.size(), allow.uid[i++])!=0) gal.value)!=0) throw AuthBackendError("wrong uid in gpolist!"); allow.emplace_back(gal); } } } Loading Loading @@ -1839,8 +1811,8 @@ namespace authdb { opt.insertChild(&optname); bool found=false; for(size_t i = 0; i < allow.count; ++i){ if( uuid_compare(cur->uuid,allow.uid[i])==0 ){ for(const uuid &al : allow ){ if( al==cur->uuid ){ found=true; groupel->appendChild(&opt); break; Loading
src/authdb.cpp +3 −7 Changes for src/authdb.cpp: 3 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -140,10 +140,8 @@ namespace authdb { group.create(_AdminBackend,&gdat); class Gpo gpo; GpoData::Allow gallow; gallow.uid=new uuid_t[1]; uuid_copy(gallow.uid[0],admingid); gallow.count=1; std::vector<uuid> gallow; gallow.emplace_back(admingid); size_t i=0; try { while(gpo_default[i][0]){ Loading @@ -162,8 +160,6 @@ namespace authdb { std::cerr << e.what() << std::endl; } delete[] gallow.uid; libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; Loading @@ -188,7 +184,7 @@ namespace authdb { } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ // AuthBackendLock admlock(_AdminBackend); AuthBackendLock admlock(_AdminBackend); if(curreq->getRequestURL().compare(0,10,"/authdb.js",10)==0){ libhttppp::HttpResponse rep; rep.setState(HTTP200); Loading
src/gpo.cpp +16 −34 Changes for src/gpo.cpp: 16 added lines, 34 removed lines. Original line number Diff line number Diff line Loading @@ -58,37 +58,37 @@ bool authdb::GpoData::getGpoValue(){ this,&_GpoDefault,"gpodefault"); } void authdb::GpoData::setAllowed(Allow &allowed){ size_t uidsize=(sizeof(uuid_t)*allowed.count); char *data=new char[uidsize+sizeof(size_t)]; memset(data,0,uidsize+sizeof(size_t)); std::copy(&allowed.count,&allowed.count+sizeof(size_t),data); for(size_t i=0; i<allowed.count; ++i){ void authdb::GpoData::setAllowed(std::vector<uuid> &allowed){ char *data=new char[allowed.size()]; memset(data,0,allowed.size()); size_t asize=allowed.size(); std::copy(&asize,&asize+sizeof(size_t),data); size_t num=0; for(uuid allow : allowed){ std::copy( reinterpret_cast<char*>(&allowed.uid[i]), reinterpret_cast<char*>(&allowed.uid[i])+sizeof(uuid_t), data+((sizeof(uuid_t)*i)+sizeof(size_t)) reinterpret_cast<const char*>(&allow), reinterpret_cast<const char*>(&allow+sizeof(uuid)), data+((sizeof(uuid)*num++)+sizeof(size_t)) ); } setAuthData<const char>(DataType::PolicyData,StorageType::BinaryStorage,this,&_Allowed,"gpoallowed",data,uidsize+sizeof(size_t)); setAuthData<const char>(DataType::PolicyData,StorageType::BinaryStorage,this,&_Allowed,"gpoallowed",data,asize); delete[] data; } void authdb::GpoData::getAlowed(Allow &allowed){ void authdb::GpoData::getAlowed(std::vector<uuid> &allowed){ try{ getAuthData<char>(DataType::PolicyData,StorageType::BinaryStorage, this,&_Allowed,"gpoallowed"); }catch(...){ return; } size_t asize=0; std::copy(_Allowed->data,_Allowed->data+sizeof(size_t),&asize); std::copy(_Allowed->data,_Allowed->data+sizeof(size_t),&allowed.count); allowed.uid=new uuid_t[allowed.count]; uuid_t *start = reinterpret_cast<uuid_t*>(_Allowed->data+sizeof(size_t)); for(size_t i =0; i<allowed.count; ++i){ uuid_copy(allowed.uid[i],*start+(i*sizeof(uuid_t))); for(size_t i =sizeof(size_t); i<asize; i+=sizeof(uuid)){ allowed.emplace_back(_Allowed->data+i); } } Loading @@ -112,24 +112,6 @@ authdb::GpoData::GpoData(const GpoData& src) : AuthData(src){ authdb::GpoData::~GpoData(){ } authdb::GpoData::Allow::Allow(){ count=0; uid=nullptr; } authdb::GpoData::Allow::Allow(const char* src, size_t srclen) : Allow(){ std::copy(src,src+sizeof(size_t),&count); uid=new uuid_t[count]; size_t ipos=0; for(size_t i =sizeof(size_t); i<srclen; i+=sizeof(uuid_t)){ std::copy(src+i,src+(i+sizeof(uuid_t)),uid[ipos++]); } } authdb::GpoData::Allow::~Allow(){ } bool authdb::Gpo::exits(AuthBackend& backend, uuid gpid, const char* name, int& ret){ std::shared_ptr<authdb::AuthData::Record> cur=std::make_shared<AuthData::Record>(); Loading
src/gpo.h +3 −9 Changes for src/gpo.h: 3 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <vector> #include <uuid/uuid.h> #include "authdb.h" Loading @@ -49,16 +50,9 @@ namespace authdb { void setGpoValue(const bool dest); bool getGpoValue(); struct Allow { Allow(); Allow(const char *src,size_t srclen); ~Allow(); size_t count; uuid_t *uid; }; public: void setAllowed(Allow &allowed); void getAlowed(Allow &allowed); void setAllowed(std::vector<uuid> &allowed); void getAlowed(std::vector<uuid> &allowed); private: AuthData::Record* _Name; AuthData::Record* _Desc; Loading
src/session.cpp +7 −7 Changes for src/session.cpp: 7 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,10 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid SessionData::GPOResult *gpores=&_lastData->_GPOResult; Gpo gpo; std::shared_ptr<class GpoData> gpodat=std::make_shared<class GpoData>(cur->uuid); std::vector<uuid> allow; rd=sizeof(authdb::AuthHeader); while(rd<end){ Loading @@ -246,8 +250,6 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid rd=backend.getPos()+cur->datasize; if(cur->type == PolicyData && strcmp(cur->fieldname,"gponame")==0){ Gpo gpo; std::shared_ptr<class GpoData> gpodat=std::make_shared<class GpoData>(cur->uuid); size_t upos=sizeof(authdb::AuthHeader); gpo.info(backend,*gpodat,upos); if(!gpores->GPOId.empty()){ Loading @@ -257,17 +259,15 @@ const authdb::SessionData *authdb::Session::addSession(AuthBackend &backend,uuid gpores->GPOId=cur->uuid; gpores->GPORes=gpodat->getGpoValue(); GpoData::Allow allow; gpodat->getAlowed(allow); for(size_t i =0; i< allow.count; ++i){ for(const uuid &al : allow){ for(uuid member : _lastData->_members){ if(member==allow.uid[i]){ if(member==al){ gpores->GPORes=gpodat->getGpoValue() ? false : true; } } } delete[] allow.uid; } } return _lastData; Loading