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

📄 snort_ftptelnet.c

📁 snort2.8.4版本
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    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);            ThisFmt->choices = tmpChoices;            NextFmt->prev_param_fmt = ThisFmt;            iRet = DoNextFormat(NextFmt, 1, ErrorString, ErrStrLen);            numChoices++;        }        while (iRet == FTPP_OR_FOUND);        if (iRet != FTPP_CHOICE_END_FOUND)        {            return FTPP_INVALID_ARG;        }        return DoNextFormat(ThisFmt, 0, ErrorString, ErrStrLen);    }    if (!allocated)    {        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));        }        NextFmt->prev_param_fmt = ThisFmt;        ThisFmt->next_param_fmt = NextFmt;        if (ThisFmt->optional)            NextFmt->prev_optional = 1;    }    else    {        NextFmt = ThisFmt;    }    /* If its not an end cmd, OR, START/END Opt...     * it must be a parameter specification.     */    /* Setup the type & format specs  */    if (!strcmp(fmt, F_INT))    {        NextFmt->type = e_int;    }    else if (!strcmp(fmt, F_NUMBER))    {        NextFmt->type = e_number;    }    else if (!strcmp(fmt, F_CHAR))    {        char *chars_allowed = NextToken(CONF_SEPARATORS);        NextFmt->type = e_char;        NextFmt->format.chars_allowed = 0;        while (*chars_allowed != 0)        {            int bitNum = (*chars_allowed & 0x1f);            NextFmt->format.chars_allowed |= (1 << (bitNum-1));            chars_allowed++;        }    }    else if (!strcmp(fmt, F_DATE))    {        FTP_DATE_FMT *DateFmt;        char *format = NextToken(CONF_SEPARATORS);        NextFmt->type = e_date;        DateFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));        if (DateFmt == NULL)        {            DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                            *(_dpd.config_file), *(_dpd.config_line));        }        NextFmt->format.date_fmt = DateFmt;        iRet = ProcessDateFormat(DateFmt, NULL, &format);        if (iRet)        {            snprintf(ErrorString, ErrStrLen,                    "Illegal format %s for token '%s'.",                    format, CMD_VALIDITY);            return FTPP_INVALID_ARG;        }    }    else if ( *fmt == *F_LITERAL )    {        char* end = index(++fmt, *F_LITERAL);        int len = end ? end - fmt : 0;            if ( len < 1 )        {            snprintf(                 ErrorString, ErrStrLen,                 "Illegal format '' for token '%s'.", CMD_VALIDITY            );            return FTPP_INVALID_ARG;        }        NextFmt->type = e_literal;        NextFmt->format.literal = (char *)calloc(1, len+1);        if ( !NextFmt->format.literal )        {            DynamicPreprocessorFatalMessage(                "%s(%d) => Failed to allocate memory\n",                *(_dpd.config_file), *(_dpd.config_line)            );        }        strncpy(NextFmt->format.literal, fmt, len);        NextFmt->format.literal[len] = '\0';    }    else if (!strcmp(fmt, F_STRING))    {        NextFmt->type = e_unrestricted;    }    else if (!strcmp(fmt, F_HOST_PORT))    {        NextFmt->type = e_host_port;    }    else if (!strcmp(fmt, F_LONG_HOST_PORT))    {        NextFmt->type = e_long_host_port;    }    else if (!strcmp(fmt, F_EXTD_HOST_PORT))    {        NextFmt->type = e_extd_host_port;    }    else    {        snprintf(ErrorString, ErrStrLen,                "Illegal format type %s for token '%s'.",                fmt, CMD_VALIDITY);        return FTPP_INVALID_ARG;    }    return DoNextFormat(NextFmt, 0, ErrorString, ErrStrLen);}/*  * Function: ProcessFTPCmdValidity(FTP_SERVER_PROTO_CONF *ServerConf, *                              char *ErrorString, int ErrStrLen) * * Purpose: Process the ftp cmd validity configuration. *          This sets the FTP command parameter validation tree. * * Arguments: ServerConf    => pointer to the FTP server configuration *            confOption    => pointer to the name of the option *            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) * */static int ProcessFTPCmdValidity(FTP_SERVER_PROTO_CONF *ServerConf,                              char *ErrorString, int ErrStrLen){    FTP_CMD_CONF *FTPCmd = NULL;    FTP_PARAM_FMT *HeadFmt = NULL;    char *cmd;    char *fmt;    int iRet;    fmt = NextToken(CONF_SEPARATORS);    if(fmt == NULL)    {        snprintf(ErrorString, ErrStrLen,                "No argument to token '%s'.", CMD_VALIDITY);        return FTPP_FATAL_ERR;    }    cmd = fmt;    if (strlen(cmd) > 4)    {        snprintf(ErrorString, ErrStrLen,                "FTP Commands are no longer than 4 characters: '%s'.",                cmd);        return FTPP_FATAL_ERR;    }    fmt = NextToken(CONF_SEPARATORS);    if(!fmt)    {        snprintf(ErrorString, ErrStrLen,                "Invalid cmd validity format.");        return FTPP_FATAL_ERR;    }    if(strcmp(START_CMD_FORMAT, fmt))    {        snprintf(ErrorString, ErrStrLen,                "Must start a cmd validity with the '%s' token.",                START_CMD_FORMAT);        return FTPP_FATAL_ERR;    }    HeadFmt = (FTP_PARAM_FMT *)calloc(1, sizeof(FTP_PARAM_FMT));    if (HeadFmt == NULL)    {        DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory\n",                                        *(_dpd.config_file), *(_dpd.config_line));    }    HeadFmt->type = e_head;    iRet = DoNextFormat(HeadFmt, 0, ErrorString, ErrStrLen);    /* Need to check to be sure we got a complete command  */    if (iRet)    {        return FTPP_FATAL_ERR;    }    SetOptionalsNext(HeadFmt, NULL, NULL, 0);    FTPCmd = ftp_cmd_lookup_find(ServerConf->cmd_lookup, cmd,                                 strlen(cmd), &iRet);    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);    }    FTPCmd->check_validity = 1;    if (FTPCmd->param_format)    {        ftpp_ui_config_reset_ftp_cmd_format(FTPCmd->param_format);        FTPCmd->param_format = NULL;    }    FTPCmd->param_format = HeadFmt;    return FTPP_SUCCESS;}/* * Function: PrintFormatDate(FTP_DATE_FMT *DateFmt) * * Purpose: Recursively prints the FTP date validation tree * * Arguments: DateFmt       => pointer to the date format node * * Returns: None * */static void PrintFormatDate(char *buf, FTP_DATE_FMT *DateFmt){    FTP_DATE_FMT *OptChild;    if (!DateFmt->empty)        _dpd.printfappend(buf, BUF_SIZE, "%s", DateFmt->format_string);    if (DateFmt->optional)    {        OptChild = DateFmt->optional;        _dpd.printfappend(buf, BUF_SIZE, "[");        PrintFormatDate(buf, OptChild);        _dpd.printfappend(buf, BUF_SIZE, "]");    }    if (DateFmt->next_a)    {        if (DateFmt->next_b)            _dpd.printfappend(buf, BUF_SIZE, "{");        OptChild = DateFmt->next_a;        PrintFormatDate(buf, OptChild);        if (DateFmt->next_b)        {            _dpd.printfappend(buf, BUF_SIZE, "|");            OptChild = DateFmt->next_b;            PrintFormatDate(buf, OptChild);            _dpd.printfappend(buf, BUF_SIZE, "}");        }    }    if (DateFmt->next)        PrintFormatDate(buf, DateFmt->next);}/* * Function: PrintCmdFmt(FTP_PARAM_FMT *CmdFmt) * * Purpose: Recursively prints the FTP command parameter validation tree * * Arguments: CmdFmt       => pointer to the parameter validation node * * Returns: None * */static void PrintCmdFmt(char *buf, FTP_PARAM_FMT *CmdFmt){    FTP_PARAM_FMT *OptChild;    switch(CmdFmt->type)    {    case e_int:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_INT);        break;    case e_number:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_NUMBER);        break;    case e_char:        _dpd.printfappend(buf, BUF_SIZE, " %s 0x%x", F_CHAR,            CmdFmt->format.chars_allowed);        break;    case e_date:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_DATE);        PrintFormatDate(buf, CmdFmt->format.date_fmt);        break;    case e_literal:        _dpd.printfappend(buf, BUF_SIZE, " %s 0x%x", F_LITERAL,                CmdFmt->format.literal);        break;    case e_unrestricted:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_STRING);        break;    case e_strformat:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_STRING_FMT);        break;    case e_host_port:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_HOST_PORT);        break;    case e_long_host_port:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_LONG_HOST_PORT);        break;    case e_extd_host_port:        _dpd.printfappend(buf, BUF_SIZE, " %s", F_EXTD_HOST_PORT);        break;    case e_head:        break;    default:    	break;    }    if (CmdFmt->optional_fmt)    {        OptChild = CmdFmt->optional_fmt;        _dpd.printfappend(buf, BUF_SIZE, "[");        PrintCmdFmt(buf, OptChild);        _dpd.printfappend(buf, BUF_SIZE, "]");    }    if (CmdFmt->numChoices)    {        int i;        _dpd.printfappend(buf, BUF_SIZE, "{");        for (i=0;i<CmdFmt->numChoices;i++)        {            if (i)                _dpd.printfappend(buf, BUF_SIZE, "|");            OptC

⌨️ 快捷键说明

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