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

📄 extensible.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
            tname[etmp2->miblen] = i;            unregister_mib(tname, etmp2->miblen+1);        }        for (i=100; i<=103; i++) {            tname[etmp2->miblen] = i;            unregister_mib(tname, etmp2->miblen+1);        }        free(etmp2);    }    relocs = NULL;    extens = NULL;    numextens = 0;    numrelocs = 0;}#define MAXMSGLINES 1000struct extensible *extens = NULL;       /* In exec.c */struct extensible *relocs = NULL;       /* In exec.c */int             numextens = 0, numrelocs = 0;   /* ditto *//* * var_extensible_shell(... * Arguments: * vp     IN      - pointer to variable entry that points here * name    IN/OUT  - IN/name requested, OUT/name found * length  IN/OUT  - length of IN/OUT oid's  * exact   IN      - TRUE if an exact match was requested * var_len OUT     - length of variable or 0 if function returned * write_method *  *//* * find a give entry in the linked list associated with a proc name  */struct extensible *get_exec_by_name(char *name){    struct extensible *etmp;    if (name == NULL)        return NULL;    for (etmp = extens; etmp != NULL && strcmp(etmp->name, name) != 0;         etmp = etmp->next);    if(NULL == etmp)        for (etmp = relocs; etmp != NULL && strcmp(etmp->name, name) != 0;         etmp = etmp->next);    return etmp;}voidexecfix_parse_config(const char *token, char *cptr){    char            tmpname[STRMAX];    struct extensible *execp;    /*     * don't allow two entries with the same name      */    cptr = copy_nword(cptr, tmpname, sizeof(tmpname));    if ((execp = get_exec_by_name(tmpname)) == NULL) {        config_perror("No exec entry registered for this exec name yet.");        return;    }    if (strlen(cptr) > sizeof(execp->fixcmd)) {        config_perror("fix command too long.");        return;    }    strncpy(execp->fixcmd, cptr, sizeof(execp->fixcmd));    execp->fixcmd[ sizeof(execp->fixcmd)-1 ] = 0;}u_char         *var_extensible_shell(struct variable * vp,                     oid * name,                     size_t * length,                     int exact,                     size_t * var_len, WriteMethod ** write_method){    static struct extensible *exten = 0;    static long     long_ret;    int len;    if (header_simple_table        (vp, name, length, exact, var_len, write_method, numextens))        return (NULL);    if ((exten = get_exten_instance(extens, name[*length - 1]))) {        switch (vp->magic) {        case MIBINDEX:            long_ret = name[*length - 1];            return ((u_char *) (&long_ret));        case ERRORNAME:        /* name defined in config file */            *var_len = strlen(exten->name);            return ((u_char *) (exten->name));        case SHELLCOMMAND:            *var_len = strlen(exten->command);            return ((u_char *) (exten->command));        case ERRORFLAG:        /* return code from the process */            len = sizeof(exten->output);            if (exten->type == EXECPROC) {                exten->result = run_exec_command( exten->command, NULL,                                                  exten->output, &len);	    } else {                exten->result = run_shell_command(exten->command, NULL,                                                  exten->output, &len);	    }            long_ret = exten->result;            return ((u_char *) (&long_ret));        case ERRORMSG:         /* first line of text returned from the process */            len = sizeof(exten->output);            if (exten->type == EXECPROC) {                exten->result = run_exec_command( exten->command, NULL,                                                  exten->output, &len);	    } else {                exten->result = run_shell_command(exten->command, NULL,                                                  exten->output, &len);	    }            *var_len = strlen(exten->output);            if (exten->output[*var_len - 1] == '\n')                exten->output[--(*var_len)] = '\0';            return ((u_char *) (exten->output));        case ERRORFIX:            *write_method = fixExecError;            long_return = 0;            return ((u_char *) & long_return);        case ERRORFIXCMD:            *var_len = strlen(exten->fixcmd);            return ((u_char *) exten->fixcmd);        }        return NULL;    }    return NULL;}intfixExecError(int action,             u_char * var_val,             u_char var_val_type,             size_t var_val_len,             u_char * statP, oid * name, size_t name_len){    struct extensible *exten;    long            tmp = 0;    int             fd;    static struct extensible ex;    FILE           *file;    if ((exten = get_exten_instance(extens, name[10]))) {        if (var_val_type != ASN_INTEGER) {            snmp_log(LOG_ERR, "Wrong type != int\n");            return SNMP_ERR_WRONGTYPE;        }        tmp = *((long *) var_val);        if ((tmp == 1) && (action == COMMIT) && (exten->fixcmd[0] != 0)) {            sprintf(ex.command, exten->fixcmd);            if ((fd = get_exec_output(&ex)) != -1) {                file = fdopen(fd, "r");                while (fgets(ex.output, sizeof(ex.output), file) != NULL);                fclose(file);                wait_on_exec(&ex);            }        }        return SNMP_ERR_NOERROR;    }    return SNMP_ERR_WRONGTYPE;}u_char         *var_extensible_relocatable(struct variable *vp,                           oid * name,                           size_t * length,                           int exact,                           size_t * var_len, WriteMethod ** write_method){    int             i;    int             len;    struct extensible *exten = 0;    static long     long_ret;    static char     errmsg[STRMAX];    char            *cp, *cp1;    struct variable myvp;    oid             tname[MAX_OID_LEN];    memcpy(&myvp, vp, sizeof(struct variable));    long_ret = *length;    for (i = 1; i <= (int) numrelocs; i++) {        exten = get_exten_instance(relocs, i);        if ((int) exten->miblen == (int) vp->namelen - 1) {            memcpy(myvp.name, exten->miboid, exten->miblen * sizeof(oid));            myvp.namelen = exten->miblen;            *length = vp->namelen;            memcpy(tname, vp->name, vp->namelen * sizeof(oid));            if (!header_simple_table                (&myvp, tname, length, -1, var_len, write_method, -1))                break;            else                exten = NULL;        }    }    if (i > (int) numrelocs || exten == NULL) {        *length = long_ret;        *var_len = 0;        *write_method = NULL;        return (NULL);    }    *length = long_ret;    if (header_simple_table(vp, name, length, exact, var_len, write_method,                            ((vp->magic == ERRORMSG) ? MAXMSGLINES : 1)))        return (NULL);    switch (vp->magic) {    case MIBINDEX:        long_ret = name[*length - 1];        return ((u_char *) (&long_ret));    case ERRORNAME:            /* name defined in config file */        *var_len = strlen(exten->name);        return ((u_char *) (exten->name));    case SHELLCOMMAND:        *var_len = strlen(exten->command);        return ((u_char *) (exten->command));    case ERRORFLAG:            /* return code from the process */        len = sizeof(exten->output);        if (exten->type == EXECPROC)            exten->result = run_exec_command( exten->command, NULL,                                              exten->output, &len);	else            exten->result = run_shell_command(exten->command, NULL,                                              exten->output, &len);        long_ret = exten->result;        return ((u_char *) (&long_ret));    case ERRORMSG:             /* first line of text returned from the process */        len = sizeof(exten->output);        if (exten->type == EXECPROC)            exten->result = run_exec_command( exten->command, NULL,                                              exten->output, &len);	else            exten->result = run_shell_command(exten->command, NULL,                                              exten->output, &len);        /*         *  Pick the output string apart into individual lines,         *  and extract the one being asked for....         */        cp1 = exten->output;        for (i = 1; i != (int) name[*length - 1]; i++) {            cp = strchr(cp1, '\n');            if (!cp) {	        *var_len = 0;	        /* wait_on_exec(exten);		??? */	        return NULL;	    }	    cp1 = ++cp;	}        /*         *  ... and quit if we've run off the end of the output         */        if (!*cp1) {            *var_len = 0;	    return NULL;	}        cp = strchr(cp1, '\n');        if (cp)            *cp = 0;        strncpy(errmsg, cp1, sizeof(errmsg));        errmsg[ sizeof(errmsg)-1 ] = 0;        *var_len = strlen(errmsg);        if (errmsg[*var_len - 1] == '\n')            errmsg[--(*var_len)] = '\0';        return ((u_char *) (errmsg));    case ERRORFIX:        *write_method = fixExecError;        long_return = 0;        return ((u_char *) & long_return);    case ERRORFIXCMD:        *var_len = strlen(exten->fixcmd);        return ((u_char *) exten->fixcmd);    }    return NULL;}netsnmp_subtree *find_extensible(netsnmp_subtree *tp, oid *tname, size_t tnamelen, int exact){    size_t          tmp;    int             i;    struct extensible *exten = 0;    struct variable myvp;    oid             name[MAX_OID_LEN];    static netsnmp_subtree mysubtree[2] =	{ { NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, NULL, NULL, 0, 0, 0,	    NULL, NULL, NULL, 0, 0, NULL, 0, 0 },	  { NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, NULL, NULL, 0, 0, 0,	    NULL, NULL, NULL, 0, 0, NULL, 0, 0 } };    for (i = 1; i <= (int) numrelocs; i++) {        exten = get_exten_instance(relocs, i);        if (exten->miblen != 0) {            memcpy(myvp.name, exten->miboid, exten->miblen * sizeof(oid));            memcpy(name, tname, tnamelen * sizeof(oid));            myvp.name[exten->miblen] = name[exten->miblen];            myvp.namelen = exten->miblen + 1;            tmp = exten->miblen + 1;            if (!header_simple_table(&myvp, name, &tmp, -1, 				     NULL, NULL, numrelocs)) {                break;	    }        }    }    if (i > (int)numrelocs || exten == NULL) {        return (tp);    }    if (mysubtree[0].name_a != NULL) {	free(mysubtree[0].name_a);	mysubtree[0].name_a = NULL;    }    mysubtree[0].name_a  = snmp_duplicate_objid(exten->miboid, exten->miblen);    mysubtree[0].namelen = exten->miblen;    mysubtree[0].variables = (struct variable *)extensible_relocatable_variables;    mysubtree[0].variables_len = sizeof(extensible_relocatable_variables) /        sizeof(*extensible_relocatable_variables);    mysubtree[0].variables_width = sizeof(*extensible_relocatable_variables);    mysubtree[1].namelen = 0;    return (mysubtree);}

⌨️ 快捷键说明

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