📄 winextdll.c
字号:
// If the OID we got back is outside our view, increment the current supported view and send it back instead. // This is for Windows extension agents that support multiple views. We want Net-SNMP to decide if we should be // called for this OID, not the extension agent, just in case there is a Net-SNMP agent in between. else if (snmp_oidtree_compare(var->name, var->name_length, winExtensionAgent_name, winExtensionAgent_name_length) > 0) { DEBUGMSGTL(("winExtDLL", "xSnmpExtensionQuery(Ex) returned an OID outside our view\n")); DEBUGMSGTL(("winExtDLL", " Setting return OID to be equal to current supported view, plus one\n")); // Set var->name to be equal to current supported view, plus one for (i = 0; i < (winExtensionAgent_name_length > MAX_OID_LEN? MAX_OID_LEN: winExtensionAgent_name_length); i++) { var->name[i] = winExtensionAgent_name[i]; } var->name_length = i; var->name[i-1]++; //return SNMP_ERR_NOSUCHNAME; } } DEBUGMSGTL(("winExtDLL", "OID being sent back to Net-SNMP: ")); DEBUGMSGOID(("winExtDLL", var->name, var->name_length)); DEBUGMSG(("winExtDLL", "\n")); DEBUGMSGTL(("winExtDLL", "win: Result of xSnmpExtensionQuery(Ex): %d\n",result)); DEBUGMSGTL(("winExtDLL", "win: Error status of xSnmpExtensionQuery(Ex): %d\n",pErrorStatus)); DEBUGMSGTL(("winExtDLL", "win: asnType: %d\n",pVarBindList.list->value.asnType)); // Set Net-SNMP ASN type based on closest match to Windows ASN type switch (pVarBindList.list->value.asnType) { case MS_ASN_OCTETSTRING: netsnmp_ASN_type = ASN_OCTET_STR; DEBUGMSGTL(("winExtDLL", "MS_ASN_OCTETSTRING = ASN_OCTET_STR\n")); break; case MS_ASN_INTEGER: // And MS_ASN_INTEGER32 netsnmp_ASN_type = ASN_INTEGER; DEBUGMSGTL(("winExtDLL", "MS_ASN_INTEGER = ASN_INTEGER\n")); break; case MS_ASN_UNSIGNED32: // SNMP v2 netsnmp_ASN_type = ASN_UNSIGNED; DEBUGMSGTL(("winExtDLL", "MS_ASN_UNSIGNED32 = ASN_UNSIGNED\n")); break; case MS_ASN_COUNTER64: // SNMP v2 netsnmp_ASN_type = ASN_COUNTER64; DEBUGMSGTL(("winExtDLL", "MS_ASN_COUNTER64 = ASN_COUNTER64\n")); break; case MS_ASN_BITS: netsnmp_ASN_type = ASN_BIT_STR; DEBUGMSGTL(("winExtDLL", "MS_ASN_BITS = ASN_BIT_STR\n")); break; case MS_ASN_OBJECTIDENTIFIER: netsnmp_ASN_type = ASN_OBJECT_ID; DEBUGMSGTL(("winExtDLL", "MS_ASN_OBJECTIDENTIFIER = ASN_OBJECT_ID\n")); break; case MS_ASN_SEQUENCE: netsnmp_ASN_type = ASN_SEQUENCE; DEBUGMSGTL(("winExtDLL", "MS_ASN_SEQUENCE = ASN_SEQUENCE\n")); break; case MS_ASN_IPADDRESS: netsnmp_ASN_type = ASN_IPADDRESS; DEBUGMSGTL(("winExtDLL", "MS_ASN_IPADDRESS = ASN_IPADDRESS\n")); break; case MS_ASN_COUNTER32: netsnmp_ASN_type = ASN_COUNTER; DEBUGMSGTL(("winExtDLL", "MS_ASN_COUNTER32 = ASN_COUNTER\n")); break; case MS_ASN_GAUGE32: netsnmp_ASN_type = ASN_GAUGE; DEBUGMSGTL(("winExtDLL", "MS_ASN_GAUGE32 = ASN_GAUGE\n")); break; case MS_ASN_TIMETICKS: netsnmp_ASN_type = ASN_TIMETICKS; DEBUGMSGTL(("winExtDLL", "MS_ASN_TIMETICKS = ASN_TIMETICKS\n")); break; case MS_ASN_OPAQUE: netsnmp_ASN_type = ASN_OPAQUE; DEBUGMSGTL(("winExtDLL", "MS_ASN_OPAQUE = ASN_OPAQUE\n")); break; default: netsnmp_ASN_type = ASN_INTEGER; DEBUGMSGTL(("winExtDLL", "unknown MS ASN type. Defaulting to ASN_INTEGER\n")); break; } DEBUGMSGTL(("winExtDLL", "Net-SNMP object type for returned value: %d\n",netsnmp_ASN_type)); switch (pVarBindList.list->value.asnType) { case MS_ASN_IPADDRESS: case MS_ASN_OCTETSTRING: strncpy(ret_szbuf_temp, pVarBindList.list->value.asnValue.string.stream, (pVarBindList.list->value.asnValue.string.length > SZBUF_MAX?SZBUF_MAX:pVarBindList.list->value.asnValue.string.length)); if (pVarBindList.list->value.asnValue.string.length < SZBUF_MAX) ret_szbuf_temp[pVarBindList.list->value.asnValue.string.length] = '\0'; else ret_szbuf_temp[SZBUF_MAX-1] = '\0'; // Printing strings that have a comma in them via DEBUGMSGTL doesn't work.. DEBUGMSGTL(("winExtDLL", "Note: Sometimes junk is outputted here even though the string is fine. Problem with DEBUGMSGTL?\n",ret_szbuf_temp)); DEBUGMSGTL(("winExtDLL", "win: String: %s\n",ret_szbuf_temp)); DEBUGMSGTL(("winExtDLL", "win: length of string response: %d\n",strlen(ret_szbuf_temp))); snmp_set_var_typed_value(var, netsnmp_ASN_type, ret_szbuf_temp, strlen(ret_szbuf_temp)); //return SNMP_ERR_NOERROR; break; case MS_ASN_INTEGER: // And MS_ASN_INTEGER32 case MS_ASN_UNSIGNED32: case MS_ASN_COUNTER64: case MS_ASN_BITS: case MS_ASN_SEQUENCE: case MS_ASN_COUNTER32: case MS_ASN_GAUGE32: case MS_ASN_TIMETICKS: case MS_ASN_OPAQUE: DEBUGMSGTL(("winExtDLL", "win: Long: %ld\n",pVarBindList.list->value.asnValue.number)); ret_long = pVarBindList.list->value.asnValue.number; // Return results snmp_set_var_typed_value(var, netsnmp_ASN_type, &ret_long, sizeof(ret_long)); //return SNMP_ERR_NOERROR; break; case MS_ASN_OBJECTIDENTIFIER: // Convert OID to Net-SNMP DEBUGMSGTL(("winExtDLL", "Returned OID: ")); DEBUGMSGWINOID(("winExtDLL", &pVarBindList.list->value.asnValue.object)); DEBUGMSG(("winExtDLL", "\n")); // Convert OID from Windows to Net-SNMP for (i = 0; i < (pVarBindList.list->value.asnValue.object.idLength > MAX_OID_LEN?MAX_OID_LEN: pVarBindList.list->value.asnValue.object.idLength); i++) { ret_oid[i] = (oid)pVarBindList.list->value.asnValue.object.ids[i]; } ret_oid_length = i; DEBUGMSGTL(("winExtDLL", "Windows OID converted to Net-SNMP: ")); DEBUGMSGOID(("winExtDLL", ret_oid, ret_oid_length)); DEBUGMSG(("winExtDLL", "\n")); snmp_set_var_typed_value(var, netsnmp_ASN_type, ret_oid, ret_oid_length * sizeof(oid)); //return SNMP_ERR_NOERROR; break; default: // The Windows agent didn't return data so set values to NULL // FIXME: We never get here. We set it to INTEGER above.. snmp_set_var_typed_value(var, NULL, NULL, NULL); break; } if (&pVarBindList) SnmpUtilVarBindListFree(&pVarBindList); } break; case MODE_SET_RESERVE1: case MODE_SET_RESERVE2: case MODE_SET_ACTION: DEBUGMSGTL(("winExtDLL", "SET requested\n")); for (request = requests; request; request=request->next) { var = request->requestvb; DEBUGMSGTL(("winExtDLL", "requested: ")); DEBUGMSGOID(("winExtDLL", var->name, var->name_length)); DEBUGMSG(("winExtDLL", "\n")); DEBUGMSGTL(("winExtDLL", "Var type requested: %d\n",var->type)); /* Loop through all the winExtensionAgent's looking for a matching handler */ xSnmpExtensionQuery = NULL; xSnmpExtensionQueryEx = NULL; for (i=0; winExtensionAgent[i].xSnmpExtensionInit && i < MAX_WINEXT_DLLS; i++) { DEBUGMSGTL(("winExtDLL", "Looping through all the winExtensionAgent's looking for a matching handler.\n")); if (snmp_oidtree_compare(var->name, var->name_length, winExtensionAgent[i].name, winExtensionAgent[i].name_length) >= 0) { DEBUGMSGTL(("winExtDLL", "Found match: ")); DEBUGMSGOID(("winExtDLL", winExtensionAgent[i].name, winExtensionAgent[i].name_length)); DEBUGMSG(("winExtDLL", "\n")); xSnmpExtensionQuery = winExtensionAgent[i].xSnmpExtensionQuery; xSnmpExtensionQueryEx = winExtensionAgent[i].xSnmpExtensionQueryEx; break; } } if (! (xSnmpExtensionQuery || xSnmpExtensionQueryEx)) { DEBUGMSGTL(("winExtDLL","Could not find a handler for the requested OID. This should never happen!!\n")); return SNMP_ERR_GENERR; } // Set Windows ASN type based on closest match to Net-SNMP ASN type switch (var->type) { case ASN_OCTET_STR: windows_ASN_type = MS_ASN_OCTETSTRING; DEBUGMSGTL(("winExtDLL", "MS_ASN_OCTETSTRING = ASN_OCTET_STR\n")); break; case ASN_INTEGER: // And MS_ASN_INTEGER32 windows_ASN_type = MS_ASN_INTEGER; DEBUGMSGTL(("winExtDLL", "MS_ASN_INTEGER = ASN_INTEGER\n")); break; case ASN_UNSIGNED: windows_ASN_type = MS_ASN_UNSIGNED32; DEBUGMSGTL(("winExtDLL", "MS_ASN_UNSIGNED32 = ASN_UNSIGNED\n")); break; case ASN_COUNTER64: windows_ASN_type = MS_ASN_COUNTER64; DEBUGMSGTL(("winExtDLL", "MS_ASN_COUNTER64 = ASN_COUNTER64\n")); break; case ASN_BIT_STR: windows_ASN_type = MS_ASN_BITS; DEBUGMSGTL(("winExtDLL", "MS_ASN_BITS = ASN_BIT_STR\n")); break; case ASN_OBJECT_ID: windows_ASN_type = MS_ASN_OBJECTIDENTIFIER; DEBUGMSGTL(("winExtDLL", "MS_ASN_OBJECTIDENTIFIER = ASN_OBJECT_ID\n")); break; case ASN_SEQUENCE: windows_ASN_type = MS_ASN_SEQUENCE; DEBUGMSGTL(("winExtDLL", "MS_ASN_SEQUENCE = ASN_SEQUENCE\n")); break; case ASN_IPADDRESS: windows_ASN_type = MS_ASN_IPADDRESS; DEBUGMSGTL(("winExtDLL", "MS_ASN_IPADDRESS = ASN_IPADDRESS\n")); break; case ASN_COUNTER: windows_ASN_type = MS_ASN_COUNTER32; DEBUGMSGTL(("winExtDLL", "MS_ASN_COUNTER32 = ASN_COUNTER\n")); break;// case ASN_GAUGE: // Same as UNSIGNED// windows_ASN_type = MS_ASN_GAUGE32;// DEBUGMSGTL(("winExtDLL", "MS_ASN_GAUGE32 = ASN_GAUGE\n"));// break; case ASN_TIMETICKS: windows_ASN_type = MS_ASN_TIMETICKS; DEBUGMSGTL(("winExtDLL", "MS_ASN_TIMETICKS = ASN_TIMETICKS\n")); break; case ASN_OPAQUE: windows_ASN_type = MS_ASN_OPAQUE; DEBUGMSGTL(("winExtDLL", "MS_ASN_OPAQUE = ASN_OPAQUE\n")); break; default: windows_ASN_type = MS_ASN_INTEGER; DEBUGMSGTL(("winExtDLL", "unknown MS ASN type. Defaulting to ASN_INTEGER\n")); break; } DEBUGMSGTL(("winExtDLL", "Net-SNMP object type for returned value: %d\n",windows_ASN_type)); // Query pVarBindList.list = (SnmpVarBind *) SnmpUtilMemAlloc(sizeof (SnmpVarBind)); if (pVarBindList.list) { // Convert OID from Net-SNMP to Windows pVarBindList.list->name.ids = (UINT *) SnmpUtilMemAlloc(sizeof (UINT) *var->name_length); if (pVarBindList.list->name.ids) { // Actual copy for (i = 0; i < var->name_length; i++) { pVarBindList.list->name.ids[i] = (UINT)var->name[i]; } pVarBindList.list->name.idLength = i; // Print OID DEBUGMSGTL(("winExtDLL","Windows OID length: %d\n",pVarBindList.list->name.idLength)); DEBUGMSGTL(("winExtDLL","Windows OID: ")); DEBUGMSGWINOID(("winExtDLL", pVarBindList.list)); DEBUGMSG(("winExtDLL", "\n")); } else { DEBUGMSGTL(("winExtDLL", "\nyCould not allocate memory for Windows SNMP varbind.\n")); return (0); } //pVarBindList.list = pVarBindList.list; pVarBindList.len = 1; } else { DEBUGMSGTL(("winExtDLL", "\nyCould not allocate memory for Windows SNMP varbind list.\n")); return (0); } // Set Windows ASN type pVarBindList.list->value.asnType = windows_ASN_type; switch (var->type) { case ASN_IPADDRESS: case ASN_OCTET_STR: strncpy(set_szbuf_temp, var->val.string, (var->val_len > SZBUF_MAX?SZBUF_MAX:var->val_len)); // Make sure string is terminated set_szbuf_temp[var->val_len > SZBUF_MAX?SZBUF_MAX:var->val_len] = '\0'; DEBUGMSGTL(("winExtDLL", "String to write: %s\n",set_szbuf_temp)); DEBUGMSGTL(("winExtDLL", "Length of string to write: %d\n",strlen(set_szbuf_temp))); pVarBindList.list->value.asnValue.string.stream = set_szbuf_temp; pVarBindList.list->value.asnValue.string.length = strlen(set_szbuf_temp); pVarBindList.list->value.asnValue.string.dynamic = 0; break; case ASN_INTEGER: // And MS_ASN_INTEGER32 case ASN_UNSIGNED: case ASN_COUNTER64: case ASN_BIT_STR: case ASN_SEQUENCE: case ASN_COUNTER:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -