/* * Function: IMAP_ParseArgs(char *) * * Purpose: Process the preprocessor arguments from the rules file and * initialize the preprocessor's data struct. This function doesn't * have to exist if it makes sense to parse the args in the init * function. * * Arguments: args => argument list * * Returns: void function * */ void IMAP_ParseArgs(IMAPConfig *config, char *args) { int ret = 0; char *arg; char errStr[ERRSTRLEN]; int errStrLen = ERRSTRLEN; if ((config == NULL) || (args == NULL)) return; config->ports[IMAP_DEFAULT_SERVER_PORT / 8] |= 1 << (IMAP_DEFAULT_SERVER_PORT % 8); config->memcap = DEFAULT_IMAP_MEMCAP; config->b64_depth = DEFAULT_DEPTH; config->qp_depth = DEFAULT_DEPTH; config->uu_depth = DEFAULT_DEPTH; config->bitenc_depth = DEFAULT_DEPTH; config->max_depth = MIN_DEPTH; *errStr = '\0'; arg = strtok(args, CONF_SEPARATORS); while ( arg != NULL ) { if ( !strcasecmp(CONF_PORTS, arg) ) { ret = ProcessPorts(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_IMAP_MEMCAP, arg) ) { ret = ProcessImapMemcap(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_B64_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_B64_DECODE, DECODE_B64); } else if ( !strcasecmp(CONF_QP_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_QP_DECODE, DECODE_QP); } else if ( !strcasecmp(CONF_UU_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_UU_DECODE, DECODE_UU); } else if ( !strcasecmp(CONF_BITENC_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_BITENC_DECODE, DECODE_BITENC); } else if ( !strcasecmp(CONF_DISABLED, arg) ) { config->disabled = 1; } else { DynamicPreprocessorFatalMessage("%s(%d) => Unknown IMAP configuration option %s\n", *(_dpd.config_file), *(_dpd.config_line), arg); } if (ret == -1) { /* ** Fatal Error, log error and exit. */ if (*errStr) { DynamicPreprocessorFatalMessage("%s(%d) => %s\n", *(_dpd.config_file), *(_dpd.config_line), errStr); } else { DynamicPreprocessorFatalMessage("%s(%d) => Undefined Error.\n", *(_dpd.config_file), *(_dpd.config_line)); } } /* Get next token */ arg = strtok(NULL, CONF_SEPARATORS); } }
/* * Function: IMAP_ParseArgs(char *) * * Purpose: Process the preprocessor arguments from the rules file and * initialize the preprocessor's data struct. This function doesn't * have to exist if it makes sense to parse the args in the init * function. * * Arguments: args => argument list * * Returns: void function * */ void IMAP_ParseArgs(IMAPConfig *config, char *args) { int ret = 0; char *arg; char errStr[ERRSTRLEN]; int errStrLen = ERRSTRLEN; if ((config == NULL) || (args == NULL)) return; config->ports[IMAP_DEFAULT_SERVER_PORT / 8] |= 1 << (IMAP_DEFAULT_SERVER_PORT % 8); config->max_mime_mem = DEFAULT_IMAP_MEMCAP; config->memcap = DEFAULT_IMAP_MEMCAP; config->b64_depth = DEFAULT_DEPTH; config->qp_depth = DEFAULT_DEPTH; config->uu_depth = DEFAULT_DEPTH; config->bitenc_depth = DEFAULT_DEPTH; config->max_depth = MIN_DEPTH; config->log_config.log_filename = 0; config->log_config.log_mailfrom = 0; config->log_config.log_rcptto = 0; config->log_config.log_email_hdrs = 0; config->log_config.email_hdrs_log_depth = 0; *errStr = '\0'; arg = strtok(args, CONF_SEPARATORS); while ( arg != NULL ) { unsigned long value = 0; if ( !strcasecmp(CONF_PORTS, arg) ) { ret = ProcessPorts(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_IMAP_MEMCAP, arg) ) { ret = _dpd.checkValueInRange(strtok(NULL, CONF_SEPARATORS), CONF_IMAP_MEMCAP, MIN_IMAP_MEMCAP, MAX_IMAP_MEMCAP, &value); config->memcap = (uint32_t)value; } else if ( !strcasecmp(CONF_MAX_MIME_MEM, arg) ) { ret = _dpd.checkValueInRange(strtok(NULL, CONF_SEPARATORS), CONF_MAX_MIME_MEM, MIN_MIME_MEM, MAX_MIME_MEM, &value); config->max_mime_mem = (int)value; } else if ( !strcasecmp(CONF_B64_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_B64_DECODE, DECODE_B64); } else if ( !strcasecmp(CONF_QP_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_QP_DECODE, DECODE_QP); } else if ( !strcasecmp(CONF_UU_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_UU_DECODE, DECODE_UU); } else if ( !strcasecmp(CONF_BITENC_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_BITENC_DECODE, DECODE_BITENC); } else if ( !strcasecmp(CONF_DISABLED, arg) ) { config->disabled = 1; } else { DynamicPreprocessorFatalMessage("%s(%d) => Unknown IMAP configuration option %s\n", *(_dpd.config_file), *(_dpd.config_line), arg); } if (ret == -1) { /* ** Fatal Error, log error and exit. */ if (*errStr) { DynamicPreprocessorFatalMessage("%s(%d) => %s\n", *(_dpd.config_file), *(_dpd.config_line), errStr); } else { DynamicPreprocessorFatalMessage("%s(%d) => Undefined Error.\n", *(_dpd.config_file), *(_dpd.config_line)); } } /* Get next token */ arg = strtok(NULL, CONF_SEPARATORS); } }
/* * Function: SMTP_ParseArgs(char *) * * Purpose: Process the preprocessor arguments from the rules file and * initialize the preprocessor's data struct. This function doesn't * have to exist if it makes sense to parse the args in the init * function. * * Arguments: args => argument list * * Returns: void function * */ void SMTP_ParseArgs(SMTPConfig *config, char *args) { int ret = 0; char *arg; char *value; char errStr[ERRSTRLEN]; int errStrLen = ERRSTRLEN; int b64_option = 0; int deprecated_options = 0; if ((config == NULL) || (args == NULL)) return; config->ports[SMTP_DEFAULT_SERVER_PORT / 8] |= 1 << (SMTP_DEFAULT_SERVER_PORT % 8); config->ports[XLINK2STATE_DEFAULT_PORT / 8] |= 1 << (XLINK2STATE_DEFAULT_PORT % 8); config->ports[SMTP_DEFAULT_SUBMISSION_PORT / 8] |= 1 << (SMTP_DEFAULT_SUBMISSION_PORT % 8); config->inspection_type = SMTP_STATELESS; config->max_command_line_len = DEFAULT_MAX_COMMAND_LINE_LEN; config->max_header_line_len = DEFAULT_MAX_HEADER_LINE_LEN; config->max_response_line_len = DEFAULT_MAX_RESPONSE_LINE_LEN; config->max_mime_depth = DEFAULT_MAX_MIME_DEPTH; config->max_mime_mem = DEFAULT_MAX_MIME_MEM; config->memcap = DEFAULT_SMTP_MEMCAP; config->alert_xlink2state = 1; config->print_cmds = 1; config->enable_mime_decoding = 0; config->b64_depth = DEFAULT_MAX_MIME_DEPTH; config->qp_depth = DEFAULT_MAX_MIME_DEPTH; config->uu_depth = DEFAULT_MAX_MIME_DEPTH; config->bitenc_depth = DEFAULT_MAX_MIME_DEPTH; config->max_depth = MIN_DEPTH; config->log_filename = 0; config->log_mailfrom = 0; config->log_rcptto = 0; config->log_email_hdrs = 0; config->email_hdrs_log_depth = DEFAULT_LOG_DEPTH; config->cmd_config = (SMTPCmdConfig *)calloc(CMD_LAST, sizeof(SMTPCmdConfig)); if (config->cmd_config == NULL) { DynamicPreprocessorFatalMessage("%s(%d) => Failed to allocate memory for SMTP " "command structure\n", *(_dpd.config_file), *(_dpd.config_line)); } *errStr = '\0'; arg = strtok(args, CONF_SEPARATORS); while ( arg != NULL ) { if ( !strcasecmp(CONF_PORTS, arg) ) { ret = ProcessPorts(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_INSPECTION_TYPE, arg) ) { value = strtok(NULL, CONF_SEPARATORS); if ( value == NULL ) { return; } if ( !strcasecmp(CONF_STATEFUL, value) ) { config->inspection_type = SMTP_STATEFUL; } else { config->inspection_type = SMTP_STATELESS; } } else if ( !strcasecmp(CONF_NORMALIZE, arg) ) { value = strtok(NULL, CONF_SEPARATORS); if ( value == NULL ) { return; } if ( !strcasecmp(CONF_NONE, value) ) { config->normalize = NORMALIZE_NONE; } else if ( !strcasecmp(CONF_ALL, value) ) { config->normalize = NORMALIZE_ALL; } else { config->normalize = NORMALIZE_CMDS; } } else if ( !strcasecmp(CONF_IGNORE_DATA, arg) ) { config->ignore_data = 1; } else if ( !strcasecmp(CONF_IGNORE_TLS_DATA, arg) ) { config->ignore_tls_data = 1; } else if ( !strcasecmp(CONF_MAX_COMMAND_LINE_LEN, arg) ) { char *endptr; value = strtok(NULL, CONF_SEPARATORS); if ( value == NULL ) return; config->max_command_line_len = strtol(value, &endptr, 10); } else if ( !strcasecmp(CONF_MAX_HEADER_LINE_LEN, arg) ) { char *endptr; value = strtok(NULL, CONF_SEPARATORS); if ( value == NULL ) return; config->max_header_line_len = strtol(value, &endptr, 10); } else if ( !strcasecmp(CONF_MAX_RESPONSE_LINE_LEN, arg) ) { char *endptr; value = strtok(NULL, CONF_SEPARATORS); if ( value == NULL ) return; config->max_response_line_len = strtol(value, &endptr, 10); } else if ( !strcasecmp(CONF_NO_ALERTS, arg) ) { config->no_alerts = 1; } else if ( !strcasecmp(CONF_ALERT_UNKNOWN_CMDS, arg) ) { config->alert_unknown_cmds = 1; } else if ( !strcasecmp(CONF_INVALID_CMDS, arg) ) { /* Parse disallowed commands */ ret = ProcessCmds(config, errStr, errStrLen, ACTION_ALERT); } else if ( !strcasecmp(CONF_VALID_CMDS, arg) ) { /* Parse allowed commands */ ret = ProcessCmds(config, errStr, errStrLen, ACTION_NO_ALERT); } else if ( !strcasecmp(CONF_NORMALIZE_CMDS, arg) ) { /* Parse normalized commands */ ret = ProcessCmds(config, errStr, errStrLen, ACTION_NORMALIZE); } else if ( !strcasecmp(CONF_ALT_MAX_COMMAND_LINE_LEN, arg) ) { /* Parse max line len for commands */ ret = ProcessAltMaxCmdLen(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_SMTP_MEMCAP, arg) ) { ret = ProcessSmtpMemcap(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_MAX_MIME_MEM, arg) ) { ret = ProcessMaxMimeMem(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_MAX_MIME_DEPTH, arg) ) { deprecated_options = 1; _dpd.logMsg("WARNING: %s(%d) => The SMTP config option 'max_mime_depth' is deprecated.\n", *(_dpd.config_file), *(_dpd.config_line)); if(!b64_option) ret = ProcessMaxMimeDepth(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_ENABLE_MIME_DECODING, arg) ) { deprecated_options = 1; _dpd.logMsg("WARNING: %s(%d) => The SMTP config option 'enable_mime_decoding' is deprecated.\n", *(_dpd.config_file), *(_dpd.config_line)); if(!b64_option) config->enable_mime_decoding = 1; } else if ( !strcasecmp(CONF_DISABLED, arg) ) { config->disabled = 1; } else if ( !strcasecmp(CONF_XLINK2STATE, arg) ) { ret = ProcessXlink2State(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_LOG_FILENAME, arg) ) { config->log_filename = 1; } else if ( !strcasecmp(CONF_LOG_MAIL_FROM, arg) ) { config->log_mailfrom = 1; } else if ( !strcasecmp(CONF_LOG_RCPT_TO, arg) ) { config->log_rcptto = 1; } else if ( !strcasecmp(CONF_LOG_EMAIL_HDRS, arg) ) { config->log_email_hdrs = 1; } else if ( !strcasecmp(CONF_EMAIL_HDRS_LOG_DEPTH, arg) ) { ret = ProcessLogDepth(config, errStr, errStrLen); } else if ( !strcasecmp(CONF_PRINT_CMDS, arg) ) { config->print_cmds = 1; } else if ( !strcasecmp(CONF_B64_DECODE, arg) ) { b64_option = 1; ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_B64_DECODE, DECODE_B64); } else if ( !strcasecmp(CONF_QP_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_QP_DECODE, DECODE_QP); } else if ( !strcasecmp(CONF_UU_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_UU_DECODE, DECODE_UU); } else if ( !strcasecmp(CONF_BITENC_DECODE, arg) ) { ret = ProcessDecodeDepth(config, errStr, errStrLen, CONF_BITENC_DECODE, DECODE_BITENC); } else { DynamicPreprocessorFatalMessage("%s(%d) => Unknown SMTP configuration option %s\n", *(_dpd.config_file), *(_dpd.config_line), arg); } if (ret == -1) { /* ** Fatal Error, log error and exit. */ if (*errStr) { DynamicPreprocessorFatalMessage("%s(%d) => %s\n", *(_dpd.config_file), *(_dpd.config_line), errStr); } else { DynamicPreprocessorFatalMessage("%s(%d) => Undefined Error.\n", *(_dpd.config_file), *(_dpd.config_line)); } } /* Get next token */ arg = strtok(NULL, CONF_SEPARATORS); } if(!b64_option) { if(config->enable_mime_decoding) config->b64_depth = config->max_mime_depth; } else if(deprecated_options) { DynamicPreprocessorFatalMessage("%s(%d) => Cannot specify 'enable_mime_decoding' or 'max_mime_depth' with " "'b64_decode_depth'\n", *(_dpd.config_file), *(_dpd.config_line), arg); } if(!config->email_hdrs_log_depth) { if(config->log_email_hdrs) { _dpd.logMsg("WARNING: %s(%d) => 'log_email_hdrs' enabled with 'email_hdrs_log_depth' = 0." "Email headers won't be logged. Please set 'email_hdrs_log_depth' > 0 to enable logging.\n", *(_dpd.config_file), *(_dpd.config_line)); } config->log_email_hdrs = 0; } }