Ejemplo n.º 1
0
  /**
   * Process a set named pipe handle state request
   *
   * @param sess SMBSrvSession
   * @param vc VirtualCircuit
   * @param tbuf SrvTransactBuffer
   * @param smbPkt SMBSrvPacket
   */
  protected static void procSetNamedPipeHandleState(
      SMBSrvSession sess, VirtualCircuit vc, SrvTransactBuffer tbuf, SMBSrvPacket smbPkt)
      throws IOException, SMBSrvException {

    // Get the request parameters

    DataBuffer setupBuf = tbuf.getSetupBuffer();
    setupBuf.skipBytes(2);
    int fid = setupBuf.getShort();

    DataBuffer paramBuf = tbuf.getParameterBuffer();
    int state = paramBuf.getShort();

    // Get the connection for the request

    TreeConnection conn = vc.findConnection(tbuf.getTreeId());

    // Get the IPC pipe file for the specified file id

    DCEPipeFile netFile = (DCEPipeFile) conn.findFile(fid);
    if (netFile == null) {
      sess.sendErrorResponseSMB(smbPkt, SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
      return;
    }

    // Debug

    if (Debug.EnableInfo && sess.hasDebug(SMBSrvSession.DBG_IPC))
      sess.debugPrintln(
          "  SetNmPHandState pipe="
              + netFile.getName()
              + ", fid="
              + fid
              + ", state=0x"
              + Integer.toHexString(state));

    // Store the named pipe state

    netFile.setPipeState(state);

    // Setup the response packet

    SMBSrvTransPacket.initTransactReply(smbPkt, 0, 0, 0, 0);

    // Send the response packet

    sess.sendResponseSMB(smbPkt);
  }
Ejemplo n.º 2
0
  /**
   * Process a transact2 query file information (via handle) request.
   *
   * @param sess SMBSrvSession
   * @param vc VirtualCircuit
   * @param tbuf Transaction request details
   * @param smbPkt SMBSrvPacket
   * @exception IOException
   * @exception SMBSrvException
   */
  protected static final void procTrans2QueryFile(
      SMBSrvSession sess, VirtualCircuit vc, SrvTransactBuffer tbuf, SMBSrvPacket smbPkt)
      throws IOException, SMBSrvException {

    // Get the tree connection details

    int treeId = tbuf.getTreeId();
    TreeConnection conn = vc.findConnection(treeId);

    if (conn == null) {
      sess.sendErrorResponseSMB(
          smbPkt, SMBStatus.NTInvalidParameter, SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
      return;
    }

    // Check if the user has the required access permission

    if (conn.hasReadAccess() == false) {

      // User does not have the required access rights

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

    // Get the file id and query path information level

    DataBuffer paramBuf = tbuf.getParameterBuffer();

    int fid = paramBuf.getShort();
    int infoLevl = paramBuf.getShort();

    // Get the file details via the file id

    NetworkFile netFile = conn.findFile(fid);

    if (netFile == null) {
      sess.sendErrorResponseSMB(smbPkt, SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
      return;
    }

    // Debug

    if (Debug.EnableInfo && sess.hasDebug(SMBSrvSession.DBG_IPC))
      sess.debugPrintln(
          "IPC$ Query File - level=0x"
              + Integer.toHexString(infoLevl)
              + ", fid="
              + fid
              + ", name="
              + netFile.getFullName());

    // Access the shared device disk interface

    try {

      // Set the return parameter count, so that the data area position can be calculated.

      smbPkt.setParameterCount(10);

      // Pack the file information into the data area of the transaction reply

      byte[] buf = smbPkt.getBuffer();
      int prmPos = DataPacker.longwordAlign(smbPkt.getByteOffset());
      int dataPos = prmPos + 4;

      // Pack the return parametes, EA error offset

      smbPkt.setPosition(prmPos);
      smbPkt.packWord(0);

      // Create a data buffer using the SMB packet. The response should always fit into a
      // single reply packet.

      DataBuffer replyBuf = new DataBuffer(buf, dataPos, buf.length - dataPos);

      // Build the file information from the network file details

      FileInfo fileInfo =
          new FileInfo(netFile.getName(), netFile.getFileSize(), netFile.getFileAttributes());

      fileInfo.setAccessDateTime(netFile.getAccessDate());
      fileInfo.setCreationDateTime(netFile.getCreationDate());
      fileInfo.setModifyDateTime(netFile.getModifyDate());
      fileInfo.setChangeDateTime(netFile.getModifyDate());

      fileInfo.setFileId(netFile.getFileId());

      // Set the file allocation size, looks like it is used as the pipe buffer size

      fileInfo.setAllocationSize(4096L);

      // Pack the file information into the return data packet

      int dataLen = QueryInfoPacker.packInfo(fileInfo, replyBuf, infoLevl, true);

      // Check if any data was packed, if not then the information level is not supported

      if (dataLen == 0) {
        sess.sendErrorResponseSMB(
            smbPkt, SMBStatus.NTInvalidParameter, SMBStatus.SRVNonSpecificError, SMBStatus.ErrSrv);
        return;
      }

      SMBSrvTransPacket.initTransactReply(smbPkt, 2, prmPos, dataLen, dataPos);
      smbPkt.setByteCount(replyBuf.getPosition() - smbPkt.getByteOffset());

      // Send the transact reply

      sess.sendResponseSMB(smbPkt);
    } catch (FileNotFoundException ex) {

      // Requested file does not exist

      sess.sendErrorResponseSMB(
          smbPkt, SMBStatus.NTObjectNotFound, SMBStatus.DOSFileNotFound, SMBStatus.ErrDos);
      return;
    } catch (PathNotFoundException ex) {

      // Requested path does not exist

      sess.sendErrorResponseSMB(
          smbPkt, SMBStatus.NTObjectPathNotFound, SMBStatus.DOSFileNotFound, SMBStatus.ErrDos);
      return;
    } catch (UnsupportedInfoLevelException ex) {

      // Requested information level is not supported

      sess.sendErrorResponseSMB(
          smbPkt, SMBStatus.NTInvalidParameter, SMBStatus.SRVNonSpecificError, SMBStatus.ErrSrv);
      return;
    } catch (DiskOfflineException ex) {

      // Filesystem is offline

      sess.sendErrorResponseSMB(
          smbPkt, SMBStatus.NTObjectPathNotFound, SMBStatus.HRDDriveNotReady, SMBStatus.ErrHrd);
    }
  }