From 66158c723e127ef41a4a60566fb8f1f53c680e54 Mon Sep 17 00:00:00 2001
From: fguigues <fguigues@localhost>
Date: Thu, 22 May 2008 07:37:52 +0000
Subject: [PATCH] Fixes:  3142: SNMP: SNMP Connection Handler should accept snmp requests on localhost 3239: On Windows, server can't load jdmkrt.jar file 3253: SNMP: wrong value for dsServerType entry

---
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java |    3 
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java             |   15 ++
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java        |  295 ++++++++++++++++++++++++++----------------------
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java    |    9 +
 opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java   |    8 
 5 files changed, 186 insertions(+), 144 deletions(-)

diff --git a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
index e5da78a..67e2120 100644
--- a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
+++ b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
@@ -93,6 +93,15 @@
   }
 
   /**
+   * Getter for the "DsApplIfProtocol" variable.
+   * @return an OID representing the connection handler:port
+   */
+  public String getDsApplIfProtocol() {
+//      return  new String("1.3.6.1..27.3.") + portNumber;
+      return DsApplIfProtocol;
+  }
+
+  /**
    * {@inheritDoc}
    * @return DsApplIfSearchOps
    */
diff --git a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java
index 8432284..b78f2d5 100644
--- a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java
+++ b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java
@@ -41,150 +41,171 @@
  */
 public class DsTableEntryImpl extends DsTableEntry implements DsEntry {
 
-  /**
-   * The serial version identifier required to satisfy the compiler because
-   * this class implements the <CODE>java.io.Serializable</CODE> interface.
-   * This value was generated using the <CODE>serialver</CODE> command-line
-   * utility included with the Java SDK.
-   */
-  private static final long serialVersionUID = -3346380035687141480L;
-  /**
-   * The debug log tracer for this class.
-   */
-  private static final DebugTracer TRACER = DebugLogger.getTracer();
-  /**
-   * Directory Server MBeanServer.
-   */
-  private MBeanServer server;
-  /**
-   * Mapping Class.
-   */
-  private SNMPMonitor monitor;
-  /**
-   * ObjectName of the entry.
-   */
-  private ObjectName entryName;
-  /**
-   * Index of the Directory Server Instance (applIndex).
-   */
-  private Integer applIndex;
+    /**
+     * The serial version identifier required to satisfy the compiler because
+     * this class implements the <CODE>java.io.Serializable</CODE> interface.
+     * This value was generated using the <CODE>serialver</CODE> command-line
+     * utility included with the Java SDK.
+     */
+    private static final long serialVersionUID = -3346380035687141480L;
+    /**
+     * The debug log tracer for this class.
+     */
+    private static final DebugTracer TRACER = DebugLogger.getTracer();
+    /**
+     * Directory Server MBeanServer.
+     */
+    private MBeanServer server;
+    /**
+     * Mapping Class.
+     */
+    private SNMPMonitor monitor;
+    /**
+     * ObjectName of the entry.
+     */
+    private ObjectName entryName;
+    /**
+     * Index of the Directory Server Instance (applIndex).
+     */
+    private Integer applIndex;
 
-  /**
-   * Creates a DsTableEntry.
-   * @param mib the SNMP Mib where the entry will be created
-   * @param server where the mapping objects will be found
-   * @param index of the entry in the DsTable
-   */
-  public DsTableEntryImpl(SnmpMib mib,
-          MBeanServer server,
-          int index) {
-    super(mib);
-    this.server = server;
-    this.monitor = SNMPMonitor.getMonitor(server);
-    this.applIndex = new Integer(index);
-  }
-
-  /**
-   * {@inheritDoc}
-   * @return DsCacheHits as Long
-   */
-  @Override
-  public Long getDsCacheHits() {
-    try {
-      Long value = Long.parseLong((String) this.monitor.getAttribute(
-              SNMPConnectionHandlerDefinitions.MONITOR_ENTRY_CACHES_OBJECTNANE,
-              "entryCacheHits"));
-      return SNMPMonitor.counter32Value(value);
-    } catch (Exception ex) {
-      if (DebugLogger.debugEnabled()) {
-        TRACER.debugCaught(DebugLogLevel.ERROR, ex);
-      }
+    /**
+     * Creates a DsTableEntry.
+     * @param mib the SNMP Mib where the entry will be created
+     * @param server where the mapping objects will be found
+     * @param index of the entry in the DsTable
+     */
+    public DsTableEntryImpl(SnmpMib mib,
+            MBeanServer server,
+            int index) {
+        super(mib);
+        this.server = server;
+        this.monitor = SNMPMonitor.getMonitor(server);
+        this.applIndex = new Integer(index);
     }
-    return 0L;
-  }
 
-  /**
-   * {@inheritDoc}
-   * @return DsCacheEntries as Long
-   */
-  @Override
-  public Long getDsCacheEntries() {
-    try {
-      Long value = Long.parseLong((String) this.monitor.getAttribute(
-              SNMPConnectionHandlerDefinitions.MONITOR_ENTRY_CACHES_OBJECTNANE,
-              "currentEntryCacheCount"));
-      return SNMPMonitor.gauge32Value(value);
-    } catch (Exception ex) {
-      if (DebugLogger.debugEnabled()) {
-        TRACER.debugCaught(DebugLogLevel.ERROR, ex);
-      }
-    }
-    return 0L;
-  }
-
-  /**
-   * {@inheritDoc}
-   * @return DsMasterEntries as Long
-   */
-  @Override
-  public Long getDsMasterEntries() {
-    Set monitorBackends = null;
-    Long result = 0L;
-    try {
-      monitorBackends = this.server.queryNames(SNMPMonitor.pattern, null);
-      for (Iterator iter = monitorBackends.iterator(); iter.hasNext();) {
-        ObjectName name = (ObjectName) iter.next();
-        Object value = this.monitor.getAttribute(name,
-                "ds-backend-entry-count");
-        if (value != null) {
-          result = result + new Long((String) value);
+    /**
+     * Getter for the "DsServerType" variable.
+     * @return a Byte[] representing the Ds Server Type
+     */
+    public Byte[] getDsServerType() {
+        try {
+            String value1 = (String) this.monitor.getAttribute(
+                    SNMPConnectionHandlerDefinitions.MONITOR_VERSION_OBJECTNAME,
+                    "fullVersion");
+            String value2 = (String) this.monitor.getAttribute(
+                    SNMPConnectionHandlerDefinitions.MONITOR_VERSION_OBJECTNAME,
+                    "buildID");
+            return SNMPMonitor.string2ByteArray(value1 + " - " + value2);
+        } catch (Exception ex) {
+            if (DebugLogger.debugEnabled()) {
+                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+            }
+            return null;
         }
-      }
-      return SNMPMonitor.gauge32Value(result);
-    } catch (Exception ex) {
-      if (DebugLogger.debugEnabled()) {
-        TRACER.debugCaught(DebugLogLevel.ERROR, ex);
-      }
     }
-    return 0L;
-  }
 
-  /**
-   * {@inheritDoc}
-   * @return DsServerDescription as String
-   */
-  @Override
-  public String getDsServerDescription() {
-    String result = null;
-    try {
-      result = (String) this.monitor.getAttribute(
+    /**
+     * {@inheritDoc}
+     * @return DsCacheHits as Long
+     */
+    @Override
+    public Long getDsCacheHits() {
+        try {
+            Long value = Long.parseLong((String) this.monitor.getAttribute(
+              SNMPConnectionHandlerDefinitions.MONITOR_ENTRY_CACHES_OBJECTNANE,
+                    "entryCacheHits"));
+            return SNMPMonitor.counter32Value(value);
+        } catch (Exception ex) {
+            if (DebugLogger.debugEnabled()) {
+                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+            }
+        }
+        return 0L;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @return DsCacheEntries as Long
+     */
+    @Override
+    public Long getDsCacheEntries() {
+        try {
+            Long value = Long.parseLong((String) this.monitor.getAttribute(
+              SNMPConnectionHandlerDefinitions.MONITOR_ENTRY_CACHES_OBJECTNANE,
+                    "currentEntryCacheCount"));
+            return SNMPMonitor.gauge32Value(value);
+        } catch (Exception ex) {
+            if (DebugLogger.debugEnabled()) {
+                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+            }
+        }
+        return 0L;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @return DsMasterEntries as Long
+     */
+    @Override
+    public Long getDsMasterEntries() {
+        Set monitorBackends = null;
+        Long result = 0L;
+        try {
+            monitorBackends = this.server.queryNames(SNMPMonitor.pattern, null);
+            for (Iterator iter = monitorBackends.iterator(); iter.hasNext();) {
+                ObjectName name = (ObjectName) iter.next();
+                Object value = this.monitor.getAttribute(name,
+                        "ds-backend-entry-count");
+                if (value != null) {
+                    result = result + new Long((String) value);
+                }
+            }
+            return SNMPMonitor.gauge32Value(result);
+        } catch (Exception ex) {
+            if (DebugLogger.debugEnabled()) {
+                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+            }
+        }
+        return 0L;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @return DsServerDescription as String
+     */
+    @Override
+    public String getDsServerDescription() {
+        String result = null;
+        try {
+            result = (String) this.monitor.getAttribute(
         SNMPConnectionHandlerDefinitions.MONITOR_SYSTEM_INFORMATION_OBJECTNAME,
-        "workingDirectory");
-    } catch (Exception ex) {
-      if (DebugLogger.debugEnabled()) {
-        TRACER.debugCaught(DebugLogLevel.ERROR, ex);
-      }
-    }
-    return result;
-  }
-
-  /**
-   * Gets the object of the entry.
-   * @return ObjectName of the entry
-   */
-  public ObjectName getObjectName() {
-    if (this.entryName == null) {
-      try {
-        this.entryName = new ObjectName(
-        SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
-        "type=DsTableEntry,name=" +
-        SNMPConnectionHandlerDefinitions.MONITOR_SYSTEM_INFORMATION_OBJECTNAME);
-      } catch (Exception ex) {
-        if (DebugLogger.debugEnabled()) {
-          TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+                    "workingDirectory");
+        } catch (Exception ex) {
+            if (DebugLogger.debugEnabled()) {
+                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+            }
         }
-      }
+        return result;
     }
-    return this.entryName;
-  }
+
+    /**
+     * Gets the object of the entry.
+     * @return ObjectName of the entry
+     */
+    public ObjectName getObjectName() {
+        if (this.entryName == null) {
+            try {
+                this.entryName = new ObjectName(
+                        SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
+                        "type=DsTableEntry,name=" +
+        SNMPConnectionHandlerDefinitions.MONITOR_SYSTEM_INFORMATION_OBJECTNAME);
+            } catch (Exception ex) {
+                if (DebugLogger.debugEnabled()) {
+                    TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+                }
+            }
+        }
+        return this.entryName;
+    }
 }
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 9a49aeb..c70e5d0 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
@@ -39,7 +39,6 @@
 import com.sun.management.snmp.SnmpEngineParameters;
 import com.sun.management.snmp.UserAcl;
 
-import java.net.InetAddress;
 import java.util.Iterator;
 import java.util.Set;
 import javax.management.MBeanServer;
@@ -363,7 +362,7 @@
                     (InetAddressAcl) new SNMPInetAddressAcl(configuration);
 
             adaptor = new SnmpV3AdaptorServer(engineParameters, null, acls,
-                    configuration.getListenPort(), InetAddress.getLocalHost());
+                    configuration.getListenPort(), null);
 
             // Enable the community to context translation for V1/V2 to V3
             adaptor.enableCommunityStringAtContext();
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 36625ca..2714626 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
@@ -31,7 +31,6 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -189,8 +188,7 @@
      */
     @Override()
     public Collection<HostPort> getListeners() {
-        // There are no listeners for this connection handler.
-        return Collections.<HostPort>emptySet();
+        return this.listeners;
     }
 
     /**
@@ -199,7 +197,7 @@
     @Override()
     public Collection<ClientConnection> getClientConnections() {
         // There are no client connections for this connection handler.
-        return Collections.<ClientConnection>emptySet();
+        return this.connectionList;
     }
 
     /**
@@ -264,7 +262,7 @@
     @SuppressWarnings("unchecked")
     private void addFile(File file) {
         try {
-            URL u = new URL("jar:file://"+ file.toString()+"!/");
+            URL u = new URL("jar:file:/"+ file.toString()+"!/");
             Class[] parameters = new Class[]{URL.class};
             URLClassLoader sysloader =
               (URLClassLoader)ClassLoader.getSystemClassLoader();
diff --git a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java
index b0c47de..085df2c 100644
--- a/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java
+++ b/opendj-sdk/opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java
@@ -271,6 +271,21 @@
       });
   }
 
+ /**
+   * Wrapper for SNMP Byte[].
+   * @param s value string
+   * @return a Byte[]
+   */
+  public static Byte[] string2ByteArray(String s) {
+    byte[] b = s.getBytes();
+    Byte[] barray = new Byte[b.length];
+    for (int index=0; index<b.length; index++) {
+        barray[index] = new Byte(b[index]);
+    }
+    return barray;
+  }
+
+
   /**
    * Wrapper for SNMP Counter32.
    * @param v value

--
Gitblit v1.10.0