pike.git / lib / modules / Protocols.pmod / SNMP.pmod / protocol.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:13:   //!   //! planned:   //! 2742 : agentX   //!   //! 2570 : v3 description   //!      #include "snmp_globals.h"   #include "snmp_errors.h"    + import Standards.ASN1.Types; +    #if 1   // --- ASN.1 hack   class asn1_application_octet_string   { -  inherit Standards.ASN1.Types.OctetString; +  inherit OctetString;    int cls = 1;    constant type_name = "APPLICATION OCTET_STRING";    int tagx;       int get_tag() { return tagx; }       void init(int tagid, string arg) {    ::value = arg;    tagx = tagid;    }   }      class asn1_application_integer   { -  inherit Standards.ASN1.Types.Integer; +  inherit Integer;    int cls = 1;    constant type_name = "APPLICATION INTEGER";    int tagx;       int get_tag() { return tagx; }       void init(int tagid, int arg) {    ::init(arg);    tagx = tagid;    }
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:107: Inside #if 1
   }    else    {    // Primitive encoding    return p ? p()->decode_primitive(contents)    : Standards.ASN1.Decode.primitive(tag, contents);    }   }      protected mapping snmp_type_proc = -  ([ 1 : Standards.ASN1.Types.asn1_boolean, -  2 : Standards.ASN1.Types.asn1_integer, -  3 : Standards.ASN1.Types.asn1_bit_string, -  4 : Standards.ASN1.Types.asn1_octet_string, -  5 : Standards.ASN1.Types.asn1_null, -  6 : Standards.ASN1.Types.asn1_identifier, +  ([ 1 : Boolean, +  2 : Integer, +  3 : BitString, +  4 : OctetString, +  5 : Null, +  6 : Identifier,    // 9 : asn1_real,    //10 : asn1_enumerated, -  16 : Standards.ASN1.Types.asn1_sequence, -  17 : Standards.ASN1.Types.asn1_set, -  19 : Standards.ASN1.Types.asn1_printable_string, -  20 : Standards.ASN1.Types.asn1_teletex_string, -  23 : Standards.ASN1.Types.asn1_utc, +  16 : Sequence, +  17 : Set, +  19 : PrintableString, +  20 : TeletexString, +  23 : UTC,       // from RFC-1065 :    64 : asn1_application_octet_string, // ipaddress    65 : asn1_application_integer, // counter    66 : asn1_application_integer, // gauge    67 : asn1_application_integer, // timeticks    68 : asn1_application_octet_string, // opaque       // v2    70 : asn1_application_integer, // counter64
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:310:         private int writemsg(string rem_addr, int rem_port, object pdu) {    //: send SNMP encoded message and return status    //: OK, in most cases :)       object msg;    string rawd;    int msize;    -  msg = Standards.ASN1.Types.asn1_sequence(({ -  Standards.ASN1.Types.asn1_integer(snmp_version-1), -  Standards.ASN1.Types.asn1_octet_string(snmp_community), +  msg = Sequence(({ +  Integer(snmp_version-1), +  OctetString(snmp_community),    pdu}));       rawd = msg->get_der();       DWRITE("protocol.writemsg: %O\n", rawd);       msize = send(rem_addr, rem_port, rawd);    return (msize = sizeof(rawd) ? SNMP_SUCCESS : SNMP_SEND_ERROR);   }   
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:360:   //! remote address an UDP port to send request to (optional)   //! @returns   //! request ID   int get_request(array(string) varlist, string|void rem_addr,    int|void rem_port) {    object pdu;    int id = get_req_id(), flg;    array vararr = ({});       foreach(varlist, string varname) -  vararr += ({Standards.ASN1.Types.asn1_sequence( -  ({Standards.ASN1.Types.asn1_identifier( -  @(array(int))(varname/".")), -  Standards.ASN1.Types.Null()}) +  vararr += ({Sequence( +  ({Identifier(@(array(int))(varname/".")), +  Null()})    )});       pdu = Protocols.LDAP.ldap_privates.asn1_context_sequence(0, -  ({Standards.ASN1.Types.asn1_integer(id), // request-id -  Standards.ASN1.Types.asn1_integer(0), // error-status -  Standards.ASN1.Types.asn1_integer(0), // error-index -  Standards.ASN1.Types.asn1_sequence(vararr)}) +  ({Integer(id), // request-id +  Integer(0), // error-status +  Integer(0), // error-index +  Sequence(vararr)})    );       // now we have PDU ...    flg = writemsg(rem_addr||remote_host,    rem_port || remote_port || SNMP_DEFAULT_PORT, pdu);       return id;   }    - object mk_asn1_val(string type, int|string val) { + Object mk_asn1_val(string type, int|string val) {   // returns appropriate ASN.1 value    -  object rv; +  Object rv;       switch(type) {    case "oid": // OID -  rv = Standards.ASN1.Types.asn1_identifier( @(array(int))(val/".") ); +  rv = Identifier( @(array(int))(val/".") );    break;       case "int": // INTEGER -  rv = Standards.ASN1.Types.asn1_integer(val); +  rv = Integer(val);    break;       case "str": // STRING -  rv = Standards.ASN1.Types.asn1_octet_string(val); +  rv = OctetString(val);    break;       case "ipaddr": // ipAddress    rv = asn1_application_octet_string(0, val[..3]);    break;       case "count": // COUNTER    rv = asn1_application_integer(1, val);    break;   
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:474:   //! request ID   int get_response(mapping varlist, mapping origdata, int|void errcode,    int|void erridx) {    //: GetResponse-PDU low call    object pdu;    int id = indices(origdata)[0], flg;    array vararr = ({});       foreach(indices(varlist), string varname)    if(arrayp(varlist[varname]) || sizeof(varlist[varname]) > 1) { -  vararr += ({Standards.ASN1.Types.asn1_sequence( -  ({Standards.ASN1.Types.asn1_identifier( -  @(array(int))(varname/".")), +  vararr += ({Sequence( +  ({Identifier(@(array(int))(varname/".")),    mk_asn1_val(varlist[varname][0], varlist[varname][1])})    )});    }       pdu = Protocols.LDAP.ldap_privates.asn1_context_sequence(2, -  ({Standards.ASN1.Types.asn1_integer(id), // request-id -  Standards.ASN1.Types.asn1_integer(errcode), // error-status -  Standards.ASN1.Types.asn1_integer(erridx), // error-index -  Standards.ASN1.Types.asn1_sequence(vararr)}) +  ({Integer(id), // request-id +  Integer(errcode), // error-status +  Integer(erridx), // error-index +  Sequence(vararr)})    );       // now we have PDU ...    flg = writemsg(origdata[id]->ip||remote_host,    origdata[id]->port || remote_port || SNMP_DEFAULT_PORT, pdu);       return id;   }      
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:514:   //! @returns   //! request ID   int get_nextrequest(array(string) varlist, string|void rem_addr,    int|void rem_port) {    //: GetNextRequest-PDU low call    object pdu;    int id = get_req_id(), flg;    array vararr = ({});       foreach(varlist, string varname) -  vararr += ({Standards.ASN1.Types.asn1_sequence( -  ({Standards.ASN1.Types.asn1_identifier( -  @(array(int))(varname/".")), -  Standards.ASN1.Types.Null()}) +  vararr += ({Sequence( +  ({Identifier(@(array(int))(varname/".")), +  Null()})    )});       pdu = Protocols.LDAP.ldap_privates.asn1_context_sequence(1, -  ({Standards.ASN1.Types.asn1_integer(id), // request-id -  Standards.ASN1.Types.asn1_integer(0), // error-status -  Standards.ASN1.Types.asn1_integer(0), // error-index -  Standards.ASN1.Types.asn1_sequence(vararr)}) +  ({Integer(id), // request-id +  Integer(0), // error-status +  Integer(0), // error-index +  Sequence(vararr)})    );       // now we have PDU ...    flg = writemsg(rem_addr||remote_host,    rem_port || remote_port || SNMP_DEFAULT_PORT, pdu);       return id;   }      //!
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:583:   //! int id=s->set_request(req, "172.21.124.32");   //!   int set_request(mapping varlist, string|void rem_addr,    int|void rem_port) {    //: SetRequest-PDU low call    object pdu;    int id = get_req_id(), flg;    array vararr = ({});       foreach(indices(varlist), string varname) -  vararr += ({Standards.ASN1.Types.asn1_sequence( -  ({Standards.ASN1.Types.asn1_identifier( -  @(array(int))(varname/".")), +  vararr += ({Sequence( +  ({Identifier(@(array(int))(varname/".")),    mk_asn1_val(varlist[varname][0], varlist[varname][1])})    )});       pdu = Protocols.LDAP.ldap_privates.asn1_context_sequence(3, -  ({Standards.ASN1.Types.asn1_integer(id), // request-id -  Standards.ASN1.Types.asn1_integer(0), // error-status -  Standards.ASN1.Types.asn1_integer(0), // error-index -  Standards.ASN1.Types.asn1_sequence(vararr)}) +  ({Integer(id), // request-id +  Integer(0), // error-status +  Integer(0), // error-index +  Sequence(vararr)})    );       // now we have PDU ...    flg = writemsg(rem_addr||remote_host,    rem_port || remote_port || SNMP_DEFAULT_PORT, pdu);       return id;   }      
pike.git/lib/modules/Protocols.pmod/SNMP.pmod/protocol.pike:661:    string lip = "1234";       locip = locip || "0.0.0.0";    if (has_value(locip,":")) // FIXME: Can't handle IPv6    locip = "0.0.0.0";    if (sizeof(locip/".") != 4)    locip = "0.0.0.0"; //FIXME: what for hell I want to do with such ugly value?    sscanf(locip, "%d.%d.%d.%d", lip[0], lip[1], lip[2], lip[3]);       foreach(indices(varlist), string varname) -  vararr += ({Standards.ASN1.Types.asn1_sequence( -  ({Standards.ASN1.Types.asn1_identifier( -  @(array(int))(varname/".")), +  vararr += ({Sequence( +  ({Identifier(@(array(int))(varname/".")),    mk_asn1_val(varlist[varname][0], varlist[varname][1])})    )});    pdu = Protocols.LDAP.ldap_privates.asn1_context_sequence(4,    ({    // enterprise OID    mk_asn1_val("oid", oid),       // ip address (UGLY!)    mk_asn1_val("ipaddr", lip),       // type (0 = coldstart, ...)    mk_asn1_val("int", type),       // enterprise type    mk_asn1_val("int", spectype),       // uptime    mk_asn1_val("tick", ticks),       // optional vars -  Standards.ASN1.Types.asn1_sequence(vararr) +  Sequence(vararr)    })       );       // now we have PDU ...    flg = writemsg(remaddr||remote_host,    remport || remote_port || SNMP_DEFAULT_TRAPPORT, pdu);       return id;   }