From d40872ae186d8c9efc7e8fd973aeb8ac7705d433 Mon Sep 17 00:00:00 2001
From: fguigues <fguigues@localhost>
Date: Mon, 19 May 2008 13:09:03 +0000
Subject: [PATCH] Fixes :

---
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java                  |   74 +++++++++++++-----------
 opendj-sdk/opends/src/messages/messages/protocol.properties                                         |    5 +
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/SNMPConnectionHandlerConfiguration.xml |   30 ++++++++++
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java                    |   16 ++++-
 4 files changed, 87 insertions(+), 38 deletions(-)

diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/SNMPConnectionHandlerConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/SNMPConnectionHandlerConfiguration.xml
index 85e0423..fa745e1 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/SNMPConnectionHandlerConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/SNMPConnectionHandlerConfiguration.xml
@@ -67,6 +67,9 @@
         <adm:synopsis>
             Specifies the port to use to send SNMP Traps.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:syntax>
             <adm:integer />
         </adm:syntax>
@@ -84,6 +87,9 @@
             access the MIB 2605 monitoring information or the USM MIB. The
             mapping between "community" and "context name" is set.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>OpenDS</adm:value>
@@ -105,6 +111,9 @@
             This property is required for SNMP v1 and v2 security configuration.
             An asterik (*) opens access to all managers. 
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>*</adm:value>
@@ -126,6 +135,9 @@
             is required for SNMP v3 security configuration.
             An asterik (*) opens access to all users. 
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>*</adm:value>
@@ -148,6 +160,9 @@
             privacy, AuthPriv : Authentication with privacy activated. 
             This property id required for SNMP V3 security configuration.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>authnopriv</adm:value>
@@ -185,6 +200,9 @@
             sent to define managers (trap-destinations). 
             This property is used in the context of SNMP v1, v2 and v3.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>OpenDS</adm:value>
@@ -209,6 +227,9 @@
             If this list is empty, V1 traps are sent to "localhost". 
             Each host in the list must be identifed by its name or complete IP Addess.
         </adm:description>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:alias>
                 <adm:synopsis>
@@ -231,6 +252,9 @@
             Specifies the USM security configuration to receive authenticated
             only SNMP requests.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>
@@ -254,6 +278,9 @@
             Directory Server MBeanServer or not allowing to access SNMP Objects
             with RMI connector if enabled.
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:defined>
                 <adm:value>false</adm:value>
@@ -273,6 +300,9 @@
         <adm:synopsis>
             Indicates the OpenDMK runtime jar file location
         </adm:synopsis>
+        <adm:requires-admin-action>
+          <adm:component-restart />
+        </adm:requires-admin-action>
         <adm:default-behavior>
             <adm:undefined />
         </adm:default-behavior>
diff --git a/opendj-sdk/opends/src/messages/messages/protocol.properties b/opendj-sdk/opends/src/messages/messages/protocol.properties
index c156ad6..c1cfe3f 100644
--- a/opendj-sdk/opends/src/messages/messages/protocol.properties
+++ b/opendj-sdk/opends/src/messages/messages/protocol.properties
@@ -1444,7 +1444,7 @@
  using configuration ds-cfg-listen-port in configuration entry %s.  This is a \
  required attribute
 SEVERE_ERR_SNMP_CONNHANDLER_CANNOT_DETERMINE_LISTEN_PORT_1460=An unexpected \
- error occurred while processing the ds-cfg-snmp-port attribute in \
+ error occurred while processing the ds-cfg-listen-port attribute in \
  configuration entry %s, which is used to specify the port on which to listen \
  for client connections:  %s
 SEVERE_ERR_SNMP_CONNHANDLER_CANNOT_BE_STARTED_1461=An unexpected \
@@ -1459,4 +1459,7 @@
  Please go under http://opendmk.dev.java.net and set the \
  ds-cfg-opendmk-jarfile configuration parameter to set the full path \
  of the required jdmkrt.jar file. The SNMP connection Handler didn't started
+SEVERE_ERR_SNMP_CONNHANDLER_BAD_CONFIGURATION_1465=An unexpected \
+ error occurred while trying to initialize the SNMP Connection Hanlder. \
+ Please check the configuration attributes
 
