net-snmp 3.6.1 → 3.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +3 -1
- package/README.md +21 -1
- package/example/snmp-receiver.js +2 -1
- package/index.js +34 -16
- package/package.json +1 -1
- package/test/receiver-test.sh +2 -3
    
        package/CONTRIBUTING.md
    CHANGED
    
    | @@ -11,7 +11,9 @@ the developers managing and developing this open source project. | |
| 11 11 |  | 
| 12 12 | 
             
            The issue tracker is the preferred channel for [bug reports](#bugs),
         | 
| 13 13 | 
             
            [features requests](#features) and [submitting pull
         | 
| 14 | 
            -
            requests](#pull-requests).
         | 
| 14 | 
            +
            requests](#pull-requests).  Please prefer the issue tracker over
         | 
| 15 | 
            +
            emailing individual project contributors as your first engagement
         | 
| 16 | 
            +
            with the project.
         | 
| 15 17 |  | 
| 16 18 | 
             
            ## What to always do
         | 
| 17 19 |  | 
    
        package/README.md
    CHANGED
    
    | @@ -540,6 +540,7 @@ var options = { | |
| 540 540 | 
             
                trapPort: 162,
         | 
| 541 541 | 
             
                version: snmp.Version1,
         | 
| 542 542 | 
             
                backwardsGetNexts: true,
         | 
| 543 | 
            +
                reportOidMismatchErrors: false,
         | 
| 543 544 | 
             
                idBitsSize: 32
         | 
| 544 545 | 
             
            };
         | 
| 545 546 |  | 
| @@ -567,7 +568,9 @@ is an object, and can contain the following items: | |
| 567 568 | 
             
             * `version` - Either `snmp.Version1` or `snmp.Version2c`, defaults to
         | 
| 568 569 | 
             
               `snmp.Version1`
         | 
| 569 570 | 
             
             * `backwardsGetNexts` - boolean to allow GetNext operations to retrieve lexicographically
         | 
| 570 | 
            -
                | 
| 571 | 
            +
               preceding OIDs, defaults to `true`
         | 
| 572 | 
            +
             * `reportOidMismatchErrors` - boolean to allow error reporting of OID mismatches between
         | 
| 573 | 
            +
               requests and responses, defaults to `false`
         | 
| 571 574 | 
             
             * `idBitsSize` - Either `16` or `32`, defaults to `32`.  Used to reduce the size
         | 
| 572 575 | 
             
                of the generated id for compatibility with some older devices.
         | 
| 573 576 |  | 
| @@ -592,6 +595,8 @@ var options = { | |
| 592 595 | 
             
                trapPort: 162,
         | 
| 593 596 | 
             
                version: snmp.Version3,
         | 
| 594 597 | 
             
                engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
         | 
| 598 | 
            +
                backwardsGetNexts: true,
         | 
| 599 | 
            +
                reportOidMismatchErrors: false,
         | 
| 595 600 | 
             
                idBitsSize: 32,
         | 
| 596 601 | 
             
                context: ""
         | 
| 597 602 | 
             
            };
         | 
| @@ -1452,6 +1457,7 @@ class: | |
| 1452 1457 | 
             
            var options = {
         | 
| 1453 1458 | 
             
                port: 162,
         | 
| 1454 1459 | 
             
                disableAuthorization: false,
         | 
| 1460 | 
            +
                includeAuthentication: false,
         | 
| 1455 1461 | 
             
                accessControlModelType: snmp.AccessControlModelType.None,
         | 
| 1456 1462 | 
             
                engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
         | 
| 1457 1463 | 
             
                address: null,
         | 
| @@ -1483,6 +1489,8 @@ an object, possibly empty, and can contain the following fields: | |
| 1483 1489 | 
             
             * `transport` - the transport family to use - defaults to `udp4`
         | 
| 1484 1490 | 
             
             * `address` - the IP address to bind to - default to `null`, which means bind to all IP
         | 
| 1485 1491 | 
             
             addresses
         | 
| 1492 | 
            +
             * `includeAuthentication` - adds the community (v1/2c) or user name (v3) information
         | 
| 1493 | 
            +
             to the notification callback - defaults to `false`
         | 
| 1486 1494 |  | 
| 1487 1495 | 
             
            The `callback` parameter is a callback function of the form
         | 
| 1488 1496 | 
             
            `function (error, notification)`.  On an error condition, the `notification`
         | 
| @@ -3174,6 +3182,18 @@ Example programs are included under the module's `example` directory. | |
| 3174 3182 |  | 
| 3175 3183 | 
             
             * Add v3 context to non-initial PDUs
         | 
| 3176 3184 |  | 
| 3185 | 
            +
            ## Version 3.6.2 - 07/04/2022
         | 
| 3186 | 
            +
             | 
| 3187 | 
            +
             * Add option for receiver to receive client authentication identity
         | 
| 3188 | 
            +
             | 
| 3189 | 
            +
            ## Version 3.6.3 - 26/04/2022
         | 
| 3190 | 
            +
             | 
| 3191 | 
            +
             * Fix logic for v3 time synchronization requirement
         | 
| 3192 | 
            +
             | 
| 3193 | 
            +
            ## Version 3.6.4 - 14/05/2022
         | 
| 3194 | 
            +
             | 
| 3195 | 
            +
             * Ignore mismatched returned OIDs by default
         | 
| 3196 | 
            +
             | 
| 3177 3197 | 
             
            # License
         | 
| 3178 3198 |  | 
| 3179 3199 | 
             
            Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
         | 
    
        package/example/snmp-receiver.js
    CHANGED
    
    
    
        package/index.js
    CHANGED
    
    | @@ -1828,6 +1828,10 @@ var Session = function (target, authenticator, options) { | |
| 1828 1828 | 
             
            			? options.backwardsGetNexts
         | 
| 1829 1829 | 
             
            			: true;
         | 
| 1830 1830 |  | 
| 1831 | 
            +
            	this.reportOidMismatchErrors = (typeof options.reportOidMismatchErrors !== 'undefined')
         | 
| 1832 | 
            +
                        ? options.reportOidMismatchErrors
         | 
| 1833 | 
            +
                        : false;
         | 
| 1834 | 
            +
             | 
| 1831 1835 | 
             
            	DEBUG = options.debug;
         | 
| 1832 1836 |  | 
| 1833 1837 | 
             
            	this.engine = new Engine (options.engineID);
         | 
| @@ -1870,6 +1874,8 @@ function _generateId (bitSize) { | |
| 1870 1874 | 
             
            }
         | 
| 1871 1875 |  | 
| 1872 1876 | 
             
            Session.prototype.get = function (oids, responseCb) {
         | 
| 1877 | 
            +
            	var reportOidMismatchErrors = this.reportOidMismatchErrors;
         | 
| 1878 | 
            +
             | 
| 1873 1879 | 
             
            	function feedCb (req, message) {
         | 
| 1874 1880 | 
             
            		var pdu = message.pdu;
         | 
| 1875 1881 | 
             
            		var varbinds = [];
         | 
| @@ -1879,10 +1885,10 @@ Session.prototype.get = function (oids, responseCb) { | |
| 1879 1885 | 
             
            					+ "match response OIDs", ResponseInvalidCode.EReqResOidNoMatch));
         | 
| 1880 1886 | 
             
            		} else {
         | 
| 1881 1887 | 
             
            			for (var i = 0; i < req.message.pdu.varbinds.length; i++) {
         | 
| 1882 | 
            -
            				if (req.message.pdu.varbinds[i].oid != pdu.varbinds[i].oid) {
         | 
| 1888 | 
            +
            				if ( reportOidMismatchErrors && req.message.pdu.varbinds[i].oid != pdu.varbinds[i].oid ) {
         | 
| 1883 1889 | 
             
            					req.responseCb (new ResponseInvalidError ("OID '"
         | 
| 1884 1890 | 
             
            							+ req.message.pdu.varbinds[i].oid
         | 
| 1885 | 
            -
            							+ "' in request at  | 
| 1891 | 
            +
            							+ "' in request at position '" + i + "' does not "
         | 
| 1886 1892 | 
             
            							+ "match OID '" + pdu.varbinds[i].oid + "' in response "
         | 
| 1887 1893 | 
             
            							+ "at position '" + i + "'", ResponseInvalidCode.EReqResOidNoMatch));
         | 
| 1888 1894 | 
             
            					return;
         | 
| @@ -1984,7 +1990,7 @@ Session.prototype.getBulk = function () { | |
| 1984 1990 | 
             
            							pdu.varbinds[respIndex].oid)) {
         | 
| 1985 1991 | 
             
            						req.responseCb (new ResponseInvalidError ("OID '"
         | 
| 1986 1992 | 
             
            								+ req.message.pdu.varbinds[reqIndex].oid
         | 
| 1987 | 
            -
            								+ "' in request at  | 
| 1993 | 
            +
            								+ "' in request at position '" + (reqIndex)
         | 
| 1988 1994 | 
             
            								+ "' does not precede OID '"
         | 
| 1989 1995 | 
             
            								+ pdu.varbinds[respIndex].oid
         | 
| 1990 1996 | 
             
            								+ "' in response at position '" + (respIndex) + "'",
         | 
| @@ -2211,7 +2217,7 @@ Session.prototype.onMsg = function (buffer) { | |
| 2211 2217 | 
             
            				return;
         | 
| 2212 2218 | 
             
            			}
         | 
| 2213 2219 | 
             
            			req.originalPdu.contextName = this.context;
         | 
| 2214 | 
            -
            			var timeSyncNeeded = ! message.msgSecurityParameters.msgAuthoritativeEngineBoots  | 
| 2220 | 
            +
            			var timeSyncNeeded = ! message.msgSecurityParameters.msgAuthoritativeEngineBoots && ! message.msgSecurityParameters.msgAuthoritativeEngineTime;
         | 
| 2215 2221 | 
             
            			this.sendV3Req (req.originalPdu, req.feedCb, req.responseCb, req.options, req.port, timeSyncNeeded);
         | 
| 2216 2222 | 
             
            		}
         | 
| 2217 2223 | 
             
            	} else if ( this.proxy ) {
         | 
| @@ -2294,6 +2300,8 @@ Session.prototype.send = function (req, noWait) { | |
| 2294 2300 | 
             
            };
         | 
| 2295 2301 |  | 
| 2296 2302 | 
             
            Session.prototype.set = function (varbinds, responseCb) {
         | 
| 2303 | 
            +
            	var reportOidMismatchErrors = this.reportOidMismatchErrors;
         | 
| 2304 | 
            +
             | 
| 2297 2305 | 
             
            	function feedCb (req, message) {
         | 
| 2298 2306 | 
             
            		var pdu = message.pdu;
         | 
| 2299 2307 | 
             
            		var varbinds = [];
         | 
| @@ -2303,10 +2311,10 @@ Session.prototype.set = function (varbinds, responseCb) { | |
| 2303 2311 | 
             
            					+ "match response OIDs", ResponseInvalidCode.EReqResOidNoMatch));
         | 
| 2304 2312 | 
             
            		} else {
         | 
| 2305 2313 | 
             
            			for (var i = 0; i < req.message.pdu.varbinds.length; i++) {
         | 
| 2306 | 
            -
            				if (req.message.pdu.varbinds[i].oid != pdu.varbinds[i].oid) {
         | 
| 2314 | 
            +
            				if ( reportOidMismatchErrors && req.message.pdu.varbinds[i].oid != pdu.varbinds[i].oid ) {
         | 
| 2307 2315 | 
             
            					req.responseCb (new ResponseInvalidError ("OID '"
         | 
| 2308 2316 | 
             
            							+ req.message.pdu.varbinds[i].oid
         | 
| 2309 | 
            -
            							+ "' in request at  | 
| 2317 | 
            +
            							+ "' in request at position '" + i + "' does not "
         | 
| 2310 2318 | 
             
            							+ "match OID '" + pdu.varbinds[i].oid + "' in response "
         | 
| 2311 2319 | 
             
            							+ "at position '" + i + "'", ResponseInvalidCode.EReqResOidNoMatch));
         | 
| 2312 2320 | 
             
            					return;
         | 
| @@ -3126,6 +3134,7 @@ var Receiver = function (options, callback) { | |
| 3126 3134 | 
             
            	this.port = options.port || 162;
         | 
| 3127 3135 | 
             
            	options.port = this.port;
         | 
| 3128 3136 | 
             
            	this.disableAuthorization = options.disableAuthorization || false;
         | 
| 3137 | 
            +
            	this.includeAuthentication = options.includeAuthentication || false;
         | 
| 3129 3138 | 
             
            	this.context = (options && options.context) ? options.context : "";
         | 
| 3130 3139 | 
             
            	this.listener = new Listener (options, this);
         | 
| 3131 3140 | 
             
            };
         | 
| @@ -3162,29 +3171,38 @@ Receiver.prototype.onMsg = function (buffer, rinfo) { | |
| 3162 3171 | 
             
            	// Inform/trap processing
         | 
| 3163 3172 | 
             
            	// debug (JSON.stringify (message.pdu, null, 2));
         | 
| 3164 3173 | 
             
            	if ( message.pdu.type == PduType.Trap || message.pdu.type == PduType.TrapV2 ) {
         | 
| 3165 | 
            -
            		this.callback (null, this.formatCallbackData (message | 
| 3174 | 
            +
            		this.callback (null, this.formatCallbackData (message, rinfo) );
         | 
| 3166 3175 | 
             
            	} else if ( message.pdu.type == PduType.InformRequest ) {
         | 
| 3167 3176 | 
             
            		message.pdu.type = PduType.GetResponse;
         | 
| 3168 3177 | 
             
            		message.buffer = null;
         | 
| 3169 3178 | 
             
            		message.setReportable (false);
         | 
| 3170 3179 | 
             
            		this.listener.send (message, rinfo);
         | 
| 3171 3180 | 
             
            		message.pdu.type = PduType.InformRequest;
         | 
| 3172 | 
            -
            		this.callback (null, this.formatCallbackData (message | 
| 3181 | 
            +
            		this.callback (null, this.formatCallbackData (message, rinfo) );
         | 
| 3173 3182 | 
             
            	} else {
         | 
| 3174 3183 | 
             
            		this.callback (new RequestInvalidError ("Unexpected PDU type " + message.pdu.type + " (" + PduType[message.pdu.type] + ")"));
         | 
| 3175 3184 | 
             
            	}
         | 
| 3176 3185 | 
             
            };
         | 
| 3177 3186 |  | 
| 3178 | 
            -
            Receiver.prototype.formatCallbackData = function ( | 
| 3179 | 
            -
            	if ( pdu.contextEngineID ) {
         | 
| 3180 | 
            -
            		pdu.contextEngineID = pdu.contextEngineID.toString('hex');
         | 
| 3187 | 
            +
            Receiver.prototype.formatCallbackData = function (message, rinfo) {
         | 
| 3188 | 
            +
            	if ( message.pdu.contextEngineID ) {
         | 
| 3189 | 
            +
            		message.pdu.contextEngineID = message.pdu.contextEngineID.toString('hex');
         | 
| 3181 3190 | 
             
            	}
         | 
| 3182 | 
            -
            	delete pdu.nonRepeaters;
         | 
| 3183 | 
            -
            	delete pdu.maxRepetitions;
         | 
| 3184 | 
            -
            	 | 
| 3185 | 
            -
            		pdu: pdu,
         | 
| 3186 | 
            -
            		rinfo: rinfo | 
| 3191 | 
            +
            	delete message.pdu.nonRepeaters;
         | 
| 3192 | 
            +
            	delete message.pdu.maxRepetitions;
         | 
| 3193 | 
            +
            	const formattedData = {
         | 
| 3194 | 
            +
            		pdu: message.pdu,
         | 
| 3195 | 
            +
            		rinfo: rinfo
         | 
| 3187 3196 | 
             
            	};
         | 
| 3197 | 
            +
            	if (this.includeAuthentication) {
         | 
| 3198 | 
            +
            		if (message.community) {
         | 
| 3199 | 
            +
            			formattedData.pdu.community = message.community;
         | 
| 3200 | 
            +
            		} else if (message.user) {
         | 
| 3201 | 
            +
            			formattedData.pdu.user = message.user.name;
         | 
| 3202 | 
            +
            		}
         | 
| 3203 | 
            +
            	}
         | 
| 3204 | 
            +
             | 
| 3205 | 
            +
            	return formattedData;
         | 
| 3188 3206 | 
             
            };
         | 
| 3189 3207 |  | 
| 3190 3208 | 
             
            Receiver.prototype.close  = function() {
         | 
    
        package/package.json
    CHANGED
    
    
    
        package/test/receiver-test.sh
    CHANGED
    
    | @@ -61,8 +61,8 @@ node ${HOME_DIR}/example/snmp-trap.js -v 3 -l authNoPriv -u ${USER_AUTH} -a ${AU | |
| 61 61 | 
             
            node ${HOME_DIR}/example/snmp-trap.js -v 3 -l authPriv -u ${USER_PRIV} -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 62 62 | 
             
            node ${HOME_DIR}/example/snmp-inform.js -v 2c -c ${COMMUNITY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 63 63 | 
             
            node ${HOME_DIR}/example/snmp-inform.js -v 3 -l noAuthNoPriv -u ${USER_NONE} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 64 | 
            -
            node ${HOME_DIR}/example/snmp-inform.js -v 3 -u ${USER_AUTH} -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 65 | 
            -
            node ${HOME_DIR}/example/snmp-inform.js -v 3 -u ${USER_PRIV} -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 64 | 
            +
            node ${HOME_DIR}/example/snmp-inform.js -v 3 -l authNoPriv -u ${USER_AUTH} -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 65 | 
            +
            node ${HOME_DIR}/example/snmp-inform.js -v 3 -l authPriv -u ${USER_PRIV} -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY} ${PARAMS} ${HOST} ${TRAP_OID}
         | 
| 66 66 | 
             
            ENDOFCMDS
         | 
| 67 67 |  | 
| 68 68 | 
             
            COUNT=1
         | 
| @@ -81,4 +81,3 @@ while read CMD ; do | |
| 81 81 | 
             
            done <${CMDS}
         | 
| 82 82 |  | 
| 83 83 | 
             
            rm -f ${CMDS}
         | 
| 84 | 
            -
             |