Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
9.3 KiB

  1. #include <stdarg.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <iostream.h>
  6. #include <fstream.h>
  7. #include <afx.h>
  8. #include <afxtempl.h>
  9. #include <objbase.h>
  10. #include <afxwin.h>
  11. #include <afxole.h>
  12. #include <afxmt.h>
  13. #include <wchar.h>
  14. #include <process.h>
  15. #include <objbase.h>
  16. #include <initguid.h>
  17. #include <bool.hpp>
  18. #include <nString.hpp>
  19. #include <ui.hpp>
  20. #include <symbol.hpp>
  21. #include <type.hpp>
  22. #include <value.hpp>
  23. #include <valueRef.hpp>
  24. #include <typeRef.hpp>
  25. #include <oidValue.hpp>
  26. #include <objType.hpp>
  27. #include <objTypV1.hpp>
  28. #include <objTypV2.hpp>
  29. #include <objId.hpp>
  30. #include <trapType.hpp>
  31. #include <notType.hpp>
  32. #include <group.hpp>
  33. #include <notGroup.hpp>
  34. #include <module.hpp>
  35. #include <sValues.hpp>
  36. #include <lex_yy.hpp>
  37. #include <ytab.hpp>
  38. #include <errorMsg.hpp>
  39. #include <errorCon.hpp>
  40. #include <scanner.hpp>
  41. #include <parser.hpp>
  42. #include <apTree.hpp>
  43. #include <oidTree.hpp>
  44. #include <pTree.hpp>
  45. #include "debug.hpp"
  46. #include "Oid.hpp"
  47. #include "OTScan.hpp"
  48. typedef struct _oidBuiltIn
  49. {
  50. const char * m_szSymbol;
  51. UINT m_nSubID;
  52. UINT m_nNextSibling;
  53. } T_OID_BUILTIN;
  54. #define BUILTIN_OID_COUNT 29
  55. static T_OID_BUILTIN g_BuiltinOIDs[] = {
  56. /*0 */ {"zero", 0, 29}, {"ccitt", 0, 2}, {"iso", 1, 28},
  57. /*3 */ {"org", 3, 29}, {"dod", 6, 29}, {"internet", 1, 29},
  58. /*6 */ {"directory", 1, 7}, {"mgmt", 2, 12}, {"mib-2", 1, 29},
  59. /*9 */ {"interfaces", 2, 10}, {"ip", 4, 11}, {"transmission", 10, 29},
  60. /*12*/ {"experimental", 3, 13}, {"private", 4, 15}, {"enterprises", 1, 29},
  61. /*15*/ {"security", 5, 16}, {"snmpV2", 6, 29}, {"snmpDomains", 1, 24},
  62. /*18*/ {"snmpUDPDomain", 1, 19}, {"snmpCLNSDomain", 2, 20}, {"snmpCONSDomain",3, 21},
  63. /*21*/ {"snmpDDPDomain", 4, 22}, {"snmpIPXDomain", 5, 23}, {"rfc1157Domain", 6, 29},
  64. /*24*/ {"snmpProxys", 2, 27}, {"rfc1157Proxy", 1, 29}, {"rfc1157Domain", 1, 29},
  65. /*27*/ {"snmpModules", 3, 28}, {"joint-iso-ccitt", 2, 28}
  66. };
  67. // DESCRIPTION:
  68. // Adds list of nodes from lstChildren to the tail of m_recursionTrace,
  69. // constructing at the same time the OID lexicographically order.
  70. // the list received as parameter should not be modified;
  71. // PARAMETERS:
  72. // (in) list of nodes to add
  73. void OidTreeScanner::UpdateRecursionTrace(SIMCNodeList *pLstChildren, SIMCNodeList *pLstTrace)
  74. {
  75. int nChld;
  76. POSITION posChld;
  77. _ASSERT((pLstChildren != NULL) && (pLstTrace != NULL), "NULL parameter error!", NULL);
  78. // for each node from the children list
  79. for (posChld = pLstChildren->GetHeadPosition(), nChld=0;
  80. posChld != NULL;
  81. nChld++)
  82. {
  83. int nList;
  84. POSITION posList;
  85. SIMCOidTreeNode *nodeChld, *nodeList;
  86. nodeChld = pLstChildren->GetNext(posChld);
  87. nodeList = NULL;
  88. // if it's the first child to add, it goes at the head of the list
  89. if (nChld == 0)
  90. {
  91. _ASSERT(pLstTrace->AddHead(nodeChld)!=NULL,
  92. "Memory Allocation error",
  93. NULL);
  94. }
  95. // otherwise, the head of the list should be an ordered list of
  96. // maximum nChld nodes. The new node is inserted in this list
  97. // with respect to it's value.
  98. else
  99. {
  100. // there are at least nChld nodes in m_recursionTrace
  101. for (nList=0, posList = pLstTrace->GetHeadPosition();
  102. nList < nChld;
  103. nList++)
  104. {
  105. POSITION posBackup = posList;
  106. nodeList = (SIMCOidTreeNode *)pLstTrace->GetNext(posBackup);
  107. _ASSERT(nodeList != NULL, "Internal OidNode List error!", NULL);
  108. // if the node to add has the value less then the current node, it
  109. // should be inserted in the list right before it.
  110. if (nodeChld->GetValue() < nodeList->GetValue())
  111. break;
  112. posList = posBackup;
  113. }
  114. if (posList != NULL)
  115. {
  116. _ASSERT(pLstTrace->InsertBefore(posList, nodeChld)!=NULL,
  117. "Memory allocation error",
  118. NULL);
  119. }
  120. else
  121. {
  122. _ASSERT(pLstTrace->AddTail(nodeChld)!=NULL,
  123. "Memory allocation error",
  124. NULL);
  125. }
  126. }
  127. }
  128. }
  129. // DESCRIPTION:
  130. // Gets the first symbol from the symbol list of the node pOidNode
  131. // PARAMETERS:
  132. // (in) pOidNode whose symbol is to be returned
  133. // (out) cszSymbol - pointer to the symbol (do not alter or free)
  134. // RETURN VALUE:
  135. // 0 on success, -1 on failure
  136. int OidTreeScanner::GetNodeSymbol(const SIMCOidTreeNode *pOidNode, const char * & cszSymbol)
  137. {
  138. const SIMCSymbolList *pSymbolList;
  139. _VERIFY(pOidNode != NULL, -1);
  140. pSymbolList = pOidNode->GetSymbolList();
  141. _VERIFY(pSymbolList != NULL, -1);
  142. if (pSymbolList->IsEmpty())
  143. {
  144. cszSymbol = (pOidNode->_pParam != NULL) ? (const char *)pOidNode->_pParam : NULL;
  145. }
  146. else
  147. {
  148. const SIMCSymbol **ppSymbol;
  149. ppSymbol = pSymbolList->GetHead();
  150. _VERIFY(ppSymbol != NULL && *ppSymbol != NULL, -1);
  151. cszSymbol = (*ppSymbol)->GetSymbolName();
  152. }
  153. return 0;
  154. }
  155. // DESCRIPTION:
  156. // Gets the complete OID information for the given pOidNode.
  157. // It supplies both the numeric value and symbolic name for each
  158. // component of the OID.
  159. // PARAMETERS:
  160. // (in) pOidNode - the node whose OID is to be found
  161. // (out) oid - the Oid object who stores the data
  162. // RETURN VALUE:
  163. // 0 on success
  164. // -1 on failure
  165. int OidTreeScanner::GetNodeOid(const SIMCOidTreeNode *pOidNode, Oid &oid)
  166. {
  167. _VERIFY(pOidNode != NULL, -1);
  168. _VERIFY(m_pOidTree != NULL, -1);
  169. do
  170. {
  171. const char * cszSymbol = NULL;
  172. _VERIFY(GetNodeSymbol(pOidNode, cszSymbol)==0, -1);
  173. _VERIFY(oid.AddComponent(pOidNode->GetValue(), cszSymbol)==0, -1);
  174. pOidNode = m_pOidTree->GetParentOf(pOidNode);
  175. } while (pOidNode != NULL);
  176. oid.ReverseComponents();
  177. return 0;
  178. }
  179. // initializes the OidTreeScanner
  180. OidTreeScanner::OidTreeScanner()
  181. {
  182. m_pOidTree = NULL;
  183. }
  184. // DESCRIPTION:
  185. // scans lexicographically the oid tree;
  186. // RETURN VALUE:
  187. // 0 on success
  188. // -1 on failure;
  189. int OidTreeScanner::Scan()
  190. {
  191. SIMCOidTreeNode *pOidNode;
  192. SIMCNodeList recursionTrace;
  193. // get the root node from the oid tree,
  194. // return "error" if no tree or no root
  195. _VERIFY(m_pOidTree != NULL, -1);
  196. pOidNode = (SIMCOidTreeNode *)m_pOidTree->GetRoot();
  197. _VERIFY(pOidNode != NULL, -1);
  198. // initialize the recursion trace list with the root node
  199. _VERIFY(recursionTrace.AddHead(pOidNode)!=NULL, -1);
  200. // start to scan the tree
  201. while (!recursionTrace.IsEmpty())
  202. {
  203. // list of current node's children
  204. SIMCNodeList *lstChildren;
  205. // allways pick up the node in the head of the list
  206. pOidNode = recursionTrace.GetHead();
  207. // then erase it from the list
  208. recursionTrace.RemoveAt(recursionTrace.GetHeadPosition());
  209. // check to see if the scanner should stop (with error code)
  210. _VERIFY(OnScanNode(pOidNode)==0, -1);
  211. // get the list of children
  212. lstChildren = (SIMCNodeList *)pOidNode->GetListOfChildNodes();
  213. // if there are children
  214. if (lstChildren != NULL)
  215. // add children to the head of the trace list
  216. UpdateRecursionTrace(lstChildren, &recursionTrace);
  217. }
  218. return 0;
  219. }
  220. // DESCRIPTION:
  221. // Fills the symbols of the built-in objects from the static table
  222. // RETURN VALUE:
  223. // 0 - on success, -1 on failure
  224. int OidTreeScanner::MergeBuiltIn()
  225. {
  226. SIMCNodeList lstOidStack;
  227. SIMCOidTreeNode *pOid;
  228. CList <unsigned int, unsigned int> wlstBuiltinStack;
  229. unsigned int nBuiltin;
  230. // initialize the two stacks with the root nodes from
  231. // the oid tree and from the builtin symbols
  232. pOid = (SIMCOidTreeNode *)m_pOidTree->GetRoot();
  233. _VERIFY(pOid != NULL, -1);
  234. _VERIFY(lstOidStack.AddHead(pOid)!=NULL, -1);
  235. _VERIFY(wlstBuiltinStack.AddHead((unsigned int)0)!=NULL, -1);
  236. // as long as there are items on the stack, process each item
  237. // item is processed only if it doesn't have a symbol associated
  238. while(!lstOidStack.IsEmpty())
  239. {
  240. const SIMCSymbolList *pSymbolList;
  241. pOid = lstOidStack.RemoveHead();
  242. nBuiltin = wlstBuiltinStack.RemoveHead();
  243. pSymbolList = pOid->GetSymbolList();
  244. _VERIFY(pSymbolList != NULL, -1);
  245. // if node already has a symbol attached, no need to dive deeper
  246. if (!pSymbolList->IsEmpty())
  247. continue;
  248. else
  249. {
  250. const SIMCNodeList *pChildList;
  251. pOid->_pParam = (void *)g_BuiltinOIDs[nBuiltin].m_szSymbol;
  252. // now push new nodes on the stacks
  253. pChildList = pOid->GetListOfChildNodes();
  254. _VERIFY(pChildList != NULL, -1);
  255. for (POSITION p = pChildList->GetHeadPosition(); p != NULL;)
  256. {
  257. unsigned int i;
  258. pOid = pChildList->GetNext(p);
  259. _VERIFY(pOid != NULL, -1);
  260. // the child nodes always begin at index nBuiltin+1 (if they exist)
  261. // and end before the parent's first sibling node.
  262. for (i = nBuiltin+1;
  263. i < g_BuiltinOIDs[nBuiltin].m_nNextSibling;
  264. i = g_BuiltinOIDs[i].m_nNextSibling)
  265. {
  266. // when the match is found, push both nodes on their stacks (in sync)
  267. // and go to another child
  268. if (g_BuiltinOIDs[i].m_nSubID == (UINT)pOid->GetValue())
  269. {
  270. _VERIFY(lstOidStack.AddHead(pOid)!=NULL, -1);
  271. _VERIFY(wlstBuiltinStack.AddHead(i)!=NULL, -1);
  272. break;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. return 0;
  279. }
  280. // DESCRIPTION:
  281. // initializes the m_pOidTree.
  282. // PARAMETERS:
  283. // (in) pointer to the SIMCOidTree to scan.
  284. void OidTreeScanner::SetOidTree(SIMCOidTree *pOidTree)
  285. {
  286. m_pOidTree = pOidTree;
  287. }
  288. OidTreeScanner::~OidTreeScanner()
  289. {
  290. }