AGENT++  4.0.3
vacm.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## AGENT++ 4.0 - vacm.h
4  _##
5  _## Copyright (C) 2000-2013 Frank Fock and Jochen Katz (agentpp.com)
6  _##
7  _## Licensed under the Apache License, Version 2.0 (the "License");
8  _## you may not use this file except in compliance with the License.
9  _## You may obtain a copy of the License at
10  _##
11  _## http://www.apache.org/licenses/LICENSE-2.0
12  _##
13  _## Unless required by applicable law or agreed to in writing, software
14  _## distributed under the License is distributed on an "AS IS" BASIS,
15  _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  _## See the License for the specific language governing permissions and
17  _## limitations under the License.
18  _##
19  _##########################################################################*/
20 #ifndef vacm_h_
21 #define vacm_h_
22 
23 #include <agent_pp/agent++.h>
24 #include <agent_pp/mib.h>
26 #include <agent_pp/snmp_pp_ext.h>
27 
28 #ifdef AGENTPP_NAMESPACE
29 namespace Agentpp
30 {
31 #endif
32 
33 #define oidSnmpModules "1.3.6.1.6.3"
34 #define oidSnmpVacmMIB "1.3.6.1.6.3.16"
35 #define oidVacmMIBObjects "1.3.6.1.6.3.16.1"
36 #define oidVacmMIBConformance "1.3.6.1.6.3.16.2"
37 
38 #define oidVacmContextTable "1.3.6.1.6.3.16.1.1"
39 #define oidVacmContextEntry "1.3.6.1.6.3.16.1.1.1"
40 #define oidVacmContextName "1.3.6.1.6.3.16.1.1.1.1"
41 
42 #define oidVacmSecurityToGroupTable "1.3.6.1.6.3.16.1.2"
43 #define oidVacmSecurityToGroupEntry "1.3.6.1.6.3.16.1.2.1"
44 #define oidVacmSecurityModel "1.3.6.1.6.3.16.1.2.1.1" // 1.index
45 #define oidVacmSecurityName "1.3.6.1.6.3.16.1.2.1.2" // 2.index
46 #define oidVacmGroupName "1.3.6.1.6.3.16.1.2.1.3"
47 #define oidVacmSecurityToGroupStorageType "1.3.6.1.6.3.16.1.2.1.4"
48 #define oidVacmSecurityToGroupStatus "1.3.6.1.6.3.16.1.2.1.5"
49 
50 #define oidVacmAccessTable "1.3.6.1.6.3.16.1.4"
51 #define oidVacmAccessEntry "1.3.6.1.6.3.16.1.4.1" // groupName 1. index
52 #define oidVacmAccessContextPrefix "1.3.6.1.6.3.16.1.4.1.1" // 2. index
53 #define oidVacmAccessSecurityModel "1.3.6.1.6.3.16.1.4.1.2" // 3. index
54 #define oidVacmAccessSecurityLevel "1.3.6.1.6.3.16.1.4.1.3" // 4. index
55 #define oidVacmAccessContextMatch "1.3.6.1.6.3.16.1.4.1.4"
56 #define oidVacmAccessReadViewName "1.3.6.1.6.3.16.1.4.1.5"
57 #define oidVacmAccessWriteViewName "1.3.6.1.6.3.16.1.4.1.6"
58 #define oidVacmAccessNotifyViewName "1.3.6.1.6.3.16.1.4.1.7"
59 #define oidVacmAccessStorageType "1.3.6.1.6.3.16.1.4.1.8"
60 #define oidVacmAccessStatus "1.3.6.1.6.3.16.1.4.1.9"
61 
62 #define oidVacmMIBViews "1.3.6.1.6.3.16.1.5"
63 #define oidVacmViewSpinLock "1.3.6.1.6.3.16.1.5.1"
64 #define oidVacmViewTreeFamilyTable "1.3.6.1.6.3.16.1.5.2"
65 #define oidVacmViewTreeFamilyEntry "1.3.6.1.6.3.16.1.5.2.1"
66 #define oidVacmViewTreeFamilyViewName "1.3.6.1.6.3.16.1.5.2.1.1" // 1. index
67 #define oidVacmViewTreeFamilySubtree "1.3.6.1.6.3.16.1.5.2.1.2" // 2. index
68 #define oidVacmViewTreeFamilyMask "1.3.6.1.6.3.16.1.5.2.1.3"
69 #define oidVacmViewTreeFamilyType "1.3.6.1.6.3.16.1.5.2.1.4"
70 #define oidVacmViewTreeFamilyStorageType "1.3.6.1.6.3.16.1.5.2.1.5"
71 #define oidVacmViewTreeFamilyStatus "1.3.6.1.6.3.16.1.5.2.1.6"
72 
73 #define oidVacmMIBCompliances "1.3.6.1.6.3.16.2.1"
74 #define oidVacmMIBGroups "1.3.6.1.6.3.16.2.2"
75 
76 // also defined in snmp++/include/v3.h
77 #ifndef oidSnmpUnavailableContexts
78 #define oidSnmpUnavailableContexts "1.3.6.1.6.3.12.1.4.0"
79 #define oidSnmpUnknownContexts "1.3.6.1.6.3.12.1.5.0"
80 #endif
81 
82 #ifndef TRUE
83 #define TRUE 1
84 #endif
85 
86 #ifndef FALSE
87 #define FALSE 0
88 #endif
89 
90 #define VACM_accessAllowed 0
91 #define VACM_notInView 1
92 #define VACM_noSuchView 2
93 #define VACM_noSuchContext 3
94 #define VACM_noGroupName 4
95 #define VACM_noAccessEntry 5
96 #define VACM_otherError 6
97 
98 #define VACM_viewFound 7
99 
100 static const char * vacmErrs[] = {
101  "accessAllowed", // 0
102  "notInView", // 1
103  "noSuchView ", // 2
104  "noSuchContext", // 3
105  "noGroupName", // 4
106  "noAccessEntry", // 5
107  "otherError", // 6
108  "viewFound" // 7 (just for safety)
109 };
110 
111 #define mibView_read 1
112 #define mibView_write 2
113 #define mibView_notify 3
114 
115 #define storageType_other 1
116 #define storageType_volatile 2
117 #define storageType_nonVolatile 3
118 #define storageType_permanent 4
119 #define storageType_readOnly 5
120 
121 #define match_exact 1
122 #define match_prefix 2
123 
124 #define view_included 1
125 #define view_excluded 2
126 
127 
128 class SnmpUnknownContexts;
130 class VacmContextTable;
132 class VacmAccessTable;
134 class Mib;
135 class Oidx;
136 
137 
139 {
140 public:
141  typedef struct
142  {
149  } ClassPointers;
150 
151  Vacm();
152  Vacm(Mib&);
153  virtual ~Vacm();
154 
169  virtual int isAccessAllowed(const int securityModel,
170  const NS_SNMP OctetStr &securityName,
171  const int securityLevel, const int viewType,
172  const NS_SNMP OctetStr &context, const Oidx &o);
173 
184  virtual int isAccessAllowed(const NS_SNMP OctetStr &viewName, const Oidx &o);
185 
198  virtual int getViewName(const int securityModel, const NS_SNMP OctetStr &securityName,
199  const int securityLevel, const int viewType,
200  const NS_SNMP OctetStr &context, NS_SNMP OctetStr &viewName);
201 
202  void incUnknownContexts();
203  NS_SNMP SnmpInt32 getUnknownContexts();
204  static const char* getErrorMsg(int nr) { return vacmErrs[nr];};
205 
214  bool addNewContext(const NS_SNMP OctetStr &newContext);
215 
221  void deleteContext(const NS_SNMP OctetStr &context);
222 
231  bool addNewGroup(const int securityModel,
232  const NS_SNMP OctetStr& securityName,
233  const NS_SNMP OctetStr& groupName,
234  const int storageType);
235 
239  void deleteGroup(const int securityModel, const NS_SNMP OctetStr& securityName);
240 
254  bool addNewAccessEntry(const NS_SNMP OctetStr& groupName,
255  const NS_SNMP OctetStr& prefix,
256  const int securityModel, const int securityLevel,
257  const int match,
258  const NS_SNMP OctetStr& readView,
259  const NS_SNMP OctetStr& writeView,
260  const NS_SNMP OctetStr& notifyView,
261  const int storageType);
262 
272  void deleteAccessEntry(const NS_SNMP OctetStr& groupName,
273  const NS_SNMP OctetStr& prefix,
274  const int securityModel, const int securityLevel);
275 
287  bool addNewView(const NS_SNMP OctetStr& viewName,
288  const Oidx& subtree,
289  const NS_SNMP OctetStr& mask,
290  const int type, const int storageType);
291 
298  void deleteView(const NS_SNMP OctetStr& viewName, const Oidx& subtree);
299 
307  ClassPointers get_vacm_tables() { return vcp; }
308 
328  void clear();
329 
330  protected:
332 };
333 
334 
336 {
337 public:
339  void incValue();
340  NS_SNMP SnmpInt32 getValue();
341 };
342 
344 {
345 public:
347  void incValue();
348  NS_SNMP SnmpInt32 getValue();
349 };
350 
351 /*********************************************************************
352 
353  VacmContextTable
354 
355  ********************************************************************/
357 {
358 
359 public:
361  ~VacmContextTable();
362 
363  bool isContextSupported(const NS_SNMP OctetStr& context);
364  bool addNewRow(const NS_SNMP OctetStr& context);
365  void deleteRow(const NS_SNMP OctetStr& context);
366 
370  virtual void clear() { MibTable::clear(); add_row("0"); }
371 };
372 
373 /*********************************************************************
374 
375  VacmSecurityToGroupTable
376 
377  ********************************************************************/
379 {
380 
381 public:
383  virtual ~VacmSecurityToGroupTable();
384 
385  virtual bool ready_for_service(Vbx*, int);
386  virtual bool could_ever_be_managed(const Oidx&, int&);
387  virtual void row_added(MibTableRow*, const Oidx&, MibTable*);
388  bool getGroupName(const int& securiyModel,
389  const NS_SNMP OctetStr& securityName,
390  NS_SNMP OctetStr& groupName);
391  bool isGroupNameOK(const NS_SNMP OctetStr&);
392  bool addNewRow(const int securityModel,
393  const NS_SNMP OctetStr& securityName,
394  const NS_SNMP OctetStr& groupName, const int storageType);
395  void deleteRow(const int securityModel,
396  const NS_SNMP OctetStr& securityName);
397 };
398 
399 /*********************************************************************
400 
401  VacmAccessTable
402 
403  ********************************************************************/
405 {
406 
407 public:
409  virtual ~VacmAccessTable();
410 
411  virtual bool ready_for_service(Vbx*, int);
412  virtual bool could_ever_be_managed(const Oidx&, int&);
413  virtual void row_added(MibTableRow*, const Oidx&, MibTable*);
414  bool getViewName(const NS_SNMP OctetStr& group,
415  const NS_SNMP OctetStr& context,
416  const int securityModel,
417  const int securityLevel,
418  const int viewType,
419  NS_SNMP OctetStr& viewName);
420 
421  bool addNewRow(const NS_SNMP OctetStr& groupName,
422  const NS_SNMP OctetStr& prefix,
423  const int securityModel, const int securityLevel,
424  const int match, const NS_SNMP OctetStr& readView,
425  const NS_SNMP OctetStr& writeView,
426  const NS_SNMP OctetStr& notifyView, const int storageType);
427  void deleteRow(const NS_SNMP OctetStr& groupName, const NS_SNMP OctetStr& prefix,
428  const int securityModel, const int securityLevel);
429 protected:
431 
432 };
433 
435 {
436 public:
437  VacmAccessTableStatus(const Oidx&, int);
439 
440  virtual MibEntryPtr clone();
441 
442 protected:
443  int base_len;
444 
445 };
446 
448 {
449 
450 public:
451  ViewNameIndex(const NS_SNMP OctetStr& vname): name(vname) {}
452  ~ViewNameIndex() { /* avoid deletion of original rows: */views.clear();}
453 
454  void add(MibTableRow* row) { views.add(row);}
455  void remove(MibTableRow* row) { views.remove(row);}
456  bool isEmpty() { return views.empty();}
457 
458  NS_SNMP OctetStr name;
460 };
461 
462 /*********************************************************************
463 
464  VacmViewTreeFamilyTable
465 
466  ********************************************************************/
467 #if !defined (AGENTPP_DECL_TEMPL_LIST_VIEWNAMEINDEX)
468 #define AGENTPP_DECL_TEMPL_LIST_VIEWNAMEINDEX
470 #endif
471 
473 {
475 public:
477  virtual ~VacmViewTreeFamilyTable();
478 
479  virtual bool ready_for_service(Vbx*, int);
480  virtual bool could_ever_be_managed(const Oidx&, int&);
481  virtual void row_added(MibTableRow*, const Oidx&, MibTable*);
482  virtual void row_activated(MibTableRow*, const Oidx&, MibTable*);
483  virtual void row_deactivated(MibTableRow*, const Oidx&, MibTable*);
484  virtual void row_delete(MibTableRow*, const Oidx&, MibTable*);
485  virtual void row_init(MibTableRow*, const Oidx&, MibTable* t=0);
486  int isInMibView(const NS_SNMP OctetStr&, const Oidx&);
487  bool addNewRow(const NS_SNMP OctetStr& viewName, const Oidx& subtree,
488  const NS_SNMP OctetStr& mask, const int type,
489  const int storageType);
490  void deleteRow(const NS_SNMP OctetStr& viewName, const Oidx& subtree);
491  virtual void clear() { StorageTable::clear(); buildViewNameIndex();}
492  virtual void reset() { StorageTable::reset(); buildViewNameIndex();}
493 
494 protected:
495  bool bit(unsigned int, NS_SNMP OctetStr&);
496  ViewNameIndex* viewsOf(const NS_SNMP OctetStr& viewName);
497  void buildViewNameIndex();
498 
500 };
501 
503 {
504 public:
505  VacmViewTreeFamilyTableStatus(const Oidx&, int);
507  virtual int set(const Vbx&);
508  virtual MibEntryPtr clone();
509 
510 protected:
511  int base_len;
512 };
513 
514 /*********************************************************************
515 
516  VacmMIB
517 
518  ********************************************************************/
520 {
521 
522 public:
524 };
525 
526 #ifdef AGENTPP_NAMESPACE
527 }
528 #endif
529 #endif