/* FUNCTION: snmp_logoid() * * Send syslog message describing an important event (e.g., SNMP set, or * SNMP access that failed). * * PARAM1: char * - community string or user name * PARAM2: type - type of operation (e.g., SNMP set) * PARAM3: oid * - pointer to OID of relevant object * PARAM4: unsigned - number of elements in OID * PARAM5: long - error (e.g., 0 (success), V3_VACM_NOT_IN_VIEW, etc.) * PARAM6: u_char * - pointer to object data * PARAM7: u_char - ASN.1 type of relevant object * * RETURNS: This function always returns 0. */ int snmp_logoid(char *community, int type, oid *var_name, unsigned var_name_len, long err, u_char *var_val, u_char valuetype) { char buf[SNMP_LOGMSG_MAXLEN]; sprintf(buf, "[SNMP]cu=%s op=%d err=%ld OIDlen=%u valtype=%u", community, type, err, var_name_len, valuetype); strcat(buf, " OID="); strcat(buf, print_oid(var_name, var_name_len)); strcat(buf, " val="); strcat(buf, snmp_print_value(var_val, valuetype)); syslog(LOG_NOTICE|LOG_SECURITY, buf); return (0); }
int main(int argc,char *argv[]) { char strbuf[BUFSIZE]; OM_uint32 oidvec[MAXOID]; OM_uint32 oidvecsize; unsigned char enc_oid_buf[BUFSIZE]; gss_OID oid = NULL; gss_buffer_desc buf; OM_uint32 stat, minor; while (fgets(strbuf,BUFSIZE,stdin)!=NULL) { if ((strbuf[0]!='#') && (strlen(strbuf) > 1)) { buf.length = strlen(strbuf) - 1; buf.value = (void *) strbuf; stat = gss_str_to_oid (&minor, &buf, &oid); printf ("gss_str_to_oid returns %u, %u\n", stat, minor); print_oid (oid); stat = gss_oid_to_str (&minor, oid, &buf); printf ("gss_oid_to_str returns %u, %u\n", stat, minor); printf ("string form of OID is \"%*.*s\"\n", buf.length, buf.length, buf.value); ilugss_free (oid); } } }
/* Build a variable binding. * * RFC 1905: Protocol Operations for SNMPv2 * * VarBind ::= * SEQUENCE { * name ObjectName * CHOICE { * value ObjectSyntax * unSpecified NULL * noSuchObject[0] NULL * noSuchInstance[1] NULL * endOfMibView[2] NULL * } * } */ u_char *snmp_var_EncodeVarBind(u_char *Buffer, int *BufLenP, struct variable_list *VarList, int Version) { struct variable_list *Vars; u_char *bufp; u_char *HeaderStart; u_char *HeaderEnd; int FakeArg = *BufLenP; #ifdef DEBUG_VARS_ENCODE int StartLen = *BufLenP; int Counter = 1; #endif bufp = Buffer; #ifdef DEBUG_VARS_ENCODE printf("VARS: Encoding Variable list into buffer at 0x%x.\n", Buffer); #endif for (Vars=VarList; Vars; Vars=Vars->next_variable) { #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding Variable 0x%x.\n", Counter, Vars); printf("VARS %d: Starting at 0x%x (%d bytes left)\n", Counter, bufp, *BufLenP); #endif /* Build the header for this variable * * Use Maximum size. */ HeaderStart = bufp; HeaderEnd = asn_build_header(HeaderStart, BufLenP, (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), FakeArg); if (HeaderEnd == NULL) return(NULL); #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding Object Identifier 0x%x (%d bytes) at 0x%x (%d bytes left)\n", Counter, Vars, Vars->name_length, HeaderEnd, *BufLenP); print_oid(Vars->name, Vars->name_length), #endif /* Now, let's put the Object Identifier into the buffer */ bufp = asn_build_objid(HeaderEnd, BufLenP, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), Vars->name, Vars->name_length); if (bufp == NULL) return(NULL); /* Now put the data in */ switch(Vars->type) { case ASN_INTEGER: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding Integer %d at 0x%x\n", Counter, *(Vars->val.integer), bufp); #endif bufp = asn_build_int(bufp, BufLenP, Vars->type, (int *)Vars->val.integer, Vars->val_len); break; case SMI_COUNTER32: case SMI_GAUGE32: /* case SMI_UNSIGNED32: */ case SMI_TIMETICKS: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding Timeticks %d at 0x%x\n", Counter, *(Vars->val.integer), bufp); #endif bufp = asn_build_unsigned_int(bufp, BufLenP, Vars->type, (u_int *)Vars->val.integer, Vars->val_len); break; case ASN_OCTET_STR: case SMI_IPADDRESS: case SMI_OPAQUE: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding String %s (%d bytes) at 0x%x\n", Counter, (Vars->val.string), Vars->val_len, bufp); #endif bufp = asn_build_string(bufp, BufLenP, Vars->type, Vars->val.string, Vars->val_len); break; case ASN_OBJECT_ID: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding Object Identifier (%d bytes) at 0x%x\n", Counter, Vars->val_len, bufp); #endif bufp = asn_build_objid(bufp, BufLenP, Vars->type, (oid *)Vars->val.objid, Vars->val_len / sizeof(oid)); break; case SMI_NOSUCHINSTANCE: case SMI_NOSUCHOBJECT: case SMI_ENDOFMIBVIEW: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding NULL at 0x%x\n", Counter, bufp); #endif if (Version == SNMP_VERSION_1) { /* SNMP Version 1 does not support these error codes. */ bufp = asn_build_null(bufp, BufLenP, SMI_NOSUCHOBJECT); } else { bufp = asn_build_exception(bufp, BufLenP, Vars->type); } break; case ASN_NULL: #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Encoding NULL at 0x%x\n", Counter, bufp); #endif bufp = asn_build_null(bufp, BufLenP, Vars->type); break; case SMI_COUNTER64: #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("Unable to encode type SMI_COUNTER64!\n")); #endif /* Fall through */ default: snmp_set_api_error(SNMPERR_UNSUPPORTED_TYPE); return(NULL); } /* ASSERT: bufp should now point to the next valid byte. */ if (bufp == NULL) return(NULL); /* Rebuild the header with the appropriate length */ #ifdef DEBUG_VARS_ENCODE printf("VARS %d: Resetting length to %d at 0x%x (%d bytes left)\n", Counter, (bufp - HeaderEnd), HeaderStart, *BufLenP); #endif HeaderEnd = asn_build_header(HeaderStart, &FakeArg, (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), (bufp - HeaderEnd)); /* Returns NULL */ if (HeaderEnd == NULL) return(NULL); #ifdef DEBUG_VARS_ENCODE Counter++; #endif } #ifdef DEBUG_VARS_ENCODE printf("VARS: Variable list of %d vars takes up %d bytes.\n", --Counter, StartLen - *BufLenP); #endif /* or the end of the entire thing */ return(bufp); }
/* FUNCTION: snmp_print_value() * Print the value into a buffer and return the buffer. * * Buffer is static to this function. * * PARAM1: u_char * var_val - ASN.1 encoded value * PARAM1: u_char var_val_type - ASN.1 type of value * * RETURNS: */ char * snmp_print_value(u_char *var_val, u_char var_val_type) { /* set an abritrarily large buffer parm for asn1 parsing. * We don't use the returned value for this anyway. */ unsigned asn_buf_size = 1000; /* */ unsigned set_var_size = _MAX_PATH; /* bytes in field to set */ long tmpvalue=0; static char datastr[_MAX_PATH]; static char datatmp[_MAX_PATH]; static oid dataoid[_MAX_PATH]; datastr[0]=0; /* null terminate */ if (!var_val) return datastr; switch (var_val_type) { case ASN_INTEGER: case COUNTER: case GAUGE: /* valid for GAUGE32 and UNSIGNED32 too */ case TIMETICKS: if (!asn_parse_int(var_val, &asn_buf_size, &var_val_type, &tmpvalue, sizeof(long))) { break; } sprintf(datastr,"%ld",tmpvalue) ; break; case ASN_BIT_STR: if (!asn_parse_bits(var_val, &asn_buf_size, &var_val_type, (unsigned char *)datatmp, &set_var_size)) { break; } strcpy(datastr,datatmp); break; case ASN_OCTET_STR: case IPADDRESS: case OPAQUE: if (!asn_parse_string(var_val, &asn_buf_size, &var_val_type, (unsigned char *)datatmp, &set_var_size)) { break; } *(datatmp + set_var_size) = '\0'; /* null terminate the strings */ strcpy(datastr,datatmp); break; case ASN_OBJECT_ID: if (!asn_parse_objid(var_val, &asn_buf_size, &var_val_type, dataoid, &set_var_size)) { break; } strcpy(datastr, print_oid(dataoid, set_var_size)); break; case ASN_NULL: strcpy (datastr, "<NULL>"); break; } return datastr; }