net-snmp 3.9.5 → 3.9.7
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/README.md +8 -0
- package/index.js +12 -22
- package/lib/mib.js +31 -29
- package/package.json +1 -1
- package/test/varbinds.js +25 -19
package/README.md
CHANGED
@@ -3297,6 +3297,14 @@ Example programs are included under the module's `example` directory.
|
|
3297
3297
|
|
3298
3298
|
* Normalize whitespace parsing for OBJECT IDENTIFIER value
|
3299
3299
|
|
3300
|
+
## Version 3.9.6 - 30/05/2023
|
3301
|
+
|
3302
|
+
* Add type constraint support for textual conventions
|
3303
|
+
|
3304
|
+
## Version 3.9.7 - 13/07/2023
|
3305
|
+
|
3306
|
+
* Add tolerance for reading malformed 32-bit unsigned integers
|
3307
|
+
|
3300
3308
|
# License
|
3301
3309
|
|
3302
3310
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/index.js
CHANGED
@@ -88,22 +88,6 @@ ObjectType.Integer32 = ObjectType.Integer;
|
|
88
88
|
ObjectType.Counter32 = ObjectType.Counter;
|
89
89
|
ObjectType.Gauge32 = ObjectType.Gauge;
|
90
90
|
ObjectType.Unsigned32 = ObjectType.Gauge32;
|
91
|
-
// SNMPv2-TC
|
92
|
-
ObjectType.AutonomousType = ObjectType["OBJECT IDENTIFIER"];
|
93
|
-
ObjectType.DateAndTime = ObjectType["OCTET STRING"];
|
94
|
-
ObjectType.DisplayString = ObjectType["OCTET STRING"];
|
95
|
-
ObjectType.InstancePointer = ObjectType["OBJECT IDENTIFIER"];
|
96
|
-
ObjectType.MacAddress = ObjectType["OCTET STRING"];
|
97
|
-
ObjectType.PhysAddress = ObjectType["OCTET STRING"];
|
98
|
-
ObjectType.RowPointer = ObjectType["OBJECT IDENTIFIER"];
|
99
|
-
ObjectType.RowStatus = ObjectType.INTEGER;
|
100
|
-
ObjectType.StorageType = ObjectType.INTEGER;
|
101
|
-
ObjectType.TestAndIncr = ObjectType.INTEGER;
|
102
|
-
ObjectType.TimeStamp = ObjectType.TimeTicks;
|
103
|
-
ObjectType.TruthValue = ObjectType.INTEGER;
|
104
|
-
ObjectType.TAddress = ObjectType["OCTET STRING"];
|
105
|
-
ObjectType.TDomain = ObjectType["OBJECT IDENTIFIER"];
|
106
|
-
ObjectType.VariablePointer = ObjectType["OBJECT IDENTIFIER"];
|
107
91
|
|
108
92
|
var PduType = {
|
109
93
|
160: "GetRequest",
|
@@ -408,6 +392,7 @@ function readUint32 (buffer) {
|
|
408
392
|
if ( ! Number.isInteger(parsedInt) ) {
|
409
393
|
throw new TypeError('Value read as integer ' + parsedInt + ' is not an integer');
|
410
394
|
}
|
395
|
+
parsedInt = (parsedInt>>>0);
|
411
396
|
if ( parsedInt < MIN_UNSIGNED_INT32 || parsedInt > MAX_UNSIGNED_INT32 ) {
|
412
397
|
throw new RangeError('Read integer ' + parsedInt + ' is outside the unsigned 32-bit range');
|
413
398
|
}
|
@@ -3174,7 +3159,7 @@ ModuleStore.prototype.getSyntaxTypes = function () {
|
|
3174
3159
|
if ( mibEntry.MACRO == "TEXTUAL-CONVENTION" ) {
|
3175
3160
|
if ( mibEntry.SYNTAX && ! syntaxTypes[mibEntry.ObjectName] ) {
|
3176
3161
|
if ( typeof mibEntry.SYNTAX == "object" ) {
|
3177
|
-
syntaxTypes[mibEntry.ObjectName] =
|
3162
|
+
syntaxTypes[mibEntry.ObjectName] = mibEntry.SYNTAX;
|
3178
3163
|
} else {
|
3179
3164
|
syntaxTypes[mibEntry.ObjectName] = syntaxTypes[mibEntry.SYNTAX];
|
3180
3165
|
}
|
@@ -3239,7 +3224,7 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
|
|
3239
3224
|
var defVal = mibEntry["DEFVAL"];
|
3240
3225
|
|
3241
3226
|
if ( syntax ) {
|
3242
|
-
constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax);
|
3227
|
+
constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax, syntaxTypes);
|
3243
3228
|
syntax = constraintsResults.syntax;
|
3244
3229
|
constraints = constraintsResults.constraints;
|
3245
3230
|
|
@@ -3269,7 +3254,7 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
|
|
3269
3254
|
maxAccess = (typeof mibEntry["MAX-ACCESS"] != "undefined" ? mibEntry["MAX-ACCESS"] : (access ? AccessToMaxAccess[access] : "not-accessible"));
|
3270
3255
|
defVal = mibEntry["DEFVAL"];
|
3271
3256
|
|
3272
|
-
constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax);
|
3257
|
+
constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax, syntaxTypes);
|
3273
3258
|
syntax = constraintsResults.syntax;
|
3274
3259
|
constraints = constraintsResults.constraints;
|
3275
3260
|
|
@@ -3349,11 +3334,14 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
|
|
3349
3334
|
}
|
3350
3335
|
} else if ( mibEntry.MACRO == "OBJECT-TYPE" ) {
|
3351
3336
|
// OBJECT-TYPE entries not in a table are scalars
|
3337
|
+
let scalarType = syntaxTypes[syntax];
|
3338
|
+
if (typeof scalarType === 'object')
|
3339
|
+
scalarType = syntaxTypes[Object.keys(scalarType)[0]];
|
3352
3340
|
var scalarDefinition = {
|
3353
3341
|
name: mibEntry.ObjectName,
|
3354
3342
|
type: MibProviderType.Scalar,
|
3355
3343
|
oid: mibEntry.OID,
|
3356
|
-
scalarType:
|
3344
|
+
scalarType: scalarType,
|
3357
3345
|
maxAccess: MaxAccess[maxAccess]
|
3358
3346
|
};
|
3359
3347
|
|
@@ -3379,9 +3367,11 @@ ModuleStore.prototype.loadBaseModules = function () {
|
|
3379
3367
|
this.parser.Serialize ();
|
3380
3368
|
};
|
3381
3369
|
|
3382
|
-
ModuleStore.getConstraintsFromSyntax = function (syntax) {
|
3370
|
+
ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
|
3383
3371
|
let constraints;
|
3384
|
-
|
3372
|
+
if ( typeof syntaxTypes[syntax] === 'object' ) {
|
3373
|
+
syntax = syntaxTypes[syntax];
|
3374
|
+
}
|
3385
3375
|
// detect INTEGER ranges, OCTET STRING sizes, and INTEGER enumerations
|
3386
3376
|
if ( typeof syntax == "object" ) {
|
3387
3377
|
let firstSyntaxKey = syntax[Object.keys(syntax)[0]];
|
package/lib/mib.js
CHANGED
@@ -60,7 +60,7 @@ var MIB = function (dir) {
|
|
60
60
|
var R = this.RowIndex;
|
61
61
|
var C = this.ColumnIndex;
|
62
62
|
|
63
|
-
if (!this.Table[FileName][R]) {
|
63
|
+
if (!this.Table[FileName][R] || C === 0) {
|
64
64
|
this.Table[FileName][R] = Object.defineProperty([], "line", {
|
65
65
|
enumerable: false,
|
66
66
|
value: row + 1
|
@@ -143,11 +143,14 @@ var MIB = function (dir) {
|
|
143
143
|
}
|
144
144
|
},
|
145
145
|
ParseLine: function (FileName, line, row) {
|
146
|
-
|
147
|
-
|
146
|
+
let len = line.length;
|
147
|
+
if (line[len - 1] === '\r')
|
148
|
+
--len;
|
149
|
+
for (var i = 0; i < len; i++) {
|
148
150
|
var char = line.charAt(i);
|
149
151
|
this.ParseChar(FileName, char, row, i);
|
150
152
|
}
|
153
|
+
this.ParseChar(FileName, '\n', row, len);
|
151
154
|
},
|
152
155
|
ParseChar: function (FileName, char, row, column) {
|
153
156
|
switch (char) {
|
@@ -310,7 +313,7 @@ var MIB = function (dir) {
|
|
310
313
|
lastGoodDeclaration = row;
|
311
314
|
break;
|
312
315
|
default:
|
313
|
-
if (symbol.
|
316
|
+
if (symbol.startsWith('--')) {//REMOVE COMMENTS
|
314
317
|
//console.log(ModuleName, symbol);
|
315
318
|
addSymbol = false;
|
316
319
|
} else {
|
@@ -670,35 +673,34 @@ var MIB = function (dir) {
|
|
670
673
|
},
|
671
674
|
BuildObject: function (Object, ObjectName, macro, i, Symbols) {
|
672
675
|
|
673
|
-
var
|
674
|
-
var m =
|
675
|
-
var
|
676
|
-
var
|
677
|
-
var
|
676
|
+
var syntaxKeyword = Symbols.indexOf('SYNTAX', i);
|
677
|
+
var m = syntaxKeyword - i;
|
678
|
+
var c1 = syntaxKeyword + 1;
|
679
|
+
var SYNTAX = Symbols[c1];
|
680
|
+
var val = Symbols[c1 + 1];
|
678
681
|
|
679
682
|
if (this.MACROS.indexOf(macro) > -1 && m < 10) {
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
}
|
688
|
-
val = val.replace("{", "").replace("}", "").split(",");
|
689
|
-
|
690
|
-
Object[ObjectName]['SYNTAX'] = {};
|
691
|
-
Object[ObjectName]['SYNTAX'][SYNTAX] = {};
|
683
|
+
if (val[0] === "{") {
|
684
|
+
c1++;
|
685
|
+
while (Symbols[c1].indexOf("}") == -1) {
|
686
|
+
c1++;
|
687
|
+
val += Symbols[c1].trim();
|
688
|
+
}
|
689
|
+
val = val.replace("{", "").replace("}", "").split(",");
|
692
690
|
|
693
|
-
|
694
|
-
|
695
|
-
}
|
696
|
-
}
|
697
|
-
break;
|
698
|
-
default:
|
699
|
-
Object[ObjectName]['SYNTAX'] = SYNTAX;
|
700
|
-
break;
|
691
|
+
Object[ObjectName]['SYNTAX'] = {};
|
692
|
+
Object[ObjectName]['SYNTAX'][SYNTAX] = {};
|
701
693
|
|
694
|
+
for (var TC = 0; TC < val.length; TC++) {
|
695
|
+
let openParenSplit = val[TC].split(/\s*\(\s*/);
|
696
|
+
Object[ObjectName]['SYNTAX'][SYNTAX][openParenSplit[1].replace(/\s*\)\s*$/, '')] = openParenSplit[0].trimStart();
|
697
|
+
}
|
698
|
+
} else if (val[0] === '(') {
|
699
|
+
const key = val.startsWith('(SIZE')? 'sizes' : 'ranges';
|
700
|
+
Object[ObjectName]['SYNTAX'] = {};
|
701
|
+
Object[ObjectName]['SYNTAX'][SYNTAX] = { [key]: this.GetRanges(val) };
|
702
|
+
} else {
|
703
|
+
Object[ObjectName]['SYNTAX'] = SYNTAX;
|
702
704
|
}
|
703
705
|
}
|
704
706
|
},
|
package/package.json
CHANGED
package/test/varbinds.js
CHANGED
@@ -1,43 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
var assert = require('assert');
|
5
|
-
var snmp = require('../');
|
1
|
+
const ber = require ('asn1-ber').Ber;
|
2
|
+
const assert = require('assert');
|
3
|
+
const snmp = require('../');
|
6
4
|
|
7
5
|
describe('parseInt()', function() {
|
8
6
|
describe('given a negative integer', function() {
|
9
|
-
|
7
|
+
const writer = new ber.Writer();
|
10
8
|
writer.writeInt(-3);
|
11
|
-
|
9
|
+
const reader = new ber.Reader(writer.buffer);
|
12
10
|
it('returns a negative integer', function() {
|
13
|
-
assert.equal(
|
11
|
+
assert.equal(snmp.ObjectParser.readInt32(reader), -3);
|
14
12
|
});
|
15
|
-
})
|
13
|
+
});
|
16
14
|
describe('given a positive integer', function() {
|
17
|
-
|
15
|
+
const writer = new ber.Writer();
|
18
16
|
writer.writeInt(3245689);
|
19
|
-
|
17
|
+
const reader = new ber.Reader(writer.buffer);
|
20
18
|
it('returns a positive integer', function() {
|
21
|
-
assert.equal(
|
19
|
+
assert.equal(snmp.ObjectParser.readInt32(reader), 3245689);
|
22
20
|
});
|
23
21
|
});
|
24
22
|
});
|
25
23
|
|
26
24
|
describe('parseUint()', function() {
|
27
25
|
describe('given a positive integer', function() {
|
28
|
-
|
26
|
+
const writer = new ber.Writer();
|
29
27
|
writer.writeInt(3242425);
|
30
|
-
|
28
|
+
const reader = new ber.Reader(writer.buffer);
|
31
29
|
it('returns a positive integer', function() {
|
32
|
-
assert.equal(
|
30
|
+
assert.equal(snmp.ObjectParser.readUint32(reader), 3242425);
|
33
31
|
});
|
34
|
-
})
|
32
|
+
});
|
35
33
|
describe('given a negative integer', function() {
|
36
|
-
|
34
|
+
const writer = new ber.Writer();
|
37
35
|
writer.writeInt(-3);
|
38
|
-
|
36
|
+
const reader = new ber.Reader(writer.buffer);
|
37
|
+
it('returns a positive integer', function() {
|
38
|
+
assert.equal(snmp.ObjectParser.readUint32(reader), 4294967293);
|
39
|
+
});
|
40
|
+
});
|
41
|
+
describe('given a large integer', function() {
|
42
|
+
const writer = new ber.Writer();
|
43
|
+
writer.writeInt(4294967294);
|
44
|
+
const reader = new ber.Reader(writer.buffer);
|
39
45
|
it('returns a positive integer', function() {
|
40
|
-
assert.equal(
|
46
|
+
assert.equal(snmp.ObjectParser.readUint32(reader), 4294967294);
|
41
47
|
});
|
42
48
|
});
|
43
49
|
});
|