Commit 1f6bd2d5 authored by jan.koester's avatar jan.koester
Browse files

needs to be fixed

parent 4f0b58b0
Loading
Loading
Loading
Loading
Loading
+60 −71
Changes for src/admin.cpp: 60 added lines, 71 removed lines.
Original line number Diff line number Diff line
@@ -1585,8 +1585,8 @@ namespace authdb {
                                    else
                                        gpodat->setGpoValue(true);
                                }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){
                                    curformdat->Value.push_back('\0');
                                    if(uuid_parse(curformdat->Value.data(),allow.uid[i++])!=0)
                                    if(uuid_parse_range(curformdat->Value.data(),curformdat->Value.data()+curformdat->Value.size(),
                                        allow.uid[i++])!=0)
                                        throw AuthBackendError("wrong uid in gpolist!");
                                }
                            }
@@ -1646,7 +1646,7 @@ namespace authdb {
                        cur.data = new char[cur.datasize];
                        backend->read((unsigned char*)cur.data,cur.datasize);

                        char curcuid[255];;
                        char curcuid[255];
                        uuid_unparse(cur.uuid,curcuid);
                        form <<"<option value=\""<< curcuid<<"\">" << cur.data << "</option>";
                        delete[] cur.data;
@@ -1705,28 +1705,19 @@ namespace authdb {

            GPOForm.parse(curreq);

            Gpo gpo;

            class GpoData gpodat(gpid);

            size_t gppos=sizeof(authdb::AuthHeader);

            gpo.info(*backend,gpodat,gppos);

            GpoData::Allow allow;
            gpodat.getAlowed(&allow);

            if(GPOForm.getBoundary()){
                GpoData *gpodat=nullptr;
                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 &&
                                curdispo->getValue()!=nullptr){
                                if( strcmp(curdispo->getValue(),"gpoid")==0 ){
                                    uuid_t gpouuid;
                                    if(uuid_parse_range(curformdat->Value.data(),
                                        curformdat->Value.data()+curformdat->Value.size(),gpouuid)==0){
                                        gpodat = new GpoData(gpouuid);
                                        break;
                                    }
                                }
                            }

                        }
                };
                if(gpodat){
                GpoData::Allow allow;
                allow.count=0;

@@ -1739,9 +1730,15 @@ namespace authdb {
                            ++allow.count;
                        }
                    }

                }

                int ret;

                if(!gpo.exits(*backend,&gpid,nullptr,ret))
                    throw AuthBackendError("GPO doesn't extsts cannot edit !");



                allow.uid = new  uuid_t[allow.count];

                size_t i = 0;
@@ -1753,17 +1750,14 @@ namespace authdb {
                    ){
                        if( strcmp(curdispo->getKey(),"name")==0 &&
                            curdispo->getValue()!=nullptr){
                                if(strcmp(curdispo->getValue(),"gponame")==0 ){
                            if(strcmp(curdispo->getValue(),"gpodesc")==0 ){
                                curformdat->Value.push_back('\0');
                                    gpodat->setName(curformdat->Value.data());
                                }else if(strcmp(curdispo->getValue(),"gpodesc")==0 ){
                                    curformdat->Value.push_back('\0');
                                    gpodat->setDesc(curformdat->Value.data());
                                gpodat.setDesc(curformdat->Value.data());
                            }else if(strcmp(curdispo->getValue(),"gpodefaultvalue")==0 ){
                                if(strncmp(curformdat->Value.data(),"false",curformdat->Value.size())==0)
                                        gpodat->setGpoValue(false);
                                    gpodat.setGpoValue(false);
                                else
                                        gpodat->setGpoValue(true);
                                    gpodat.setGpoValue(true);
                            }else if(strcmp(curdispo->getValue(),"gpoingroup")==0 ){
                                curformdat->Value.push_back('\0');
                                if(uuid_parse(curformdat->Value.data(),allow.uid[i++])!=0)
@@ -1773,12 +1767,10 @@ namespace authdb {
                    }
                }

                    gpodat->setAllowed(&allow);

                    Gpo gpo;
                    gpo.create(*backend,gpodat);
                gpodat.setAllowed(&allow);
                gpo.remove(*backend,gpid);
                gpo.create(*backend,&gpodat);
                delete[] allow.uid;
                    delete gpodat;

                libhttppp::HttpResponse rep;
                rep.setState(HTTP307);
@@ -1790,50 +1782,31 @@ namespace authdb {
                rep.send(curreq,nullptr,0);
                return;
            }
            }

            libhtmlpp::HtmlPage page;

            libhtmlpp::HtmlString form,out;

            libhtmlpp::HtmlElement *formel=nullptr,groupel,ngroupel;

            size_t rd=sizeof(AuthHeader),end=backend->end();
            while(rd<end){
                authdb::AuthData::Record cur;

                cur.type=EmptyData;

                backend->setPos(rd);
                backend->read((unsigned char*)&cur,sizeof(AuthData::Record));

                rd=backend->getPos()+cur.datasize;
            libhtmlpp::HtmlElement *formel=nullptr,*groupel,*ngroupel;

                if( uuid_compare(cur.uuid ,gpid)==0 && cur.type == PolicyData && strcmp(cur.fieldname,"gponame")==0){
                    class GpoData gdat(cur.uuid);
                    try {
                        class Gpo gpo;
                        size_t upos=sizeof(authdb::AuthHeader);
                        gpo.info(*backend,gdat,upos);
                        form << "<table>"
                                << "<form method=\"post\" enctype=\"multipart/form-data\">"
            form << "<form method=\"post\" enctype=\"multipart/form-data\">"
                    << "<table>"
                    << "<tr><td><label for=\"gpoid\">Policy ID:</label></td>"
                    << "<td></td><td><input  type=\"text\" name=\"gpoid\" value=\"" << cgpid << "\" class=\"gpoform\" readonly></td></tr>"
                    << "<tr><td><label for=\"gponame\">Policy Name:</label></td>"
                                << "<td></td><td><input type=\"text\" name=\"gponame\"  class=\"gpoform\"  value=\"" << gdat.getName() <<"\" readonly></td></tr>"
                    << "<td></td><td><input type=\"text\" name=\"gponame\"  class=\"gpoform\"  value=\"" << gpodat.getName() <<"\" readonly></td></tr>"
                    << "<tr><td><label for=\"gpodesc\">Policy Description:</label></td>"
                                << "<td></td><td><input type=\"text\" name=\"gpodesc\"  class=\"gpoform\" value=\"" << gdat.getDesc() <<"\"></td></tr>"
                    << "<td></td><td><input type=\"text\" name=\"gpodesc\"  class=\"gpoform\" value=\"" << gpodat.getDesc() <<"\"></td></tr>"
                    << "<tr><td><label for=\"gpodefaultvalue\">Default Value:</label></td>"
                    << "<td></td><td><select name=\"gpodefaultvalue\" id=\"gpodefaultvalue\">";

                                if(gdat.getGpoValue())
            if(gpodat.getGpoValue())
                form << "<option value=\"false\">Permitted</option>"
                                            << "<option value=\"true\" default>Allowed</option>";
                        << "<option value=\"true\" selected=\"selected\">Allowed</option>";
            else
                                    form << "<option value=\"false\" default>Permitted</option>"
                                            << "<option value=\"true\">Allowed</option>";

                       form  << "</select></td></tr>"
                form << "<option value=\"false\" selected=\"selected\">Permitted</option>";
            form << "<option value=\"true\">Allowed</option>"
                    << "</select></td></tr>"
                    << "<tr><td><select id=\"notingroup\" class=\"selectionlist\" multiple>"
                    << "</select></td><td class=\"switchgpogroup\">"
                    << "<p><a class=\"button\" onclick=\"moveElement('notingroup','gpoingroup')\">&rarr;</a>"
@@ -1841,14 +1814,28 @@ namespace authdb {
                    << "<td><select name=\"gpoingroup\" id=\"gpoingroup\" class=\"selectionlist\" multiple>"
                    << "</select></td></tr>"
                    << "<tr><td></td><td></td><td><input type=\"submit\" value=\"Save\"></td></tr>"
                                << "</form>"
                                << "</table>";
                    << "</table>"
                    << "</form>";

            formel=(libhtmlpp::HtmlElement*)form.parse();

            ngroupel=formel->getElementbyID("notingroup");
            groupel=formel->getElementbyID("gpoingroup");

            size_t rd=sizeof(AuthHeader),end=backend->end();
            while(rd<end){
                authdb::AuthData::Record cur;

                cur.type=EmptyData;

                backend->setPos(rd);
                backend->read((unsigned char*)&cur,sizeof(AuthData::Record));

                rd=backend->getPos()+cur.datasize;

                if( uuid_compare(cur.uuid ,gpid)==0 && cur.type == PolicyData && strcmp(cur.fieldname,"gponame")==0){
                    try {


                        size_t urd=sizeof(AuthHeader),uend=backend->end();
                        while(urd<uend){
@@ -1859,8 +1846,6 @@ namespace authdb {
                            if(cur.type == GroupData && strcmp(cur.fieldname,"groupname")==0){
                                cur.data = new char[cur.datasize];
                                backend->read((unsigned char*)cur.data,cur.datasize);
                                        GpoData::Allow allow;
                                        gdat.getAlowed(&allow);

                                char curcuid[255];;
                                uuid_unparse(cur.uuid,curcuid);
@@ -1875,14 +1860,18 @@ namespace authdb {

                                bool found=false;
                                for(size_t i = 0; i < allow.count; ++i){
                                    char auid[255];;
                                    uuid_unparse(allow.uid[i],auid);

                                    if( uuid_compare(cur.uuid,allow.uid[i])==0 ){
                                        found=true;
                                                    groupel.appendChild(&opt);
                                        groupel->appendChild(&opt);
                                        break;
                                    }
                                }

                                if(!found)
                                            ngroupel.appendChild(&opt);
                                    ngroupel->appendChild(&opt);
                                delete[] cur.data;
                            }
                        }
+6 −5
Changes for src/gpo.cpp: 6 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -219,11 +219,12 @@ void authdb::GpoData::setAllowed(Allow *allowed){
        uuid_copy(_Allowed->uuid,fuuid);
        _Allowed->type=DataType::PolicyData;
        _Allowed->storage=StorageType::BinaryStorage;

        snprintf(_Allowed->fieldname,255,"%s","gpoallowed");

        _Allowed->datasize = sizeof(GpoData::Allow)+(sizeof(uuid_t)*allowed->count);
        _Allowed->data=new char [_Allowed->datasize];
        memset(_Allowed->data,0,_Allowed->datasize);
        memcpy(_Allowed->data,allowed,sizeof(*allowed));
        char *start =_Allowed->data+sizeof(GpoData::Allow);
        for(int i=0; i< allowed->count; ++i){
            memcpy(start+(i*sizeof(uuid_t)),&allowed->uid[i],sizeof(uuid_t));
@@ -234,15 +235,16 @@ void authdb::GpoData::getAlowed(Allow *allowed){
    if(!_Allowed){
        for(const AuthData *curdat=this; curdat; curdat=curdat->next()){
            if(
                curdat->Data && curdat->Data->storage &&
                curdat->Data && curdat->Data->storage==StorageType::BinaryStorage &&
                curdat->Data->type==DataType::PolicyData &&
                strcmp(curdat->Data->fieldname,"gpoallowed") ==0
            ){
                _Allowed=curdat->Data;
                allowed->count =((Allow*)_Allowed->data)->count;
                allowed->uid = new uuid_t[allowed->count];
                char *start =_Allowed->data+sizeof(GpoData::Allow);
                for(size_t i=0; i<allowed->count; ++i){
                    memcpy(allowed->uid[i],_Allowed+(i*sizeof(uuid_t)),sizeof(uuid_t));
                    memcpy(allowed->uid[i],start+(i*sizeof(uuid_t)),sizeof(uuid_t));
                }
                return;
            }
@@ -338,8 +340,7 @@ void authdb::Gpo::info(AuthBackend &backend, class GpoData& dat, size_t &pos){
        backend.setPos(pos);
        backend.read((unsigned char*)cur,sizeof(AuthData::Record));
        pos=backend.getPos()+cur->datasize;
        if(cur->type == PolicyData && uuid_compare(dat.Data->uuid,cur->uuid) == 0
        ){
        if(cur->type == PolicyData && uuid_compare(dat.Data->uuid,cur->uuid) == 0){

            if(!getRecord(backend,dat,DataType::PolicyData))
                continue;