📄 smoid.c
字号:
}
/* check octet strings to make sure that size specified */
else if (usSyntax == MIBSYNoctstr) {
if (fCheckISR && (usSizeRange == MIBSRno)) {
yyerror("Row \"%s\" has index item \"%s\" which must have a size specified",
pT->pszName, pO->pszName);
}
}
/* checks for NOLENGTH */
if (pIndx->usItype == MIBITnlobj) {
/* check for syntax */
if ((usSyntax != MIBSYNoctstr) &&
(usSyntax != MIBSYNoid)) {
yyerror("Row \"%s\" has index item \"%s\" with NOLENGTH specified, but is not OCTET STRING or OBJECT IDENTIFIER",
pT->pszName, pO->pszName);
}
/* check for last item */
if (pIndx->pNext != NULL) {
yyerror("Row \"%s\" has index item \"%s\" which NOLENGTH specifed which is not last item",
pT->pszName, pO->pszName);
}
}
}
}
}
/* no defval */
if (pT->ut.oid.usDefVal != MIBDFVno) {
yyerror("Row \"%s\" can have not a DEFAULT value specified",
pT->pszName);
}
break;
case MIBOTobj:
/* SNMP object */
/* syntax is not "seq of" or "seq" */
if ((pT->ut.oid.syn.usSyntax == MIBSYNseq) ||
(pT->ut.oid.syn.usSyntax == MIBSYNseqOf)) {
yyerror("Object \"%s\" has invalid syntax",
pT->pszName);
}
/* check if in table (ie parent is a row) */
pSeq = NULL;
if ((pO != NULL) && (pO->ut.oid.usOType == MIBOTrow)) {
/* get sequence containing item */
pSeq = pO->ut.oid.syn.usi.pSeq;
} else if ((pO != NULL) && (pO->ut.oid.usOType != MIBOToid)) {
/* parent not row or OID */
yyerror("Object \"%s\" must be registered under a row or an object identifier",
pT->pszName);
}
/* check to see if in sequence */
if (pSeq != NULL) {
/* in a row, check if in sequence for row */
for (pSi = pSeq->ut.seq.pSeqIL; pSi != NULL;
pSi = pSi->pNext) {
/* check for match in sequence with object */
if (pSi->pOid == pT)
break;
}
if (pSi == NULL) {
/* object not in sequence */
yyerror("Object \"%s\" is not in sequence for Row \"%s\"",
pT->pszName, pO->pszName);
} else
pT->ut.oid.pDefSeq = pSeq;
}
usSyntax = pT->ut.oid.rsyn.usSyntax;
fNoSR = ((usSizeRange = pT->ut.oid.rsyn.usSizeRange) == MIBSRno);
/* check that size/range specified */
if (fCheckSR && fNoSR) {
if (usSyntax == MIBSYNoctstr) {
/* octet string - need size */
yywarning("\"%s\" should have SIZE specified",
pT->pszName);
} else if (usSyntax == MIBSYNint) {
/* integer - need range */
yywarning("\"%s\" should have range specified",
pT->pszName);
}
}
/* access is read-only or read-write */
if ((pT->ut.oid.usAccess != MIBACCro) &&
(pT->ut.oid.usAccess != MIBACCrw) &&
(pT->ut.oid.usAccess != MIBACCbad) &&
!fAllowAccess) {
yyerror("\"%s\" must have access of \"read-only\" or \"read-write\"",
pT->pszName);
}
/* status is mandatory, deprecated, or obsolete */
if ((pT->usStatus != MIBSTAma) &&
(pT->usStatus != MIBSTAde) &&
(pT->usStatus != MIBSTAob) &&
(pT->usStatus != MIBSTAbad) &&
!fAllowOpt) {
yyerror("\"%s\" must have status of \"mandatory\", \"deprecated\", or \"obsolete\"",
pT->pszName);
}
/* check for index */
if (pT->ut.oid.cIndx != 0) {
/* has INDEX clause */
if (!fAllowIndx)
yyerror("\"%s\" can not have INDEX items specified",
pT->pszName);
else if (pSeq != NULL)
yyerror("\"%s\" can not have INDEX items specified and be in a sequence",
pT->pszName);
else {
/* item has INDEX clause */
/* check that all items are syntax types
and NOLENGTH clause used correctly */
for (pIndx = pT->ut.oid.pIndxL; pIndx != NULL;
pIndx = pIndx->pNext) {
if ((pIndx->usItype == MIBITobj) ||
(pIndx->usItype == MIBITnlobj)) {
yyerror("\"%s\" has index item \"%s\" which is an object and not a syntax type",
pT->pszName, (pIndx->pOid)->pszName);
}
else if (pIndx->usItype == MIBITnloct) {
/* index is no length OCTET STRING */
/* check that no items follow */
if (pIndx->pNext != NULL) {
yyerror("\"%s\" has index item NOLENGTH OCTET STRING which is not the last item",
pT->pszName);
continue;
}
} else if (pIndx->usItype == MIBITnloid) {
/* index is no length OBJECT IDENTIFIER */
/* check that no items follow */
if (pIndx->pNext != NULL) {
yyerror("\"%s\" has index item NOLENGTH OBJECT IDENTIFIER which is not the last item",
pT->pszName);
continue;
}
}
}
}
}
/* defval must be compatible with type */
if (pT->ut.oid.usDefVal != MIBDFVno) {
/* default value specified */
switch (usSyntax) {
case MIBSYNbad:
/* bad syntax - ignore */
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
case MIBSYNint:
/* integer */
if ((pT->ut.oid.usDefVal != MIBDFVbstr) &&
(pT->ut.oid.usDefVal != MIBDFVhstr) &&
(pT->ut.oid.usDefVal != MIBDFVint) &&
(pT->ut.oid.usDefVal != MIBDFVneg)) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
/*?? put in checks for range */
break;
case MIBSYNoctstr:
/* octet string */
if ((pT->ut.oid.usDefVal != MIBDFVstr) &&
(pT->ut.oid.usDefVal != MIBDFVbstr) &&
(pT->ut.oid.usDefVal != MIBDFVhstr)) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
/*?? put in checks for size */
break;
case MIBSYNoid:
/* object identifier */
if (pT->ut.oid.usDefVal == MIBDFVoid) {
/* all done */
break;
}
if (pT->ut.oid.usDefVal != MIBDFVna) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
/* lookup name and see if item is an OID type */
pNa = StrTabSearch(pT->ut.oid.udv.pszDefVal);
pO = NULL;
if ((pNa != NULL) && (pNa->pSym != NULL) &&
((pNa->pSym)->pMod == pMod)) {
pO = pNa->pSym;
if (pO->usType == MIBSYMimp) {
/* item is import */
pO->ut.imp.cUse++;
pO = pO->ut.imp.pImpSym;
}
}
if ((pO == NULL) || (pO->usType != MIBSYMoid)) {
yyerror("\"%s\" doesn't name OID object in current module",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
/* change defval type to OID */
pT->ut.oid.usDefVal = MIBDFVoid;
pT->ut.oid.udv.pOid = pO;
break;
case MIBSYNipaddr:
case MIBSYNnaddr:
/* ip or network address */
if (pT->ut.oid.usDefVal == MIBDFVint) {
if (pT->ut.oid.udv.ulDefVal != 0L) {
yyerror("\"%s\" has invalid default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
break;
}
/* change type to IPaddress */
pT->ut.oid.usDefVal = MIBDFVip;
} else if (pT->ut.oid.usDefVal == MIBDFVhstr) {
if (strlen(pT->ut.oid.udv.pszDefVal) != 8) {
yyerror("\"%s\" has invalid default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
break;
}
/* convert to IP address */
for (psz = pT->ut.oid.udv.pszDefVal, i = 0;
i < 4; i++) {
pT->ut.oid.udv.ipDefVal[i] = (BYTE)((hexVal(psz[2*i]) << 4) |
hexVal(psz[2*i+1]));
}
pT->ut.oid.usDefVal = MIBDFVip;
} else if (pT->ut.oid.usDefVal != MIBDFVip) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
break;
} else {
/*?? put in checks for value */
}
break;
case MIBSYNenum:
/* enumerated */
if (pT->ut.oid.usDefVal != MIBDFVna) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
break;
}
/* check that name is one of the enumerated values */
if (pT->ut.oid.syn.usSyntax == MIBSYNtc)
pE = (pT->ut.oid.syn.usi.pTC)->ut.tc.syn.usi.pEnumL;
else
pE = pT->ut.oid.syn.usi.pEnumL;
for (;pE != NULL; pE = pE->pNext) {
if (strcmp(pT->ut.oid.udv.pszDefVal,
pE->pszName) == 0)
break;
}
if (pE == NULL) {
yyerror("\"%s\" has invalid default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
break;
}
break;
case MIBSYNcntr:
case MIBSYNgauge:
/* counter or gauge */
if (!fAllowDV) {
if (((pT->ut.oid.usDefVal == MIBDFVbstr) ||
(pT->ut.oid.usDefVal == MIBDFVhstr) ||
(pT->ut.oid.usDefVal == MIBDFVint) ||
(pT->ut.oid.usDefVal == MIBDFVneg)) &&
(pT->ut.oid.udv.ulDefVal == 0L)) {
yywarning("\"%s\" has gratuitous default value",
pT->pszName);
} else {
yyerror("\"%s\" should not have a default value specified",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
}
}
else if ((pT->ut.oid.usDefVal != MIBDFVbstr) &&
(pT->ut.oid.usDefVal != MIBDFVhstr) &&
(pT->ut.oid.usDefVal != MIBDFVint)) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno;/* set to no value */
}
break;
case MIBSYNticks:
/* time ticks */
if ((pT->ut.oid.usDefVal != MIBDFVbstr) &&
(pT->ut.oid.usDefVal != MIBDFVhstr) &&
(pT->ut.oid.usDefVal != MIBDFVint)) {
yyerror("\"%s\" has invalid type for default value",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
/*?? put in checks for range */
break;
default:
/* all other types */
yyerror("\"%s\" must not have default value specified",
pT->pszName);
pT->ut.oid.usDefVal = MIBDFVno; /* set to no value */
break;
}
}
break;
case MIBOTunk: /* unknown or bad */
default:
break;
}
}
} /* checkOIDs */
/* end of file: SMOID.C */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -