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

📄 mta_sendmail.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 4 页
字号:
 /**//** static void open_sendmailst(BOOL config) * *  Description: * *    Closes old sendmail.st file, then tries to open the new sendmail.st file *    and guess it's version. If it succeeds, it initializes the stat_* *    pointers and the stats_size variable. * *  Parameters: * *    config: TRUE if function has been called during the configuration process * *  Returns: * *    nothing * */    static voidopen_sendmailst(BOOL config){    int             filelen;    if (sendmailst_fh != -1) {        while (close(sendmailst_fh) == -1 && errno == EINTR) {            /*             * do nothing              */        }    }    sendmailst_fh = open(sendmailst_fn, O_RDONLY);    if (sendmailst_fh == -1) {        print_error(LOG_ERR, config, TRUE,                    "mibII/mta_sendmail.c:open_sendmailst",                    "could not open file \"%s\"", sendmailst_fn);        return;    }    filelen = read(sendmailst_fh, (void *) &stats, sizeof stats);    if (((struct statisticsV8_10 *) stats)->stat_magic == STAT_MAGIC) {        if (((struct statisticsV8_12_QUAR *) stats)->stat_version ==            STAT_VERSION_8_12_QUAR            && ((struct statisticsV8_12_QUAR *) stats)->stat_size ==            sizeof(struct statisticsV8_12_QUAR)            && filelen == sizeof(struct statisticsV8_12_QUAR)) {            DEBUGMSGTL(("mibII/mta_sendmail.c:open_sendmailst",                        "looks like file \"%s\" has been created by sendmail V8.10.0 or newer\n",                        sendmailst_fn));            stat_nf = (((struct statisticsV8_12_QUAR *) stats)->stat_nf);            stat_bf = (((struct statisticsV8_12_QUAR *) stats)->stat_bf);            stat_nt = (((struct statisticsV8_12_QUAR *) stats)->stat_nt);            stat_bt = (((struct statisticsV8_12_QUAR *) stats)->stat_bt);            stat_nr = (((struct statisticsV8_12_QUAR *) stats)->stat_nr);            stat_nd = (((struct statisticsV8_12_QUAR *) stats)->stat_nd);            stats_size = sizeof(struct statisticsV8_12_QUAR);        } else		 if (((struct statisticsV8_10 *) stats)->stat_version ==            STAT_VERSION_8_10            && ((struct statisticsV8_10 *) stats)->stat_size ==            sizeof(struct statisticsV8_10)            && filelen == sizeof(struct statisticsV8_10)) {            DEBUGMSGTL(("mibII/mta_sendmail.c:open_sendmailst",                        "looks like file \"%s\" has been created by sendmail V8.10.0 or newer\n",                        sendmailst_fn));            stat_nf = (((struct statisticsV8_10 *) stats)->stat_nf);            stat_bf = (((struct statisticsV8_10 *) stats)->stat_bf);            stat_nt = (((struct statisticsV8_10 *) stats)->stat_nt);            stat_bt = (((struct statisticsV8_10 *) stats)->stat_bt);            stat_nr = (((struct statisticsV8_10 *) stats)->stat_nr);            stat_nd = (((struct statisticsV8_10 *) stats)->stat_nd);            stats_size = sizeof(struct statisticsV8_10);        } else if (((struct statisticsV8_9 *) stats)->stat_version ==                   STAT_VERSION_8_9                   && ((struct statisticsV8_9 *) stats)->stat_size ==                   sizeof(struct statisticsV8_9)                   && filelen == sizeof(struct statisticsV8_9)) {            DEBUGMSGTL(("mibII/mta_sendmail.c:open_sendmailst",                        "looks like file \"%s\" has been created by sendmail V8.9.x\n",                        sendmailst_fn));            stat_nf = (((struct statisticsV8_9 *) stats)->stat_nf);            stat_bf = (((struct statisticsV8_9 *) stats)->stat_bf);            stat_nt = (((struct statisticsV8_9 *) stats)->stat_nt);            stat_bt = (((struct statisticsV8_9 *) stats)->stat_bt);            stat_nr = (((struct statisticsV8_9 *) stats)->stat_nr);            stat_nd = (((struct statisticsV8_9 *) stats)->stat_nd);            stats_size = sizeof(struct statisticsV8_9);        } else {            print_error(LOG_WARNING, config, FALSE,                        "mibII/mta_sendmail.c:open_sendmailst",                        "could not guess version of statistics file \"%s\"",                        sendmailst_fn);            while (close(sendmailst_fh) == -1 && errno == EINTR) {                /*                 * do nothing                  */            }            sendmailst_fh = -1;        }    } else {        if (((struct statisticsV8_8 *) stats)->stat_size ==            sizeof(struct statisticsV8_8)            && filelen == sizeof(struct statisticsV8_8)) {            DEBUGMSGTL(("mibII/mta_sendmail.c:open_sendmailst",                        "looks like file \"%s\" has been created by sendmail V8.8.x\n",                        sendmailst_fn));            stat_nf = (((struct statisticsV8_8 *) stats)->stat_nf);            stat_bf = (((struct statisticsV8_8 *) stats)->stat_bf);            stat_nt = (((struct statisticsV8_8 *) stats)->stat_nt);            stat_bt = (((struct statisticsV8_8 *) stats)->stat_bt);            stat_nr = (long *) NULL;            stat_nd = (long *) NULL;            stats_size = sizeof(struct statisticsV8_8);        } else {            print_error(LOG_WARNING, config, FALSE,                        "mibII/mta_sendmail.c:open_sendmailst",                        "could not guess version of statistics file \"%s\"",                        sendmailst_fn);            while (close(sendmailst_fh) == -1 && errno == EINTR) {                /*                 * do nothing                  */            }            sendmailst_fh = -1;        }    }} /**/ static voidcount_queuegroup(struct QGrp *qg){    struct QDir    *d;    char            cwd[200];    time_t          current_time = time(NULL);    if (current_time <= (qg->last + dir_cache_time)) {        return;    }    if (getcwd(cwd, sizeof cwd) == NULL) {        snmp_log(LOG_ERR,                 "mibII/mta_sendmail.c:count_queuegroup: could not get current working directory\n");        return;    }    qg->count = 0;    qg->size = 0;    for (d = qg->dirs; d != NULL; d = d->next) {        DIR            *dp;        struct dirent  *dirp;        struct stat     filestat;        if (chdir(d->dir) != 0)            continue;        dp = opendir(".");        if (dp == NULL)            continue;        while ((dirp = readdir(dp)) != NULL) {            if (dirp->d_name[0] == 'd' && dirp->d_name[1] == 'f') {                if (stat(dirp->d_name, &filestat) == 0) {                    qg->size += (filestat.st_size + 999) / 1000;                }            } else if (dirp->d_name[0] == 'q' && dirp->d_name[1] == 'f') {                qg->count++;            }        }        closedir(dp);    }    qg->last = current_time;    chdir(cwd);}/** static void add_queuegroup(const char *name, const char *path) * * Description: * *   Adds a queuegroup of 'name' with root path 'path' to the static *   list of queue groups.  if 'path' ends in a *, we expand it out to *   all matching subdirs.  also look for 'qf' subdirectories. * * Parameters: * *   qgname: name of the queuegroup discovered *   path: path of queuegroup discovered */static voidadd_queuegroup(const char *name, char *path){    char            parentdir[FILENAMELEN];    char           *p;    struct QDir    *new = NULL;    struct QDir    *subdir = NULL;    DIR            *dp;    struct dirent  *dirp;    if (nqgrps == MAXQUEUEGROUPS) {        /*         * xxx error          */        return;    }    if (strlen(path) > FILENAMELEN - 10) {        /*         * xxx error          */        return;    }    p = path + strlen(path) - 1;    if (*p == '*') {            /* multiple queue dirs */        /*         * remove *          */        *p = '\0';        strcpy(parentdir, path);        /*         * remove last directory component from parentdir          */        for (p = parentdir + strlen(parentdir) - 1; p >= parentdir; p--) {            if (*p == '/') {                *p = '\0';                break;            }        }        if (p < parentdir) {            /*             * no trailing / ?!?              */            /*             * xxx error              */            return;        }        p++;        /*         * p is now the prefix we need to match          */        if ((dp = opendir(parentdir)) == NULL) {            /*             * xxx can't open parentdir              */            return;        }        while ((dirp = readdir(dp)) != NULL) {            if (!strncmp(dirp->d_name, p, strlen(p)) &&                dirp->d_name[0] != '.') {                /*                 * match, add it to the list                  */                /*                 * single queue directory                  */                subdir = (struct QDir *) malloc(sizeof(struct QDir));                snprintf(subdir->dir, FILENAMELEN - 5, "%s/%s", parentdir,                         dirp->d_name);                subdir->next = new;                new = subdir;            }        }        closedir(dp);    } else {        /*         * single queue directory          */        new = (struct QDir *) malloc(sizeof(struct QDir));        strcpy(new->dir, path);        new->next = NULL;    }    /*     * check 'new' for /qf directories      */    for (subdir = new; subdir != NULL; subdir = subdir->next) {        char            qf[FILENAMELEN + 1];        snprintf(qf, FILENAMELEN, "%s/qf", subdir->dir);        if ((dp = opendir(qf)) != NULL) {            /*             * it exists !              */            strcpy(subdir->dir, qf);            closedir(dp);        }    }    /*     * we now have the list of directories in 'new'; create the queuegroup     * object      */    qgrps[nqgrps].name = strdup(name);    qgrps[nqgrps].last = 0;    qgrps[nqgrps].count = 0;    qgrps[nqgrps].size = 0;    qgrps[nqgrps].dirs = new;    nqgrps++;}/** 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 directories. * *  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 BOOLread_sendmailcf(BOOL config){    FILE           *sendmailcf_fp;    char            line[500];    char           *filename;    char           *qgname, *p;    int             linenr;    int             linelen;    int             found_sendmailst = 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\"", 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;    /*     * reset queuegroups      */    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';

⌨️ 快捷键说明

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