Commit 5c46316b authored by jan.koester's avatar jan.koester
Browse files

gpo add worked

parent 24135e8f
Loading
Loading
Loading
Loading
Loading
+50 −13
Changes for src/admin.cpp: 50 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -1658,17 +1658,6 @@ namespace authdb {
            rep.setContentType("text/html");
            rep.setContentLength(out.size());
            rep.send(curreq,out.c_str(),out.size());


            // char rurl[255];
            // snprintf(rurl,255,"/settings/%s/listgpos",cdid);
            //
            // libhttppp::HttpResponse rep;
            // rep.setState(HTTP303);
            // rep.setVersion(HTTPVERSION(1.1));
            // rep.setHeaderData("Location")->push_back(rurl);
            // rep.setContentType("text/html");
            // rep.send(curreq,nullptr,0);
        }

        void listGpos(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
@@ -1683,14 +1672,62 @@ namespace authdb {

            uuid_parse(cdid,did);

            libhtmlpp::HtmlElement root=_IndexElement;
            DomainBackend dbackend(_AdminBackend);

            AuthBackend *backend=nullptr;

            if(strcmp(cdid,"admin") == 0 ){
                backend=&_AdminBackend;
            }else if(uuid_parse(cdid,did) == 0 ){
                backend=dbackend.data(did);
            }else{
                throw AuthBackendError("createGroups: could not parse uuid!");
            }

            if(!backend)
                throw AuthBackendError("createGroups: no backend seleted!");

            libhtmlpp::HtmlElement root=_IndexElement,domel("ul");
            libhtmlpp::HtmlElement *content=root.getElementbyID("content");

            libhtmlpp::HtmlString list,out;

            size_t rd=sizeof(authdb::AuthHeader),end=backend->end();

            Gpo gpo;

            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(cur.type == PolicyData && strcmp(cur.fieldname,"gponame")==0){
                    class GpoData gdat(cur.uuid);
                    try {
                        size_t upos=sizeof(authdb::AuthHeader);
                        gpo.info(*backend,gdat,upos);

                        libhtmlpp::HtmlString gpoli;

                        char cruid[20];
                        uuid_unparse(cur.uuid,cruid);
                        gpoli << "<li> " << gdat.getName() << "</li>";
                        domel.appendChild(gpoli.parse());
                    }catch(AuthBackendError &e){
                        std::cerr << e.what() << std::endl;
                    }
                }
            }
            content->appendChild((libhtmlpp::Element*)&domel);

            list << "<div><ul class=\"gpotoolbar\" ><li><a class=\"button\" href=\"/settings/"<< cdid << "/creategpo\">Create Group Policy</a></li></ul></div>";

            content->insertChild(list.parse());
            content->appendChild(list.parse());

            libhtmlpp::print(&root,out,true);

+37 −2
Changes for src/gpo.cpp: 37 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ void authdb::GpoData::setAllowed(Allow *allowed){

        if(!_Allowed){
            while(curec){
                if(curec->Data->type == authdb::GroupData &&
                if(curec->Data->type == authdb::PolicyData &&
                    uuid_compare(curec->Data->uuid,Data->uuid)==0 &&
                    strcmp(curec->Data->fieldname,"gpoallowed")==0
                ){
@@ -212,7 +212,7 @@ void authdb::GpoData::setAllowed(Allow *allowed){
        _Allowed->type=DataType::PolicyData;
        _Allowed->storage=StorageType::BinaryStorage;

        snprintf(_Allowed->fieldname,255,"%s","groupmembers");
        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);
@@ -295,3 +295,38 @@ void authdb::Gpo::create(AuthBackend& backend, class GpoData* dat){
        backend.write((unsigned char*)curec->Data->data,curec->Data->datasize);
    }
}

void authdb::Gpo::info(AuthBackend &backend, class GpoData& dat, size_t &pos){
    size_t end=backend.end();

    if(uuid_is_null(dat.Data->uuid))
        throw AuthBackendError("gpo info gpoid required!");

    while(pos<end){
        authdb::AuthData::Record *cur=new AuthData::Record;
        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(!getRecord(backend,dat,DataType::PolicyData))
                continue;

            if(strcmp(dat.Data->fieldname,"gponame")==0){
                dat._Name=dat.Data;
            }else if(strcmp(dat.Data->fieldname,"desc")==0){
                dat._Desc=dat.Data;
            }else if(strcmp(dat.Data->fieldname,"gpoallowed")==0){
                dat._Allowed=dat.Data;
            }else if(strcmp(dat.Data->fieldname,"gpodefault")==0){
                dat._GpoDefault=dat.Data;
            }

            AuthData::Record *_Desc;
            AuthData::Record *_GpoDefault;
            AuthData::Record *_Allowed;
        }
        delete cur;
    }
}
+1 −0
Changes for src/gpo.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -67,5 +67,6 @@ namespace authdb {
    public:
        bool exits(AuthBackend &backend,uuid_t *gpid,const char *name, int &ret);
        void create(AuthBackend& backend, class GpoData* dat);
        void info(AuthBackend &backend, class GpoData& dat, size_t &pos);
    };
};