⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snort_ftptelnet.c

📁 入侵检测SNORT.最近更新的基于网络检测的IDS.希望能给大家带来方便.
💻 C
📖 第 1 页 / 共 5 页
字号:
         * Let's check to see if the entire string was valid.         * If there is an address here, then there was an         * invalid character in the string.         */        if((*pcEnd) || (iCode < 0))        {            snprintf(ErrorString, ErrStrLen,                    "Invalid argument to token '%s'.  "                    "Code must be a positive number",                    confOption);            return FTPP_FATAL_ERR;        }        FTPCmd->dir_response = iCode;    }    if(!iEndCmds)    {        snprintf(ErrorString, ErrStrLen,                "Must end '%s' configuration with '%s'.",                confOption, END_PORT_LIST);        return FTPP_FATAL_ERR;    }    return FTPP_SUCCESS;}/* * Function: SetOptionalsNext(FTP_PARAM_FMT *ThisFmt, *                            FTP_PARAM_FMT *NextFmt, *                            FTP_PARAM_FMT **choices, *                            int numChoices) * * Purpose: Recursively updates the next value for nodes in the FTP *          Parameter validation tree. * * Arguments: ThisFmt       => pointer to an FTP parameter validation node *            NextFmt       => pointer to an FTP parameter validation node *            choices       => pointer to a list of FTP parameter *                             validation nodes *            numChoices    => the number of nodes in the list * * Returns: int     => an error code integer (0 = success, *                     >0 = non-fatal error, <0 = fatal error) * */static void SetOptionalsNext(FTP_PARAM_FMT *ThisFmt, FTP_PARAM_FMT *NextFmt,                             FTP_PARAM_FMT **choices, int numChoices){    if (!ThisFmt)        return;    if (ThisFmt->optional)    {        if (ThisFmt->next_param_fmt == NULL)        {            ThisFmt->next_param_fmt = NextFmt;            if (numChoices)            {                ThisFmt->numChoices = numChoices;                ThisFmt->choices = (FTP_PARAM_FMT **)calloc(numChoices, sizeof(FTP_PARAM_FMT *));                if (ThisFmt->choices == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                                memcpy(ThisFmt->choices, choices, sizeof(FTP_PARAM_FMT *) * numChoices);            }        }        else        {            SetOptionalsNext(ThisFmt->next_param_fmt, NextFmt,                choices, numChoices);        }    }    else    {        int i;        SetOptionalsNext(ThisFmt->optional_fmt, ThisFmt->next_param_fmt,            ThisFmt->choices, ThisFmt->numChoices);        for (i=0;i<ThisFmt->numChoices;i++)        {            SetOptionalsNext(ThisFmt->choices[i], ThisFmt,                choices, numChoices);        }        SetOptionalsNext(ThisFmt->next_param_fmt, ThisFmt,            choices, numChoices);    }}/* * Function: ProcessDateFormat(FTP_DATE_FMT *dateFmt, *                             FTP_DATE_FMT *LastNonOptFmt, *                             char **format) * * Purpose: Sets the value for nodes in the FTP Date validation tree. * * Arguments: dateFmt       => pointer to an FTP date validation node *            LastNonOptFmt => pointer to previous FTP date validation node *            format        => pointer to next part of date validation string *                             Updated on function exit. * * Returns: int     => an error code integer (0 = success, *                     >0 = non-fatal error, <0 = fatal error) * */static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,                             FTP_DATE_FMT *LastNonOptFmt,                             char **format){    char *curr_format;    int iRet = FTPP_SUCCESS;    int curr_len = 0;    char *curr_ch;    char *start_ch;    FTP_DATE_FMT *CurrFmt = dateFmt;    if (!dateFmt)        return FTPP_INVALID_ARG;    if (!format || !*format)        return FTPP_INVALID_ARG;    start_ch = curr_ch = *format;    while (*curr_ch != '\0')    {        switch (*curr_ch)        {        case 'n':        case 'C':        case '+':        case '-':        case '.':            curr_len++;            curr_ch++;            break;        case '[':            curr_ch++;            if (curr_len > 0)            {                FTP_DATE_FMT *OptFmt;                OptFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));                if (OptFmt == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                curr_format = (char *)calloc(curr_len + 1, sizeof(char));                if (curr_format == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                strncpy(curr_format, start_ch, curr_len);                CurrFmt->format_string = curr_format;                curr_len = 0;                CurrFmt->optional = OptFmt;                OptFmt->prev = CurrFmt;                iRet = ProcessDateFormat(OptFmt, CurrFmt, &curr_ch);                if (iRet != FTPP_SUCCESS)                {                    free(OptFmt);                    free(curr_format);                    return iRet;                }            }            start_ch = curr_ch;            break;        case ']':            curr_ch++;            if (curr_len > 0)            {                curr_format = (char *)calloc(curr_len + 1, sizeof(char));                if (curr_format == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                strncpy(curr_format, start_ch, curr_len);                CurrFmt->format_string = curr_format;                curr_len = 0;            }            *format = curr_ch;            return FTPP_SUCCESS;            break;        case '{':            curr_ch++;            {                FTP_DATE_FMT *NewFmt;                NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));                if (NewFmt == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                if (curr_len > 0)                {                    curr_format = (char *)calloc(curr_len + 1, sizeof(char));                    if (curr_format == NULL)                    {                        DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                        *(_dpd.config_file), *(_dpd.config_line));                    }                    strncpy(curr_format, start_ch, curr_len);                    CurrFmt->format_string = curr_format;                    curr_len = 0;                }                else                {                    CurrFmt->empty = 1;                }                NewFmt->prev = LastNonOptFmt;                CurrFmt->next_a = NewFmt;                iRet = ProcessDateFormat(NewFmt, CurrFmt, &curr_ch);                if (iRet != FTPP_SUCCESS)                {                    return iRet;                }                NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));                if (NewFmt == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                NewFmt->prev = LastNonOptFmt;                CurrFmt->next_b = NewFmt;                iRet = ProcessDateFormat(NewFmt, CurrFmt, &curr_ch);                if (iRet != FTPP_SUCCESS)                {                    return iRet;                }                if (curr_ch != NULL)                {                    NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));                    if (NewFmt == NULL)                    {                        DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                        *(_dpd.config_file), *(_dpd.config_line));                    }                    NewFmt->prev = CurrFmt;                    CurrFmt->next = NewFmt;                    iRet = ProcessDateFormat(NewFmt, CurrFmt, &curr_ch);                    if (iRet != FTPP_SUCCESS)                    {                        return iRet;                    }                }            }            break;        case '}':            curr_ch++;            if (curr_len > 0)            {                curr_format = (char *)calloc(curr_len + 1, sizeof(char));                if (curr_format == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                strncpy(curr_format, start_ch, curr_len);                CurrFmt->format_string = curr_format;                curr_len = 0;                *format = curr_ch;                return FTPP_SUCCESS;            }            else            {                CurrFmt->empty = 1;                *format = curr_ch;                return FTPP_SUCCESS;            }            break;        case '|':            curr_ch++;            if (curr_len > 0)            {                curr_format = (char *)calloc(curr_len + 1, sizeof(char));                if (curr_format == NULL)                {                    DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                    *(_dpd.config_file), *(_dpd.config_line));                }                strncpy(curr_format, start_ch, curr_len);                CurrFmt->format_string = curr_format;                curr_len = 0;                *format = curr_ch;                return FTPP_SUCCESS;            }            else            {                CurrFmt->empty = 1;                *format = curr_ch;                return FTPP_SUCCESS;            }            break;        default:            /* Uh, shouldn't get this.  */            return FTPP_INVALID_ARG;            break;        }    }    if (curr_len > 0)    {        curr_format = (char *)calloc(curr_len + 1, sizeof(char));        if (curr_format == NULL)        {            DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                            *(_dpd.config_file), *(_dpd.config_line));        }        strncpy(curr_format, start_ch, curr_len);        CurrFmt->format_string = curr_format;        start_ch = curr_ch;        curr_len = 0;    }    /* Should've closed all options & ORs  */    *format = curr_ch;    return FTPP_SUCCESS;}/* * Function: DoNextFormat(FTP_PARAM_FMT *ThisFmt, int allocated, *                 char *ErrorString, int ErrStrLen) * * Purpose: Processes the next FTP parameter validation node. * * Arguments: ThisFmt       => pointer to an FTP parameter validation node *            allocated     => indicator whether the next node is allocated *            ErrorString   => error string buffer *            ErrStrLen     => the length of the error string buffer * * Returns: int     => an error code integer (0 = success, *                     >0 = non-fatal error, <0 = fatal error) * */int DoNextFormat(FTP_PARAM_FMT *ThisFmt, int allocated,                 char *ErrorString, int ErrStrLen){    FTP_PARAM_FMT *NextFmt;    int iRet = FTPP_SUCCESS;    char *fmt = NextToken(CONF_SEPARATORS);    if (!fmt)        return FTPP_INVALID_ARG;    if(!strcmp(END_CMD_FORMAT, fmt))    {        return FTPP_SUCCESS;    }    if (!strcmp(fmt, OR_FMT))    {        return FTPP_OR_FOUND;    }    if (!strcmp(fmt, END_OPT_FMT))    {        return FTPP_OPT_END_FOUND;    }    if (!strcmp(fmt, END_CHOICE_FMT))    {        return FTPP_CHOICE_END_FOUND;    }    if (!strcmp(fmt, START_OPT_FMT))    {        NextFmt = (FTP_PARAM_FMT *)calloc(1, sizeof(FTP_PARAM_FMT));        if (NextFmt == NULL)        {            DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                            *(_dpd.config_file), *(_dpd.config_line));        }        ThisFmt->optional_fmt = NextFmt;        NextFmt->optional = 1;        NextFmt->prev_param_fmt = ThisFmt;        if (ThisFmt->optional)            NextFmt->prev_optional = 1;        iRet = DoNextFormat(NextFmt, 1, ErrorString, ErrStrLen);        if (iRet != FTPP_OPT_END_FOUND)        {            return FTPP_INVALID_ARG;        }        return DoNextFormat(ThisFmt, 0, ErrorString, ErrStrLen);    }    if (!strcmp(fmt, START_CHOICE_FMT))    {        int numChoices = 1;        do        {            FTP_PARAM_FMT **tmpChoices = (FTP_PARAM_FMT **)calloc(numChoices, sizeof(FTP_PARAM_FMT *));            if (tmpChoices == NULL)            {                DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                *(_dpd.config_file), *(_dpd.config_line));            }            if (ThisFmt->numChoices)            {                /* explicit check that we have enough room for copy */                if (numChoices <= ThisFmt->numChoices)                    DynamicPreprocessorFatalMessage("%s(%d) => Can't do memcpy - index out of range \n",                                                    *(_dpd.config_file), *(_dpd.config_line));                memcpy(tmpChoices, ThisFmt->choices,                     sizeof(FTP_PARAM_FMT*) * ThisFmt->numChoices);            }            NextFmt = (FTP_PARAM_FMT *)calloc(1, sizeof(FTP_PARAM_FMT));            if (NextFmt == NULL)            {                DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                *(_dpd.config_file), *(_dpd.config_line));            }            ThisFmt->numChoices = numChoices;            tmpChoices[numChoices-1] = NextFmt;            if (ThisFmt->choices)                free(ThisFmt->choices);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -