示例#1
0
//
// Create socket to serve as channel for command inputs/outputs.
//
void CmdAgent::mkIo(const CmdLine& config)
{
    String optK("ibufsize");
    int ibufSize = S32(config.opt(optK), IBUF_SIZE /*defaultV*/);
    optK = "obufsize";
    int obufSize = S32(config.opt(optK), OBUF_SIZE /*defaultV*/);

    io_ = new UdpClient(ibufSize, obufSize);
}
示例#2
0
//!
//! Reset instance with given command line. Three options can be specified in
//! the command line: capconfig, capfilter, and capname. The capconfig option is a
//! colon-delimited string containing the following parameters: agentstacksize,
//! bepromiscuous, bufsize, capicpkts, caplength, capogpkts, and looptimeout. The
//! default capconfig option is: "131072:true:0x1000000:true:1518:true:300". The
//! capfilter option is a string containing a pcap-format filter. The default
//! capfilter option is an empty string. The capname option allows free-format
//! naming of network traffic captures. The default capname option is an empty
//! string.
//!
void CapConfig::reset(const CmdLine& cmdLine)
{
    delete[] filter_;

    bool useDefaults = true;
    const String* defaultV = 0;
    String optK("capconfig");
    const String* optV = cmdLine.opt(optK, defaultV);
    if (optV != 0)
    {
        bool makeCopy = false;
        char delim = ':';
        DelimitedTxt txt(*optV, makeCopy, delim);

        int growBy = 0;
        unsigned int capacity = 7 + 1;
        bool trimLines = true;
        StringVec vec(txt, trimLines, capacity, growBy);
        if (vec.numItems() == 7)
        {
            agentStackSize_ = U32(&vec[0], AGENT_STACK_SIZE /*defaultV*/);
            bePromiscuous_ = Bool(&vec[1], true /*defaultV*/);
            bufSize_ = S32(&vec[2], BUF_SIZE /*defaultV*/);
            capIcPkts_ = Bool(&vec[3], true /*defaultV*/);
            capLength_ = S32::isValid(vec[4].ascii(), CAP_LENGTH_MIN, CAP_LENGTH_MAX)? S32(vec[4]): CAP_LENGTH;
            capOgPkts_ = Bool(&vec[5], true /*defaultV*/);
            loopTimeout_ = S32(&vec[6], LOOP_TIMEOUT /*defaultV*/);
            size_t size = 1;
            char* s = new char[size];
            s[0] = 0;
            filter_ = s;
            useDefaults = false;
            name_.reset();
        }
    }

    if (useDefaults)
    {
        filter_ = 0;
        reset();
    }

    optK = "capfilter";
    optV = cmdLine.opt(optK, defaultV);
    if (optV != 0)
    {
        size_t size = optV->byteSize();
        char* s = new char[size];
        memcpy(s, optV->raw(), size);
        delete[] filter_;
        filter_ = s;
    }

    optK = "capname";
    name_ = *cmdLine.opt(optK, &name_);
}
示例#3
0
//
// Bind debugger socket. Use port address specified by the debugger option if
// available. Use given default address otherwise.
//
void CmdAgent::bind(const CmdLine& config, unsigned int defaultAddr)
{

    // Use default dbugger address.
    unsigned short port = 0U;
    dbugger_.reset(defaultAddr, port);

    // Use specified dbugger address.
    String optK("dbugger");
    const String* dbugger = config.opt(optK, 0 /*defaultV*/);
    if (dbugger != 0)
    {
        bool portIsOptional = true;
        char delim = COLON;
        dbugger_.reset(dbugger->ascii(), delim, portIsOptional);
    }

    // Bind dbugger socket.
    // Consider port binding optional.
    bool ok = io_->bind(dbugger_.addr(), dbugger_.port());
    if ((!ok) && (dbugger_.port() != 0))
    {
        io_->bind(dbugger_.addr(), port);
    }

    // Save effective dbugger address.
    io_->getMyAddr(dbugger_);
}
示例#4
0
//
// env [--expandEnv]
//
bool MiscDbugCmd::doEnv(const CmdLine& req)
{
    wchar_t* envW = GetEnvironmentStringsW();
    StringVec env;

    String optK("expandEnv");
    bool expandEnv = Bool(req.opt(optK), false /*defaultV*/);
    DelimitedTxt txt(EQUALS_SIGN);
    String k;
    String kv;
    String v;
    for (const wchar_t* w = envW; *w;)
    {
        kv = w;
        txt.setTxt(kv, false /*makeCopy*/);
        (txt.next(k, true /*doTrimLine*/) && getenv(k, v, expandEnv))?
            env.add(k + EQUALS_SIGN + v):
            env.add(kv);
        size_t n = wcslen(w);
        w += n + 1;
    }

    FreeEnvironmentStringsW(envW);
    env.sort();
    String rsp(env.stringify(NEW_LINE));
    respond(req, rsp);

    bool cmdIsValid = true;
    return cmdIsValid;
}
示例#5
0
bool MiscDbugCmd::updateAcl(const CmdLine& req)
{
    bool updated;

    String optK("acl");
    const String* optV = req.opt(optK, 0 /*defaultV*/);
    if (optV == 0)
    {
        updated = false;
    }
    else
    {
        unsigned int cap = ACL_CAP0;
        char delim = ',';
        IpAddrSet addrRange(optV->ascii(), delim, cap);
        sysIo_->setAcl(addrRange);
        updated = true;
    }

    return updated;
}
示例#6
0
//
// version-show [--v]
//
bool MiscDbugCmd::doVersionShow(const CmdLine& req)
{

    // Start with hosting OS version.
    String rsp;
    const wchar_t* osVer = Process::osVer();
    swprintf(rsp, L"%9s: %s\n", L"osVer", osVer);
    delete[] osVer;

    // Then module versions.
    String optK("v");
    Bool showAll(req.opt(optK), false /*defaultV*/);
    Process myProc(Process::myId());
    myProc.apply(showAll? showModule: showExe, &rsp);

    // Terminating response.
    respond(req, rsp);

    bool cmdIsValid = true;
    return cmdIsValid;
}
示例#7
0
bool MiscDbugCmd::rmFromAcl(const CmdLine& req)
{
    bool updated = false;

    String optK("remove");
    Bool removing(req.opt(optK), false /*defaultV*/);
    if (removing)
    {
        IpAddrSet addrRange;
        bool ok = getAddrRange(req, addrRange);
        if (ok)
        {
            IpAddrSet acl(sysIo_->acl());
            updated = acl.rm(addrRange);
            if (updated)
            {
                sysIo_->setAcl(acl);
            }
        }
    }

    return updated;
}
示例#8
0
void CmdAgent::connect(const CmdLine& config)
{

    // dbuggee option is required.
    String optK("dbuggee");
    const String* dbuggee = config.opt(optK, 0 /*defaultV*/);
    if (dbuggee == 0)
    {
        errDesc_ = "dbuggee option is required";
        return;
    }

    // Prepare to communicate with debuggee.
    char delim = COLON;
    bool portIsOptional = false;
    if (dbuggee_.reset(dbuggee->ascii(), delim, portIsOptional))
    {
        bind(config, INADDR_ANY);
        io_->connect(dbuggee_);
        return;
    }

    errDesc_ = "debuggee not found";
}