예제 #1
0
void Dhcp6Server::ProcessSolicit(Message &aMessage, otIp6Address &aDst, uint8_t *aTransactionId)
{
    IaNa iana;
    ClientIdentifier clientIdentifier;
    uint16_t optionOffset;
    uint16_t offset = aMessage.GetOffset();
    uint16_t length = aMessage.GetLength() - aMessage.GetOffset();

    // Client Identifier (discard if not present)
    VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionClientIdentifier)) > 0);
    SuccessOrExit(ProcessClientIdentifier(aMessage, optionOffset, clientIdentifier));

    // Server Identifier (assuming Rapid Commit, discard if present)
    VerifyOrExit(FindOption(aMessage, offset, length, kOptionServerIdentifier) == 0);

    // Rapid Commit (assuming Rapid Commit, discard if not present)
    VerifyOrExit(FindOption(aMessage, offset, length, kOptionRapidCommit) > 0);

    // Elapsed Time if present
    if ((optionOffset = FindOption(aMessage, offset, length, kOptionElapsedTime)) > 0)
    {
        SuccessOrExit(ProcessElapsedTime(aMessage, optionOffset));
    }

    // IA_NA (discard if not present)
    VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionIaNa)) > 0);
    SuccessOrExit(ProcessIaNa(aMessage, optionOffset, iana));

    SuccessOrExit(SendReply(aDst, aTransactionId, clientIdentifier, iana));

exit:
    return;
}
예제 #2
0
otError Dhcp6Server::ProcessIaNa(Message &aMessage, uint16_t aOffset, IaNa &aIaNa)
{
    otError error = OT_ERROR_NONE;
    uint16_t optionOffset;
    uint16_t length;

    VerifyOrExit((aMessage.Read(aOffset, sizeof(aIaNa), &aIaNa) == sizeof(aIaNa)), error = OT_ERROR_PARSE);

    aOffset += sizeof(aIaNa);
    length = aIaNa.GetLength() + sizeof(Dhcp6Option) - sizeof(IaNa);

    VerifyOrExit(length <= aMessage.GetLength() - aOffset, error = OT_ERROR_PARSE);

    mPrefixAgentsMask = 0;

    while (length > 0)
    {
        VerifyOrExit((optionOffset = FindOption(aMessage, aOffset, length, kOptionIaAddress)) > 0);
        SuccessOrExit(error = ProcessIaAddress(aMessage, optionOffset));

        length -= ((optionOffset - aOffset) + sizeof(IaAddress));
        aOffset = optionOffset + sizeof(IaAddress);
    }

exit:
    return error;
}
예제 #3
0
	//*************************************************************************
	// Method:		SetOptionHelpString
	// Description: changes the help string for an existing item
	//
	// Parameters:
	//	itemName - the name of the item to set the help string for
	//	helpString - the string to set as the button's help text
	//
	// Return Value: None
	//*************************************************************************
	void SIOptionsList::SetOptionHelpString(String *itemName, String *helpString)
	{
		SIOption *item = FindOption(itemName);
		if (item)
		{
			item->helpString = helpString;
			if (OnOptionsUpdate)
				OnOptionsUpdate->Invoke(this);
		}
	}
예제 #4
0
	//*************************************************************************
	// Method:		SetOptionTag
	// Description: changes the user-defined tag object for an existing item
	//
	// Parameters:
	//	itemName - the name of the item to set the tag for
	//	tag - the user-defined object to assign to the button
	//
	// Return Value: None
	//*************************************************************************
	void SIOptionsList::SetOptionTag(String *itemName, Object *tag)
	{
		SIOption* item = FindOption(itemName);
		if (item)
		{
			item->tag = tag;
			if (OnOptionsUpdate)
				OnOptionsUpdate->Invoke(this);
		}
	}
예제 #5
0
	//*************************************************************************
	// Method:		SetOptionDisplayString
	// Description: changes the display string for an existing item
	//
	// Parameters:
	//	itemName - the name of the item to set the display string for
	//	displayString - the string to set as the displayed menu item text
	//
	// Return Value: None
	//*************************************************************************
	void SIOptionsList::SetOptionDisplayString(String *itemName, String *displayString)
	{
		SIOption *item = FindOption(itemName);
		if (item)
		{
			item->displayName = displayString;
			if (OnOptionsUpdate)
				OnOptionsUpdate->Invoke(this);
		}
	}
예제 #6
0
    static bool ParseShortOption(const CommandLineOptionDefinition * options,
                                 CommandLineArgEnumerator *argEnumerator,
                                 const char *argument)
    {
        const CommandLineOptionDefinition * option = nullptr;

        const char * shortOption = &argument[1];
        for (; *shortOption != '\0'; shortOption++)
        {
            option = FindOption(options, shortOption[0]);
            if (option == nullptr)
            {
                Console::Error::WriteLine("Unknown option: -%c", shortOption[0]);
                return false;
            }
            if (option->Type == CMDLINE_TYPE_SWITCH)
            {
                if (!ParseOptionValue(option, nullptr))
                {
                    return false;
                }
            }
            else if (shortOption[1] != '\0')
            {
                if (!ParseOptionValue(option, &shortOption[1]))
                {
                    return false;
                }
                return true;
            }
        }

        if (option != nullptr && option->Type != CMDLINE_TYPE_SWITCH)
        {
            const char * valueString = nullptr;
            if (!argEnumerator->TryPopString(&valueString))
            {
                Console::Error::WriteLine("Expected value for option: %c", option->ShortName);
                return false;
            }

            if (!ParseOptionValue(option, valueString))
            {
                return false;
            }
        }

        return true;
    }
예제 #7
0
const wxCmdLineOption*
wxCmdLineParserData::FindOptionByAnyName(const wxString& name)
{
    int i = FindOption(name);
    if ( i == wxNOT_FOUND )
    {
        i = FindOptionByLongName(name);

        if ( i == wxNOT_FOUND )
        {
            wxFAIL_MSG( wxS("Unknown option ") + name );
            return NULL;
        }
    }

    return &m_options[(size_t)i];
}
예제 #8
0
// Find the address of the variable holding the specified option default
void* Options::GetDefault (const char* pcszName_)
{
    OPTION* p = FindOption(pcszName_);

    if (p)
    {
        switch (p->nType)
        {
            case OT_BOOL:       return &p->fDefault;
            case OT_INT:        return &p->nDefault;
//          case OT_STRING:     return &p->pcszDefault;     // Don't use - points to read-only string table!
        }
    }

    // This should never happen, thanks to a compile-time check in the header
    static void* pv = NULL;
    return &pv;
}
예제 #9
0
파일: djsshconf.c 프로젝트: Brainiarc7/pbis
static DWORD RemoveOption(struct SshConf *conf, const char *name)
{
    DWORD ceError = ERROR_SUCCESS;
    int line;

    for(line = 0; line < conf->lineCount; line++)
    {
        line = FindOption(conf, line, name);
        if(line == -1)
            break;

        BAIL_ON_CENTERIS_ERROR(ceError = RemoveLine(conf, &line));
        if(line > 0)
            line--;
    }

error:
    UpdatePublicLines(conf);
    return ceError;
}
예제 #10
0
	void C_Select::OnDraw(C_DrawContext& drawContext) {
		int nb_options = (int)m_Options.size();
		int height = m_Selected ? m_RowHeight*(nb_options+1) : m_RowHeight;

		Set(m_Rect.x, m_Rect.y, m_RowWidth, height); //only change the rect, no resize
		C_Rect<int> rect{0, 0, m_Rect.w, height};

		drawContext.SetColor(0x825809);
		drawContext.DrawFillRectangle(rect);

		C_Option* selection = nullptr;

		if(FindOption(m_Selection)) {
			selection = GetOption(m_Selection);
		}

		if(selection) {
			C_Text& text = selection->GetText();
			text.SetPosition(5, 3);
			drawContext.BlitSurface(&text);
		}

		if(m_Selected) {
			std::map<int, C_Option>::iterator it = m_Options.begin();

			for (int i = 0; i < nb_options && it != m_Options.end(); ++i, ++it) {
				C_Option& option = it->second;

				C_Text& text = option.GetText();
				text.SetPosition(5, 3 + i * m_RowHeight + m_RowHeight);
				drawContext.BlitSurface(&text);
			}
		}

		m_Dirty = false;
	}
예제 #11
0
파일: djsshconf.c 프로젝트: Brainiarc7/pbis
static BOOLEAN TestOption(PCSTR rootPrefix, struct SshConf *conf, PCSTR binary, PCSTR testFlag, PCSTR optionName, LWException **exc)
{
    DWORD ceError = ERROR_SUCCESS;
    BOOLEAN result = FALSE;
    PSTR command = NULL;
    PSTR commandOutput = NULL;
    int existingLine;

    if(rootPrefix == NULL)
        rootPrefix = "";
    DJ_LOG_INFO("Testing option %s", optionName);

    existingLine = FindOption(conf, 0, optionName);
    if(existingLine != -1)
    {
        if(!strcmp(conf->lines[existingLine].value.value, "yes"))
        {
            //The option is already enabled, so it must be supported
            result = TRUE;
            goto cleanup;
        }
    }

    /* Most versions of sshd support the -t option which runs it in test
       mode. Test mode is used to verify that a config file is correct, or
       in our case that the passed options are valid.

       The only version of sshd known to not support -t is the version that
       comes with Solaris 9. However, this version does not support the -o
       option, and it will error out if the -o option is used. The Solaris
       9 version of sshd does not support any of the options we'd like to
       enable, so it will correctly fail all of the option tests.

       Sshd will either complain about the first invalid option that is
       passed with -o, or it will complain about all invalid options. -o
       BadOption=yes is passed to verify that sshd understands -o, and to
       make doubly sure that it will not start listening on a port.

       The -v option can be used to test whether ssh (the client) supports
       given options.  Passing -v to ssh will cause it to print out its
       version number and not attempt to connect to a machine. All versions of
       ssh seem to parse the options passed with -o even when -v is passed.

       Ssh will either complain about the first invalid option that is
       passed with -o, or it will complain about all invalid options. -o
       BadOption=yes is passed to verify that ssh understands -o.
     */
    LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
        &command, "%s%s %s -o %s=yes -o BadOption=yes 2>&1",
        rootPrefix, binary, testFlag, optionName));

    ceError = CTCaptureOutput(command, &commandOutput);
    /* Some versions of sshd will return an error code because an invalid
       option was passed, but not all will. */
    if(ceError == ERROR_BAD_COMMAND)
        ceError = ERROR_SUCCESS;
    LW_CLEANUP_CTERR(exc, ceError);

    if(strstr(commandOutput, optionName) != NULL)
    {
        DJ_LOG_INFO("Option %s not supported", optionName);
        goto cleanup;
    }

    if(strstr(commandOutput, "BadOption") == NULL)
    {
        DJ_LOG_INFO("Sshd does not support -o");
        goto cleanup;
    }

    DJ_LOG_INFO("Option %s supported", optionName);
    result = TRUE;

cleanup:
    CT_SAFE_FREE_STRING(command);
    CT_SAFE_FREE_STRING(commandOutput);
    return result;
}
예제 #12
0
파일: djsshconf.c 프로젝트: Brainiarc7/pbis
/* Copy a ssh configuration line and add it below the old line. */
static DWORD SetOption(struct SshConf *conf, const char *name, const char *value)
{
    DWORD ceError = ERROR_SUCCESS;
    int line = -1;
    DynamicArray printedLine;
    struct SshLine lineObj;
    int found = 0;

    memset(&lineObj, 0, sizeof(struct SshLine));
    memset(&printedLine, 0, sizeof(printedLine));

    for(line = 0; line < conf->lineCount; line++)
    {
        line = FindOption(conf, line, name);
        if(line == -1)
            break;
        found++;
        if(!strcmp(conf->lines[line].value.value, value))
            continue;

        //Insert a commented out version of the line
        BAIL_ON_CENTERIS_ERROR(ceError = GetPrintedLine(&printedLine, conf, line));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.leadingWhiteSpace));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.name.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.name.trailingSeparator));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.value.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTAllocateStringPrintf(
            &lineObj.value.trailingSeparator,
            "#Overwritten by lwidentity: %s",
            printedLine.data));
        BAIL_ON_CENTERIS_ERROR(ceError = CTArrayInsert(&conf->private_data,
                    line, sizeof(struct SshLine), &lineObj, 1));
        memset(&lineObj, 0, sizeof(lineObj));
        UpdatePublicLines(conf);
        conf->modified = 1;
        line++;

        //Change the option value of the line
        CT_SAFE_FREE_STRING(conf->lines[line].value.value);
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(value,
            &conf->lines[line].value.value));
    }

    /*If the option wasn't already in the file, search for comments that
      mention the option, and insert the line after the comment*/
    for(line = 0; !found && line < conf->lineCount; line++)
    {
        if(strstr(conf->lines[line].value.trailingSeparator, name) == NULL)
            continue;

        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.leadingWhiteSpace));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(name,
            &lineObj.name.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(" ",
            &lineObj.name.trailingSeparator));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(value,
            &lineObj.value.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.value.trailingSeparator));
        BAIL_ON_CENTERIS_ERROR(ceError = CTArrayInsert(&conf->private_data,
                    line + 1, sizeof(struct SshLine), &lineObj, 1));
        memset(&lineObj, 0, sizeof(lineObj));
        conf->modified = 1;
        found++;
    }

    /*If the option wasn't even in a comment, just add the option at the
      end of the file
      */
    if(!found)
    {
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.leadingWhiteSpace));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(name,
            &lineObj.name.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(" ",
            &lineObj.name.trailingSeparator));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup(value,
            &lineObj.value.value));
        BAIL_ON_CENTERIS_ERROR(ceError = CTStrdup("",
            &lineObj.value.trailingSeparator));
        BAIL_ON_CENTERIS_ERROR(ceError = CTArrayAppend(&conf->private_data,
                    sizeof(struct SshLine), &lineObj, 1));
        memset(&lineObj, 0, sizeof(lineObj));
        conf->modified = 1;
    }

