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

📄 snort_ftptelnet.c

📁 snort2.8.4版本
💻 C
📖 第 1 页 / 共 5 页
字号:
        if (FTPCmd == NULL)        {            /* Add it to the list  */            FTPCmd = (FTP_CMD_CONF *)calloc(1, sizeof(FTP_CMD_CONF));            if (FTPCmd == NULL)            {                DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                                *(_dpd.config_file), *(_dpd.config_line));            }            strncpy(FTPCmd->cmd_name, cmd, sizeof(FTPCmd->cmd_name) - 1);            FTPCmd->cmd_name[sizeof(FTPCmd->cmd_name) - 1] = '\0';                        FTPCmd->max_param_len = ServerConf->def_max_param_len;            ftp_cmd_lookup_add(ServerConf->cmd_lookup, cmd,                               strlen(cmd), FTPCmd);        }        pcToken = NextToken(CONF_SEPARATORS);        if (!pcToken)        {            snprintf(ErrorString, ErrStrLen,                    "FTP Dir Cmds must have associated response code: '%s'.",                    cmd);            return FTPP_FATAL_ERR;        }        iCode = strtol(pcToken, &pcEnd, 10);        /*         * 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;}static int ProcessFTPIgnoreDataChan(FTP_SERVER_PROTO_CONF *ServerConf,                                    char *confOption,                                    char *ErrorString, int ErrStrLen){    char *pcToken;    pcToken = NextToken(CONF_SEPARATORS);    if (pcToken == NULL)    {        snprintf(ErrorString, ErrStrLen, "No argument provided to option '%s'. "                                         "Argument must be 'yes' or 'no'.",                                         confOption);        return FTPP_FATAL_ERR;    }    if (!strcasecmp("yes", pcToken))    {        ServerConf->data_chan = 1;    }    else if (!strcasecmp("no", pcToken))    {        if (ServerConf->data_chan == 1)        {            snprintf(ErrorString, ErrStrLen, "Both 'data_chan' and "            "'ignore_data_chan' configured with conflicting options.");            return FTPP_FATAL_ERR;        }        ServerConf->data_chan = 0;    }    else    {        snprintf(ErrorString, ErrStrLen, "Invalid argument to token '%s'. "                 "Argument must be 'yes' or 'no'.", confOption);        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;

⌨️ 快捷键说明

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