📄 mta_sendmail.c
字号:
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\"", sendmailcf_fn); } break; case 'O': switch (line[1]) { case ' ': /* * long option */ if (strncasecmp(line + 2, "StatusFile", 10) == 0) { filename = line + 12; } else if (strncasecmp(line + 2, "QueueDirectory", 14) == 0) { filename = line + 16; } else { /* * not an option we care about */ break; } /* * make sure it's the end of the option */ if (*filename != ' ' && *filename != '=') break; /* * skip WS */ while (*filename == ' ') filename++; /* * must be O <option> = <file> */ if (*filename++ != '=') { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d in config file \"%s\" ist missing an '='", linenr, sendmailcf_fn); break; } /* * skip WS */ 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", linenr, sendmailcf_fn); break; } if (strncasecmp(line + 2, "StatusFile", 10) == 0) { strncpy(sendmailst_fn, filename, sizeof(sendmailst_fn)); sendmailst_fn[ sizeof(sendmailst_fn)-1 ] = 0; 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) { add_queuegroup("mqueue", filename); } else { print_error(LOG_CRIT, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "This shouldn't happen."); abort(); } 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", 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", linenr, sendmailcf_fn); break; } add_queuegroup("mqueue", line + 2); break; } break; case 'Q': /* * found a queue group */ p = qgname = line + 1; while (*p && *p != ',') { p++; } if (*p == '\0') { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a weird queuegroup", linenr, sendmailcf_fn); break; } /* * look for the directory */ filename = NULL; *p++ = '\0'; while (*p != '\0') { /* * skip WS */ while (*p && *p == ' ') p++; if (*p == 'P') { /* found path */ while (*p && *p != '=') p++; if (*p++ != '=') { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a weird queuegroup", linenr, sendmailcf_fn); break; } filename = p; /* * find next ',', turn into \0 */ while (*p && *p != ',') p++; *p = '\0'; } /* * skip to next , */ while (*p && *p != ',') { p++; } } /* * we found a directory */ if (filename) { add_queuegroup(qgname, filename); } else { print_error(LOG_WARNING, config, FALSE, "mibII/mta_sendmail.c:read_sendmailcf", "line %d config file \"%s\" contains a weird queuegroup: no directory", linenr, sendmailcf_fn); } 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); } 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_nword * function is used to copy the filename. * * Parameters: * * token: first word of the line * * line: rest of the line * * Returns: * * nothing * */ static voidmta_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_nword(line, sendmailst_fn, sizeof(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_nword(line, sendmailcf_fn, sizeof(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++; } add_queuegroup("mqueue", line); 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: * * nothing * */ voidinit_mta_sendmail(void){ REGISTER_MIB("mibII/mta_sendmail", mta_variables, variable3, mta_variables_oid); snmpd_register_config_handler("sendmail_config", mta_sendmail_parse_config, NULL, "file"); snmpd_register_config_handler("sendmail_stats", mta_sendmail_parse_config, NULL, "file"); snmpd_register_config_handler("sendmail_queue", mta_sendmail_parse_config, NULL, "directory"); snmpd_register_config_handler("sendmail_index", mta_sendmail_parse_config, NULL, "integer");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -