Example #1
0
  /**
   * Unpack a string from the byte area
   *
   * @param uni boolean
   * @return String
   */
  public final String unpackString(boolean uni) {

    // Check for Unicode or ASCII

    String ret = null;

    if (uni) {

      // Word align the current buffer position

      m_pos = DataPacker.wordAlign(m_pos);
      ret = DataPacker.getUnicodeString(m_smbbuf, m_pos, m_smbbuf.length - m_pos);
      if (ret != null) m_pos += (ret.length() * 2) + 2;
    } else {

      // Unpack the ASCII string

      ret = DataPacker.getString(m_smbbuf, m_pos, m_smbbuf.length - m_pos);
      if (ret != null) m_pos += ret.length() + 1;
    }

    // Return the string

    return ret;
  }
Example #2
0
  /**
   * Process a special IPC$ file open request.
   *
   * @param sess SMBSrvSession
   * @param smbPkt SMBSrvPacket
   * @exception IOException
   * @exception SMBSrvException
   */
  protected static void procIPCFileOpen(SMBSrvSession sess, SMBSrvPacket smbPkt)
      throws IOException, SMBSrvException {

    // Get the data bytes position and length

    int dataPos = smbPkt.getByteOffset();
    int dataLen = smbPkt.getByteCount();
    byte[] buf = smbPkt.getBuffer();

    // Extract the filename string

    String fileName = DataPacker.getString(buf, dataPos, dataLen);

    // Debug

    if (Debug.EnableInfo && sess.hasDebug(SMBSrvSession.DBG_IPC))
      sess.debugPrintln("IPC$ Open file = " + fileName);

    // Check if the requested IPC$ file is valid

    int pipeType = DCEPipeType.getNameAsType(fileName);
    if (pipeType == -1) {
      sess.sendErrorResponseSMB(smbPkt, SMBStatus.DOSFileNotFound, SMBStatus.ErrDos);
      return;
    }

    // Get the tree connection details

    TreeConnection conn = sess.findTreeConnection(smbPkt);

    if (conn == null) {
      sess.sendErrorResponseSMB(smbPkt, SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv);
      return;
    }

    // Create a network file for the special pipe

    DCEPipeFile pipeFile = new DCEPipeFile(pipeType);
    pipeFile.setGrantedAccess(NetworkFile.READWRITE);

    // Add the file to the list of open files for this tree connection

    int fid = -1;

    try {
      fid = conn.addFile(pipeFile, sess);
    } catch (TooManyFilesException ex) {

      // Too many files are open on this connection, cannot open any more files.

      sess.sendErrorResponseSMB(smbPkt, SMBStatus.DOSTooManyOpenFiles, SMBStatus.ErrDos);
      return;
    }

    // Build the open file response

    smbPkt.setParameterCount(15);

    smbPkt.setAndXCommand(0xFF);
    smbPkt.setParameter(1, 0); // AndX offset

    smbPkt.setParameter(2, fid);
    smbPkt.setParameter(3, 0); // file attributes
    smbPkt.setParameter(4, 0); // last write time
    smbPkt.setParameter(5, 0); // last write date
    smbPkt.setParameterLong(6, 0); // file size
    smbPkt.setParameter(8, 0);
    smbPkt.setParameter(9, 0);
    smbPkt.setParameter(10, 0); // named pipe state
    smbPkt.setParameter(11, 0);
    smbPkt.setParameter(12, 0); // server FID (long)
    smbPkt.setParameter(13, 0);
    smbPkt.setParameter(14, 0);

    smbPkt.setByteCount(0);

    // Send the response packet

    sess.sendResponseSMB(smbPkt);
  }