Loading src/admin.cpp +1 −1 Changes for src/admin.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -1580,7 +1580,7 @@ namespace authdb { int ret; if(!gpo.exits(*backend,gpid,nullptr,ret)) if(!gpo.exists(*backend,gpid,nullptr,ret)) throw AuthBackendError("GPO doesn't extsts cannot edit !"); libhttppp::HttpForm GPOForm; Loading src/api.cpp +48 −21 Changes for src/api.cpp: 48 added lines, 21 removed lines. Original line number Diff line number Diff line Loading @@ -42,6 +42,33 @@ #include "gpo.h" #include "session.h" /******************************************************************************* * Copyright (c) 2025, Jan Koester * All rights reserved. * * BSD-3-Clause *******************************************************************************/ #include <memory> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <json-c/json.h> #include <json-c/json_types.h> #include <json-c/json_object.h> #include "hash.h" #include "hash/sha512.h" #include "authdb.h" #include "backend.h" #include "api.h" #include "user.h" #include "client.h" #include "gpo.h" #include "session.h" namespace authdb { namespace { Loading @@ -64,11 +91,12 @@ namespace { return cmd; } // Helper: safe forward advance with bounds checking bool advance_record_window(size_t& rd, size_t end, size_t datasize, size_t headerBytes) { if (rd + headerBytes > end) return false; // header out of bounds size_t next = rd + headerBytes + datasize; if (next < rd || next > end) return false; // overflow or out of bounds // Helper: after reading a record header, compute next rd with bounds checks. // Assumes backend position is at end of the header bytes for this record. bool compute_next_rd(size_t& rd, size_t end, size_t datasize, size_t header_end_pos) { if (header_end_pos > end) return false; size_t next = header_end_pos + datasize; if (next < header_end_pos || next > end) return false; // overflow / OOB rd = next; return true; } Loading Loading @@ -113,7 +141,7 @@ public: class Gpo gpo; int ret = -1; // NOTE: assuming method name is 'exists' (was 'exits' in original) // If your API method is actually "exits", revert this to exits(...) if (gpo.exists(_Backend, ::uuid::uuid(id), nullptr, ret)) { json_object_object_add(value, id, json_object_new_boolean(true)); } else { Loading Loading @@ -255,14 +283,15 @@ public: while (rd < end) { _Backend.setPos(rd); // read header of record if (!_Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record))) { break; } // read header of record (API returns void) _Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record)); // Validate window before using cur->datasize if (!advance_record_window(rd, end, cur->datasize, sizeof(AuthData::Record))) { // header_end_pos is at current backend position after reading header size_t header_end_pos = _Backend.getPos(); // Validate and compute next rd using cur->datasize if (!compute_next_rd(rd, end, cur->datasize, header_end_pos)) { break; } Loading @@ -273,9 +302,7 @@ public: size_t upos = sizeof(AuthHeader); user.info(_Backend, *udat, upos); // Compare username first (normal compare is OK) if (name == udat->getUsername()) { // Constant-time compare of password hashes if (constant_time_eq(pwsalt, udat->getPwHash())) { const SessionData* sdat = AuthSession.addSession(_Backend, _Did.value, cur->ruid); Loading Loading @@ -325,11 +352,11 @@ public: std::make_shared<authdb::AuthData::Record>(); _Backend.setPos(rd); if (!_Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record))) { break; } if (!advance_record_window(rd, end, cur->datasize, sizeof(AuthData::Record))) { _Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record)); size_t header_end_pos = _Backend.getPos(); if (!compute_next_rd(rd, end, cur->datasize, header_end_pos)) { break; } Loading Loading @@ -461,7 +488,7 @@ public: int fcount = json_object_array_length(cmd); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, /*val*/) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, val) { if (strcmp("sessioninfo", key) == 0) { if (!_SessionData) continue; Loading src/gpo.cpp +2 −2 Changes for src/gpo.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ authdb::GpoData::GpoData(const GpoData& src) : AuthData(src){ authdb::GpoData::~GpoData(){ } bool authdb::Gpo::exits(AuthBackend& backend,const uuid::uuid &gpid, const char* name, int& ret){ bool authdb::Gpo::exists(AuthBackend& backend,const uuid::uuid &gpid, const char* name, int& ret){ std::shared_ptr<authdb::AuthData::Record> cur=std::make_shared<AuthData::Record>(); size_t rd=sizeof(authdb::AuthHeader),end=backend.end(); Loading Loading @@ -154,7 +154,7 @@ void authdb::Gpo::create(AuthBackend& backend, class GpoData* dat){ if(uuid::uuid(dat->Data.ruid).empty()) throw authdb::AuthBackendError("Create GPO: GUID not set !"); if(exits(backend,dat->Data.ruid,dat->getName(),exi)){ if(exists(backend,dat->Data.ruid,dat->getName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create GPO: GPOname already Exists aborting!"); Loading src/gpo.h +1 −1 Changes for src/gpo.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ namespace authdb { class Gpo { public: bool exits(AuthBackend &backend,const uuid::uuid &gpid,const char *name, int &ret); bool exists(AuthBackend &backend,const uuid::uuid &gpid,const char *name, int &ret); void create(AuthBackend& backend, class GpoData* dat); void remove(AuthBackend &backend,const uuid::uuid &gpid); void info(AuthBackend &backend, class GpoData& dat, size_t &pos); Loading Loading
src/admin.cpp +1 −1 Changes for src/admin.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -1580,7 +1580,7 @@ namespace authdb { int ret; if(!gpo.exits(*backend,gpid,nullptr,ret)) if(!gpo.exists(*backend,gpid,nullptr,ret)) throw AuthBackendError("GPO doesn't extsts cannot edit !"); libhttppp::HttpForm GPOForm; Loading
src/api.cpp +48 −21 Changes for src/api.cpp: 48 added lines, 21 removed lines. Original line number Diff line number Diff line Loading @@ -42,6 +42,33 @@ #include "gpo.h" #include "session.h" /******************************************************************************* * Copyright (c) 2025, Jan Koester * All rights reserved. * * BSD-3-Clause *******************************************************************************/ #include <memory> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <json-c/json.h> #include <json-c/json_types.h> #include <json-c/json_object.h> #include "hash.h" #include "hash/sha512.h" #include "authdb.h" #include "backend.h" #include "api.h" #include "user.h" #include "client.h" #include "gpo.h" #include "session.h" namespace authdb { namespace { Loading @@ -64,11 +91,12 @@ namespace { return cmd; } // Helper: safe forward advance with bounds checking bool advance_record_window(size_t& rd, size_t end, size_t datasize, size_t headerBytes) { if (rd + headerBytes > end) return false; // header out of bounds size_t next = rd + headerBytes + datasize; if (next < rd || next > end) return false; // overflow or out of bounds // Helper: after reading a record header, compute next rd with bounds checks. // Assumes backend position is at end of the header bytes for this record. bool compute_next_rd(size_t& rd, size_t end, size_t datasize, size_t header_end_pos) { if (header_end_pos > end) return false; size_t next = header_end_pos + datasize; if (next < header_end_pos || next > end) return false; // overflow / OOB rd = next; return true; } Loading Loading @@ -113,7 +141,7 @@ public: class Gpo gpo; int ret = -1; // NOTE: assuming method name is 'exists' (was 'exits' in original) // If your API method is actually "exits", revert this to exits(...) if (gpo.exists(_Backend, ::uuid::uuid(id), nullptr, ret)) { json_object_object_add(value, id, json_object_new_boolean(true)); } else { Loading Loading @@ -255,14 +283,15 @@ public: while (rd < end) { _Backend.setPos(rd); // read header of record if (!_Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record))) { break; } // read header of record (API returns void) _Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record)); // Validate window before using cur->datasize if (!advance_record_window(rd, end, cur->datasize, sizeof(AuthData::Record))) { // header_end_pos is at current backend position after reading header size_t header_end_pos = _Backend.getPos(); // Validate and compute next rd using cur->datasize if (!compute_next_rd(rd, end, cur->datasize, header_end_pos)) { break; } Loading @@ -273,9 +302,7 @@ public: size_t upos = sizeof(AuthHeader); user.info(_Backend, *udat, upos); // Compare username first (normal compare is OK) if (name == udat->getUsername()) { // Constant-time compare of password hashes if (constant_time_eq(pwsalt, udat->getPwHash())) { const SessionData* sdat = AuthSession.addSession(_Backend, _Did.value, cur->ruid); Loading Loading @@ -325,11 +352,11 @@ public: std::make_shared<authdb::AuthData::Record>(); _Backend.setPos(rd); if (!_Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record))) { break; } if (!advance_record_window(rd, end, cur->datasize, sizeof(AuthData::Record))) { _Backend.read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(AuthData::Record)); size_t header_end_pos = _Backend.getPos(); if (!compute_next_rd(rd, end, cur->datasize, header_end_pos)) { break; } Loading Loading @@ -461,7 +488,7 @@ public: int fcount = json_object_array_length(cmd); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, /*val*/) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, val) { if (strcmp("sessioninfo", key) == 0) { if (!_SessionData) continue; Loading
src/gpo.cpp +2 −2 Changes for src/gpo.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ authdb::GpoData::GpoData(const GpoData& src) : AuthData(src){ authdb::GpoData::~GpoData(){ } bool authdb::Gpo::exits(AuthBackend& backend,const uuid::uuid &gpid, const char* name, int& ret){ bool authdb::Gpo::exists(AuthBackend& backend,const uuid::uuid &gpid, const char* name, int& ret){ std::shared_ptr<authdb::AuthData::Record> cur=std::make_shared<AuthData::Record>(); size_t rd=sizeof(authdb::AuthHeader),end=backend.end(); Loading Loading @@ -154,7 +154,7 @@ void authdb::Gpo::create(AuthBackend& backend, class GpoData* dat){ if(uuid::uuid(dat->Data.ruid).empty()) throw authdb::AuthBackendError("Create GPO: GUID not set !"); if(exits(backend,dat->Data.ruid,dat->getName(),exi)){ if(exists(backend,dat->Data.ruid,dat->getName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create GPO: GPOname already Exists aborting!"); Loading
src/gpo.h +1 −1 Changes for src/gpo.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ namespace authdb { class Gpo { public: bool exits(AuthBackend &backend,const uuid::uuid &gpid,const char *name, int &ret); bool exists(AuthBackend &backend,const uuid::uuid &gpid,const char *name, int &ret); void create(AuthBackend& backend, class GpoData* dat); void remove(AuthBackend &backend,const uuid::uuid &gpid); void info(AuthBackend &backend, class GpoData& dat, size_t &pos); Loading