Commit 00a4bd7c authored by jan.koester's avatar jan.koester
Browse files

login bugfixes

parent 1a01a7d9
Loading
Loading
Loading
Loading
Loading
+4 −0
Changes for plugin/ad/ad.cpp: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1299,6 +1299,10 @@ std::vector<uint8_t> ActiveDirectory::handleCldap(const uint8_t *data, size_t le
    };
    walk(filter);

    /* a fully-qualified DnsDomain may carry a trailing root dot (example.com.) */
    while (!dnsDomain.empty() && dnsDomain.back() == '.')
        dnsDomain.pop_back();

    /* pick the domain: by DnsDomain, else the first */
    std::lock_guard<std::mutex> lock(_Lock);
    Dom *dom = nullptr;
+49 −0
Changes for src/rpc/netlogon.cpp: 49 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -22,8 +22,19 @@ namespace {
        NETR_LOGONSAMLOGONEX      = 39,
        NETR_LOGONGETDOMAININFO   = 34,
        NETR_GETDCNAME            = 11,
        NETR_ENUMTRUSTEDDOMAINS   = 19,   /* NetrEnumerateTrustedDomains */
        DSR_ENUMDOMAINTRUSTS      = 40,   /* DsrEnumerateDomainTrusts    */
    };

    /* a [string] wchar_t* : conformant+varying, NUL-terminated */
    void pushWStr(NdrPush &p, const std::string &s) {
        auto u = crypto::utf16le(s);
        uint32_t n = uint32_t(u.size() / 2) + 1;   /* incl. NUL */
        p.u32(n); p.u32(0); p.u32(n);
        p.bytes(u);
        p.u16(0);
    }

    constexpr uint32_t ST_OK = 0x00000000;
    constexpr uint32_t ST_ACCESS = 0xC0000022;
    constexpr uint32_t ST_NO_TRUST = 0xC0000199;   /* NO_TRUST_SAM_ACCOUNT */
@@ -124,6 +135,44 @@ DispatchResult netlogonDispatch(uint16_t opnum, const std::vector<uint8_t> &stub
            p.u32(ST_OK);
            return DispatchResult{ST_OK, false, 0, p.buf};
        }
        case DSR_ENUMDOMAINTRUSTS: {
            /* return this domain as the sole (primary, in-forest) trust so the
             * client can build its domain context at boot/logon. */
            DomainInfo di = primaryDomain();
            NdrPush p;
            p.u32(1);                 /* DomainCount */
            p.ref(true);              /* Domains array ptr */
            p.u32(1);                 /* conformant max_count */
            /* NETR_DOMAIN_TRUST scalar part */
            p.ref(true);              /* NetbiosDomainName ptr */
            p.ref(true);              /* DnsDomainName ptr */
            p.u32(0x1d);              /* Flags: IN_FOREST|TREEROOT|PRIMARY|NATIVE */
            p.u32(0);                 /* ParentIndex */
            p.u32(2);                 /* TrustType = UPLEVEL */
            p.u32(0);                 /* TrustAttributes */
            p.ref(true);              /* DomainSid ptr */
            p.bytes(di.guid, 16);     /* DomainGuid */
            /* deferred buffers, in field order */
            pushWStr(p, di.netbios);
            pushWStr(p, di.dnsName);
            p.sid(di.sid);
            p.u32(ST_OK);
            return DispatchResult{ST_OK, false, 0, p.buf};
        }
        case NETR_ENUMTRUSTEDDOMAINS: {
            /* NETR_BLOB: a MULTI_SZ (UTF-16, double-NUL terminated) of names */
            DomainInfo di = primaryDomain();
            std::vector<uint8_t> blob = crypto::utf16le(di.netbios);
            blob.push_back(0); blob.push_back(0);   /* NUL after the name */
            blob.push_back(0); blob.push_back(0);   /* final empty -> double NUL */
            NdrPush p;
            p.u32(uint32_t(blob.size()));   /* cbBuffer */
            p.ref(true);                    /* Buffer ptr */
            p.u32(uint32_t(blob.size()));   /* conformant max_count */
            p.bytes(blob);
            p.u32(ST_OK);
            return DispatchResult{ST_OK, false, 0, p.buf};
        }
        default:
            r.fault = true; r.faultCode = 0x1C010002;   /* PasswordSet2/LogonSamLogonEx: next */
            return r;