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

📄 snort_httpinspect.c

📁 Linux snort-2.4.4源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
                              char *ErrorString, int ErrStrLen){    char *pcToken;    char *pcEnd;    int  iDirLen;    pcToken = strtok(NULL, CONF_SEPARATORS);    if(pcToken == NULL)    {        snprintf(ErrorString, ErrStrLen,                 "No argument to token '%s'.", OVERSIZE_DIR);        return -1;    }    /*    **  Grab the oversize directory length    */    iDirLen = strtol(pcToken, &pcEnd, 10);    if(*pcEnd || iDirLen < 0)    {        snprintf(ErrorString, ErrStrLen,                 "Invalid argument to token '%s'.", OVERSIZE_DIR);                return -1;    }    ServerConf->long_dir = iDirLen;    return 0;}/***  NAME**      ProcessGlobalConf::*//****  This is where we process the global configuration for HttpInspect.****  We set the values of the global configuraiton here.  Any errors that**  are encountered are specified in the error string and the type of**  error is returned through the return code, i.e. fatal, non-fatal.****  The configuration options that are dealt with here are:**      - global_alert**          This tells us whether to do any internal alerts or not, on**          a global scale.**      - max_pipeline**          Tells HttpInspect how many pipeline requests to buffer looking**          for a response before inspection.**      - inspection_type**          What type of inspection for HttpInspect to do, stateless or**          stateful.****  @param GlobalConf  pointer to the global configuration**  @param ErrorString error string buffer**  @param ErrStrLen   the lenght of the error string buffer****  @return an error code integer **          (0 = success, >0 = non-fatal error, <0 = fatal error)****  @retval  0 successs**  @retval -1 generic fatal error**  @retval  1 generic non-fatal error*/static int ProcessGlobalConf(HTTPINSPECT_GLOBAL_CONF *GlobalConf,                             char *ErrorString, int ErrStrLen){    int  iRet;    char *pcToken;    int  iTokens = 0;    while((pcToken = strtok(NULL, CONF_SEPARATORS)))    {        /*        **  Show that we at least got one token        */        iTokens = 1;        /*        **  Search for configuration keywords        */        if(!strcmp(MAX_PIPELINE, pcToken))        {            if((iRet = ProcessMaxPipeline(GlobalConf, ErrorString, ErrStrLen)))            {                return iRet;            }        }        else if(!strcmp(INSPECT_TYPE, pcToken))        {            if((iRet = ProcessInspectType(GlobalConf, ErrorString, ErrStrLen)))            {                return iRet;            }        }        else if(!strcmp(IIS_UNICODE_MAP, pcToken))        {            if((iRet = ProcessIISUnicodeMap(&GlobalConf->iis_unicode_map,                                         &GlobalConf->iis_unicode_map_filename,                                            &GlobalConf->iis_unicode_codepage,                                            ErrorString,ErrStrLen)))            {                return iRet;            }        }        else if(!strcmp(ANOMALOUS_SERVERS, pcToken))        {            /*            **  This is easy to configure since we just look for the token            **  and turn on the option.            */            GlobalConf->anomalous_servers = 1;        }        else if(!strcmp(PROXY_ALERT, pcToken))        {            GlobalConf->proxy_alert = 1;        }        else        {            snprintf(ErrorString, ErrStrLen,                    "Invalid keyword '%s' for '%s' configuration.",                      pcToken, GLOBAL);            return -1;        }    }    /*    **  If there are not any tokens to the configuration, then    **  we let the user know and log the error.  return non-fatal    **  error.    */    if(!iTokens)    {        snprintf(ErrorString, ErrStrLen,                "No tokens to '%s' configuration.", GLOBAL);        return -1;    }    /*    **  Let's check to make sure that we get a default IIS Unicode Codemap    */    if(!GlobalConf->iis_unicode_map)    {        snprintf(ErrorString, ErrStrLen,                 "Global configuration must contain an IIS Unicode Map "                 "configuration.  Use token '%s'.", IIS_UNICODE_MAP);        return -1;    }    return 0;}/***  NAME**    ProcessProfile::*//****  Process the PROFILE configuration.****  This function verifies that the argument to the profile configuration**  is valid.  We also check to make sure there is no additional**  configuration after the PROFILE.  This is no allowed, so we**  alert on that fact.****  @param ServerConf  pointer to the server configuration**  @param ErrorString error string buffer**  @param ErrStrLen   the length of the error string buffer****  @return an error code integer **          (0 = success, >0 = non-fatal error, <0 = fatal error)****  @retval  0 successs**  @retval -1 generic fatal error**  @retval  1 generic non-fatal error*/static int ProcessProfile(HTTPINSPECT_GLOBAL_CONF *GlobalConf,                          HTTPINSPECT_CONF *ServerConf,                          char *ErrorString, int ErrStrLen){    char *pcToken;    int  iRet;    pcToken = strtok(NULL, CONF_SEPARATORS);    if(pcToken == NULL)    {        snprintf(ErrorString, ErrStrLen,                "No argument to '%s'.", PROFILE);        return -1;    }    /*    **  Load the specific type of profile    */    if(!strcmp(APACHE, pcToken))    {        if((iRet = hi_ui_config_set_profile_apache(ServerConf)))        {            if(iRet == HI_MEM_ALLOC_FAIL)            {                snprintf(ErrorString, ErrStrLen,                        "Memory allocation failed while setting the '%s' "                        "profile.", APACHE);                return -1;            }            else            {                snprintf(ErrorString, ErrStrLen,                        "Undefined error code for set_profile_apache.");                return -1;            }        }    }    else if(!strcmp(IIS, pcToken))    {        if((iRet = hi_ui_config_set_profile_iis(ServerConf,                                                 GlobalConf->iis_unicode_map)))        {            if(iRet == HI_MEM_ALLOC_FAIL)            {                snprintf(ErrorString, ErrStrLen,                        "Memory allocation failed while setting the '%s' "                        "profile.", IIS);                return -1;            }            else            {                snprintf(ErrorString, ErrStrLen,                        "Undefined error code for set_profile_iis.");                return -1;            }        }    }    else if(!strcmp(ALL, pcToken))    {        if((iRet = hi_ui_config_set_profile_all(ServerConf,                                                GlobalConf->iis_unicode_map)))        {            if(iRet == HI_MEM_ALLOC_FAIL)            {                snprintf(ErrorString, ErrStrLen,                        "Memory allocation failed while setting the '%s' "                        "profile.", ALL);                return -1;            }            else            {                snprintf(ErrorString, ErrStrLen,                        "Undefined error code for set_profile_all.");                return -1;            }        }    }    else    {        snprintf(ErrorString, ErrStrLen,                "Invalid profile argument '%s'.", pcToken);        return -1;    }    return 0;}/***  NAME**    ProcessPorts::*//****  Process the port list for the server configuration.****  This configuration is a list of valid ports and is ended by a **  delimiter.****  @param ServerConf  pointer to the server configuration**  @param ErrorString error string buffer**  @param ErrStrLen   the length of the error string buffer****  @return an error code integer **          (0 = success, >0 = non-fatal error, <0 = fatal error)****  @retval  0 successs**  @retval -1 generic fatal error**  @retval  1 generic non-fatal error*/static int ProcessPorts(HTTPINSPECT_CONF *ServerConf,                        char *ErrorString, int ErrStrLen){    char *pcToken;    char *pcEnd;    int  iPort;    int  iEndPorts = 0;    pcToken = strtok(NULL, CONF_SEPARATORS);    if(!pcToken)    {        snprintf(ErrorString, ErrStrLen,                "Invalid port list format.");        return -1;    }    if(strcmp(START_PORT_LIST, pcToken))    {        snprintf(ErrorString, ErrStrLen,                "Must start a port list with the '%s' token.",                START_PORT_LIST);        return -1;    }        while((pcToken = strtok(NULL, CONF_SEPARATORS)))    {        if(!strcmp(END_PORT_LIST, pcToken))        {            iEndPorts = 1;            break;        }        iPort = strtol(pcToken, &pcEnd, 10);        /*        **  Validity check for port        */        if(*pcEnd)        {            snprintf(ErrorString, ErrStrLen,                    "Invalid port number.");            return -1;        }        if(iPort < 0 || iPort > 65535)        {            snprintf(ErrorString, ErrStrLen,                    "Invalid port number.  Must be between 0 and "                    "65535.");            return -1;        }        ServerConf->ports[iPort] = 1;        if(ServerConf->port_count < 65536)            ServerConf->port_count++;    }    if(!iEndPorts)    {        snprintf(ErrorString, ErrStrLen,                "Must end '%s' configuration with '%s'.",                PORTS, END_PORT_LIST);        return -1;    }    return 0;}/***  NAME**    ProcessFlowDepth::*//****  Configure the flow depth for a server.****  Check that the value for flow depth is within bounds**  and is a valid number.****  @param ServerConf  pointer to the server configuration**  @param ErrorString error string buffer**  @param ErrStrLen   the length of the error string buffer****  @return an error code integer **          (0 = success, >0 = non-fatal error, <0 = fatal error)****  @retval  0 successs**  @retval -1 generic fatal error**  @retval  1 generic non-fatal error*/static int ProcessFlowDepth(HTTPINSPECT_CONF *ServerConf,                            char *ErrorString, int ErrStrLen){    char *pcToken;    int  iFlowDepth;    char *pcEnd;    pcToken = strtok(NULL, CONF_SEPARATORS);    if(pcToken == NULL)    {        snprintf(ErrorString, ErrStrLen,                "No argument to '%s' token.", FLOW_DEPTH);        return -1;    }    iFlowDepth = strtol(pcToken, &pcEnd, 10);    if(*pcEnd)    {        snprintf(ErrorString, ErrStrLen,                "Invalid argument to '%s'.", FLOW_DEPTH);        return -1;    }    /* -1 here is okay, which means ignore ALL server side traffic */    if(iFlowDepth < -1 || iFlowDepth > 1460)    {        snprintf(ErrorString, ErrStrLen,                "Invalid argument to '%s'.  Must be between 0 and "                "1460.", FLOW_DEPTH);        return -1;    }    ServerConf->flow_depth = iFlowDepth;    return 0;}/***  NAME**    ProcessChunkLength::*//****  Process and verify the chunk length for the server configuration.**  **  @param ServerConf  pointer to the server configuration**  @param ErrorString error string buffer**  @param ErrStrLen   the length of the error string buffer****  @return an error code integer **          (0 = success, >0 = non-fatal error, <0 = fatal error)****  @retval  0 successs**  @retval -1 generic fatal error**  @retval  1 generic non-fatal error*/static int ProcessChunkLength(HTTPINSPECT_CONF *ServerConf,                              char *ErrorString, int ErrStrLen){    char *pcToken;    int  iChunkLength;    char *pcEnd;    pcToken = strtok(NULL, CONF_SEPARATORS);    if(pcToken == NULL)    {        snprintf(ErrorString, ErrStrLen,                "No argument to '%s' token.", CHUNK_LENGTH);        return -1;    }    iChunkLength = strtol(pcToken, &pcEnd, 10);    if(*pcEnd)    {        snprintf(ErrorString, ErrStrLen,                "Invalid argument to '%s'.", CHUNK_LENGTH);        return -1;    }    if(iChunkLength < 0)    {

⌨️ 快捷键说明

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