mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Christophe Sovant
31.59.2008 a036cff9de96bad3f2b1131c2b4e311d13a3507d
Update SNMP user list, enable encryption in the SNMP managers and  add news functions in snmp.xml
5 files modified
370 ■■■■■ changed files
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/agent.security 6 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/manager.security 9 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/snmp.xml 271 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/snmp/SNMPGet.java 79 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/snmp/SNMPSet.java 5 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/agent.security
@@ -44,8 +44,10 @@
## BEGIN: Test users ##
#######################
userEntry=localEngineID,myUser,,usmHMACMD5AuthProtocol,mypasswd
userEntry=localEngineID,myUser2,,usmHMACMD5AuthProtocol,mypasswd2
userEntry=localEngineID,myUser1,,usmNoAuthProtocol
userEntry=localEngineID,myUser2,,usmHMACMD5AuthProtocol,mypasswd
userEntry=localEngineID,myUser3,,usmHMACMD5AuthProtocol,mypasswd,usmDESPrivProtocol,mypasswd
userEntry=localEngineID,myUser4,,usmHMACMD5AuthProtocol,mypasswd2
#######################
## END: Test users   ##
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/manager.security
@@ -31,6 +31,9 @@
# User and security configuration
userEntry=0x8000002a017f000001000000a1,snmpAdmin,null,usmHMACMD5AuthProtocol,passadmin
userEntry=0x8000002a017f000001000000a1,defaultUser,,usmHMACMD5AuthProtocol,password
userEntry=0x8000002a017f000001000000a1,myUser,,usmHMACMD5AuthProtocol,mypasswd
userEntry=0x8000002a017f000001000000a1,myUser2,,usmHMACMD5AuthProtocol,mypasswd2
userEntry=0x8000002a017f000001000000a1,defaultUser,,usmHMACMD5AuthProtocol,password,,,3,true
userEntry=0x8000002a017f000001000000a1,myUser1,,usmNoAuthProtocol
userEntry=0x8000002a017f000001000000a1,myUser2,,usmHMACMD5AuthProtocol,mypasswd
userEntry=0x8000002a017f000001000000a1,myUser3,,usmHMACMD5AuthProtocol,mypasswd,usmDESPrivProtocol,mypasswd
userEntry=0x8000002a017f000001000000a1,myUser4,,usmHMACMD5AuthProtocol,mypasswd2
opendj-sdk/opends/tests/shared/functions/snmp.xml
@@ -62,43 +62,49 @@
      </function-arg-def>
      <function-arg-def name="snmpOIDs" type="optional">
        <function-arg-description>
          Bind password
          SNMP OID to query
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>      
      <function-arg-def name="snmpCommunity" type="required">
        <function-arg-description>
          Bind DN
          SNMP community/context
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpUser" type="optional">
        <function-arg-description>
          Bind DN
          SNMP user used for v3 requests
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityLevel" type="optional">
        <function-arg-description>
          Bind DN
          SNMP security level used for v3 requests
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>      
      <function-arg-def name="snmpSecurityFile" type="optional">
        <function-arg-description>
          Bind password
          Path to the SNMP security file
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpStatus" type="required">
        <function-arg-description>
          Bind password
          Expected status of the SNMP request
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpValidOIDs" type="optional">
        <function-arg-description>
          Bind password
          Check if the values returned for the OIDs are correct
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpWalk" type="optional">
        <function-arg-description>
          Perform a walk request
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
@@ -147,6 +153,9 @@
        if snmpValidOIDs:
          STAFCmdParamsList.append('-n %s' % snmpValidOIDs)
        
        if snmpWalk:
          STAFCmdParamsList.append('-w %s' % snmpWalk)
        STAFCmdParams=' '.join(STAFCmdParamsList)
        
        STAFCmd='SNMPGet'
