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

test

parent e833dd61
Loading
Loading
Loading
Loading
+25 −0
Changes for src/daemon.cpp: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -235,6 +235,24 @@ std::string acceptNtlm(Server &s, const std::string &arg) {
    }
}

/* JOINED: the short domain name and computer name of each joined domain --
 * what an SMB server must call its workgroup and itself for NTLM logins
 * that the DC checks (Samba >= 4.23 compares them with the NTLMv2 blob) */
std::string joinedDomains(Server &s) {
    std::string out;
    for (auto &dp : s.domains) {
        if (dp->cfg.auth != Auth::Kerberos || dp->cfg.krbPrincipal.empty()) continue;
        std::string computer = dp->cfg.krbPrincipal;
        if (computer.back() == '$') computer.pop_back();
        std::string nb = netbiosName(*dp);
        if (!clean(nb) || !clean(computer) || nb.find('\t') != std::string::npos ||
            computer.find('\t') != std::string::npos)
            continue;
        out += "J\t" + nb + "\t" + computer + "\n";
    }
    return out + End;
}

long long nowSec() {
    return std::chrono::duration_cast<std::chrono::seconds>(Clock::now().time_since_epoch()).count();
}
@@ -378,6 +396,9 @@ bool resolve(Server &s, Cmd cmd, const std::string &arg, const std::string &line
    case Cmd::Auth:
        out = acceptAuth(s, arg);
        return true;
    case Cmd::Joined:
        out = joinedDomains(s);
        return true;
    case Cmd::PwEnt:
    case Cmd::GrEnt:
        out.clear();
@@ -403,6 +424,10 @@ std::string answer(Server &s, const std::string &line, uid_t peer) {
        resolve(s, cmd, arg, line, out, error);
        return out;
    }
    if (cmd == Cmd::Joined) {  /* a join or leave shows at once: uncached */
        resolve(s, cmd, arg, line, out, error);
        return out;
    }
    if (s.cache.get(line, out)) return out;
    if (resolve(s, cmd, arg, line, out, error)) {
        bool lookup = cmd != Cmd::PwEnt && cmd != Cmd::GrEnt && cmd != Cmd::Groups;
+2 −1
Changes for src/directory.cpp: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -517,7 +517,8 @@ std::string Directory::handle(Cmd cmd, const std::string &arg) {
    case Cmd::Groups: return groupsOf(arg);
    case Cmd::Krb5:
    case Cmd::Ntlm:
    case Cmd::Auth: break;  /* the daemon's (acceptor.h, netlogon.h) */
    case Cmd::Auth:
    case Cmd::Joined: break;  /* the daemon's (acceptor.h, netlogon.h) */
    }
    return End;
}
+1 −1
Changes for src/protocol.cpp: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ const Name Names[] = {
    { Cmd::PwNam, "PWNAM", true }, { Cmd::PwUid, "PWUID", true }, { Cmd::PwEnt, "PWENT", false },
    { Cmd::GrNam, "GRNAM", true }, { Cmd::GrGid, "GRGID", true }, { Cmd::GrEnt, "GRENT", false },
    { Cmd::Groups, "GROUPS", true }, { Cmd::Krb5, "KRB5", true }, { Cmd::Ntlm, "NTLM", true },
    { Cmd::Auth, "AUTH", true },
    { Cmd::Auth, "AUTH", true }, { Cmd::Joined, "JOINED", false },
};

bool printable(const std::string &s) {
+8 −2
Changes for src/protocol.h: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -29,7 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * connection:
 *
 *   PWNAM <name> | PWUID <id> | PWENT | GRNAM <name> | GRGID <id> | GRENT |
 *   GROUPS <user> | KRB5 <base64 token> | AUTH <base64 user NUL password>
 *   GROUPS <user> | KRB5 <base64 token> | AUTH <base64 user NUL password> |
 *   JOINED
 *
 * KRB5 (root only: sharedd, for ksmbd's Kerberos logins) answers
 *
@@ -42,6 +43,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * or just END for a user of none of our domains.
 *
 * JOINED (sharedd: the names ksmbd must use as a domain member) answers a
 * line per joined domain, then END:
 *
 *   J <NetBIOS domain> <computer name>
 *
 * ids in the text form of <sys/uid_r.h> (1000, {guid}). The answer is a
 * line per record, then END -- or ERR <message> when the directory could
 * not be asked:
@@ -61,7 +67,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace adconnect {

enum class Cmd { PwNam, PwUid, PwEnt, GrNam, GrGid, GrEnt, Groups, Krb5, Ntlm, Auth };
enum class Cmd { PwNam, PwUid, PwEnt, GrNam, GrGid, GrEnt, Groups, Krb5, Ntlm, Auth, Joined };

struct User {
    std::string name, uid, gid, gecos, dir, shell;