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

test

parent 08cdb970
Loading
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ namespace authdb {
    // --- SessionBlock serialization ---

    // Wire format:
    //   [4B magic 'SESB']
    //   [16B sid][16B uid][16B did]
    //   [4B member_count]
    //   [16B * member_count member uuids]
@@ -67,6 +68,8 @@ namespace authdb {
    //   [4B gpo_count]
    //   [for each GPO: 16B GPOId + 1B GPORes]

    static constexpr uint8_t SESSION_MAGIC[4] = {'S', 'E', 'S', 'B'};

    std::vector<uint8_t> SessionBlock::serialize(const SessionData &sess) {
        uuid::uuid sid, uid, did;
        sess.getSid(sid);
@@ -83,13 +86,17 @@ namespace authdb {
        std::vector<std::pair<uuid::uuid, bool>> gpo_results;
        sess.getGPOResults(gpo_results);

        // Header: 16+16+16 + 4 + members*16 + 4 + username + 4 + gpos*17
        size_t total = 48 + 4 + (members.size() * 16) + 4 + username_len
        // Magic(4) + Header: 16+16+16 + 4 + members*16 + 4 + username + 4 + gpos*17
        size_t total = 4 + 48 + 4 + (members.size() * 16) + 4 + username_len
                     + 4 + (gpo_results.size() * 17);

        std::vector<uint8_t> buf(total);
        size_t pos = 0;

        // Magic
        std::memcpy(buf.data() + pos, SESSION_MAGIC, 4);
        pos += 4;

        // SID
        std::memcpy(buf.data() + pos, sid.value, 16);
        pos += 16;
@@ -143,9 +150,12 @@ namespace authdb {
                                    std::vector<uuid::uuid> &members,
                                    std::string &username,
                                    std::vector<std::pair<uuid::uuid, bool>> &gpo_results) {
        if (data.size() < 56) return false;
        if (data.size() < 60) return false;  // 4 magic + 48 uuids + 4 member_count + 4 username_len

        size_t pos = 0;
        // Check magic
        if (std::memcmp(data.data(), SESSION_MAGIC, 4) != 0) return false;

        size_t pos = 4;

        std::memcpy(sid.value, data.data() + pos, 16);
        pos += 16;