📄 nslogging.c
字号:
if ( request->requestvb->type != ASN_INTEGER ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE); return SNMP_ERR_WRONGTYPE; } switch ( *request->requestvb->val.integer ) { case RS_ACTIVE: case RS_NOTINSERVICE: /* * Can only work on existing rows */ if (!logh) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_INCONSISTENTVALUE; } break; case RS_CREATEANDWAIT: case RS_CREATEANDGO: /* * Can only work with new rows */ if (logh) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_INCONSISTENTVALUE; } /* * Normally, we'd create the row at a later stage * (probably during the RESERVE2 or ACTION passes) * * But we need to check that the values are * consistent during the ACTION pass (which is the * latest that an error can be safely handled), * so the values all need to be set up before this * (i.e. during the RESERVE2 pass) * So the new row needs to be created before that * in order to have somewhere to put them. * * That's why we're doing this here. */ idx = table_info->indexes; logh = netsnmp_register_loghandler( /* not really, but we need a valid type */ NETSNMP_LOGHANDLER_STDOUT, *idx->val.integer); if (!logh) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_GENERR); /* ??? */ return SNMP_ERR_GENERR; } idx = idx->next_variable; logh->type = 0; logh->token = strdup(idx->val.string); netsnmp_insert_iterator_context(request, (void*)logh); break; case RS_DESTROY: /* * Can work with new or existing rows */ break; case RS_NOTREADY: default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE); return SNMP_ERR_WRONGVALUE; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); return SNMP_NOSUCHOBJECT; continue; } } break; case MODE_SET_RESERVE2: for (request=requests; request; request=request->next) { if ( request->status != 0 ) { return SNMP_ERR_NOERROR; /* Already got an error */ } logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case NSLOGGING_TYPE: /* * If we're creating a row using createAndGo, * we need to set the type early, so that we * can validate it in the ACTION pass. * * Remember that we need to be able to reverse this */ if ( logh ) logh->type = *request->requestvb->val.integer; break; /* * Don't need to handle nsLogToken or nsLogStatus in this pass */ } } break; case MODE_SET_ACTION: for (request=requests; request; request=request->next) { if (requests->processed != 0) continue; if ( request->status != 0 ) { return SNMP_ERR_NOERROR; /* Already got an error */ } logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case NSLOGGING_STATUS: /* * This is where we can check the internal consistency * of the request. Basically, for a row to be marked * 'active', then there needs to be a valid type value. */ switch ( *request->requestvb->val.integer ) { case RS_ACTIVE: case RS_CREATEANDGO: if ( !logh->type ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_INCONSISTENTVALUE; } break; } break; /* * Don't need to handle nsLogToken or nsLogType in this pass */ } } break; case MODE_SET_FREE: case MODE_SET_UNDO: /* * If any resources were allocated in either of the * two RESERVE passes, they need to be released here, * and any assignments (in RESERVE2) reversed. * * Nothing additional will have been done during ACTION * so this same code can do for UNDO as well. */ for (request=requests; request; request=request->next) { if (requests->processed != 0) continue; logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case NSLOGGING_TYPE: /* * If we've been setting the type, and the request * has failed, then revert to an unset type. * * We need to be careful here - if the reason it failed is * that the type was already set, then we shouldn't "undo" * the assignment (since it won't actually have been made). * * Check the current value against the 'new' one. If they're * the same, then this is probably a successful assignment, * and the failure was elsewhere, so we need to undo it. * (Or else there was an attempt to write the same value!) */ if ( logh && logh->type == *request->requestvb->val.integer ) logh->type = 0; break; case NSLOGGING_STATUS: temp = *request->requestvb->val.integer; if ( logh && ( temp == RS_CREATEANDGO || temp == RS_CREATEANDWAIT)) { netsnmp_remove_loghandler( logh ); } break; /* * Don't need to handle nsLogToken in this pass */ } } break; case MODE_SET_COMMIT: for (request=requests; request; request=request->next) { if (requests->processed != 0) continue; if ( request->status != 0 ) { return SNMP_ERR_NOERROR; /* Already got an error */ } logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request); if (!logh) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_COMMITFAILED); return SNMP_ERR_COMMITFAILED; /* Shouldn't happen! */ } table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case NSLOGGING_MAXLEVEL: logh->pri_max = *request->requestvb->val.integer; break; case NSLOGGING_STATUS: switch (*request->requestvb->val.integer) { case RS_ACTIVE: case RS_CREATEANDGO: logh->enabled = 1; break; case RS_NOTINSERVICE: case RS_CREATEANDWAIT: logh->enabled = 0; break; case RS_DESTROY: netsnmp_remove_loghandler( logh ); break; } break; } } break; } return SNMP_ERR_NOERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -