Commit 78bc45ef authored by jan.koester's avatar jan.koester
Browse files

basic work gpo

parent efc73993
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for src/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ list(APPEND authdbSrcs
    domain.cpp
    group.cpp
    session.cpp
    gpo.cpp
    hash.cpp
    hash/sha512.cpp
)
+39 −0
Changes for src/admin.cpp: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1459,6 +1459,43 @@ namespace authdb {
            rep.send(curreq,nullptr,0);
        }

        void reloadSession(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            char csid[255],cdid[255];
            uuid_t sid,did;

            uuid_clear(sid);

            if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/reloadsession/%s",cdid,csid)<0){
                throw AuthBackendError("removeSession: wrong url!");
            }

            uuid_parse(csid,sid);
            uuid_parse(cdid,did);

            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("login: could not parse uuid!");
            }

            _Session.relSession(*backend,sid);

            char rurl[255];
            snprintf(rurl,255,"/settings/%s/listsessions",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 login(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            libhttppp::HttpForm form;

@@ -1662,6 +1699,8 @@ namespace authdb {
                listSessions(curreq,tid,args);
            }else if(strncmp("removesession",url,13)==0){
                removeSession(curreq,tid,args);
            }else if(strncmp("reloadsession",url,13)==0){
                reloadSession(curreq,tid,args);
            }else{
URLNOTFOUND:
                uuid_t did;
+128 −0
Changes for src/gpo.cpp: 128 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2025, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <cstring>

#include "types.h"
#include "gpo.h"

namespace authdb {
        inline void setGpoData(AuthData *dat,AuthData::Record **varclass,const char *varname,const char *value){
        AuthData::Record *target=*varclass;

        AuthData *curec=dat;

        uuid_t gid;
        uuid_copy(gid,dat->Data->uuid);

        if(!target){
            while(curec){
                if(curec->Data->type == authdb::PolicyData &&
                    uuid_compare(curec->Data->uuid,target->uuid)==0 &&
                    strcmp(curec->Data->fieldname,varname)==0
                ){

                    target=curec->Data;
                    target->datasize=0;
                    delete[] target->data;
                    target->data=nullptr;
                    break;
                }
                curec=curec->next();
            }
        }

        if(!target){
            target=new AuthData::Record;
            *varclass=dat->append(*target)->Data;
            target=*varclass;
        }

        target->start=0xFE;
        uuid_copy(target->uuid,gid);
        target->type=DataType::PolicyData;
        target->storage=StorageType::TextStorage;

        snprintf(target->fieldname,255,"%s",varname);
        target->datasize=strlen(value)+1;
        target->data= new char[target->datasize];
        strcpy(target->data,value);


    }

    inline const char *getGpoData(const AuthData *dat,AuthData::Record **varclass,const char *varname){
        if(*varclass && (*varclass)->data ){
            return (*varclass)->data;
        }else{
            for(const AuthData *curdat=dat; curdat; curdat=curdat->next()){
                if(curdat->Data && curdat->Data->storage == StorageType::TextStorage &&
                    curdat->Data->type==DataType::PolicyData
                    && strcmp(curdat->Data->fieldname,varname)==0){
                    *varclass=curdat->Data;
                    return curdat->Data->data;
                }
            }
        }
        std::string err;
        err=varname;
        err+=" data not found !";
        throw(authdb::AuthBackendError(err.c_str()));
    }
}

void authdb::GpoData::setName(const char* src){
    setGpoData(this,&_Name,"gponame",src);
}

const char * authdb::GpoData::getName(){
    return getGpoData(this,&_Name,"gponame");
}

void authdb::GpoData::setDesc(const char* src){
    setGpoData(this,&_Desc,"gpodesc",src);
}

const char * authdb::GpoData::getDesc(){
    return getGpoData(this,&_Desc,"gpodesc");
}

authdb::GpoData::GpoData(uuid_t gpid) : AuthData(gpid){
    _Name=nullptr;
    _Desc=nullptr;
    _Allowed=nullptr;
}

authdb::GpoData::GpoData(const GpoData& src) : AuthData(src){
    _Name=nullptr;
    _Desc=nullptr;
    _Allowed=nullptr;
}

authdb::GpoData::~GpoData(){
}

+62 −0
Changes for src/gpo.h: 62 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2025, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <uuid/uuid.h>

#include "authdb.h"
#include "backend.h"

#pragma once

namespace authdb {
    class GpoData : public AuthData{
    public:
        GpoData(uuid_t gpid);
        GpoData(const GpoData& src);
        ~GpoData();

        void setName(const char *src);
        const char *getName();

        void setDesc(const char *src);
        const char *getDesc();


        void setAllowed(bool src);
        bool getAlowed();

    private:
        AuthData::Record *_Name;
        AuthData::Record *_Desc;
        AuthData::Record *_Allowed;
        friend class Gpo;
    };

    class Gpo {
    public:

    };
};
+85 −0
Changes for src/session.cpp: 85 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "backend.h"
#include "group.h"
#include "types.h"
#include "authdb.h"

authdb::SessionData::SessionData(uuid_t sessionid, uuid_t userid, uuid_t domainid,
                                 uuid_t *group,size_t groupsize){
@@ -200,6 +201,90 @@ void authdb::Session::remSession(uuid_t sessionid){
    }
}

void authdb::Session::relSession(AuthBackend &backend,uuid_t sessionid){
    Group group;

    SessionData::Groups grpdat;

    grpdat.count=0;

    std::string username;

    SessionData *cursess=nullptr;

    for(SessionData *cur=_firstData; cur; cur=cur->_next){
        if(uuid_compare(cur->_sid,sessionid)==0){
            cursess=cur;
            break;
        }
    }

    if(!cursess)
        throw AuthBackendError("reload session: sessionid not found !");

    size_t rd=sizeof(authdb::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(cur.type == UserData && strcmp(cur.fieldname,"username")==0
            && uuid_compare(cur.uuid,cursess->_uid)==0){

            char *tmp=new char[cur.datasize];
            backend.read((unsigned char*)tmp,cur.datasize);
            username=tmp;
            delete[] tmp;
        }

        if(cur.type == GroupData && strcmp(cur.fieldname,"groupname")==0){
            class GroupData grpi(cur.uuid);
            size_t upos=sizeof(authdb::AuthHeader);
            group.info(backend,grpi,upos);

            if(grpi.isMember(cursess->_uid))
                ++grpdat.count;
        }
    }

    grpdat.gid = new uuid_t[grpdat.count];

    size_t count=0;

    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 == GroupData && strcmp(cur.fieldname,"groupname")==0){
            class GroupData grpi(cur.uuid);
            size_t upos=sizeof(authdb::AuthHeader);
            group.info(backend,grpi,upos);

            if(grpi.isMember(cursess->_uid))
                uuid_copy(grpdat.gid[count++],cur.uuid);
        }
    }
    delete[] cursess->_member.gid;

    cursess->_member.gid=new uuid_t[grpdat.count];
    for(size_t i=0; i<grpdat.count; ++i)
        uuid_copy(cursess->_member.gid[i],grpdat.gid[i]);
    cursess->_member.count=grpdat.count;

}


const authdb::SessionData * authdb::Session::firstData() const{
    return _firstData;
}
Loading