📄 mta_sendmail.c
字号:
{ /* do nothing */ } sendmailst_fh = -1; } }}/**//** static BOOL read_sendmailcf(BOOL config) * * Description: * * Tries to open the file named in sendmailcf_fn and to get the names of * the mailers, the status file and the mailqueue directory. * * Parameters: * * config: TRUE if function has been called during the configuration process * * Returns: * * TRUE : config file has been successfully opened * * FALSE : could not open config file * */static BOOL read_sendmailcf(BOOL config){ FILE *sendmailcf_fp; char line[500]; char *filename; int linenr; int linelen; int found_sendmailst = FALSE; int found_mqueue = FALSE; int i; sendmailcf_fp = fopen(sendmailcf_fn, "r"); if (sendmailcf_fp == NULL) { print_error(LOG_ERR, config, TRUE, "mibII/mta_sendmail.c:read_sendmailcf", "could not open file \"%s\"\n", sendmailcf_fn); return FALSE; } /* initializes the standard mailers, which aren't necessarily mentioned in the sendmail.cf file */ strcpy(mailernames[0],"prog"); strcpy(mailernames[1],"*file*"); strcpy(mailernames[2],"*include*"); mailers=3; linenr = 1; while (fgets(line, sizeof line, sendmailcf_fp) != NULL) { linelen = strlen(line); if (line[linelen - 1] != '\n') { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d in config file \"%s\" is too long\n", linenr, sendmailcf_fn); while (fgets(line, sizeof line, sendmailcf_fp) != NULL && line[strlen(line) - 1] != '\n') /* skip rest of the line */ { /* nothing to do */ } linenr++; continue; } line[--linelen] = '\0'; switch (line[0]) { case 'M': if (mailers < MAXMAILERS) { for (i=1; line[i] != ',' && ! isspace(line[i]) && line[i] != '\0' && i <= MNAMELEN; i++) { mailernames[mailers][i-1] = line[i]; } mailernames[mailers][i-1] = '\0'; DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","found mailer \"%s\"\n",mailernames[mailers])); for (i=0; i < mailers && strcmp(mailernames[mailers], mailernames[i]) != 0; i++) { /* nothing to do */ } if (i == mailers) { mailers++; } else { if (i < 3) { DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","mailer \"%s\" already existed, but since it's one of the predefined mailers, that's probably nothing to worry about\n", mailernames[mailers])); } else { DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","mailer \"%s\" already existed\n",mailernames[mailers])); } mailernames[mailers][0]='\0'; } } else { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "found too many mailers in config file \"%s\"\n", sendmailcf_fn); } break; case 'O': switch (line[1]) { case ' ': if (strncasecmp(line + 2, "StatusFile", 10) == 0) { filename = line + 12; } else if (strncasecmp(line + 2, "QueueDirectory", 14) == 0) { filename = line + 16; } else { break; } if (*filename != ' ' && *filename != '=') { break; } while (*filename == ' ') { filename++; } if (*filename != '=') { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d in config file \"%s\" ist missing an '='\n", linenr, sendmailcf_fn); break; } filename++; while (*filename == ' ') { filename++; } if (strlen(filename) > FILENAMELEN) { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a filename that's too long\n", linenr, sendmailcf_fn); break; } if (strncasecmp(line + 2, "StatusFile", 10) == 0) { strcpy(sendmailst_fn, filename); found_sendmailst = TRUE; DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","found statatistics file \"%s\"\n", sendmailst_fn)); } else if (strncasecmp(line + 2, "QueueDirectory", 14) == 0) { strcpy(mqueue_dn, filename); found_mqueue = TRUE; DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","found mailqueue directory \"%s\"\n", mqueue_dn)); } else { print_error(LOG_CRIT, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "This shouldn't happen.\n"); } break; case 'S': if (strlen(line+2) > FILENAMELEN) { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a filename that's too long\n", linenr, sendmailcf_fn); break; } strcpy(sendmailst_fn, line+2); found_sendmailst = TRUE; DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","found statatistics file \"%s\"\n", sendmailst_fn)); break; case 'Q': if (strlen(line+2) > FILENAMELEN) { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a filename that's too long\n", linenr, sendmailcf_fn); break; } strcpy(mqueue_dn, line+2); found_mqueue = TRUE; DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf","found mailqueue directory \"%s\"\n", mqueue_dn)); break; } break; } linenr++; } for (i = 0; i < 10 && fclose(sendmailcf_fp) != 0; i++) { /* nothing to do */ } for (i = mailers; i < MAXMAILERS; i++) { mailernames[i][0] = '\0'; } if (found_sendmailst) { open_sendmailst(config); } if (found_mqueue) { if (mqueue_dp) { while (closedir(mqueue_dp) == -1 && errno == EINTR) { /* do nothing */ } } mqueue_dp = opendir(mqueue_dn); if (mqueue_dp == NULL) { print_error(LOG_ERR, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "could not open mailqueue directory \"%s\" mentioned in config file \"%s\"\n", mqueue_dn, sendmailcf_fn); } } return TRUE;}/**//** static void mta_sendmail_parse_config(const char* token, char *line) * * Description: * * Called by the agent for each configuration line that belongs to this module. * The possible tokens are: * * sendmail_config - filename of the sendmail configutarion file * sendmail_stats - filename of the sendmail statistics file * sendmail_queue - name of the sendmail mailqueue directory * sendmail_index - the ApplIndex to use for the table * sendmail_stats_t - the time (in seconds) to cache statistics * sendmail_queue_t - the time (in seconds) to cache the directory scanning results * * For "sendmail_config", "sendmail_stats" and "sendmail_queue", the copy_word * function is used to copy the filename. * * Parameters: * * token: first word of the line * * line: rest of the line * * Returns: * * nothing * */static void mta_sendmail_parse_config(const char *token, char *line){ if (strlen(line) > FILENAMELEN) /* Might give some false alarm, but better to be safe than sorry */ { config_perror("line too long"); return; } if (strcasecmp(token,"sendmail_stats") == 0) { while (isspace(*line)) { line++; } copy_word(line, sendmailst_fn); open_sendmailst(TRUE); if (sendmailst_fh == -1) { char str[FILENAMELEN+50]; sprintf (str, "couldn't open file \"%s\"", sendmailst_fn); config_perror(str); return; } DEBUGMSGTL(("mibII/mta_sendmail.c:mta_sendmail_parse_config", "opened statistics file \"%s\"\n", sendmailst_fn)); return; } else if (strcasecmp(token,"sendmail_config") == 0) { while (isspace(*line)) { line++; } copy_word(line, sendmailcf_fn); read_sendmailcf(TRUE); DEBUGMSGTL(("mibII/mta_sendmail.c:mta_sendmail_parse_config", "read config file \"%s\"\n", sendmailcf_fn)); return; } else if (strcasecmp(token,"sendmail_queue") == 0) { while (isspace(*line)) { line++; } copy_word(line, mqueue_dn); if (mqueue_dp != NULL) { while (closedir(mqueue_dp) == -1 && errno == EINTR) { /* do nothing */ } } mqueue_dp = opendir(mqueue_dn); if (mqueue_dp == NULL) { char str[FILENAMELEN+50]; sprintf (str, "could not open mailqueue directory \"%s\"", mqueue_dn); config_perror(str); return; } DEBUGMSGTL(("mibII/mta_sendmail.c:mta_sendmail_parse_config", "opened mailqueue directory \"%s\"\n", mqueue_dn)); return; } else if (strcasecmp(token,"sendmail_index") == 0) { while (isspace(*line)) { line++; } applindex = atol(line); if (applindex < 1) { config_perror("invalid index number"); applindex = 1; } } else if (strcasecmp(token,"sendmail_stats_t") == 0) { while (isspace(*line)) { line++; } stat_cache_time = atol(line); if (stat_cache_time < 1) { config_perror("invalid cache time"); applindex = 5; } } else if (strcasecmp(token,"sendmail_queue_t") == 0) { while (isspace(*line)) { line++; } dir_cache_time = atol(line); if (dir_cache_time < 1) { config_perror("invalid cache time"); applindex = 10; } } else { config_perror("mibII/mta_sendmail.c says: What should I do with that token? Did you ./configure the agent properly?"); } return;}/**//** void init_mta_sendmail(void) * * Description: * * Called by the agent to initialize the module. The function will register * the OID tree and the config handler and try some default values for the * sendmail.cf and sendmail.st files and for the mailqueue directory. * * Parameters: * * none * * Returns:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -