u_char * var_hrswinst(struct variable * vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { SWI_t *swi = &_myswi; /* XXX static for now */ int sw_idx = 0; static char string[SNMP_MAXPATH]; u_char *ret = NULL; struct stat stat_buf; if (vp->magic < HRSWINST_INDEX) { if (header_hrswinst(vp, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; } else { sw_idx = header_hrswInstEntry(vp, name, length, exact, var_len, write_method); if (sw_idx == MATCH_FAILED) return NULL; } switch (vp->magic) { case HRSWINST_CHANGE: case HRSWINST_UPDATE: string[0] = '\0'; if (swi->swi_directory != NULL) { strncpy(string, swi->swi_directory, sizeof(string)); string[ sizeof(string)-1 ] = 0; } if (*string && (stat(string, &stat_buf) != -1)) { if (stat_buf.st_mtime > starttime.tv_sec) /* * changed 'recently' - i.e. since this agent started */ long_return = (stat_buf.st_mtime - starttime.tv_sec) * 100; else long_return = 0; /* predates this agent */ } else #if NETSNMP_NO_DUMMY_VALUES return NULL; #else long_return = 363136200; #endif ret = (u_char *) & long_return; break; case HRSWINST_INDEX: long_return = sw_idx; ret = (u_char *) & long_return; break; case HRSWINST_NAME: { strncpy(string, swi->swi_name, sizeof(string) - 1); /* * This will be unchanged from the initial "null" * value, if swi->swi_name is not defined */ string[sizeof(string) - 1] = '\0'; *var_len = strlen(string); ret = (u_char *) string; } break; case HRSWINST_ID: *var_len = nullOidLen; ret = (u_char *) nullOid; break; case HRSWINST_TYPE: { #ifdef HAVE_PKGINFO /* * at least on solaris2 this works */ char *catg = pkgparam(swi->swi_name, "CATEGORY"); if (catg == NULL) { long_return = 1; /* unknown */ } else { if (strstr(catg, "system") != NULL) { long_return = 2; /* operatingSystem */ } else if (strstr(catg, "application") != NULL) { long_return = 4; /* applcation */ } else { long_return = 1; /* unknown */ } free(catg); } #else # ifdef HAVE_LIBRPM char *rpm_groups; if ( headerGetEntry(swi->swi_h, RPMTAG_GROUP, NULL, (void **) &rpm_groups, NULL) ) { if ( strstr(rpm_groups, "System Environment") != NULL ) long_return = 2; /* operatingSystem */ else long_return = 4; /* applcation */ } else { long_return = 1; /* unknown */ } # else long_return = 1; /* unknown */ # endif #endif ret = (u_char *) & long_return; } break; case HRSWINST_DATE: { #ifdef HAVE_LIBRPM int_32 *rpm_data; if ( headerGetEntry(swi->swi_h, RPMTAG_INSTALLTIME, NULL, (void **) &rpm_data, NULL) ) { time_t installTime = *rpm_data; ret = date_n_time(&installTime, var_len); } else { ret = date_n_time(0, var_len); } #else if (swi->swi_directory != NULL) { snprintf(string, sizeof(string), "%s/%s", swi->swi_directory, swi->swi_name); string[ sizeof(string)-1 ] = 0; stat(string, &stat_buf); ret = date_n_time(&stat_buf.st_mtime, var_len); } else { #if NETSNMP_NO_DUMMY_VALUES return NULL; #endif sprintf(string, "back in the mists of time"); *var_len = strlen(string); ret = (u_char *) string; } #endif } break; default: DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrswinst\n", vp->magic)); ret = NULL; break; } Release_HRSW_token(); return ret; }
/* --------------------------------------------------------------------- */ int netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags) { rpmts ts; rpmdbMatchIterator mi; Header h; char *n, *v, *r, *g; int32_t *t; time_t install_time; size_t date_len; int i = 1; netsnmp_swinst_entry *entry; ts = rpmtsCreate(); rpmtsSetVSFlags( ts, (_RPMVSF_NOSIGNATURES|_RPMVSF_NODIGESTS)); mi = rpmtsInitIterator( ts, RPMDBI_PACKAGES, NULL, 0); if (mi == NULL) NETSNMP_LOGONCE((LOG_ERR, "rpmdbOpen() failed\n")); while (NULL != (h = rpmdbNextIterator( mi ))) { const u_char *dt; entry = netsnmp_swinst_entry_create( i++ ); if (NULL == entry) continue; /* error already logged by function */ CONTAINER_INSERT(container, entry); h = headerLink( h ); headerGetEntry( h, RPMTAG_NAME, NULL, (void**)&n, NULL); headerGetEntry( h, RPMTAG_VERSION, NULL, (void**)&v, NULL); headerGetEntry( h, RPMTAG_RELEASE, NULL, (void**)&r, NULL); headerGetEntry( h, RPMTAG_GROUP, NULL, (void**)&g, NULL); headerGetEntry( h, RPMTAG_INSTALLTIME, NULL, (void**)&t, NULL); entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s-%s-%s", n, v, r); if (entry->swName_len > sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName); entry->swType = (NULL != strstr( g, "System Environment")) ? 2 /* operatingSystem */ : 4; /* application */ install_time = *t; dt = date_n_time( &install_time, &date_len ); if (date_len != 8 && date_len != 11) { snmp_log(LOG_ERR, "Bogus length from date_n_time for %s", entry->swName); entry->swDate_len = 0; } else { entry->swDate_len = date_len; memcpy(entry->swDate, dt, entry->swDate_len); } headerFree( h ); } rpmdbFreeIterator( mi ); rpmtsFree( ts ); DEBUGMSGTL(("swinst:load:arch", "loaded %d entries\n", (int)CONTAINER_SIZE(container))); return 0; }
/* --------------------------------------------------------------------- */ int netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags) { DIR *d; struct dirent *dp; struct stat stat_buf; #ifdef HAVE_PKGINFO char *v, *c; #endif char buf[ BUFSIZ ]; unsigned char *cp; time_t install_time; size_t date_len; int i = 1; netsnmp_swinst_entry *entry; #ifdef HAVE_LIBPKG struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; struct pkg *pkg = NULL; char pkgname[ SNMP_MAXPATH ]; char pkgdate[ BUFSIZ ]; int pkgng = 0; if (pkg_init(NULL, NULL)) { snmp_log( LOG_ERR, "SWInst: error initializing pkgng db\n" ); return 1; } if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) { snmp_log( LOG_ERR, "SWInst: error opening pkgng db\n" ); return 1; } if (pkg_status(NULL) == PKG_STATUS_ACTIVE) { pkgng = 1; } else { snmp_log( LOG_INFO, "SWInst: not a pkgng system\n" ); } /* if we are using FreeBSD's pkgng */ if (pkgng) { if ((it = pkgdb_query(db, NULL, MATCH_ALL)) == NULL) { snmp_log( LOG_ERR, "SWInst: error querying pkgng db\n" ); return 1; } while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) { pkg_snprintf(pkgname, sizeof(pkgname), "%n-%v", pkg, pkg); pkg_snprintf(pkgdate, sizeof(pkgdate), "%t", pkg); entry = netsnmp_swinst_entry_create( i++ ); if (NULL == entry) continue; /* error already logged by function */ CONTAINER_INSERT(container, entry); entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s", pkgname ); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; install_time = atoi(pkgdate); cp = date_n_time( &install_time, &date_len ); memcpy( entry->swDate, cp, date_len ); entry->swDate_len = date_len; } pkgdb_it_free(it); pkgdb_close(db); pkg_shutdown(); } else { #endif /* HAVE_LIBPKG */ if ( !pkg_directory[0] ) { return 1; /* Can't report installed packages if there isn't a list of them! */ } d = opendir( pkg_directory ); if (!d) return 1; while ((dp = readdir(d)) != NULL) { if ( '.' == dp->d_name[0] ) continue; snprintf( buf, BUFSIZ, "%s/%s", pkg_directory, dp->d_name ); if (stat( buf, &stat_buf ) < 0) continue; entry = netsnmp_swinst_entry_create( i++ ); if (NULL == entry) continue; /* error already logged by function */ CONTAINER_INSERT(container, entry); #ifdef HAVE_PKGINFO v = pkgparam( dp->d_name, "VERSION" ); c = pkgparam( dp->d_name, "CATEGORY" ); entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s-%s", dp->d_name, v ); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; entry->swType = (NULL != strstr( c, "system")) ? 2 /* operatingSystem */ : 4; /* application */ /* Do we need to free 'v' & 'c' ??? */ #else entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s", dp->d_name ); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; /* no information about O/S vs application packages ??? */ #endif install_time = stat_buf.st_mtime; cp = date_n_time( &install_time, &date_len ); memcpy( entry->swDate, cp, date_len ); entry->swDate_len = date_len; } closedir( d ); #ifdef HAVE_LIBPKG } #endif DEBUGMSGTL(("swinst:load:arch"," loaded %d entries\n", (int)CONTAINER_SIZE(container))); return 0; }
u_char * var_hrsys(struct variable * vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { static char string[1024]; #if defined(solaris2) /* max size of nvram property */ char bootparam[8192]; #endif time_t now; #ifndef NR_TASKS int nproc = 0; #endif #ifdef linux FILE *fp; #endif #if CAN_USE_SYSCTL && defined(CTL_KERN) && defined(KERN_MAXPROC) static int maxproc_mib[] = { CTL_KERN, KERN_MAXPROC }; int buf_size; #endif #if defined(hpux10) || defined(hpux11) struct pst_static pst_buf; #endif if (header_hrsys(vp, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; switch (vp->magic) { case HRSYS_UPTIME: long_return = get_uptime(); return (u_char *) & long_return; case HRSYS_DATE: #if defined(HAVE_MKTIME) && defined(HAVE_STIME) *write_method=ns_set_time; #endif (void *) time(&now); return (u_char *) date_n_time(&now, var_len); case HRSYS_LOAD_DEV: long_return = get_load_dev(); return (u_char *) & long_return; case HRSYS_LOAD_PARAM: #ifdef linux if((fp = fopen("/proc/cmdline", "r")) != NULL) { fgets(string, sizeof(string), fp); fclose(fp); } else { return NULL; } #elif defined(solaris2) *write_method=set_solaris_bootcommand_parameter; if ( get_solaris_eeprom_parameter("boot-command",bootparam) ) { snmp_log(LOG_ERR,"unable to lookup boot-command from eeprom\n"); return NULL; } strlcpy(string,bootparam,sizeof(string)); #else #if NO_DUMMY_VALUES return NULL; #endif sprintf(string, "ask Dave"); /* XXX */ #endif *var_len = strlen(string); return (u_char *) string; case HRSYS_USERS: long_return = count_users(); return (u_char *) & long_return; case HRSYS_PROCS: #if USING_HOST_HR_SWRUN_MODULE long_return = count_processes(); #else #if NO_DUMMY_VALUES return NULL; #endif long_return = 0; #endif return (u_char *) & long_return; case HRSYS_MAXPROCS: #if defined(NR_TASKS) long_return = NR_TASKS; /* <linux/tasks.h> */ #elif CAN_USE_SYSCTL && defined(CTL_KERN) && defined(KERN_MAXPROC) buf_size = sizeof(nproc); if (sysctl(maxproc_mib, 2, &nproc, &buf_size, NULL, 0) < 0) return NULL; long_return = nproc; #elif defined(hpux10) || defined(hpux11) pstat_getstatic(&pst_buf, sizeof(struct pst_static), 1, 0); long_return = pst_buf.max_proc; #elif defined(solaris2) long_return=get_max_solaris_processes(); if(long_return == -1) return NULL; #elif defined(NPROC_SYMBOL) auto_nlist(NPROC_SYMBOL, (char *) &nproc, sizeof(int)); long_return = nproc; #else #if NO_DUMMY_VALUES return NULL; #endif long_return = 0; #endif return (u_char *) & long_return; default: DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrsys\n", vp->magic)); } return NULL; } /* end var_hrsys */
static int iptNetflowModule_handler( netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *request) { struct snmp_vars *sys; oid obj; char buf[225]; char *p = NULL; long value; obj = request->requestvb->name[request->requestvb->name_length - 2]; sys = find_varinfo(modinfos, obj); if (!sys) { netsnmp_request_set_error(request, SNMP_ERR_NOSUCHNAME); return SNMP_ERR_NOERROR; } if (reqinfo->mode != MODE_GET) { netsnmp_request_set_error(request, SNMP_ERR_READONLY); return SNMP_ERR_NOERROR; } switch (obj) { case MODINFO_NAME_ID: p = MODINFO_NAME; break; case MODINFO_DATE_ID: { size_t len; struct stat st; modinfo_fname(".", buf, sizeof(buf)); if (stat(buf, &st) < 0) break; p = (char *)date_n_time(&st.st_mtime, &len); snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, p, len); return SNMP_ERR_NOERROR; } default: p = modinfo_read_string(sys->name, buf, sizeof(buf)); } if (!p) { netsnmp_request_set_error(request, SNMP_ERR_NOSUCHNAME); return SNMP_ERR_NOERROR; } switch (sys->type) { case ASN_INTEGER: value = atoi(p); snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)&value, sizeof(value)); break; case ASN_OCTET_STR: snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)p, strcspn(p, "\n")); break; default: netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE); } return SNMP_ERR_NOERROR; }
/** handles requests for the schedTable table */ int schedTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; netsnmp_tdata_row *row; struct schedTable_entry *entry; int recalculate = 0; size_t len; char *cp; char owner[SCHED_STR1_LEN+1]; char name[ SCHED_STR1_LEN+1]; int ret; DEBUGMSGTL(("disman:schedule:mib", "Schedule handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct schedTable_entry *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info( request); switch (tinfo->colnum) { case COLUMN_SCHEDDESCR: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedDescr, strlen(entry->schedDescr)); break; case COLUMN_SCHEDINTERVAL: snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, entry->schedInterval); break; case COLUMN_SCHEDWEEKDAY: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, &entry->schedWeekDay, sizeof(entry->schedWeekDay)); break; case COLUMN_SCHEDMONTH: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedMonth, sizeof(entry->schedMonth)); break; case COLUMN_SCHEDDAY: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedDay, sizeof(entry->schedDay)); break; case COLUMN_SCHEDHOUR: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedHour, sizeof(entry->schedHour)); break; case COLUMN_SCHEDMINUTE: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedMinute, sizeof(entry->schedMinute)); break; case COLUMN_SCHEDCONTEXTNAME: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->schedContextName, strlen(entry->schedContextName)); break; case COLUMN_SCHEDVARIABLE: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *)entry->schedVariable, entry->schedVariable_len*sizeof(oid)); break; case COLUMN_SCHEDVALUE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->schedValue); break; case COLUMN_SCHEDTYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->schedType); break; case COLUMN_SCHEDADMINSTATUS: ret = (entry->flags & SCHEDULE_FLAG_ENABLED ) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_SCHEDOPERSTATUS: ret = (entry->flags & SCHEDULE_FLAG_ENABLED ) ? TV_TRUE : TV_FALSE; /* * Check for one-shot entries that have already fired */ if ((entry->schedType == SCHED_TYPE_ONESHOT) && (entry->schedLastRun != 0 )) ret = 3; /* finished(3) */ snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_SCHEDFAILURES: snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, entry->schedFailures); break; case COLUMN_SCHEDLASTFAILURE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->schedLastFailure); break; case COLUMN_SCHEDLASTFAILED: /* * Convert 'schedLastFailed' timestamp * into DateAndTime string */ cp = (char *) date_n_time( &entry->schedLastFailed, &len ); snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, cp, len); break; case COLUMN_SCHEDSTORAGETYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->schedStorageType); break; case COLUMN_SCHEDROWSTATUS: ret = (entry->flags & SCHEDULE_FLAG_ACTIVE ) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_SCHEDTRIGGERS: snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, entry->schedTriggers); break; } } break; /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct schedTable_entry *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info( request); switch (tinfo->colnum) { case COLUMN_SCHEDDESCR: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, SCHED_STR2_LEN); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDINTERVAL: ret = netsnmp_check_vb_uint( request->requestvb ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDWEEKDAY: ret = netsnmp_check_vb_type_and_size( request->requestvb, ASN_OCTET_STR, 1); /* XXX - check for bit(7) set */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDMONTH: ret = netsnmp_check_vb_type_and_size( /* max_size ?? */ request->requestvb, ASN_OCTET_STR, 2); /* XXX - check for bit(12)-bit(15) set */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDDAY: ret = netsnmp_check_vb_type_and_size( /* max_size ?? */ request->requestvb, ASN_OCTET_STR, 4+4); /* XXX - check for bit(62) or bit(63) set */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDHOUR: ret = netsnmp_check_vb_type_and_size( /* max_size ?? */ request->requestvb, ASN_OCTET_STR, 3); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDMINUTE: ret = netsnmp_check_vb_type_and_size( /* max_size ?? */ request->requestvb, ASN_OCTET_STR, 8); /* XXX - check for bit(60)-bit(63) set */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDCONTEXTNAME: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, SCHED_STR1_LEN); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDVARIABLE: ret = netsnmp_check_vb_oid( request->requestvb ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDVALUE: ret = netsnmp_check_vb_int( request->requestvb ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDTYPE: ret = netsnmp_check_vb_int_range( request->requestvb, SCHED_TYPE_PERIODIC, SCHED_TYPE_ONESHOT ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDADMINSTATUS: ret = netsnmp_check_vb_truthvalue( request->requestvb ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDSTORAGETYPE: ret = netsnmp_check_vb_int_range( request->requestvb, ST_NONE, ST_READONLY ); /* XXX - check valid/consistent assignments */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_SCHEDROWSTATUS: ret = netsnmp_check_vb_rowstatus( request->requestvb, (entry ? RS_ACTIVE: RS_NONEXISTENT)); /* XXX - check consistency assignments */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_SCHEDROWSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Create an (empty) new row structure */ memset(owner, 0, SCHED_STR1_LEN+1); memset(name, 0, SCHED_STR1_LEN+1); memcpy(owner, tinfo->indexes->val.string, tinfo->indexes->val_len); memcpy(name, tinfo->indexes->next_variable->val.string, tinfo->indexes->next_variable->val_len); row = schedTable_createEntry(owner, name); if (!row) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } netsnmp_insert_tdata_row(request, row); } } } break; case MODE_SET_FREE: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_SCHEDROWSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Tidy up after a failed row creation request */ entry = (struct schedTable_entry *) netsnmp_tdata_extract_entry(request); if (entry && !(entry->flags & SCHEDULE_FLAG_VALID)) { row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); schedTable_removeEntry(row); } } } } break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { entry = (struct schedTable_entry *) netsnmp_tdata_extract_entry(request); if (!entry) { /* * New rows must be created via the RowStatus column */ netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOCREATION); /* or inconsistentName? */ return SNMP_ERR_NOERROR; } } break; case MODE_SET_UNDO: break; case MODE_SET_COMMIT: /* * All these assignments are "unfailable", so it's * (reasonably) safe to apply them in the Commit phase */ entry = NULL; for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct schedTable_entry *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info( request); switch (tinfo->colnum) { case COLUMN_SCHEDDESCR: memset(entry->schedDescr, 0, sizeof(entry->schedDescr)); memcpy(entry->schedDescr, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_SCHEDINTERVAL: entry->schedInterval = *request->requestvb->val.integer; recalculate = 1; break; case COLUMN_SCHEDWEEKDAY: entry->schedWeekDay = request->requestvb->val.string[0]; recalculate = 1; break; case COLUMN_SCHEDMONTH: entry->schedMonth[0] = request->requestvb->val.string[0]; entry->schedMonth[1] = request->requestvb->val.string[1]; recalculate = 1; break; case COLUMN_SCHEDDAY: memset(entry->schedDay, 0, sizeof(entry->schedDay)); memcpy(entry->schedDay, request->requestvb->val.string, request->requestvb->val_len); recalculate = 1; break; case COLUMN_SCHEDHOUR: entry->schedHour[0] = request->requestvb->val.string[0]; entry->schedHour[1] = request->requestvb->val.string[1]; entry->schedHour[2] = request->requestvb->val.string[2]; recalculate = 1; break; case COLUMN_SCHEDMINUTE: memset(entry->schedMinute, 0, sizeof(entry->schedMinute)); memcpy(entry->schedMinute, request->requestvb->val.string, request->requestvb->val_len); recalculate = 1; break; case COLUMN_SCHEDCONTEXTNAME: memset(entry->schedContextName, 0, sizeof(entry->schedContextName)); memcpy(entry->schedContextName, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_SCHEDVARIABLE: memset(entry->schedVariable, 0, sizeof(entry->schedVariable)); memcpy(entry->schedVariable, request->requestvb->val.string, request->requestvb->val_len); entry->schedVariable_len = request->requestvb->val_len/sizeof(oid); break; case COLUMN_SCHEDVALUE: entry->schedValue = *request->requestvb->val.integer; break; case COLUMN_SCHEDTYPE: entry->schedType = *request->requestvb->val.integer; break; case COLUMN_SCHEDADMINSTATUS: if (*request->requestvb->val.integer == TV_TRUE) entry->flags |= SCHEDULE_FLAG_ENABLED; else entry->flags &= ~SCHEDULE_FLAG_ENABLED; break; case COLUMN_SCHEDSTORAGETYPE: entry->schedStorageType = *request->requestvb->val.integer; break; case COLUMN_SCHEDROWSTATUS: switch (*request->requestvb->val.integer) { case RS_ACTIVE: entry->flags |= SCHEDULE_FLAG_ACTIVE; break; case RS_CREATEANDGO: entry->flags |= SCHEDULE_FLAG_ACTIVE; entry->flags |= SCHEDULE_FLAG_VALID; entry->session = netsnmp_iquery_pdu_session(reqinfo->asp->pdu); break; case RS_CREATEANDWAIT: entry->flags |= SCHEDULE_FLAG_VALID; entry->session = netsnmp_iquery_pdu_session(reqinfo->asp->pdu); break; case RS_DESTROY: row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); schedTable_removeEntry(row); } recalculate = 1; break; } } if (recalculate) { netsnmp_assert(entry); sched_nextTime(entry); } break; } return SNMP_ERR_NOERROR; }
static u_char * when_dumped(char *filesys, int level, size_t * length) { time_t dumpdate = 0, tmp; FILE *dump_fp; char line[1024]; char *cp1, *cp2, *cp3; /* * Look for the relevent entries in /etc/dumpdates * * This is complicated by the fact that disks are * mounted using block devices, but dumps are * done via the raw character devices. * Thus the device names in /etc/dumpdates and * /etc/mnttab don't match. * These comparisons are therefore made using the * final portion of the device name only. */ if (*filesys == '\0') /* No filesystem name? */ return date_n_time(NULL, length); cp1 = strrchr(filesys, '/'); /* Find the last element of the current FS */ if (cp1 == NULL) cp1 = filesys; if ((dump_fp = fopen("/etc/dumpdates", "r")) == NULL) return date_n_time(NULL, length); while (fgets(line, sizeof(line), dump_fp) != NULL) { cp2 = strchr(line, ' '); /* Start by looking at the device name only */ if (cp2 != NULL) { *cp2 = '\0'; cp3 = strrchr(line, '/'); /* and find the last element */ if (cp3 == NULL) cp3 = line; if (strcmp(cp1, cp3) != 0) /* Wrong FS */ continue; ++cp2; while (isspace(0xFF & *cp2)) ++cp2; /* Now find the dump level */ if (level == FULL_DUMP) { if (*(cp2++) != '0') continue; /* Not interested in partial dumps */ while (isspace(0xFF & *cp2)) ++cp2; dumpdate = ctime_to_timet(cp2); fclose(dump_fp); return date_n_time(&dumpdate, length); } else { /* Partial Dump */ if (*(cp2++) == '0') continue; /* Not interested in full dumps */ while (isspace(0xFF & *cp2)) ++cp2; tmp = ctime_to_timet(cp2); if (tmp > dumpdate) dumpdate = tmp; /* Remember the 'latest' partial dump */ } } } fclose(dump_fp); return date_n_time(&dumpdate, length); }
/* --------------------------------------------------------------------- */ int netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags) { DIR *d; struct dirent *dp; struct stat stat_buf; #ifdef HAVE_PKGINFO char *v, *c; #endif char buf[ BUFSIZ ]; unsigned char *cp; time_t install_time; size_t date_len; int i = 1; netsnmp_swinst_entry *entry; if ( !pkg_directory[0] ) { return 1; /* Can't report installed packages if there isn't a list of them! */ } d = opendir( pkg_directory ); while (d != NULL && (dp = readdir(d)) != NULL) { if ( '.' == dp->d_name[0] ) continue; entry = netsnmp_swinst_entry_create( i++ ); if (NULL == entry) continue; /* error already logged by function */ CONTAINER_INSERT(container, entry); #ifdef HAVE_PKGINFO v = pkgparam( dp->d_name, "VERSION" ); c = pkgparam( dp->d_name, "CATEGORY" ); entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s-%s", dp->d_name, v ); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; entry->swType = (NULL != strstr( c, "system")) ? 2 /* operatingSystem */ : 4; /* application */ /* Do we need to free 'v' & 'c' ??? */ #else entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s", dp->d_name ); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; /* no information about O/S vs application packages ??? */ #endif snprintf( buf, BUFSIZ, "%s/%s", pkg_directory, dp->d_name ); stat( buf, &stat_buf ); install_time = stat_buf.st_mtime; cp = date_n_time( &install_time, &date_len ); memcpy( entry->swDate, cp, date_len ); entry->swDate_len = date_len; } closedir( d ); DEBUGMSGTL(("swinst:load:arch"," loaded %d entries\n", (int)CONTAINER_SIZE(container))); return 0; }
void log_notification(struct hostent *host, netsnmp_pdu *pdu, netsnmp_transport *transport) { long tmpl; struct timeval now; netsnmp_table_row *row; static oid snmptrapoid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; size_t snmptrapoid_len = OID_LENGTH(snmptrapoid); netsnmp_variable_list *vptr; u_char *logdate; size_t logdate_size; time_t timetnow; u_long vbcount = 0; u_long tmpul; int col; if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_APP_DONT_LOG)) { return; } DEBUGMSGTL(("log_notification", "logging something\n")); row = netsnmp_create_table_data_row(); default_num++; /* * indexes to the table */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, "default", strlen("default")); netsnmp_table_row_add_index(row, ASN_UNSIGNED, &default_num, sizeof(default_num)); /* * add the data */ gettimeofday(&now, NULL); tmpl = netsnmp_timeval_uptime(&now); netsnmp_set_row_column(row, COLUMN_NLMLOGTIME, ASN_TIMETICKS, (u_char *) & tmpl, sizeof(tmpl)); time(&timetnow); logdate = date_n_time(&timetnow, &logdate_size); netsnmp_set_row_column(row, COLUMN_NLMLOGDATEANDTIME, ASN_OCTET_STR, logdate, logdate_size); netsnmp_set_row_column(row, COLUMN_NLMLOGENGINEID, ASN_OCTET_STR, pdu->securityEngineID, pdu->securityEngineIDLen); if (transport && transport->domain == netsnmpUDPDomain) { /* * lame way to check for the udp domain */ /* * no, it is the correct way to do it -- jbpn */ struct sockaddr_in *addr = (struct sockaddr_in *) pdu->transport_data; if (addr) { char buf[sizeof(in_addr_t) + sizeof(addr->sin_port)]; in_addr_t locaddr = htonl(addr->sin_addr.s_addr); u_short portnum = htons(addr->sin_port); memcpy(buf, &locaddr, sizeof(in_addr_t)); memcpy(buf + sizeof(in_addr_t), &portnum, sizeof(addr->sin_port)); netsnmp_set_row_column(row, COLUMN_NLMLOGENGINETADDRESS, ASN_OCTET_STR, buf, sizeof(in_addr_t) + sizeof(addr->sin_port)); } } netsnmp_set_row_column(row, COLUMN_NLMLOGENGINETDOMAIN, ASN_OBJECT_ID, (const u_char *) transport->domain, sizeof(oid) * transport->domain_length); netsnmp_set_row_column(row, COLUMN_NLMLOGCONTEXTENGINEID, ASN_OCTET_STR, pdu->contextEngineID, pdu->contextEngineIDLen); netsnmp_set_row_column(row, COLUMN_NLMLOGCONTEXTNAME, ASN_OCTET_STR, pdu->contextName, pdu->contextNameLen); for (vptr = pdu->variables; vptr; vptr = vptr->next_variable) { if (snmp_oid_compare(snmptrapoid, snmptrapoid_len, vptr->name, vptr->name_length) == 0) { netsnmp_set_row_column(row, COLUMN_NLMLOGNOTIFICATIONID, ASN_OBJECT_ID, vptr->val.string, vptr->val_len); } else { netsnmp_table_row *myrow; myrow = netsnmp_create_table_data_row(); /* * indexes to the table */ netsnmp_table_row_add_index(myrow, ASN_OCTET_STR, "default", strlen("default")); netsnmp_table_row_add_index(myrow, ASN_UNSIGNED, &default_num, sizeof(default_num)); vbcount++; netsnmp_table_row_add_index(myrow, ASN_UNSIGNED, &vbcount, sizeof(vbcount)); /* * OID */ netsnmp_set_row_column(myrow, COLUMN_NLMLOGVARIABLEID, ASN_OBJECT_ID, (u_char *) vptr->name, vptr->name_length * sizeof(oid)); /* * value */ switch (vptr->type) { case ASN_OBJECT_ID: tmpul = 7; col = COLUMN_NLMLOGVARIABLEOIDVAL; break; case ASN_INTEGER: tmpul = 4; col = COLUMN_NLMLOGVARIABLEINTEGER32VAL; break; case ASN_UNSIGNED: tmpul = 2; col = COLUMN_NLMLOGVARIABLEUNSIGNED32VAL; break; case ASN_COUNTER: tmpul = 1; col = COLUMN_NLMLOGVARIABLECOUNTER32VAL; break; case ASN_TIMETICKS: tmpul = 3; col = COLUMN_NLMLOGVARIABLETIMETICKSVAL; break; case ASN_OCTET_STR: tmpul = 6; col = COLUMN_NLMLOGVARIABLEOCTETSTRINGVAL; break; default: /* * unsupported */ DEBUGMSGTL(("log_notification", "skipping type %d\n", vptr->type)); continue; } netsnmp_set_row_column(myrow, COLUMN_NLMLOGVARIABLEVALUETYPE, ASN_INTEGER, (u_char *) & tmpul, sizeof(tmpul)); netsnmp_set_row_column(myrow, col, vptr->type, vptr->val.string, vptr->val_len); DEBUGMSGTL(("log_notification", "adding a row to the variables table\n")); netsnmp_table_dataset_add_row(nlmLogVarTable, myrow); } } /* * store the row */ netsnmp_table_dataset_add_row(nlmLogTable, row); check_log_size(0, NULL); DEBUGMSGTL(("log_notification", "done logging something\n")); }