Commit c0ea549f authored by jan.koester's avatar jan.koester
Browse files

no mem leaks

parent adbf5140
Loading
Loading
Loading
Loading
+12 −5
Changes for src/authdb.cpp: 12 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -490,7 +490,7 @@ namespace authdb {
                        << "<li><span>Storagetype: </span><span>" << ddat.getStorageType() << "</span></li>"
                        << "<li><span>Storageoptions: </span><span>" << ddat.getStorageOptions() << "</span></li>"
                        << "</ul></td><td><ul class=\"usertoolbar\" >"
                        << "<li><a class=\"button\" href=\"/admin/removeuser/" << crdid << "\">RemoveDomain</a></li>"
                        << "<li><a class=\"button\" href=\"/admin/removedomain/" << crdid << "\">RemoveDomain</a></li>"
                        << "</ul></td></tr>";
                    }catch(AuthBackendError &e){
                        std::cerr << e.what() << std::endl;
@@ -498,7 +498,7 @@ namespace authdb {
                }
            }

            list  << "<div><ul class=\"domaintoolbar\" >"
            list  << "</table></div><div><ul class=\"domaintoolbar\" >"
                  << "<li><a class=\"button\" href=\"/admin/createdomain\">CreateDomain</a>"
                  << "</li></ul></div>";

@@ -544,6 +544,7 @@ namespace authdb {

                        if(tmp=="filename"){
                            stortype=BinaryStorage;
                            continue;
                        }

                        bool numeric=true;
@@ -558,7 +559,6 @@ namespace authdb {

                        if(numeric){
                            stortype=StorageType::IntStorage;

                        }

                    }
@@ -583,22 +583,29 @@ namespace authdb {
                        memcpy(dodat.data,curformdat->Value.data(),
                               curformdat->Value.size());
                        dodat.data[curformdat->Value.size()]='\0';

                        ddat.Data->append(dodat);
                        delete[] dodat.data;
                    }else if(dodat.storage==IntStorage){
                        dodat.datasize=sizeof(int);
                        dodat.data=(char*)new int;
                        int val=atoi(curformdat->Value.data());
                        int val=0;
                        std::copy(curformdat->Value.begin(),curformdat->Value.end(),&val);
                        memcpy(dodat.data,&val,
                               dodat.datasize);

                        ddat.Data->append(dodat);
                        delete (int*)dodat.data;
                    }else {
                        dodat.datasize=curformdat->Value.size();
                        dodat.data=new char[dodat.datasize];
                        memcpy(dodat.data,curformdat->Value.data(),
                               dodat.datasize);
                    }

                        ddat.Data->append(dodat);
                        delete[] dodat.data;
                    }
                }
                Domain domain;
                domain.create(_Backend,&ddat);
                std::cout << "domain created!" << std::endl;
+33 −2
Changes for src/domain.cpp: 33 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -26,10 +26,12 @@
 *******************************************************************************/

#include <cstring>
#include <unistd.h>

#include "domain.h"
#include "types.h"


namespace authdb {
    inline void setDomainData(AuthData *dat,AuthData::Record **varclass,const char *varname,const char *value){
        AuthData::Record *target=*varclass;
@@ -153,6 +155,9 @@ namespace authdb {
authdb::DomainData::DomainData(uuid_t uuid){
    uuid_copy(did,uuid);
    Data=new AuthData(did);
    _name=nullptr;
    _storageType=nullptr;
    _storageOptions=nullptr;
}

authdb::DomainData::~DomainData(){
@@ -188,13 +193,17 @@ const char * authdb::DomainData::getStorageOptions(){
void authdb::Domain::create(authdb::AuthBackend& backend,class DomainData *data){
    int exi=0;

    try{
        if(exits(backend,&data->did,data->getDomainName(),exi)){
            switch(exi){
                case 1:
                throw authdb::AuthBackendError("Create User: Username already Exists aborting!");
                    throw authdb::AuthBackendError("Create Domain: Domainname already Exists aborting!");
                default:
                throw authdb::AuthBackendError("Create User: UUID already Exists aborting!");
                    throw authdb::AuthBackendError("Create Domain: UUID already Exists aborting!");
            }
        }
    }catch(...){

    }

    size_t wd=backend.end();
@@ -209,7 +218,29 @@ void authdb::Domain::create(authdb::AuthBackend& backend,class DomainData *data)
}

void authdb::Domain::remove(AuthBackend& backend, const uuid_t uid){
     authdb::AuthData::Record cur;

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

    while(rd<end){
        backend.setPos(rd);
        backend.read((unsigned char*)&cur,sizeof(AuthData::Record));
        rd=backend.getPos()+cur.datasize;
        if( uuid_compare(cur.uuid,uid) ==0 &&
            cur.type==DataType::DomainData &&
            strcmp(cur.fieldname,"domainOptions")==0){

            cur.data=new char[cur.datasize];
            backend.read((unsigned char*)cur.data,cur.datasize);

            unlink(cur.data);

            delete[] cur.data;
        }
    }

    delRecord(backend,uid,DataType::DomainData);

}