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

📄 mta_sendmail.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *  MTA-MIB implementation for sendmail - mibII/mta_sendmail.c *  Christoph Mammitzsch <Christoph.Mammitzsch@tu-clausthal.de> * * todo: put queue directory into description? * *  13.02.2002: *    - support sendmail 8.12 queue groups * * *  05.04.2000: * *    - supports sendmail 8.10.0 statistics files now *    - function read_option has been removed * *  12.04.2000: * *    - renamed configuration tokens: *        sendmail config        -> sendmail_config *        sendmail stats         -> sendmail_stats *        sendmail queue         -> sendmail_queue *        sendmail index         -> sendmail_index *        sendmail statcachetime -> sendmail_stats_t *        sendmail dircacetime   -> sendmail_queue_t * *    - now using snmpd_register_config_handler instead of config_parse_dot_conf * *  15.04.2000: * *    - introduced new function print_error *    - changed open_sendmailst and read_sendmailcf to use the new function *    - changed calls to open_sendmailst and read_sendmailcf *    - added some error handling to calls to chdir(), close() and closedir() * *//** "include files" */#ifdef __lint# define SNMP_NO_DEBUGGING 1    /* keeps lint from complaining about the DEBUGMSG* macros */#endif#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "mta_sendmail.h"#include <sys/types.h>#include <stdio.h>#include <ctype.h>#ifdef HAVE_STRING_H# include <string.h>#else# include <strings.h>#endif#if HAVE_STDLIB_H#include <stdlib.h>#endif#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#ifdef HAVE_FCNTL_H# include <fcntl.h>#endif#if HAVE_DIRENT_H#include <dirent.h>#else# define dirent direct# if HAVE_SYS_NDIR_H#  include <sys/ndir.h># endif# if HAVE_SYS_DIR_H#  include <sys/dir.h># endif# if HAVE_NDIR_H#  include <ndir.h># endif#endif#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif#if HAVE_STDARG_H#include <stdarg.h>#else#include <varargs.h>#endif#include <errno.h> /**//** "macros and variables for registering the OID tree" */    /*     * prefix for all OIDs      */static FindVarMethod var_mtaEntry;static FindVarMethod var_mtaGroupEntry;static oid      mta_variables_oid[] = { 1, 3, 6, 1, 2, 1, 28 };/* * bits that indicate what's needed to compute the value  */#define   NEEDS_STATS   (1 << 6)#define   NEEDS_DIR     (1 << 7)#define   NEEDS         (NEEDS_STATS | NEEDS_DIR)/* * symbolic names for the magic values  */enum {    MTARECEIVEDMESSAGES = 3 | NEEDS_STATS,    MTASTOREDMESSAGES = 4 | NEEDS_DIR,    MTATRANSMITTEDMESSAGES = 5 | NEEDS_STATS,    MTARECEIVEDVOLUME = 6 | NEEDS_STATS,    MTASTOREDVOLUME = 7 | NEEDS_DIR,    MTATRANSMITTEDVOLUME = 8 | NEEDS_STATS,    MTAGROUPSTOREDMESSAGES = 17 | NEEDS_DIR,    MTAGROUPSTOREDVOLUME = 18 | NEEDS_DIR,    MTAGROUPRECEIVEDMESSAGES = 19 | NEEDS_STATS,    MTAGROUPREJECTEDMESSAGES = 20 | NEEDS_STATS,    MTAGROUPTRANSMITTEDMESSAGES = 22 | NEEDS_STATS,    MTAGROUPRECEIVEDVOLUME = 23 | NEEDS_STATS,    MTAGROUPTRANSMITTEDVOLUME = 25 | NEEDS_STATS,    MTAGROUPNAME = 43,    MTAGROUPHIERARCHY = 49,};/* * structure that tells the agent, which function returns what values  */static struct variable3 mta_variables[] = {    {MTARECEIVEDMESSAGES, ASN_COUNTER, RONLY, var_mtaEntry, 3, {1, 1, 1}},    {MTASTOREDMESSAGES, ASN_GAUGE, RONLY, var_mtaEntry, 3, {1, 1, 2}},    {MTATRANSMITTEDMESSAGES, ASN_COUNTER, RONLY, var_mtaEntry, 3,     {1, 1, 3}},    {MTARECEIVEDVOLUME, ASN_COUNTER, RONLY, var_mtaEntry, 3, {1, 1, 4}},    {MTASTOREDVOLUME, ASN_GAUGE, RONLY, var_mtaEntry, 3, {1, 1, 5}},    {MTATRANSMITTEDVOLUME, ASN_COUNTER, RONLY, var_mtaEntry, 3, {1, 1, 6}},    {MTAGROUPRECEIVEDMESSAGES, ASN_COUNTER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 2}},    {MTAGROUPREJECTEDMESSAGES, ASN_COUNTER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 3}},    {MTAGROUPSTOREDMESSAGES, ASN_GAUGE, RONLY, var_mtaGroupEntry, 3,     {2, 1, 4}},    {MTAGROUPTRANSMITTEDMESSAGES, ASN_COUNTER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 5}},    {MTAGROUPRECEIVEDVOLUME, ASN_COUNTER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 6}},    {MTAGROUPSTOREDVOLUME, ASN_GAUGE, RONLY, var_mtaGroupEntry, 3,     {2, 1, 7}},    {MTAGROUPTRANSMITTEDVOLUME, ASN_COUNTER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 8}},    {MTAGROUPNAME, ASN_OCTET_STR, RONLY, var_mtaGroupEntry, 3, {2, 1, 25}},    {MTAGROUPHIERARCHY, ASN_INTEGER, RONLY, var_mtaGroupEntry, 3,     {2, 1, 31}},}; /**//** "other macros and structures" */    /*     * for boolean values      */#ifndef FALSE#define FALSE 0#endif#ifndef TRUE#define TRUE  1#endif#ifndef BOOL#define BOOL  short#endif    /*     * important constants      */#define FILENAMELEN     200     /* maximum length for filenames */#define MAXMAILERS       25     /* maximum number of mailers (copied from the sendmail sources) */#define MAXQUEUEGROUPS   50     /* maximum # of queue groups (copied from sendmail) */#define MNAMELEN         20     /* maximum length of mailernames (copied from the sendmail sources) */#define STAT_VERSION_8_9  2     /* version of sendmail V8.9.x statistics files (copied from the sendmail sources) */#define STAT_VERSION_8_10 3     /* version of sendmail V8.10.x statistics files (copied from the sendmail sources) */#define STAT_VERSION_8_12_QUAR 4     /* version of sendmail V8.12.x statistics files using -D_FFR_QUARANTINE (commercial and edge-living opensource*/#define STAT_MAGIC  0x1B1DE     /* magic value to identify statistics files from sendmail V8.9.x or higher (copied from the sendmail sources) */    /*     * structure of sendmail.st file from sendmail V8.10.x (copied from the sendmail sources)      */struct statisticsV8_12_QUAR {    int             stat_magic; /* magic number */    int             stat_version;       /* stat file version */    time_t          stat_itime; /* file initialization time */    short           stat_size;  /* size of this structure */    long            stat_cf;    /* # from connections */    long            stat_ct;    /* # to connections */    long            stat_cr;    /* # rejected connections */    long            stat_nf[MAXMAILERS];        /* # msgs from each mailer */    long            stat_bf[MAXMAILERS];        /* kbytes from each mailer */    long            stat_nt[MAXMAILERS];        /* # msgs to each mailer */    long            stat_bt[MAXMAILERS];        /* kbytes to each mailer */    long            stat_nr[MAXMAILERS];        /* # rejects by each mailer */    long            stat_nd[MAXMAILERS];        /* # discards by each mailer */    long            stat_nq[MAXMAILERS];        /* # quarantines by each mailer*/};    struct statisticsV8_10 {    int             stat_magic; /* magic number */    int             stat_version;       /* stat file version */    time_t          stat_itime; /* file initialization time */    short           stat_size;  /* size of this structure */    long            stat_cf;    /* # from connections */    long            stat_ct;    /* # to connections */    long            stat_cr;    /* # rejected connections */    long            stat_nf[MAXMAILERS];        /* # msgs from each mailer */    long            stat_bf[MAXMAILERS];        /* kbytes from each mailer */    long            stat_nt[MAXMAILERS];        /* # msgs to each mailer */    long            stat_bt[MAXMAILERS];        /* kbytes to each mailer */    long            stat_nr[MAXMAILERS];        /* # rejects by each mailer */    long            stat_nd[MAXMAILERS];        /* # discards by each mailer */};/* * structure of sendmail.st file from sendmail V8.9.x (copied from the sendmail sources)  */struct statisticsV8_9 {    int             stat_magic; /* magic number */    int             stat_version;       /* stat file version */    time_t          stat_itime; /* file initialization time */    short           stat_size;  /* size of this structure */    long            stat_nf[MAXMAILERS];        /* # msgs from each mailer */    long            stat_bf[MAXMAILERS];        /* kbytes from each mailer */    long            stat_nt[MAXMAILERS];        /* # msgs to each mailer */    long            stat_bt[MAXMAILERS];        /* kbytes to each mailer */    long            stat_nr[MAXMAILERS];        /* # rejects by each mailer */    long            stat_nd[MAXMAILERS];        /* # discards by each mailer */};/* * structure of sendmail.st file from sendmail V8.8.x (copied from the sendmail sources)  */struct statisticsV8_8 {    time_t          stat_itime; /* file initialization time */    short           stat_size;  /* size of this structure */    long            stat_nf[MAXMAILERS];        /* # msgs from each mailer */    long            stat_bf[MAXMAILERS];        /* kbytes from each mailer */    long            stat_nt[MAXMAILERS];        /* # msgs to each mailer */    long            stat_bt[MAXMAILERS];        /* kbytes to each mailer */}; /**/    /*     * queue groups (strictly a sendmail 8.12+ thing      */    struct QDir {    char            dir[FILENAMELEN + 1];    struct QDir    *next;};struct QGrp {    char           *name;       /* name of queuegroup */    time_t          last;       /* last time we counted */    int             count;      /* # of files */    int             size;       /* size of files */    struct QDir    *dirs;       /* directories in queue group */};/** "static variables" *//* * a list of all the queue groups, NULL terminated  */static struct QGrp qgrps[MAXQUEUEGROUPS];static int      nqgrps = 0;static char     sendmailst_fn[FILENAMELEN + 1]; /* name of statistics file */static int      sendmailst_fh = -1;     /* filehandle for statistics file */static char     sendmailcf_fn[FILENAMELEN + 1]; /* name of sendmails config file */static char     mailernames[MAXMAILERS][MNAMELEN + 1];  /* array of mailer names */static int      mailers = MAXMAILERS;   /* number of mailer names in array */static long    *stat_nf;        /* pointer to stat_nf array within the statistics structure */static long    *stat_bf;        /* pointer to stat_bf array within the statistics structure */static long    *stat_nt;        /* pointer to stat_nt array within the statistics structure */static long    *stat_bt;        /* pointer to stat_bt array within the statistics structure */static long    *stat_nr;        /* pointer to stat_nr array within the statistics structure,                                 * only valid for statistics files from sendmail >=V8.9.0    */static long    *stat_nd;        /* pointer to stat_nd array within the statistics structure,                                 * only valid for statistics files from sendmail >=V8.9.0    */static int      stats_size;     /* size of statistics structure */static long     stats[sizeof(struct statisticsV8_12_QUAR) / sizeof(long) + 1];       /* buffer for statistics structure */static time_t   lastreadstats;  /* time stats file has been read */static long     applindex = 1;  /* ApplIndex value for OIDs */static long     stat_cache_time = 5;    /* time (in seconds) to wait before reading stats file again */static long     dir_cache_time = 10;    /* time (in seconds) to wait before scanning queue directoy again */ /**//** static void print_error(int priority, BOOL config, BOOL config_only, char *function, char *format, ...) * *  Description: * *    Called to print errors. It uses the config_perror or the snmp_log function *    depending on whether the config parameter is TRUE or FALSE. * *  Parameters: * *    priority:    priority to be used when calling the snmp_log function * *    config:      indicates whether this function has been called during the *                 configuration process or not. If set to TRUE, the function *                 config_perror will be used to report the error. * *    config_only: if set to TRUE, the error will only be printed when function *                 has been called during the configuration process. * *    function:    name of the calling function. Used when printing via snmp_log. * *    format:      format string for the error message * *    ...:         additional parameters to insert into the error message string * */#if HAVE_STDARG_H    static voidprint_error(int priority, BOOL config, BOOL config_only,            const char *function, const char *format, ...)#else    static voidprint_error(va_alist)     va_dcl#endif{    va_list         ap;    char            buffer[2 * FILENAMELEN + 200];      /* I know, that's not perfectly safe, but since I don't use more                                                         * than two filenames in one error message, that should be enough */#if HAVE_STDARG_H    va_start(ap, format);#else    int             priority;    BOOL            config;    BOOL            config_only;    const char     *function;    const char     *format;    va_start(ap);    priority = va_arg(ap, int);    config = va_arg(ap, BOOL);    config_only = va_arg(ap, BOOL);    function = va_arg(ap, char *);    format = va_arg(ap, char *);#endif    vsnprintf(buffer, sizeof(buffer), format, ap);    if (config) {        config_perror(buffer);    } else if (!config_only) {        snmp_log(priority, "%s: %s\n", function, buffer);    }    va_end(ap);}

⌨️ 快捷键说明

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