int main(int argc, char **argv) { int opt; int use_var = 0; const char *pattern = "/files//*"; struct timeval stop, start; while ((opt = getopt(argc, argv, "n")) != -1) { switch (opt) { case 'n': use_var = 1; break; default: fprintf(stderr, "Usage: %s [-n] [pattern]\n", argv[0]); fprintf(stderr, " without '-n', iterate matches\n"); fprintf(stderr, " with '-n', use a variable and aug_ns_*\n"); exit(EXIT_FAILURE); break; } } struct augeas *aug = aug_init(NULL, NULL, 0); if (optind < argc) pattern = argv[optind]; gettimeofday(&start, NULL); if (use_var) { dump_var(aug, pattern); } else { dump_match(aug, pattern); } gettimeofday(&stop, NULL); print_time_taken(&start, &stop); return 0; }
int handle_var_list(struct agent_snmp_session *asp) { struct variable_list *varbind_ptr; u_char statType; u_char *statP; size_t statLen; u_short acl; WriteMethod *write_method; AddVarMethod *add_method; int noSuchObject = TRUE; int count, view; count = 0; varbind_ptr = asp->start; if ( !varbind_ptr ) { return SNMP_ERR_NOERROR; } while (1) { count++; statp_loop: statP = getStatPtr( varbind_ptr->name, &varbind_ptr->name_length, &statType, &statLen, &acl, asp->exact, &write_method, asp->pdu, &noSuchObject); if (statP == NULL && (asp->rw != WRITE || write_method == NULL)) { /* Careful -- if the varbind was lengthy, it will have allocated some memory. */ snmp_set_var_value(varbind_ptr, NULL, 0); varbind_ptr->val.integer = NULL; varbind_ptr->val_len = 0; if ( asp->exact ) { if ( noSuchObject == TRUE ){ statType = SNMP_NOSUCHOBJECT; } else { statType = SNMP_NOSUCHINSTANCE; } } else { statType = SNMP_ENDOFMIBVIEW; } if (asp->pdu->version == SNMP_VERSION_1) { asp->pdu->errstat = SNMP_ERR_NOSUCHNAME; asp->pdu->errindex = count; return SNMP_ERR_NOSUCHNAME; } else if (asp->rw == WRITE) { asp->pdu->errstat = ( noSuchObject ? SNMP_ERR_NOTWRITABLE : SNMP_ERR_NOCREATION ); asp->pdu->errindex = count; return asp->pdu->errstat; } else varbind_ptr->type = statType; } /* Delegated variables should be added to the relevant outgoing request */ else if ( IS_DELEGATED(statType)) { add_method = (AddVarMethod*)statP; statType = (*add_method)( asp, varbind_ptr ); } /* GETNEXT/GETBULK should just skip inaccessible entries */ else if ((view = in_a_view(varbind_ptr->name, &varbind_ptr->name_length, asp->pdu, varbind_ptr->type)) && !asp->exact) { if (view != 5) send_easy_trap(SNMP_TRAP_AUTHFAIL, 0); goto statp_loop; } /* Other access problems are permanent */ else if (( asp->rw == WRITE && !(acl & 2)) || view) { if (asp->pdu->version == SNMP_VERSION_1 || asp->rw != WRITE) { if (ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_VERBOSE)) DEBUGMSGTL(("snmp_agent", " >> noSuchName (read-only)\n")); ERROR_MSG("read-only"); statType = SNMP_ERR_NOSUCHNAME; } else { if (ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_VERBOSE)) DEBUGMSGTL(("snmp_agent", " >> notWritable\n")); ERROR_MSG("Not Writable"); statType = SNMP_ERR_NOTWRITABLE; } asp->pdu->errstat = statType; asp->pdu->errindex = count; send_easy_trap(SNMP_TRAP_AUTHFAIL, 0); return statType; } else { /* dump verbose info */ if (ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_VERBOSE) && statP) dump_var(varbind_ptr->name, varbind_ptr->name_length, statType, statP, statLen); /* FINALLY we can act on SET requests ....*/ if ( asp->rw == WRITE ) { if ( write_method != NULL ) { statType = (*write_method)(asp->mode, varbind_ptr->val.string, varbind_ptr->type, varbind_ptr->val_len, statP, varbind_ptr->name, varbind_ptr->name_length); if (statType != SNMP_ERR_NOERROR) { asp->pdu->errstat = statType; asp->pdu->errindex = count; return statType; } } else { if (!goodValue(varbind_ptr->type, varbind_ptr->val_len, statType, statLen)){ if (asp->pdu->version == SNMP_VERSION_1) statType = SNMP_ERR_BADVALUE; else statType = SNMP_ERR_WRONGTYPE; /* poor approximation */ asp->pdu->errstat = statType; asp->pdu->errindex = count; return statType; } /* actually do the set if necessary */ if (asp->mode == COMMIT) setVariable(varbind_ptr->val.string, varbind_ptr->type, varbind_ptr->val_len, statP, statLen); } } /* ... or save the results from assorted GETs */ else { snmp_set_var_value(varbind_ptr, statP, statLen); varbind_ptr->type = statType; } } if ( varbind_ptr == asp->end ) return SNMP_ERR_NOERROR; varbind_ptr = varbind_ptr->next_variable; if ( asp->mode == RESERVE1 ) snmp_vars_inc++; } }