error:
    UpdatePublicLines(conf);
    FreeSshLineContents(&lineObj);
    CTArrayFree(&printedLine);
    return ceError;
}
예제 #13
0
bool Options::Load (int argc_, char* argv_[])
{
    FILE* hfOptions = fopen(OSD::MakeFilePath(MFP_SETTINGS, OPTIONS_FILE), "r");
    if (hfOptions)
    {
        char szLine[256];
        while (fgets(szLine, sizeof(szLine), hfOptions))
        {
            char *pszValue = strchr(szLine, '=');
            char *pszName = strtok(szLine, " \t=");

            if (!pszName || !pszValue)
                continue;

            // Skip delimiters up to the value, and take the value up to a <CR> or <LF>
            pszValue++;
            strtok(pszValue += strspn(pszValue, " \t=\r\n"), "\r\n");

            // Look for the option in the list
            for (OPTION* p = aOptions ; p->pcszName ; p++)
            {
                if (!strcasecmp(pszName, p->pcszName))
                {
                    // Remember that a value has been found for this option
                    p->fSpecified = true;

                    // Extract the appropriate value type from the string
                    switch (p->nType)
                    {
                        case OT_BOOL:       *p->pf = *pszValue ? IsTrue(pszValue) : p->fDefault;    break;
                        case OT_INT:        *p->pn = *pszValue ? atoi(pszValue) : p->nDefault;      break;
                        case OT_STRING:     strcpy(p->ppsz, *pszValue ? pszValue : p->pcszDefault); break;
                    }
                }
            }
        }

        // We're done with the file
        fclose(hfOptions);
    }

    // Set the default values for any missing options, or all if the config version has changed
    bool fIncompatible = GetOption(cfgversion) != CFG_VERSION;
    SetDefaults(fIncompatible);

    // Process any commmand-line arguments to look for options
    while (argc_ && --argc_)
    {
        const char* pcszOption = *++argv_;
        if (*pcszOption == '-')
        {
            // Find the option in the list of known options
            OPTION* p = FindOption(pcszOption+1);

            if (p)
            {
                switch (p->nType)
                {
                    case OT_BOOL:   *p->pf = (argv_[1] && *argv_[1] == '-') || (argc_-- && IsTrue(*++argv_)); continue;
                    case OT_INT:    *p->pn = atoi(*++argv_);    break;
                    case OT_STRING: strcpy(p->ppsz, *++argv_);  break;
                }

                argc_--;
            }
            else
                TRACE("Unknown command-line option: %s\n", pcszOption);
        }
        else
        {
            static int nDrive = 1;

            // Bare filenames will be inserted into drive 1 then 2
            switch (nDrive++)
            {
                case 1:
                    SetOption(disk1, pcszOption);
                    SetOption(drive1,drvFloppy);
                    g_nAutoLoad = AUTOLOAD_DISK;
                    break;

                case 2:
                    SetOption(disk2, pcszOption);
                    SetOption(drive2,drvFloppy);
                    break;

                default:
                    TRACE("Unexpected command-line parameter: %s\n", pcszOption);
                    break;
            }
        }
    }

    return true;
}
예제 #14
0
    static bool ParseLongOption(
        const CommandLineOptionDefinition* options, CommandLineArgEnumerator* argEnumerator, const char* argument)
    {
        // Get just the option name
        char optionName[64];
        const char* equalsCh = strchr(argument, '=');
        if (equalsCh != nullptr)
        {
            String::Set(optionName, sizeof(optionName), argument, equalsCh - argument);
        }
        else
        {
            String::Set(optionName, sizeof(optionName), argument);
        }

        // Find a matching option definition
        const CommandLineOptionDefinition* option = FindOption(options, optionName);
        if (option == nullptr)
        {
            Console::Error::WriteLine("Unknown option: --%s", optionName);
            return false;
        }

        if (equalsCh == nullptr)
        {
            if (option->Type == CMDLINE_TYPE_SWITCH)
            {
                ParseOptionValue(option, nullptr);
            }
            else
            {
                const char* valueString = nullptr;
                if (!argEnumerator->TryPopString(&valueString))
                {
                    Console::Error::WriteLine("Expected value for option: %s", optionName);
                    return false;
                }

                if (!ParseOptionValue(option, valueString))
                {
                    return false;
                }
            }
        }
        else
        {
            if (option->Type == CMDLINE_TYPE_SWITCH)
            {
                Console::Error::WriteLine("Option is a switch: %s", optionName);
                return false;
            }
            else
            {
                if (!ParseOptionValue(option, equalsCh + 1))
                {
                    return false;
                }
            }
        }

        return true;
    }