@@ -159,6 +168,12 @@
        opends_jarfile='%s/%s' % (DIRECTORY_INSTANCE_DIR,SNMP_OPENDS_JARFILE)
        snmpPath='%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
        jdmk_jarfile='%s/jdmkrt.jar' % snmpPath
        emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
        if os.path.exists(emma_jarfile):
          cp = 'CLASSPATH=%s%s%s%s%s%s.' \
          % (opends_jarfile,separator,jdmk_jarfile,separator,emma_jarfile,separator)
        else:
        cp = 'CLASSPATH=%s%s%s%s.' \
        % (opends_jarfile,separator,jdmk_jarfile,separator)
        
@@ -224,43 +239,43 @@
      </function-arg-def>  
      <function-arg-def name="snmpOIDs" type="optional">
        <function-arg-description>
          Bind password
          SNMP OID to query
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpCommunity" type="required">
        <function-arg-description>
          Bind DN
          SNMP community/context
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpUser" type="optional">
        <function-arg-description>
          Bind DN
          SNMP user used for v3 requests
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityLevel" type="optional">
        <function-arg-description>
          Bind DN
          SNMP security level used for v3 requests
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>  
      <function-arg-def name="snmpSecurityFile" type="optional">
        <function-arg-description>
          Bind password
          Path to the SNMP security file
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpStatus" type="required">
        <function-arg-description>
          Bind password
          Expected status of the SNMP request
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpValidOIDs" type="optional">
        <function-arg-description>
          Bind password
          Check if the values returned for the OIDs are correct
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
@@ -321,6 +336,12 @@
        opends_jarfile='%s/%s' % (DIRECTORY_INSTANCE_DIR,SNMP_OPENDS_JARFILE)
        snmpPath='%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
        jdmk_jarfile='%s/jdmkrt.jar' % snmpPath
        emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
        if os.path.exists(emma_jarfile):
          cp = 'CLASSPATH=%s%s%s%s%s%s.' \
          % (opends_jarfile,separator,jdmk_jarfile,separator,emma_jarfile,separator)
        else:
        cp = 'CLASSPATH=%s%s%s%s.' \
        % (opends_jarfile,separator,jdmk_jarfile,separator)
        
@@ -378,13 +399,13 @@
      </function-arg-def>  
      <function-arg-def name="snmpTrapCommunity" type="required">
        <function-arg-description>
          Bind DN
          SNMP trap community
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>  
      <function-arg-def name="snmpTrapNumber" type="required">
        <function-arg-description>
          Bind password
          Number of expected traps
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
@@ -464,4 +485,208 @@
      
    </sequence>
  </function>
  <!-- Restart SNMP Connection Handler -->
  <function name="restartSNMPConnectionHandler" scope="local">
    <function-prolog>
      This function restart the SNMP Connection Handler using dsconfig
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="dsPath"
                        type="optional"
                        default="'%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
        <function-arg-description>
          Pathname to installation root
        </function-arg-description>
        <function-arg-property name="type" value="filepath" />
      </function-arg-def>
      <function-arg-def name="dsInstanceHost"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Directory server hostname or IP address
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="dsInstancePort" type="required">
        <function-arg-description>
          Directory server port number
        </function-arg-description>
        <function-arg-property name="type" value="Port number" />
      </function-arg-def>
      <function-arg-def name="dsInstanceDn" type="required">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN" />
      </function-arg-def>
      <function-arg-def name="dsInstancePswd" type="required">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string" />
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0.
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
        <function-arg-property name="type" value="string" />
      </function-arg-def>
    </function-map-args>
    <sequence>
      <!-- Build the command -->
      <script>
        STAFCmdParamsList=[]
        STAFCmdParams=''
        if dsPath:
          dsBinPath='%s/%s' % (dsPath,fileFolder)
        if dsInstanceHost:
          STAFCmdParamsList.append('-h %s' % dsInstanceHost)
        if dsInstancePort:
          STAFCmdParamsList.append('-p %s' % dsInstancePort)
        if dsInstanceDn:
          STAFCmdParamsList.append('-D "%s"' % dsInstanceDn)
        if dsInstancePswd:
          STAFCmdParamsList.append('-w "%s"' % dsInstancePswd)
        STAFCmdParamsList.append('-n')
        STAFCmdParamsList.append('set-connection-handler-prop')
        STAFCmdParamsList.append('--handler-name "SNMP Connection Handler"')
        STAFCmdParams=' '.join(STAFCmdParamsList)
        STAFCmd='%s/%s%s' % (dsBinPath,DSCONFIG,fileExt)
      </script>
      <call function="'runCommand'">
        {
        'name'      : 'Disable the SNMP Connection Handler' ,
        'location'  : location ,
        'command'   : STAFCmd ,
        'arguments' : '%s --set enabled:false' % STAFCmdParams ,
        'expectedRC': expectedRC
        }
      </call>
      <call function="'runCommand'">
        {
        'name'      : 'Enable the SNMP Connection Handler' ,
        'location'  : location ,
        'command'   : STAFCmd ,
        'arguments' : '%s --set enabled:true' % STAFCmdParams ,
        'expectedRC': expectedRC
        }
      </call>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
  <!-- Compare SNMP values -->
  <function name="compareSNMPValues" scope="local">
    <function-prolog>
      This function compare SNMP Values
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="snmpHost"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Directory server hostname or IP address
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="snmpPort" type="required">
        <function-arg-description>
          Directory server SNMP port number
        </function-arg-description>
        <function-arg-property name="type" value="Port number"/>
      </function-arg-def>
      <function-arg-def name="snmpCommunity" type="required">
        <function-arg-description>
          SNMP community/context
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
        <function-arg-property name="type" value="integer"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <message>
        'get the current mib values'
      </message>
      <call function="'SNMPGet'">
        {
        'location'      : location ,
        'snmpVersion'   : '1',
        'snmpHost'      : snmpHost ,
        'snmpPort'      : snmpPort ,
        'snmpCommunity' : snmpCommunity ,
        'snmpOIDs'      : '' ,
        'snmpStatus'    : 'noError' ,
        'snmpWalk'      : 'True' ,
        'expectedRC'    : expectedRC
        }
      </call>
      <script>
        CURRENT_VALUES = {}
        CURRENT_VALUES = create_table_fromoutput(STAXResult[0][1])
        result = compare_snmp_values(DEFAULT_VALUES, CURRENT_VALUES)
      </script>
      <message>
        'result: %s' % result
      </message>
      <call function="'checktestStringNotPresent'">
        {
        'returnString' : result ,
        'testString'   : 'ERROR'
        }
      </call>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/shared/java/snmp/SNMPGet.java