diff --git a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java
index de3d54b..9a49aeb 100644
--- a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java
+++ b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java
@@ -51,6 +51,7 @@
 import org.opends.server.util.StaticUtils;
 import org.opends.server.util.Validator;
 
+import static org.opends.messages.ProtocolMessages.*;
 
 /**
  * The SNMPClassLoaderProvider.
@@ -61,76 +62,64 @@
      * The debug log tracer for this class.
      */
     private static final DebugTracer TRACER = DebugLogger.getTracer();
-
     /**
      * The current configuration state.
      */
     private SNMPConnectionHandlerCfg currentConfig;
-
-
     /**
      * MBeanServer of OpenDS.
      */
     private MBeanServer server;
-
     /**
      * MIB to manage.
      */
     private DIRECTORY_SERVER_MIBImpl dsMib;
-
     /**
      * ObjectName of the MIB2605.
      */
     private ObjectName mibObjName;
-
     /**
      * ObjectName of the SnmpAdaptor.
      */
     private ObjectName snmpObjName;
-
     /**
      * SNMP Port Number for SNMP requests.
      */
     private int snmpPort = 161;
-
     /**
      * Default SNMP trap port Number for SNMP Traps.
      */
     private int snmpTrapPort = 162;
-
-
     /**
      * Registration of the SNMP MBeans.
      */
     private boolean registeredSNMPMBeans = false;
-
     /**
      * The unique name for this connection handler.
      */
     private String connectionHandlerName;
-
     /**
      * ObjectName of the UsmMIB.
      */
     private ObjectName UsmObjName;
-
     private SnmpV3AdaptorServer snmpAdaptor;
-
     private String contextName;
 
     /**
      * Default constructor.
      */
     public SNMPClassLoaderProvider() {
-      // No implementation required
+    // No implementation required
     }
 
     /**
      * Initialization.
      * @param configuration The configuration
+     * @throws java.lang.Exception if the SNMP connecvtion handler
+     * could not be initialized
      */
     public void initializeConnectionHandler(
-            SNMPConnectionHandlerCfg configuration) {
+            SNMPConnectionHandlerCfg configuration) throws Exception {
 
 
         // Keep the connection handler configuration
@@ -212,8 +201,8 @@
         return this.UsmObjName;
     }
 
-     // private methods
-    private void initializeConnectionHandler() {
+    // private methods
+    private void initializeConnectionHandler() throws Exception {
 
 
         // Compute the connectionHandler name
@@ -237,6 +226,11 @@
             // Create the SNMP Adaptor with the appropriated parameters
             this.snmpAdaptor = this.getSnmpAdaptor(this.currentConfig);
 
+            if (this.snmpAdaptor == null) {
+                throw new Exception(
+                      ERR_SNMP_CONNHANDLER_BAD_CONFIGURATION.get().toString());
+            }
+
             // Create the Usm MIB to allow user management
             if (this.registeredSNMPMBeans) {
 
@@ -245,9 +239,10 @@
                         "type=USM_MIB");
 
                 try {
-                     this.snmpAdaptor.registerUsmMib(server, this.UsmObjName);
-                }
-                catch (Exception ex) {
+                    this.snmpAdaptor.registerUsmMib(server, this.UsmObjName);
+                } catch (Exception ex) {
+                    throw new Exception(
+                       ERR_SNMP_CONNHANDLER_BAD_CONFIGURATION.get().toString());
                 }
             }
 
@@ -255,7 +250,12 @@
 
             // Send a coldStart SNMP Trap.
             this.snmpAdaptor.setTrapPort(snmpTrapPort);
-            this.snmpAdaptor.snmpV1Trap(0, 0, null);
+            this.snmpAdaptor.snmpV1Trap(
+                    null,
+                    this.currentConfig.getTrapsCommunity(),
+                    0,
+                    0,
+                    null);
 
             // Create an instance of the customized MIB
             this.mibObjName = new ObjectName(
@@ -275,10 +275,11 @@
             if (debugEnabled()) {
                 TRACER.debugCaught(DebugLogLevel.ERROR, ex);
             }
+            throw new Exception(
+                    ERR_SNMP_CONNHANDLER_BAD_CONFIGURATION.get().toString());
         }
     }
 
