static {
   DEFAULT_FLAGS =
       NTLMSSP_NEGOTIATE_NTLM
           | (Config.getBoolean("jcifs.smb.client.useUnicode", true)
               ? NTLMSSP_NEGOTIATE_UNICODE
               : NTLMSSP_NEGOTIATE_OEM);
   DEFAULT_DOMAIN = Config.getProperty("jcifs.smb.client.domain", null);
   byte[] domain = new byte[0];
   if (DEFAULT_DOMAIN != null) {
     try {
       domain = DEFAULT_DOMAIN.getBytes(UNI_ENCODING);
     } catch (IOException ex) {
     }
   }
   int domainLength = domain.length;
   byte[] server = new byte[0];
   try {
     String host = NbtAddress.getLocalHost().getHostName();
     if (host != null) {
       try {
         server = host.getBytes(UNI_ENCODING);
       } catch (IOException ex) {
       }
     }
   } catch (UnknownHostException ex) {
   }
   int serverLength = server.length;
   byte[] targetInfo =
       new byte
           [(domainLength > 0 ? domainLength + 4 : 0)
               + (serverLength > 0 ? serverLength + 4 : 0)
               + 4];
   int offset = 0;
   if (domainLength > 0) {
     writeUShort(targetInfo, offset, 2);
     offset += 2;
     writeUShort(targetInfo, offset, domainLength);
     offset += 2;
     System.arraycopy(domain, 0, targetInfo, offset, domainLength);
     offset += domainLength;
   }
   if (serverLength > 0) {
     writeUShort(targetInfo, offset, 1);
     offset += 2;
     writeUShort(targetInfo, offset, serverLength);
     offset += 2;
     System.arraycopy(server, 0, targetInfo, offset, serverLength);
   }
   DEFAULT_TARGET_INFORMATION = targetInfo;
 }
 static {
   DEFAULT_FLAGS =
       NTLMSSP_NEGOTIATE_NTLM
           | (Config.getBoolean("jcifs.smb.client.useUnicode", true)
               ? NTLMSSP_NEGOTIATE_UNICODE
               : NTLMSSP_NEGOTIATE_OEM);
   DEFAULT_DOMAIN = Config.getProperty("jcifs.smb.client.domain", null);
   DEFAULT_USER = Config.getProperty("jcifs.smb.client.username", null);
   DEFAULT_PASSWORD = Config.getProperty("jcifs.smb.client.password", null);
   String defaultWorkstation = null;
   try {
     defaultWorkstation = NbtAddress.getLocalHost().getHostName();
   } catch (UnknownHostException ex) {
   }
   DEFAULT_WORKSTATION = defaultWorkstation;
   LM_COMPATIBILITY = Config.getInt("jcifs.smb.lmCompatibility", 0);
 }
Exemple #3
0
  @Override
  public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    NetworkInterface<InetAddress> iface = svc.getNetInterface();

    // Get interface address from NetworkInterface
    //
    if (iface.getType() != NetworkInterface.TYPE_INET)
      throw new NetworkInterfaceNotSupportedException(
          "Unsupported interface type, only TYPE_INET currently supported");

    /*
     * TODO: Use it or loose it.
     * Commented out because it is not currently used in this monitor
     */
    // get parameters
    // int retry = ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY);
    // int timeout = ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT);

    // Extract the address
    //
    InetAddress ipv4Addr = (InetAddress) iface.getAddress();

    // Default is a failed status
    //
    PollStatus serviceStatus = PollStatus.unavailable();

    // Attempt to retrieve NetBIOS name of this interface in order
    // to determine if SMB is supported.
    //
    NbtAddress nbtAddr = null;

    /*
     * This try block was updated to reflect the behavior of the plugin.
     */
    final String hostAddress = InetAddressUtils.str(ipv4Addr);

    final boolean doNodeStatus =
        ParameterMap.getKeyedBoolean(parameters, DO_NODE_STATUS, DO_NODE_STATUS_DEFAULT);

    try {
      nbtAddr = NbtAddress.getByName(hostAddress);

      if (doNodeStatus) {
        nbtAddr.getNodeType();
      }

      if (!nbtAddr.getHostName().equals(hostAddress)) serviceStatus = PollStatus.available();

    } catch (UnknownHostException uhE) {
      serviceStatus =
          logDown(
              Level.DEBUG,
              "Unknown host exception generated for "
                  + hostAddress
                  + ", reason: "
                  + uhE.getLocalizedMessage());
    } catch (RuntimeException rE) {
      serviceStatus = logDown(Level.ERROR, "Unexpected runtime exception", rE);
    } catch (Throwable e) {
      serviceStatus = logDown(Level.DEBUG, "Unexpected exception", e);
    }

    //
    // return the status of the service
    //
    return serviceStatus;
  }