@@ -73,7 +73,8 @@
              " -l <securityLevel>" +
              " -f <securityFile>" +
              " -s <connectionStatus>" +
              " -n <checkOIDs>");
              " -n <checkOIDs>" +
              " -w <snmpwalk>");
      rc = 1;
    } else {
      for (int i = 0; i < args.length; i++) {
@@ -121,6 +122,9 @@
          case 'n':
            validOIDs = new Boolean(val).booleanValue();
            break;
          case 'w':
            walk = new Boolean(val).booleanValue();
            break;
          default:
            System.out.println("Unknown option -" + opt.charAt(1) + ".");
            rc = 1;
@@ -207,6 +211,11 @@
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();
          // Activate encryption
          engineParameters.activateEncryption();
          // Set the security file
          engineParameters.setSecurityFile(securityFile);
          // Create the session
@@ -257,6 +266,7 @@
          agentV3.setMaxTries(maxRetries);
          agentV3.setParams(paramsV3);
          if (securityLevel != SnmpDefinitions.noAuthNoPriv) {
          // Discover timeliness of creation and boot
          //
         try {
@@ -280,6 +290,7 @@
            rc = 1;
          }
          }
          if (rc == 0) {
            // Set the default peer (agent) to a SnmpSession
@@ -318,15 +329,25 @@
   */
  public int getRequest() {
    int rc = 0;
    String previousOID = "";
    try {
      // Build the list of variables you want to query
      //
      final SnmpVarBindList list = new SnmpVarBindList("Get varbind list");
      // Read all TEST-MIB variables.
      // Read specific OIDs
      //
      if (walk) {
        // Walk request
        //
         list.addVarBind("0.0");
         previousOID = "0.0";
      } else {
        // Get request
      //
      list.addVarBind(oids);
      }
      // Make the SNMP get request
      //
@@ -335,14 +356,24 @@
              " GET request for SNMP agent on \"" + remoteHost +
              "\" at port \"" + port + "\".");
      while (previousOID.compareTo("end") != 0) {
        SnmpRequest request = null;
        if (walk) {
          // Walk request
          //
          request = session.snmpGetNextRequest(null, list);
        } else {
      // Get request
      //
      SnmpRequest request = session.snmpGetRequest(null, list);
          request = session.snmpGetRequest(null, list);
        }
      // Check for a timeout of the request
      //
      boolean completed = request.waitForCompletion((maxRetries + 1) * timeOut);
        boolean completed =
                request.waitForCompletion((maxRetries + 1) * timeOut);
      if (completed == false) {
          if (connectStatus.compareTo("reqTimeout") != 0) {
        System.out.println(
                "getRequest() of SNMPGet: Request timed out, " +
                "check reachability of agent.");
@@ -354,9 +385,13 @@
                request.toString() + ".");
        rc = 1;
          } else {
            System.out.println(
                    "getRequest() of SNMPGet: Request timed out as expected.");
          }
      }
      if (rc == 0) {
        if (rc == 0 && completed) {
        System.out.println(
                "getRequest() of SNMPGet: Finish SNMP V" +
                version + " GET request.");
@@ -379,12 +414,20 @@
                    "getRequest() of SNMPGet: Get request failed as " +
                    "expected with " + connectStatus + " status.");
          } else {
              if (walk && errorStatus.compareTo("noSuchName") == 0) {
                System.out.println(
                        "getRequest() of SNMPGet: Get request failed as " +
                        "expected with " + connectStatus + " status.");
              } else {
            System.out.println(
                    "getRequest() of SNMPGet: Get request should " +
                    "fail with " + connectStatus + " status.");
            rc = 1;
          }
            }
            previousOID = "end";
        } else {
          // Now we shall display the content of the result
          //
@@ -392,8 +435,30 @@
          System.out.println("getRequest() of SNMPGet: Result=");
            String tmpOID = "";
            String realOID = "";
          for (int i = 0; i < resp.getVarBindCount(); i++) {
            System.out.println(resp.getVarBindAt(i));
              tmpOID = resp.getVarBindAt(i).getOid().toString();
              int endIndex = tmpOID.lastIndexOf(".");
              String indexOID = tmpOID.substring(endIndex, tmpOID.length());
              realOID = tmpOID.substring(0, endIndex);
              if (realOID.startsWith("1.3.6.1.2.1.66.2")) {
                endIndex = realOID.lastIndexOf(".");
                realOID = realOID.substring(0, endIndex);
              }
              String name = resp.getVarBindAt(i).resolveVarName(realOID).getName();
              String value = resp.getVarBindAt(i).getStringValue();
              System.out.println(name + indexOID + "=" + value);
              if (walk) {
                list.removeVarBind(previousOID);
                list.addVarBind(tmpOID);
                previousOID = tmpOID;
              } else {
                previousOID = "end";
              }
          }
          if (connectStatus.compareTo("noError") != 0) {
@@ -437,6 +502,7 @@
          }
        }
      }
      }
    } catch (Exception e) {
      System.out.println(
              "connect() of SNMPGet catched an unexpected exception: " +
@@ -511,6 +577,7 @@
  String securityFile = null;
  static String connectStatus = null;
  boolean validOIDs = true;
  boolean walk = false;
  // SnmpSession
  SnmpSession session = null;
opendj-sdk/opends/tests/shared/java/snmp/SNMPSet.java
@@ -207,6 +207,11 @@
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();
          // Activate encryption
          engineParameters.activateEncryption();
          // Set the security file
          engineParameters.setSecurityFile(securityFile);
          // Create the session