-
     /**
      * Finalize.
      */
@@ -287,7 +288,12 @@
         try {
 
             // Send a trap when stop
-            this.snmpAdaptor.snmpV1Trap(0, 0, null);
+            this.snmpAdaptor.snmpV1Trap(
+                    null,
+                    this.currentConfig.getTrapsCommunity(),
+                    0,
+                    0,
+                    null);
 
             String[] names = this.snmpAdaptor.getMibs();
 
@@ -297,13 +303,13 @@
             this.server.unregisterMBean(this.snmpObjName);
 
             if (this.server.isRegistered(this.mibObjName)) {
-               this.server.unregisterMBean(this.mibObjName);
+                this.server.unregisterMBean(this.mibObjName);
             }
 
 
             this.server.unregisterMBean(new ObjectName(
-                        SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
-                        "type=group,name=DsMib"));
+                    SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
+                    "type=group,name=DsMib"));
 
             // Unregister the created SNMP MBeans
             if (this.registeredSNMPMBeans) {
@@ -328,9 +334,8 @@
         }
     }
 
-
     private SnmpV3AdaptorServer getSnmpAdaptor(
-        SNMPConnectionHandlerCfg configuration) {
+            SNMPConnectionHandlerCfg configuration) {
 
         Validator.ensureNotNull(configuration);
         SnmpV3AdaptorServer adaptor = null;
@@ -339,7 +344,10 @@
             // Set the USM security file
             String usmConfigPath = configuration.getSecurityAgentFile();
             File file = StaticUtils.getFileForPath(usmConfigPath);
-            System.setProperty("jdmk.security.file",file.getAbsolutePath());
+            if ((!file.isFile()) || (!file.exists())) {
+                return null;
+            }
+            System.setProperty("jdmk.security.file", file.getAbsolutePath());
             // Create the Security Parameters for the engine
             SnmpEngineParameters engineParameters = new SnmpEngineParameters();
 
@@ -347,12 +355,12 @@
             engineParameters.activateEncryption();
 
             // Create the UACL controller
-            UserAcl uacls = (UserAcl)new SNMPUserAcl(configuration);
+            UserAcl uacls = (UserAcl) new SNMPUserAcl(configuration);
             engineParameters.setUserAcl(uacls);
 
             // V1/V2 Security parameters
             InetAddressAcl acls =
-              (InetAddressAcl)new SNMPInetAddressAcl(configuration);
+                    (InetAddressAcl) new SNMPInetAddressAcl(configuration);
 
             adaptor = new SnmpV3AdaptorServer(engineParameters, null, acls,
                     configuration.getListenPort(), InetAddress.getLocalHost());
@@ -363,7 +371,7 @@
             return adaptor;
         } catch (Exception ex) {
             TRACER.debugError("Could not instanciate the SNMP Adaptor");
-            return adaptor;
+            return null;
         }
     }
 }
diff --git a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java
index f13a30f..36625ca 100644
--- a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java
+++ b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java
@@ -46,7 +46,9 @@
 
 import org.opends.server.admin.std.server.SNMPConnectionHandlerCfg;
 
+import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.InitializationException;
 import static org.opends.messages.ProtocolMessages.*;
 import static org.opends.server.loggers.ErrorLogger.*;
 
@@ -92,9 +94,9 @@
     /**
      * {@inheritDoc}
      */
-    @Override()
     public void initializeConnectionHandler(
-            SNMPConnectionHandlerCfg configuration) {
+            SNMPConnectionHandlerCfg configuration)
+            throws ConfigException, InitializationException {
 
         if (configuration == null) {
             Message message = ERR_SNMP_CONNHANDLER_NO_CONFIGURATION.get();
@@ -145,8 +147,14 @@
         this.provider = new SNMPClassLoaderProvider();
 
         // Call the delegate class
-        this.provider.initializeConnectionHandler(this.currentConfig);
-
+        try {
+          this.provider.initializeConnectionHandler(this.currentConfig);
+        }
+        catch (Exception ex) {
+            Message message = ERR_SNMP_CONNHANDLER_BAD_CONFIGURATION.get();
+            logError(message);
+            return;
+        }
     }
 
     /**

--
Gitblit v1.10.0