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

📄 mta_sendmail.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 4 页
字号:
    snmpd_register_config_handler("sendmail_stats_t",                                  mta_sendmail_parse_config, NULL,                                  "cachetime/sec");    snmpd_register_config_handler("sendmail_queue_t",                                  mta_sendmail_parse_config, NULL,                                  "cachetime/sec");    strcpy(sendmailcf_fn, "/etc/mail/sendmail.cf");    if (read_sendmailcf(FALSE) == FALSE) {        strcpy(sendmailcf_fn, "/etc/sendmail.cf");        read_sendmailcf(FALSE);    }    if (sendmailst_fh == -1) {        strcpy(sendmailst_fn, "/etc/mail/statistics");        open_sendmailst(FALSE);        if (sendmailst_fh == -1) {            strcpy(sendmailst_fn, "/etc/mail/sendmail.st");            open_sendmailst(FALSE);        }    }} /**//** unsigned char *var_mtaEntry(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) * *  Description: * *    Called by the agent in order to get the values for the mtaTable. * *  Parameters: * *    see agent documentation * *  Returns: * *    see agent documentation * */unsigned char  *var_mtaEntry(struct variable *vp,             oid * name,             size_t * length,             int exact, size_t * var_len, WriteMethod ** write_method){    static long     long_ret;    auto int        i;    auto int        result;    auto time_t     current_time;    int             global_count = 0;    int             global_size = 0;    if (exact) {        if (*length != vp->namelen + 1) {            return NULL;        }        result =            snmp_oid_compare(name, *length - 1, vp->name, vp->namelen);        if (result != 0 || name[*length - 1] != applindex) {            return NULL;        }    } else {        if (*length <= vp->namelen) {            result = -1;        } else {            result =                snmp_oid_compare(name, *length - 1, vp->name, vp->namelen);        }        if (result > 0) {            return NULL;        }        if (result == 0 && name[*length - 1] >= applindex) {            return NULL;        }        if (result < 0) {            memcpy(name, vp->name, (int) vp->namelen * (int) sizeof *name);            *length = vp->namelen + 1;        }        name[vp->namelen] = applindex;    }    *write_method = (WriteMethod *) NULL;    *var_len = sizeof(long);    /* default to 'long' results */    if (vp->magic & NEEDS_STATS) {        if (sendmailst_fh == -1)            return NULL;        current_time = time(NULL);        if (current_time == (time_t) - 1            || current_time > lastreadstats + stat_cache_time) {            if (lseek(sendmailst_fh, 0, SEEK_SET) == -1) {                snmp_log(LOG_ERR,                         "mibII/mta_sendmail.c:var_mtaEntry: could not rewind to the beginning of file \"%s\"\n",                         sendmailst_fn);                return NULL;            }            if (read(sendmailst_fh, (void *) &stats, stats_size) !=                stats_size) {                snmp_log(LOG_ERR,                         "mibII/mta_sendmail.c:var_mtaEntry: could not read from statistics file \"%s\"\n",                         sendmailst_fn);                return NULL;            }            if (current_time != (time_t) - 1) {                lastreadstats = current_time;            }        }    }    if (vp->magic & NEEDS_DIR) {        global_count = 0;        global_size = 0;        /*         * count all queue group messages          */        for (i = 0; i < nqgrps; i++) {            count_queuegroup(&qgrps[i]);            global_count += qgrps[i].count;            global_size += qgrps[i].size;        }    }    switch (vp->magic) {    case MTARECEIVEDMESSAGES:        long_ret = 0;        for (i = 0; i < MAXMAILERS; i++) {            long_ret += stat_nf[i];        }        return (unsigned char *) &long_ret;    case MTASTOREDMESSAGES:        long_ret = global_count;        return (unsigned char *) &long_ret;    case MTATRANSMITTEDMESSAGES:        long_ret = 0;        for (i = 0; i < MAXMAILERS; i++) {            long_ret += stat_nt[i];        }        return (unsigned char *) &long_ret;    case MTARECEIVEDVOLUME:        long_ret = 0;        for (i = 0; i < MAXMAILERS; i++) {            long_ret += stat_bf[i];        }        return (unsigned char *) &long_ret;    case MTASTOREDVOLUME:        long_ret = global_size;        return (unsigned char *) &long_ret;    case MTATRANSMITTEDVOLUME:        long_ret = 0;        for (i = 0; i < MAXMAILERS; i++) {            long_ret += stat_bt[i];        }        return (unsigned char *) &long_ret;    default:        snmp_log(LOG_ERR,                 "mibII/mta_sendmail.c:mtaEntry: unknown magic value\n");    }    return NULL;} /**//** unsigned char *var_mtaGroupEntry(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) * *  Description: * *    Called by the agent in order to get the values for the mtaGroupTable. * *  Parameters: * *    see agent documentation * *  Returns: * *    see agent documentation * */unsigned char  *var_mtaGroupEntry(struct variable *vp,                  oid * name,                  size_t * length,                  int exact, size_t * var_len, WriteMethod ** write_method){    static long     long_ret;    auto long       row;    auto int        result;    auto time_t     current_time;    if (exact) {        if (*length != vp->namelen + 2) {            return NULL;        }        result =            snmp_oid_compare(name, *length - 2, vp->name, vp->namelen);        if (result != 0 || name[*length - 2] != applindex            || name[*length - 1] <= 0            || name[*length - 1] > mailers + nqgrps) {            return NULL;        }    } else {        if (*length < vp->namelen) {            result = -1;        } else {            result =                snmp_oid_compare(name, vp->namelen, vp->name, vp->namelen);        }        if (result > 0) {            /*             * OID prefix too large              */            return NULL;        }        if (result == 0) {            /*             * OID prefix matches exactly,...              */            if (*length > vp->namelen && name[vp->namelen] > applindex) {                /*                 * ... but ApplIndex too large                  */                return NULL;            }            if (*length > vp->namelen && name[vp->namelen] == applindex) {                /*                 * ... ApplIndex ok,...                  */                if (*length > vp->namelen + 1                    && name[vp->namelen + 1] >= 1) {                    if (name[vp->namelen + 1] >= mailers + nqgrps) {                        /*                         * ... but mailernr too large                          */                        return NULL;                    } else {                        name[vp->namelen + 1]++;                    }                } else {                    name[vp->namelen + 1] = 1;                }            } else {                name[vp->namelen] = applindex;                name[vp->namelen + 1] = 1;            }        } else {                /* OID prefix too small */            memcpy(name, vp->name, (int) vp->namelen * (int) sizeof *name);            name[vp->namelen] = applindex;            name[vp->namelen + 1] = 1;        }        *length = vp->namelen + 2;    }    *write_method = 0;    *var_len = sizeof(long);    /* default to 'long' results */    if (vp->magic & NEEDS_STATS) {        if (sendmailst_fh == -1)            return NULL;        current_time = time(NULL);        if (current_time == (time_t) - 1 ||            current_time > lastreadstats + stat_cache_time) {            if (lseek(sendmailst_fh, 0, SEEK_SET) == -1) {                snmp_log(LOG_ERR,                         "mibII/mta_sendmail.c:var_mtaGroupEntry: could not rewind to beginning of file \"%s\"\n",                         sendmailst_fn);                return NULL;            }            if (read(sendmailst_fh, (void *) &stats, stats_size) !=                stats_size) {                snmp_log(LOG_ERR,                         "mibII/mta_sendmail.c:var_mtaGroupEntry: could not read statistics file \"%s\"\n",                         sendmailst_fn);                return NULL;            }            if (current_time != (time_t) - 1) {                lastreadstats = current_time;            }        }    }    row = name[*length - 1] - 1;    /*     * if this is a mailer but we're asking for queue-group only info,      * bump there      */    if (!exact && row < mailers && (vp->magic == MTAGROUPSTOREDMESSAGES ||                                    vp->magic == MTAGROUPSTOREDVOLUME)) {        row = mailers;        name[*length - 1] = row + 1;    }    if (row < mailers) {        switch (vp->magic) {        case MTAGROUPRECEIVEDMESSAGES:            long_ret = (long) stat_nf[row];            return (unsigned char *) &long_ret;        case MTAGROUPREJECTEDMESSAGES:            if (stat_nr != NULL && stat_nd != NULL) {                long_ret = (long) (stat_nr[row] + stat_nd[row]);        /* Number of rejected plus number of discarded messages */                return (unsigned char *) &long_ret;            } else {                return NULL;            }        case MTAGROUPTRANSMITTEDMESSAGES:            long_ret = (long) stat_nt[row];            return (unsigned char *) &long_ret;        case MTAGROUPRECEIVEDVOLUME:            long_ret = (long) stat_bf[row];            return (unsigned char *) &long_ret;        case MTAGROUPTRANSMITTEDVOLUME:            long_ret = (long) stat_bt[row];            return (unsigned char *) &long_ret;        case MTAGROUPNAME:            *var_len = strlen(mailernames[row]);            return (unsigned char *) (*var_len >                                      0 ? mailernames[row] : NULL);        case MTAGROUPHIERARCHY:            long_ret = (long) -1;            return (unsigned char *) &long_ret;        default:            return NULL;        }    } else {        /*         * this is the queue group part of the table          */        row -= mailers;        switch (vp->magic) {        case MTAGROUPSTOREDMESSAGES:            count_queuegroup(&qgrps[row]);            long_ret = (long) qgrps[row].count;            return (unsigned char *) &long_ret;        case MTAGROUPSTOREDVOLUME:            count_queuegroup(&qgrps[row]);            long_ret = (long) qgrps[row].size;            return (unsigned char *) &long_ret;        case MTAGROUPNAME:            *var_len = strlen(qgrps[row].name);            return (unsigned char *) (*var_len >                                      0 ? qgrps[row].name : NULL);        case MTAGROUPHIERARCHY:            long_ret = (long) -2;            return (unsigned char *) &long_ret;        default:            return NULL;        }    }    return NULL;} /**/

⌨️ 快捷键说明

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