[AGENT++] persistent storage for UsmUserTable in usmMIB

Jochen Katz katz at agentpp.com
Sat Oct 22 13:06:05 CEST 2005


Hi,

> I have a question regarding persistent storage.

> I thought that code below will save user info in the usmMIB file.
> 
>      UsmUserTable *uut = new UsmUserTable(); 
>      uut->addNewRow("unsecureUser", SNMPv3_usmNoAuthProtocol, SNMPv3_usmNoPrivProtocol, "", ""); 
>      uut->addNewRow("MD5", SNMPv3_usmHMACMD5AuthProtocol, SNMPv3_usmNoPrivProtocol, "MD5UserAuthPassword", "");
>      ...
>      mib.add(new usm_mib(uut)); 
>      mib.save_all(); 
> 
> But it is not.
> Why UsmUserTable info is not saved in the file usmMIB?

addNewRow() adds the rows with the default storage type volatile, so
these rows are not saved.

With the current version of agent++ you will have to find the row in the
mib ant then replace the value. With the patch below (will be in the
next release) addNewRow() is changed to return the new row and you can
write:

MibTableRow *x;
x=      uut->addNewRow(...);
x->get_nth(11)->replace_value(new SnmpInt32(4));

Regards,
  Jochen


Index: include/agent_pp/v3_mib.h
===================================================================
RCS file: /home/cvs/AGENT_PP/include/agent_pp/v3_mib.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -b -r1.6 -r1.7
--- include/agent_pp/v3_mib.h   18 Jun 2005 19:02:38 -0000      1.6
+++ include/agent_pp/v3_mib.h   22 Oct 2005 09:36:04 -0000      1.7
@@ -190,7 +190,7 @@
    *
    * @note This function takes the localized keys as param.
    */
-  boolean addNewRow(const NS_SNMP OctetStr& engineID,
+  MibTableRow *addNewRow(const NS_SNMP OctetStr& engineID,
                     const NS_SNMP OctetStr& userName,
                     const NS_SNMP OctetStr& securityName,
                    int authProtocol, const NS_SNMP OctetStr& authKey,
@@ -205,7 +205,7 @@
    *
    * @note This function takes the localized keys as param.
    */
-  boolean addNewRow(const NS_SNMP OctetStr& engineID,
+  MibTableRow *addNewRow(const NS_SNMP OctetStr& engineID,
                     const NS_SNMP OctetStr& userName,
                    int authProtocol, const NS_SNMP OctetStr& authKey,
                    int privProtocol, const NS_SNMP OctetStr& privKey,
@@ -225,7 +225,7 @@
    *
    * @note This function takes the passwords as param.
    */
-  boolean addNewRow(const NS_SNMP OctetStr& userName,
+  MibTableRow *addNewRow(const NS_SNMP OctetStr& userName,
                     const NS_SNMP OctetStr& securityName,
                     int authProtocol,
                     int privProtocol,
@@ -240,7 +240,7 @@
    *
    * @note This function takes the passwords as param.
    */
-  boolean addNewRow(const NS_SNMP OctetStr& userName,
+  MibTableRow *addNewRow(const NS_SNMP OctetStr& userName,
                     int authProtocol,
                     int privProtocol,
                     const NS_SNMP OctetStr& authPassword,
Index: src/v3_mib.cpp
===================================================================
RCS file: /home/cvs/AGENT_PP/src/v3_mib.cpp,v
retrieving revision 1.7
retrieving revision 1.9
diff -u -w -b -r1.7 -r1.9
--- src/v3_mib.cpp      18 Jun 2005 19:02:38 -0000      1.7
+++ src/v3_mib.cpp      22 Oct 2005 10:47:39 -0000      1.9
@@ -622,7 +622,7 @@
   ml->set_value(o.as_string());
 }

-boolean UsmUserTable::addNewRow(const OctetStr& userName,
+MibTableRow *UsmUserTable::addNewRow(const OctetStr& userName,
                                 const OctetStr& securityName,
                                 int authProtocol,
                                 int privProtocol,
@@ -658,7 +658,7 @@
       LOG(res);
       LOG_END;
     }
-    return FALSE;
+    return 0;
   }

   res = usm->get_auth_priv()->password_to_key_priv(authProtocol,
@@ -687,10 +687,13 @@
   }

   // add User into MIB
-  if (!addNewRow(engineID, userName, securityName,
-                 authProtocol, OctetStr(authKey, authKeyLength),
-                 privProtocol, OctetStr(privKey, privKeyLength)))
-     return FALSE;
+  MibTableRow *new_row = addNewRow(engineID, userName, securityName,
+                                  authProtocol,
+                                  OctetStr(authKey, authKeyLength),
+                                  privProtocol,
+                                  OctetStr(privKey, privKeyLength));
+  if (!new_row)
+     return 0;

   // add passwords for user to USM for discovery
   if (usm->add_usm_user(userName, securityName, authProtocol, privProtocol,
@@ -698,12 +701,12 @@
        != SNMPv3_USM_OK)
   {
     deleteRow(engineID, userName);
-    return FALSE;
+    return 0;
   }
-  return TRUE;
+  return new_row;
 }

-boolean UsmUserTable::addNewRow(const OctetStr& engineID,
+MibTableRow *UsmUserTable::addNewRow(const OctetStr& engineID,
                                const OctetStr& userName,
                                 const OctetStr& securityName,
                                int authProtocol,
@@ -721,7 +724,7 @@
                                authProtocol, authKey, privProtocol,
privKey)
        != SNMPv3_USM_OK)
     {
-      return FALSE;
+      return 0;
     }
     else
     {
@@ -733,11 +736,11 @@
     }
   }

-  // if row exists: delete old row and add the new
-  if (find_index(newIndex))
-    remove_row(newIndex);
+  // check for existing row
+  MibTableRow *newRow = find_index(newIndex);

-  MibTableRow *newRow = add_row(newIndex);
+  if (!newRow)
+      newRow = add_row(newIndex);

   newRow->get_nth(2)->replace_value(securityName.clone());
   newRow->get_nth(3)->replace_value(newIndex.clone());
@@ -798,7 +801,7 @@
   newRow->get_nth(11)->replace_value(new SnmpInt32(2));
   newRow->get_nth(12)->replace_value(new SnmpInt32(rowActive));

-  return TRUE;
+  return newRow;
 }

 boolean UsmUserTable::deleteRow(const OctetStr& engineID,
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: v3_diff.txt
Url: http://lists.agentpp.org/pipermail/agentpp/attachments/20051022/e56db0bc/attachment.txt 


More information about the AGENTPP mailing list