1 17 package org.alfresco.filesys.smb.server; 18 19 import java.io.FileNotFoundException ; 20 import java.io.IOException ; 21 22 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 23 import org.alfresco.filesys.server.auth.ClientInfo; 24 import org.alfresco.filesys.server.auth.InvalidUserException; 25 import org.alfresco.filesys.server.auth.SrvAuthenticator; 26 import org.alfresco.filesys.server.core.InvalidDeviceInterfaceException; 27 import org.alfresco.filesys.server.core.ShareType; 28 import org.alfresco.filesys.server.core.SharedDevice; 29 import org.alfresco.filesys.server.filesys.AccessDeniedException; 30 import org.alfresco.filesys.server.filesys.DiskDeviceContext; 31 import org.alfresco.filesys.server.filesys.DiskInterface; 32 import org.alfresco.filesys.server.filesys.FileAccess; 33 import org.alfresco.filesys.server.filesys.FileAction; 34 import org.alfresco.filesys.server.filesys.FileInfo; 35 import org.alfresco.filesys.server.filesys.FileOfflineException; 36 import org.alfresco.filesys.server.filesys.FileOpenParams; 37 import org.alfresco.filesys.server.filesys.FileSharingException; 38 import org.alfresco.filesys.server.filesys.FileStatus; 39 import org.alfresco.filesys.server.filesys.NetworkFile; 40 import org.alfresco.filesys.server.filesys.SearchContext; 41 import org.alfresco.filesys.server.filesys.SrvDiskInfo; 42 import org.alfresco.filesys.server.filesys.TooManyConnectionsException; 43 import org.alfresco.filesys.server.filesys.TooManyFilesException; 44 import org.alfresco.filesys.server.filesys.TreeConnection; 45 import org.alfresco.filesys.server.filesys.UnsupportedInfoLevelException; 46 import org.alfresco.filesys.server.filesys.VolumeInfo; 47 import org.alfresco.filesys.smb.DataType; 48 import org.alfresco.filesys.smb.FindFirstNext; 49 import org.alfresco.filesys.smb.InvalidUNCPathException; 50 import org.alfresco.filesys.smb.PCShare; 51 import org.alfresco.filesys.smb.PacketType; 52 import org.alfresco.filesys.smb.SMBDate; 53 import org.alfresco.filesys.smb.SMBStatus; 54 import org.alfresco.filesys.util.DataBuffer; 55 import org.alfresco.filesys.util.DataPacker; 56 import org.apache.commons.logging.Log; 57 import org.apache.commons.logging.LogFactory; 58 59 65 class LanManProtocolHandler extends CoreProtocolHandler 66 { 67 68 70 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 71 72 74 protected static final int LockShared = 0x01; 75 protected static final int LockOplockRelease = 0x02; 76 protected static final int LockChangeType = 0x04; 77 protected static final int LockCancel = 0x08; 78 protected static final int LockLargeFiles = 0x10; 79 80 83 protected LanManProtocolHandler() 84 { 85 super(); 86 } 87 88 93 protected LanManProtocolHandler(SMBSrvSession sess) 94 { 95 super(sess); 96 } 97 98 103 public String getName() 104 { 105 return "LanMan"; 106 } 107 108 114 protected final int procAndXCommands(SMBSrvPacket outPkt) 115 { 116 117 119 int andxCmd = m_smbPkt.getAndXCommand(); 120 int andxOff = m_smbPkt.getParameter(1) + RFCNetBIOSProtocol.HEADER_LEN; 121 122 124 outPkt.setAndXCommand(andxCmd); 125 outPkt.setParameter(1, andxOff - RFCNetBIOSProtocol.HEADER_LEN); 126 127 129 int paramBlk = SMBSrvPacket.WORDCNT; 130 131 133 int endOfPkt = outPkt.getByteOffset() + outPkt.getByteCount(); 134 boolean andxErr = false; 135 136 while (andxCmd != SMBSrvPacket.NO_ANDX_CMD && andxErr == false) 137 { 138 139 141 int prevEndOfPkt = endOfPkt; 142 143 switch (andxCmd) 144 { 145 146 148 case PacketType.TreeConnectAndX: 149 endOfPkt = procChainedTreeConnectAndX(andxOff, outPkt, endOfPkt); 150 break; 151 } 152 153 155 andxCmd = m_smbPkt.getAndXParameter(andxOff, 0) & 0x00FF; 156 andxOff = m_smbPkt.getAndXParameter(andxOff, 1); 157 158 160 outPkt.setAndXCommand(prevEndOfPkt, andxCmd); 161 outPkt.setAndXParameter(paramBlk, 1, prevEndOfPkt - RFCNetBIOSProtocol.HEADER_LEN); 162 163 165 paramBlk = prevEndOfPkt; 166 167 169 if (outPkt.getErrorCode() != SMBStatus.Success) 170 andxErr = true; 171 } 172 173 175 return endOfPkt; 176 } 177 178 186 protected final int procChainedTreeConnectAndX(int cmdOff, SMBSrvPacket outPkt, int endOff) 187 { 188 189 191 int flags = m_smbPkt.getAndXParameter(cmdOff, 2); 192 int pwdLen = m_smbPkt.getAndXParameter(cmdOff, 3); 193 194 196 int dataPos = m_smbPkt.getAndXByteOffset(cmdOff); 197 int dataLen = m_smbPkt.getAndXByteCount(cmdOff); 198 byte[] buf = m_smbPkt.getBuffer(); 199 200 202 String pwd = null; 203 204 if (pwdLen > 0) 205 { 206 pwd = new String (buf, dataPos, pwdLen); 207 dataPos += pwdLen; 208 dataLen -= pwdLen; 209 } 210 211 213 String uncPath = DataPacker.getString(buf, dataPos, dataLen); 214 if (uncPath == null) 215 { 216 outPkt.setError(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 217 return endOff; 218 } 219 220 222 dataPos += uncPath.length() + 1; dataLen -= uncPath.length() + 1; 225 String service = DataPacker.getString(buf, dataPos, dataLen); 226 if (service == null) 227 { 228 outPkt.setError(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 229 return endOff; 230 } 231 232 235 int servType = ShareType.ServiceAsType(service); 236 if (servType == ShareType.UNKNOWN && service.compareTo("?????") != 0) 237 { 238 outPkt.setError(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 239 return endOff; 240 } 241 242 244 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TREE)) 245 logger.debug("ANDX Tree Connect AndX - " + uncPath + ", " + service); 246 247 249 PCShare share = null; 250 251 try 252 { 253 share = new PCShare(uncPath); 254 } 255 catch (org.alfresco.filesys.smb.InvalidUNCPathException ex) 256 { 257 outPkt.setError(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 258 return endOff; 259 } 260 261 263 if (servType == ShareType.NAMEDPIPE && share.getShareName().compareTo("IPC$") == 0) 264 servType = ShareType.ADMINPIPE; 265 266 268 SharedDevice shareDev = null; 269 270 try 271 { 272 273 275 shareDev = m_sess.getSMBServer().findShare(share.getNodeName(), share.getShareName(), servType, 276 getSession(), true); 277 } 278 catch (InvalidUserException ex) 279 { 280 281 283 outPkt.setError(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 284 return endOff; 285 } 286 catch (Exception ex) 287 { 288 289 291 outPkt.setError(SMBStatus.SRVInvalidNetworkName, SMBStatus.ErrSrv); 292 return endOff; 293 } 294 295 297 if (shareDev == null || (servType != ShareType.UNKNOWN && shareDev.getType() != servType)) 298 { 299 outPkt.setError(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos); 300 return endOff; 301 } 302 303 305 SrvAuthenticator auth = getSession().getSMBServer().getAuthenticator(); 306 int filePerm = FileAccess.Writeable; 307 308 if (auth != null && auth.getAccessMode() == SrvAuthenticator.SHARE_MODE) 309 { 310 311 313 filePerm = auth.authenticateShareConnect(m_sess.getClientInformation(), shareDev, pwd, m_sess); 314 if (filePerm < 0) 315 { 316 317 319 outPkt.setError(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 320 return endOff; 321 } 322 } 323 324 326 try 327 { 328 329 331 int treeId = m_sess.addConnection(shareDev); 332 outPkt.setTreeId(treeId); 333 334 336 TreeConnection tree = m_sess.findConnection(treeId); 337 tree.setPermission(filePerm); 338 339 341 if (tree.getInterface() != null) 342 tree.getInterface().treeOpened(m_sess, tree); 343 344 346 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TREE)) 347 logger.debug("ANDX Tree Connect AndX - Allocated Tree Id = " + treeId); 348 } 349 catch (TooManyConnectionsException ex) 350 { 351 352 354 outPkt.setError(SMBStatus.SRVNoResourcesAvailable, SMBStatus.ErrSrv); 355 return endOff; 356 } 357 358 360 outPkt.setAndXParameterCount(endOff, 2); 361 outPkt.setAndXParameter(endOff, 0, SMBSrvPacket.NO_ANDX_CMD); 362 outPkt.setAndXParameter(endOff, 1, 0); 363 364 366 int pos = outPkt.getAndXByteOffset(endOff); 367 byte[] outBuf = outPkt.getBuffer(); 368 pos = DataPacker.putString(ShareType.TypeAsService(shareDev.getType()), outBuf, pos, true); 369 int bytLen = pos - outPkt.getAndXByteOffset(endOff); 370 outPkt.setAndXByteCount(endOff, bytLen); 371 372 374 return pos; 375 } 376 377 384 protected final void procFindClose(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 385 { 386 387 389 if (m_smbPkt.checkPacketIsValid(1, 0) == false) 390 { 391 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 392 return; 393 } 394 395 397 int treeId = m_smbPkt.getTreeId(); 398 TreeConnection conn = m_sess.findConnection(treeId); 399 400 if (conn == null) 401 { 402 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 403 return; 404 } 405 406 408 if (conn.hasReadAccess() == false) 409 { 410 411 413 m_sess.sendErrorResponseSMB(SMBStatus.NTAccessDenied, SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 414 return; 415 } 416 417 419 int searchId = m_smbPkt.getParameter(0); 420 421 423 SearchContext ctx = m_sess.getSearchContext(searchId); 424 425 if (ctx == null) 426 { 427 428 430 m_sess.sendSuccessResponseSMB(); 431 return; 432 } 433 434 436 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 437 logger.debug("Close trans search [" + searchId + "]"); 438 439 441 m_sess.deallocateSearchSlot(searchId); 442 443 445 m_sess.sendSuccessResponseSMB(); 446 } 447 448 453 protected final void procLockingAndX(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 454 { 455 456 458 if (m_smbPkt.checkPacketIsValid(8, 0) == false) 459 { 460 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 461 return; 462 } 463 464 466 int treeId = m_smbPkt.getTreeId(); 467 TreeConnection conn = m_sess.findConnection(treeId); 468 469 if (conn == null) 470 { 471 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 472 return; 473 } 474 475 477 if (conn.hasReadAccess() == false) 478 { 479 480 482 m_sess.sendErrorResponseSMB(SMBStatus.NTAccessDenied, SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 483 return; 484 } 485 486 488 int fid = m_smbPkt.getParameter(2); 489 int lockType = m_smbPkt.getParameter(3); 490 long lockTmo = m_smbPkt.getParameterLong(4); 491 int lockCnt = m_smbPkt.getParameter(6); 492 int unlockCnt = m_smbPkt.getParameter(7); 493 494 NetworkFile netFile = conn.findFile(fid); 495 496 if (netFile == null) 497 { 498 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos); 499 return; 500 } 501 502 504 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_LOCK)) 505 logger.debug("File Lock [" + netFile.getFileId() + "] : type=0x" + Integer.toHexString(lockType) + ", tmo=" 506 + lockTmo + ", locks=" + lockCnt + ", unlocks=" + unlockCnt); 507 508 510 outPkt.setParameterCount(2); 511 outPkt.setAndXCommand(0xFF); 512 outPkt.setParameter(1, 0); 513 outPkt.setByteCount(0); 514 515 517 m_sess.sendResponseSMB(outPkt); 518 } 519 520 525 protected final void procLogoffAndX(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 526 { 527 528 530 if (m_smbPkt.checkPacketIsValid(15, 1) == false) 531 { 532 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 533 return; 534 } 535 536 538 m_sess.sendSuccessResponseSMB(); 539 } 540 541 546 protected final void procOpenAndX(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 547 { 548 549 551 if (m_smbPkt.checkPacketIsValid(15, 1) == false) 552 { 553 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 554 return; 555 } 556 557 559 int treeId = m_smbPkt.getTreeId(); 560 TreeConnection conn = m_sess.findConnection(treeId); 561 562 if (conn == null) 563 { 564 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 565 return; 566 } 567 568 570 if (conn.hasReadAccess() == false) 571 { 572 573 575 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 576 return; 577 } 578 579 583 if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 584 { 585 586 588 IPCHandler.processIPCRequest(m_sess, outPkt); 589 return; 590 } 591 else if (conn.getSharedDevice().getType() != ShareType.DISK) 592 { 593 594 596 m_sess.sendErrorResponseSMB(SMBStatus.SRVNoAccessRights, SMBStatus.ErrSrv); 599 return; 600 } 601 602 604 int flags = m_smbPkt.getParameter(2); 605 int access = m_smbPkt.getParameter(3); 606 int srchAttr = m_smbPkt.getParameter(4); 607 int fileAttr = m_smbPkt.getParameter(5); 608 int crTime = m_smbPkt.getParameter(6); 609 int crDate = m_smbPkt.getParameter(7); 610 int openFunc = m_smbPkt.getParameter(8); 611 int allocSiz = m_smbPkt.getParameterLong(9); 612 613 615 String fileName = m_smbPkt.unpackString(m_smbPkt.isUnicode()); 616 if (fileName == null) 617 { 618 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 619 return; 620 } 621 622 624 SMBDate crDateTime = null; 625 if (crTime > 0 && crDate > 0) 626 crDateTime = new SMBDate(crDate, crTime); 627 628 FileOpenParams params = new FileOpenParams(fileName, openFunc, access, srchAttr, fileAttr, allocSiz, crDateTime 629 .getTime()); 630 631 633 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_FILE)) 634 logger.debug("File Open AndX [" + treeId + "] params=" + params); 635 636 638 int fid; 639 NetworkFile netFile = null; 640 int respAction = 0; 641 642 try 643 { 644 645 647 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 648 649 651 int fileSts = disk.fileExists(m_sess, conn, fileName); 652 653 if (fileSts == FileStatus.NotExist) 654 { 655 656 658 if (FileAction.createNotExists(openFunc)) 659 { 660 661 663 if (conn.hasWriteAccess() == false) 664 { 665 666 668 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 669 return; 670 } 671 672 674 netFile = disk.createFile(m_sess, conn, params); 675 676 678 respAction = FileAction.FileCreated; 679 } 680 else 681 { 682 683 685 if (fileSts == FileStatus.DirectoryExists) 686 { 687 688 690 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 691 } 692 else 693 { 694 695 697 m_sess.sendErrorResponseSMB(SMBStatus.DOSFileNotFound, SMBStatus.ErrDos); 698 } 699 return; 700 } 701 } 702 else 703 { 704 705 707 netFile = disk.openFile(m_sess, conn, params); 708 709 711 if (FileAction.truncateExistingFile(openFunc)) 712 respAction = FileAction.FileTruncated; 713 else 714 respAction = FileAction.FileExisted; 715 } 716 717 719 fid = conn.addFile(netFile, getSession()); 720 721 } 722 catch (InvalidDeviceInterfaceException ex) 723 { 724 725 727 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 728 return; 729 } 730 catch (TooManyFilesException ex) 731 { 732 733 735 m_sess.sendErrorResponseSMB(SMBStatus.DOSTooManyOpenFiles, SMBStatus.ErrDos); 736 return; 737 } 738 catch (AccessDeniedException ex) 739 { 740 741 743 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 744 return; 745 } 746 catch (FileSharingException ex) 747 { 748 749 751 m_sess.sendErrorResponseSMB(SMBStatus.DOSFileSharingConflict, SMBStatus.ErrDos); 752 return; 753 } 754 catch (FileOfflineException ex) 755 { 756 757 759 m_sess.sendErrorResponseSMB(SMBStatus.NTFileOffline, SMBStatus.HRDDriveNotReady, SMBStatus.ErrHrd); 760 return; 761 } 762 catch (java.io.IOException ex) 763 { 764 765 767 m_sess.sendErrorResponseSMB(SMBStatus.DOSFileNotFound, SMBStatus.ErrDos); 768 return; 769 } 770 771 773 outPkt.setParameterCount(15); 774 775 outPkt.setAndXCommand(0xFF); 776 outPkt.setParameter(1, 0); 778 outPkt.setParameter(2, fid); 779 outPkt.setParameter(3, netFile.getFileAttributes()); 781 SMBDate modDate = null; 782 783 if (netFile.hasModifyDate()) 784 modDate = new SMBDate(netFile.getModifyDate()); 785 786 outPkt.setParameter(4, modDate != null ? modDate.asSMBTime() : 0); outPkt.setParameter(5, modDate != null ? modDate.asSMBDate() : 0); outPkt.setParameterLong(6, netFile.getFileSizeInt()); outPkt.setParameter(8, netFile.getGrantedAccess()); 790 outPkt.setParameter(9, OpenAndX.FileTypeDisk); 791 outPkt.setParameter(10, 0); outPkt.setParameter(11, respAction); 793 outPkt.setParameter(12, 0); outPkt.setParameter(13, 0); 795 outPkt.setParameter(14, 0); 796 797 outPkt.setByteCount(0); 798 799 801 m_sess.sendResponseSMB(outPkt); 802 } 803 804 809 protected final void procReadAndX(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 810 { 811 812 814 if (m_smbPkt.checkPacketIsValid(10, 0) == false) 815 { 816 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 817 return; 818 } 819 820 822 int treeId = m_smbPkt.getTreeId(); 823 TreeConnection conn = m_sess.findConnection(treeId); 824 825 if (conn == null) 826 { 827 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 828 return; 829 } 830 831 833 if (conn.hasReadAccess() == false) 834 { 835 836 838 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 839 return; 840 } 841 842 845 if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 846 { 847 848 850 IPCHandler.processIPCRequest(m_sess, outPkt); 851 return; 852 } 853 854 856 int fid = m_smbPkt.getParameter(2); 857 int offset = m_smbPkt.getParameterLong(3); 858 int maxCount = m_smbPkt.getParameter(5); 859 860 NetworkFile netFile = conn.findFile(fid); 861 862 if (netFile == null) 863 { 864 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos); 865 return; 866 } 867 868 870 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_FILEIO)) 871 logger.debug("File Read AndX [" + netFile.getFileId() + "] : Size=" + maxCount + " ,Pos=" + offset); 872 873 875 byte[] buf = outPkt.getBuffer(); 876 int dataPos = 0; 877 int rdlen = 0; 878 879 try 880 { 881 882 884 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 885 886 888 outPkt.setParameterCount(12); 889 dataPos = outPkt.getByteOffset(); 890 892 894 int dataLen = buf.length - dataPos; 895 if (dataLen < maxCount) 896 maxCount = dataLen; 897 898 900 rdlen = disk.readFile(m_sess, conn, netFile, buf, dataPos, maxCount, offset); 901 } 902 catch (InvalidDeviceInterfaceException ex) 903 { 904 905 907 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 908 return; 909 } 910 catch (AccessDeniedException ex) 911 { 912 913 917 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_FILEIO)) 918 logger.debug("File Read Error [" + netFile.getFileId() + "] : " + ex.toString()); 919 920 922 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 923 return; 924 } 925 catch (java.io.IOException ex) 926 { 927 928 930 logger.error("File Read Error [" + netFile.getFileId() + "] : ", ex); 931 932 934 m_sess.sendErrorResponseSMB(SMBStatus.HRDReadFault, SMBStatus.ErrHrd); 935 return; 936 } 937 938 940 outPkt.setAndXCommand(0xFF); outPkt.setParameter(1, 0); 942 outPkt.setParameter(2, 0); outPkt.setParameter(3, 0); outPkt.setParameter(4, 0); outPkt.setParameter(5, rdlen); outPkt.setParameter(6, dataPos - RFCNetBIOSProtocol.HEADER_LEN); 947 949 951 for (int i = 7; i < 12; i++) 952 outPkt.setParameter(i, 0); 953 954 956 outPkt.setByteCount((dataPos + rdlen) - outPkt.getByteOffset()); 957 958 960 m_sess.sendResponseSMB(outPkt); 961 } 962 963 970 protected void procRenameFile(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 971 { 972 973 975 if (m_smbPkt.checkPacketIsValid(1, 4) == false) 976 { 977 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 978 return; 979 } 980 981 984 int treeId = m_smbPkt.getTreeId(); 985 TreeConnection conn = m_sess.findConnection(treeId); 986 987 if (conn == null) 988 { 989 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos); 990 return; 991 } 992 993 995 if (conn.hasWriteAccess() == false) 996 { 997 998 1000 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1001 return; 1002 } 1003 1004 1006 boolean isUni = m_smbPkt.isUnicode(); 1007 1008 1010 m_smbPkt.resetBytePointer(); 1011 1012 1014 if (m_smbPkt.unpackByte() != DataType.ASCII) 1015 { 1016 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1017 return; 1018 } 1019 1020 String oldName = m_smbPkt.unpackString(isUni); 1021 if (oldName == null) 1022 { 1023 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1024 return; 1025 } 1026 1027 1029 if (m_smbPkt.unpackByte() != DataType.ASCII) 1030 { 1031 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1032 return; 1033 } 1034 1035 String newName = m_smbPkt.unpackString(isUni); 1036 if (oldName == null) 1037 { 1038 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1039 return; 1040 } 1041 1042 1044 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_FILE)) 1045 logger.debug("File Rename [" + treeId + "] old name=" + oldName + ", new name=" + newName); 1046 1047 1049 int fid; 1050 NetworkFile netFile = null; 1051 1052 try 1053 { 1054 1055 1057 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 1058 1059 1061 disk.renameFile(m_sess, conn, oldName, newName); 1062 } 1063 catch (InvalidDeviceInterfaceException ex) 1064 { 1065 1066 1068 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1069 return; 1070 } 1071 catch (java.io.IOException ex) 1072 { 1073 1074 1076 m_sess.sendErrorResponseSMB(SMBStatus.DOSFileNotFound, SMBStatus.ErrDos); 1077 return; 1078 } 1079 1080 1082 outPkt.setParameterCount(0); 1083 outPkt.setByteCount(0); 1084 1085 1087 m_sess.sendResponseSMB(outPkt); 1088 } 1089 1090 1095 protected void procSessionSetup(SMBSrvPacket outPkt) throws SMBSrvException, IOException , 1096 TooManyConnectionsException 1097 { 1098 1099 1101 int dataPos = m_smbPkt.getByteOffset(); 1102 int dataLen = m_smbPkt.getByteCount(); 1103 byte[] buf = m_smbPkt.getBuffer(); 1104 1105 1107 int maxBufSize = m_smbPkt.getParameter(2); 1108 int maxMpx = m_smbPkt.getParameter(3); 1109 int vcNum = m_smbPkt.getParameter(4); 1110 1111 1113 byte[] pwd = null; 1114 int pwdLen = m_smbPkt.getParameter(7); 1115 1116 if (pwdLen > 0) 1117 { 1118 pwd = new byte[pwdLen]; 1119 for (int i = 0; i < pwdLen; i++) 1120 pwd[i] = buf[dataPos + i]; 1121 dataPos += pwdLen; 1122 dataLen -= pwdLen; 1123 } 1124 1125 1127 String user = DataPacker.getString(buf, dataPos, dataLen); 1128 if (user == null) 1129 { 1130 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1131 return; 1132 } 1133 else 1134 { 1135 1136 1138 dataLen -= user.length() + 1; 1139 dataPos += user.length() + 1; 1140 } 1141 1142 1144 String domain = ""; 1145 1146 if (dataLen > 0) 1147 { 1148 1149 1151 domain = DataPacker.getString(buf, dataPos, dataLen); 1152 if (domain == null) 1153 { 1154 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1155 return; 1156 } 1157 else 1158 { 1159 1160 1162 dataLen -= domain.length() + 1; 1163 dataPos += domain.length() + 1; 1164 } 1165 } 1166 1167 1169 String clientOS = ""; 1170 1171 if (dataLen > 0) 1172 { 1173 1174 1176 clientOS = DataPacker.getString(buf, dataPos, dataLen); 1177 if (clientOS == null) 1178 { 1179 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1180 return; 1181 } 1182 } 1183 1184 1186 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_NEGOTIATE)) 1187 logger.debug("Session setup from user=" + user + ", password=" + pwd + ", domain=" + domain + ", os=" 1188 + clientOS + ", VC=" + vcNum + ", maxBuf=" + maxBufSize + ", maxMpx=" + maxMpx); 1189 1190 1192 m_sess.setClientMaximumBufferSize(maxBufSize); 1193 m_sess.setClientMaximumMultiplex(maxMpx); 1194 1195 1197 ClientInfo client = new ClientInfo(user, pwd); 1198 client.setDomain(domain); 1199 client.setOperatingSystem(clientOS); 1200 if (m_sess.hasRemoteAddress()) 1201 client.setClientAddress(m_sess.getRemoteAddress().getHostAddress()); 1202 1203 if (m_sess.getClientInformation() == null) 1204 { 1205 1206 1208 m_sess.setClientInformation(client); 1209 } 1210 else 1211 { 1212 1213 1215 ClientInfo curClient = m_sess.getClientInformation(); 1216 1217 if (curClient.getUserName() == null || curClient.getUserName().length() == 0) 1218 { 1219 1220 1222 m_sess.setClientInformation(client); 1223 } 1224 else 1225 { 1226 1227 1229 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_NEGOTIATE)) 1230 logger.debug("Session already has client information set"); 1231 } 1232 } 1233 1234 1236 SrvAuthenticator auth = getSession().getSMBServer().getAuthenticator(); 1237 boolean isGuest = false; 1238 1239 if (auth != null && auth.getAccessMode() == SrvAuthenticator.USER_MODE) 1240 { 1241 1242 1244 int sts = auth.authenticateUser(client, m_sess, SrvAuthenticator.LANMAN); 1245 if (sts > 0 && (sts & SrvAuthenticator.AUTH_GUEST) != 0) 1246 isGuest = true; 1247 else if (sts != SrvAuthenticator.AUTH_ALLOW) 1248 { 1249 1250 1252 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1253 return; 1254 } 1255 } 1256 1257 1259 client.setGuest(isGuest); 1260 getSession().setLoggedOn(true); 1261 1262 1264 outPkt.setParameterCount(3); 1265 outPkt.setParameter(0, 0); outPkt.setParameter(1, 0); outPkt.setParameter(2, isGuest ? 1 : 0); 1268 outPkt.setByteCount(0); 1269 1270 outPkt.setTreeId(0); 1271 outPkt.setUserId(0); 1272 1273 1275 int flags = outPkt.getFlags(); 1277 flags &= ~SMBSrvPacket.FLG_CASELESS; 1278 outPkt.setFlags(flags); 1279 outPkt.setFlags2(SMBSrvPacket.FLG2_LONGFILENAMES); 1280 1281 1283 int pos = outPkt.getByteOffset(); 1284 buf = outPkt.getBuffer(); 1285 1286 pos = DataPacker.putString("Java", buf, pos, true); 1287 pos = DataPacker.putString("JLAN Server " + m_sess.getServer().isVersion(), buf, pos, true); 1288 pos = DataPacker.putString(m_sess.getServer().getConfiguration().getDomainName(), buf, pos, true); 1289 1290 outPkt.setByteCount(pos - outPkt.getByteOffset()); 1291 1292 1294 if (m_smbPkt.hasAndXCommand() && dataPos < m_smbPkt.getReceivedLength()) 1295 { 1296 1297 1299 pos = procAndXCommands(outPkt); 1300 } 1301 else 1302 { 1303 1304 1306 outPkt.setAndXCommand(SMBSrvPacket.NO_ANDX_CMD); 1307 } 1308 1309 1311 m_sess.sendResponseSMB(outPkt, pos); 1312 1313 1315 m_sess.setState(SMBSrvSessionState.SMBSESSION); 1316 1317 1319 m_sess.getSMBServer().sessionLoggedOn(m_sess); 1320 } 1321 1322 1328 protected void procTransact2(SMBSrvPacket outPkt) throws IOException , SMBSrvException 1329 { 1330 1331 1333 if (m_smbPkt.checkPacketIsValid(15, 0) == false) 1334 { 1335 1336 1338 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 1339 return; 1340 } 1341 1342 1345 int treeId = m_smbPkt.getTreeId(); 1346 TreeConnection conn = m_sess.findConnection(treeId); 1347 1348 if (conn == null) 1349 { 1350 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 1351 return; 1352 } 1353 1354 1356 if (conn.hasReadAccess() == false) 1357 { 1358 1359 1361 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1362 return; 1363 } 1364 1365 1367 SMBSrvTransPacket tranPkt = new SMBSrvTransPacket(m_smbPkt.getBuffer()); 1368 1369 1371 SrvTransactBuffer transBuf = null; 1372 int subCmd = tranPkt.getSubFunction(); 1373 1374 if (tranPkt.getTotalParameterCount() == tranPkt.getParameterBlockCount() 1375 && tranPkt.getTotalDataCount() == tranPkt.getDataBlockCount()) 1376 { 1377 1378 1382 transBuf = new SrvTransactBuffer(tranPkt); 1383 } 1384 else 1385 { 1386 1387 1389 transBuf = new SrvTransactBuffer(tranPkt.getSetupCount(), tranPkt.getTotalParameterCount(), tranPkt 1390 .getTotalDataCount()); 1391 transBuf.setType(tranPkt.getCommand()); 1392 transBuf.setFunction(subCmd); 1393 1394 1396 byte[] buf = tranPkt.getBuffer(); 1397 1398 transBuf.appendSetup(buf, tranPkt.getSetupOffset(), tranPkt.getSetupCount() * 2); 1399 transBuf.appendParameter(buf, tranPkt.getParameterBlockOffset(), tranPkt.getParameterBlockCount()); 1400 transBuf.appendData(buf, tranPkt.getDataBlockOffset(), tranPkt.getDataBlockCount()); 1401 } 1402 1403 1405 transBuf.setReturnLimits(tranPkt.getMaximumReturnSetupCount(), tranPkt.getMaximumReturnParameterCount(), 1406 tranPkt.getMaximumReturnDataCount()); 1407 1408 1412 if (transBuf.isMultiPacket()) 1413 { 1414 1415 1417 m_sess.setTransaction(transBuf); 1418 1419 1421 m_sess.sendSuccessResponseSMB(); 1422 return; 1423 } 1424 1425 1428 if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 1429 { 1430 IPCHandler.procTransaction(transBuf, m_sess, outPkt); 1431 return; 1432 } 1433 1434 1436 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TRAN)) 1437 logger.debug("Transaction [" + treeId + "] tbuf=" + transBuf); 1438 1439 1441 processTransactionBuffer(transBuf, outPkt); 1442 } 1443 1444 1450 protected void procTransact2Secondary(SMBSrvPacket outPkt) throws IOException , SMBSrvException 1451 { 1452 1453 1455 if (m_smbPkt.checkPacketIsValid(8, 0) == false) 1456 { 1457 1458 1460 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 1461 return; 1462 } 1463 1464 1467 int treeId = m_smbPkt.getTreeId(); 1468 TreeConnection conn = m_sess.findConnection(treeId); 1469 1470 if (conn == null) 1471 { 1472 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 1473 return; 1474 } 1475 1476 1478 if (conn.hasReadAccess() == false) 1479 { 1480 1481 1483 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1484 return; 1485 } 1486 1487 1489 if (m_sess.hasTransaction() == false 1490 || (m_sess.getTransaction().isType() == PacketType.Transaction && m_smbPkt.getCommand() != PacketType.TransactionSecond) 1491 || (m_sess.getTransaction().isType() == PacketType.Transaction2 && m_smbPkt.getCommand() != PacketType.Transaction2Second)) 1492 { 1493 1494 1497 m_sess.sendErrorResponseSMB(SMBStatus.SRVNonSpecificError, SMBStatus.ErrSrv); 1498 return; 1499 } 1500 1501 1503 SMBSrvTransPacket tpkt = new SMBSrvTransPacket(m_smbPkt.getBuffer()); 1504 byte[] buf = tpkt.getBuffer(); 1505 SrvTransactBuffer transBuf = m_sess.getTransaction(); 1506 1507 1509 int plen = tpkt.getSecondaryParameterBlockCount(); 1510 if (plen > 0) 1511 { 1512 1513 1515 DataBuffer paramBuf = transBuf.getParameterBuffer(); 1516 paramBuf.appendData(buf, tpkt.getSecondaryParameterBlockOffset(), plen); 1517 } 1518 1519 1521 int dlen = tpkt.getSecondaryDataBlockCount(); 1522 if (dlen > 0) 1523 { 1524 1525 1527 DataBuffer dataBuf = transBuf.getDataBuffer(); 1528 dataBuf.appendData(buf, tpkt.getSecondaryDataBlockOffset(), dlen); 1529 } 1530 1531 1533 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TRAN)) 1534 logger.debug("Transaction Secondary [" + treeId + "] paramLen=" + plen + ", dataLen=" + dlen); 1535 1536 1538 int totParam = tpkt.getTotalParameterCount(); 1539 int totData = tpkt.getTotalDataCount(); 1540 1541 int paramDisp = tpkt.getParameterBlockDisplacement(); 1542 int dataDisp = tpkt.getDataBlockDisplacement(); 1543 1544 if ((paramDisp + plen) == totParam && (dataDisp + dlen) == totData) 1545 { 1546 1547 1549 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TRAN)) 1550 logger.debug("Transaction complete, processing ..."); 1551 1552 1554 m_sess.setTransaction(null); 1555 1556 1559 if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 1560 { 1561 IPCHandler.procTransaction(transBuf, m_sess, outPkt); 1562 return; 1563 } 1564 1565 1567 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TRAN)) 1568 logger.debug("Transaction second [" + treeId + "] tbuf=" + transBuf); 1569 1570 1572 processTransactionBuffer(transBuf, outPkt); 1573 } 1574 else 1575 { 1576 1577 1580 m_sess.sendSuccessResponseSMB(); 1581 } 1582 } 1583 1584 1592 private final void processTransactionBuffer(SrvTransactBuffer tbuf, SMBSrvPacket outPkt) throws IOException , 1593 SMBSrvException 1594 { 1595 1596 1598 switch (tbuf.getFunction()) 1599 { 1600 1601 1603 case PacketType.Trans2FindFirst: 1604 procTrans2FindFirst(tbuf, outPkt); 1605 break; 1606 1607 1609 case PacketType.Trans2FindNext: 1610 procTrans2FindNext(tbuf, outPkt); 1611 break; 1612 1613 1615 case PacketType.Trans2QueryFileSys: 1616 procTrans2QueryFileSys(tbuf, outPkt); 1617 break; 1618 1619 1621 case PacketType.Trans2QueryPath: 1622 procTrans2QueryPath(tbuf, outPkt); 1623 break; 1624 1625 1627 default: 1628 1629 1631 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 1632 break; 1633 } 1634 } 1635 1636 1644 protected final void procTrans2FindFirst(SrvTransactBuffer tbuf, SMBSrvPacket outPkt) throws java.io.IOException , 1645 SMBSrvException 1646 { 1647 1648 1650 int treeId = m_smbPkt.getTreeId(); 1651 TreeConnection conn = m_sess.findConnection(treeId); 1652 1653 if (conn == null) 1654 { 1655 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 1656 return; 1657 } 1658 1659 1661 if (conn.hasReadAccess() == false) 1662 { 1663 1664 1666 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1667 return; 1668 } 1669 1670 1672 DataBuffer paramBuf = tbuf.getParameterBuffer(); 1673 1674 int srchAttr = paramBuf.getShort(); 1675 int maxFiles = paramBuf.getShort(); 1676 int srchFlag = paramBuf.getShort(); 1677 int infoLevl = paramBuf.getShort(); 1678 paramBuf.skipBytes(4); 1679 1680 String srchPath = paramBuf.getString(tbuf.isUnicode()); 1681 1682 1684 if (srchPath == null || srchPath.length() == 0) 1685 { 1686 1687 1689 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1690 return; 1691 } 1692 1693 1695 SearchContext ctx = null; 1696 DiskInterface disk = null; 1697 int searchId = -1; 1698 1699 try 1700 { 1701 1702 1704 disk = (DiskInterface) conn.getSharedDevice().getInterface(); 1705 1706 1708 searchId = m_sess.allocateSearchSlot(); 1709 if (searchId == -1) 1710 { 1711 1712 1714 m_sess.sendErrorResponseSMB(SMBStatus.SRVNoResourcesAvailable, SMBStatus.ErrSrv); 1715 return; 1716 } 1717 1718 1720 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 1721 logger.debug("Start trans search [" + searchId + "] - " + srchPath + ", attr=0x" 1722 + Integer.toHexString(srchAttr) + ", maxFiles=" + maxFiles + ", infoLevel=" + infoLevl 1723 + ", flags=0x" + Integer.toHexString(srchFlag)); 1724 1725 1727 ctx = disk.startSearch(m_sess, conn, srchPath, srchAttr); 1728 if (ctx != null) 1729 { 1730 1731 1733 ctx.setTreeId(treeId); 1734 ctx.setMaximumFiles(maxFiles); 1735 } 1736 else 1737 { 1738 1739 1741 m_sess.sendErrorResponseSMB(SMBStatus.DOSFileNotFound, SMBStatus.ErrDos); 1742 return; 1743 } 1744 1745 1747 m_sess.setSearchContext(searchId, ctx); 1748 1749 1751 SrvTransactBuffer replyBuf = new SrvTransactBuffer(tbuf); 1752 DataBuffer dataBuf = replyBuf.getDataBuffer(); 1753 1754 1756 int maxLen = replyBuf.getReturnDataLimit(); 1757 1758 1760 boolean resumeReq = (srchFlag & FindFirstNext.ReturnResumeKey) != 0 ? true : false; 1761 1762 1764 int fileCnt = 0; 1765 int packLen = 0; 1766 int lastNameOff = 0; 1767 1768 boolean pktDone = false; 1769 boolean searchDone = false; 1770 1771 FileInfo info = new FileInfo(); 1772 1773 while (pktDone == false && fileCnt < maxFiles) 1774 { 1775 1776 1778 if (ctx.nextFileInfo(info) == false) 1779 { 1780 1781 1783 pktDone = true; 1784 searchDone = true; 1785 } 1786 1787 1789 else if (FindInfoPacker.calcInfoSize(info, infoLevl, false, true) <= maxLen) 1790 { 1791 1792 1794 if (resumeReq) 1795 { 1796 dataBuf.putZeros(4); 1797 maxLen -= 4; 1798 } 1799 1800 1802 lastNameOff = dataBuf.getPosition(); 1803 1804 1806 packLen = FindInfoPacker.packInfo(info, dataBuf, infoLevl, tbuf.isUnicode()); 1807 1808 1810 fileCnt++; 1811 1812 1814 maxLen -= packLen; 1815 } 1816 else 1817 { 1818 1819 1821 ctx.restartAt(info); 1822 1823 1825 pktDone = true; 1826 } 1827 } 1828 1829 1831 paramBuf = replyBuf.getParameterBuffer(); 1832 1833 paramBuf.putShort(searchId); 1834 paramBuf.putShort(fileCnt); 1835 paramBuf.putShort(ctx.hasMoreFiles() ? 0 : 1); 1836 paramBuf.putShort(0); 1837 paramBuf.putShort(lastNameOff); 1838 1839 1841 SMBSrvTransPacket tpkt = new SMBSrvTransPacket(outPkt.getBuffer()); 1842 tpkt.doTransactionResponse(m_sess, replyBuf); 1843 1844 1846 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 1847 logger.debug("Search [" + searchId + "] Returned " + fileCnt + " files, moreFiles=" 1848 + ctx.hasMoreFiles()); 1849 1850 1852 if (searchDone == true) 1853 { 1854 1855 1857 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 1858 logger.debug("End start search [" + searchId + "] (Search complete)"); 1859 1860 1862 m_sess.deallocateSearchSlot(searchId); 1863 } 1864 } 1865 catch (FileNotFoundException ex) 1866 { 1867 1868 1870 if (searchId != -1) 1871 m_sess.deallocateSearchSlot(searchId); 1872 1873 1875 m_sess.sendErrorResponseSMB(SMBStatus.DOSNoMoreFiles, SMBStatus.ErrDos); 1876 } 1878 catch (InvalidDeviceInterfaceException ex) 1879 { 1880 1881 1883 if (searchId != -1) 1884 m_sess.deallocateSearchSlot(searchId); 1885 1886 1888 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 1889 } 1890 catch (UnsupportedInfoLevelException ex) 1891 { 1892 1893 1895 if (searchId != -1) 1896 m_sess.deallocateSearchSlot(searchId); 1897 1898 1900 m_sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv); 1901 } 1902 } 1903 1904 1912 protected final void procTrans2FindNext(SrvTransactBuffer tbuf, SMBSrvPacket outPkt) throws java.io.IOException , 1913 SMBSrvException 1914 { 1915 1916 1918 int treeId = m_smbPkt.getTreeId(); 1919 TreeConnection conn = m_sess.findConnection(treeId); 1920 1921 if (conn == null) 1922 { 1923 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 1924 return; 1925 } 1926 1927 1929 if (conn.hasReadAccess() == false) 1930 { 1931 1932 1934 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 1935 return; 1936 } 1937 1938 1940 DataBuffer paramBuf = tbuf.getParameterBuffer(); 1941 1942 int searchId = paramBuf.getShort(); 1943 int maxFiles = paramBuf.getShort(); 1944 int infoLevl = paramBuf.getShort(); 1945 int reskey = paramBuf.getInt(); 1946 int srchFlag = paramBuf.getShort(); 1947 1948 String resumeName = paramBuf.getString(tbuf.isUnicode()); 1949 1950 1952 SearchContext ctx = null; 1953 DiskInterface disk = null; 1954 1955 try 1956 { 1957 1958 1960 disk = (DiskInterface) conn.getSharedDevice().getInterface(); 1961 1962 1964 ctx = m_sess.getSearchContext(searchId); 1965 if (ctx == null) 1966 { 1967 1968 1970 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 1971 logger.debug("Search context null - [" + searchId + "]"); 1972 1973 1975 m_sess.sendErrorResponseSMB(SMBStatus.DOSNoMoreFiles, SMBStatus.ErrDos); 1976 return; 1977 } 1978 1979 1981 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 1982 logger.debug("Continue search [" + searchId + "] - " + resumeName + ", maxFiles=" + maxFiles 1983 + ", infoLevel=" + infoLevl + ", flags=0x" + Integer.toHexString(srchFlag)); 1984 1985 1987 SrvTransactBuffer replyBuf = new SrvTransactBuffer(tbuf); 1988 DataBuffer dataBuf = replyBuf.getDataBuffer(); 1989 1990 1992 int maxLen = replyBuf.getReturnDataLimit(); 1993 1994 1996 boolean resumeReq = (srchFlag & FindFirstNext.ReturnResumeKey) != 0 ? true : false; 1997 1998 2000 int fileCnt = 0; 2001 int packLen = 0; 2002 int lastNameOff = 0; 2003 2004 boolean pktDone = false; 2005 boolean searchDone = false; 2006 2007 FileInfo info = new FileInfo(); 2008 2009 while (pktDone == false && fileCnt < maxFiles) 2010 { 2011 2012 2014 if (ctx.nextFileInfo(info) == false) 2015 { 2016 2017 2019 pktDone = true; 2020 searchDone = true; 2021 } 2022 2023 2025 else if (FindInfoPacker.calcInfoSize(info, infoLevl, false, true) <= maxLen) 2026 { 2027 2028 2030 if (resumeReq) 2031 dataBuf.putZeros(4); 2032 2033 2035 lastNameOff = dataBuf.getPosition(); 2036 2037 2039 packLen = FindInfoPacker.packInfo(info, dataBuf, infoLevl, tbuf.isUnicode()); 2040 2041 2043 fileCnt++; 2044 2045 2047 maxLen -= packLen; 2048 } 2049 else 2050 { 2051 2052 2054 ctx.restartAt(info); 2055 2056 2058 pktDone = true; 2059 } 2060 } 2061 2062 2064 paramBuf = replyBuf.getParameterBuffer(); 2065 2066 paramBuf.putShort(fileCnt); 2067 paramBuf.putShort(ctx.hasMoreFiles() ? 0 : 1); 2068 paramBuf.putShort(0); 2069 paramBuf.putShort(lastNameOff); 2070 2071 2073 SMBSrvTransPacket tpkt = new SMBSrvTransPacket(outPkt.getBuffer()); 2074 tpkt.doTransactionResponse(m_sess, replyBuf); 2075 2076 2078 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 2079 logger.debug("Search [" + searchId + "] Returned " + fileCnt + " files, moreFiles=" 2080 + ctx.hasMoreFiles()); 2081 2082 2084 if (searchDone == true) 2085 { 2086 2087 2089 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_SEARCH)) 2090 logger.debug("End start search [" + searchId + "] (Search complete)"); 2091 2092 2094 m_sess.deallocateSearchSlot(searchId); 2095 } 2096 } 2097 catch (FileNotFoundException ex) 2098 { 2099 2100 2102 if (searchId != -1) 2103 m_sess.deallocateSearchSlot(searchId); 2104 2105 2107 m_sess.sendErrorResponseSMB(SMBStatus.DOSNoMoreFiles, SMBStatus.ErrDos); 2108 } 2110 catch (InvalidDeviceInterfaceException ex) 2111 { 2112 2113 2115 if (searchId != -1) 2116 m_sess.deallocateSearchSlot(searchId); 2117 2118 2120 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2121 } 2122 catch (UnsupportedInfoLevelException ex) 2123 { 2124 2125 2127 if (searchId != -1) 2128 m_sess.deallocateSearchSlot(searchId); 2129 2130 2132 m_sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv); 2133 } 2134 } 2135 2136 2144 protected final void procTrans2QueryFileSys(SrvTransactBuffer tbuf, SMBSrvPacket outPkt) 2145 throws java.io.IOException , SMBSrvException 2146 { 2147 2148 2150 int treeId = m_smbPkt.getTreeId(); 2151 TreeConnection conn = m_sess.findConnection(treeId); 2152 2153 if (conn == null) 2154 { 2155 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 2156 return; 2157 } 2158 2159 2161 if (conn.hasReadAccess() == false) 2162 { 2163 2164 2166 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 2167 return; 2168 } 2169 2170 2172 DataBuffer paramBuf = tbuf.getParameterBuffer(); 2173 2174 int infoLevl = paramBuf.getShort(); 2175 2176 2178 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_INFO)) 2179 logger.debug("Query File System Info - level = 0x" + Integer.toHexString(infoLevl)); 2180 2181 2183 try 2184 { 2185 2186 2188 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 2189 DiskDeviceContext diskCtx = (DiskDeviceContext) conn.getContext(); 2190 2191 2193 outPkt.setParameterCount(10); 2194 2195 2197 byte[] buf = outPkt.getBuffer(); 2198 int prmPos = DataPacker.longwordAlign(outPkt.getByteOffset()); 2199 int dataPos = prmPos; 2201 2205 DataBuffer replyBuf = new DataBuffer(buf, dataPos, buf.length - dataPos); 2206 2207 2209 SrvDiskInfo diskInfo = null; 2210 VolumeInfo volInfo = null; 2211 2212 switch (infoLevl) 2213 { 2214 2215 2217 case DiskInfoPacker.InfoStandard: 2218 2219 2221 diskInfo = getDiskInformation(disk, diskCtx); 2222 2223 2225 DiskInfoPacker.packStandardInfo(diskInfo, replyBuf); 2226 break; 2227 2228 2230 case DiskInfoPacker.InfoVolume: 2231 2232 2234 volInfo = getVolumeInformation(disk, diskCtx); 2235 2236 2238 DiskInfoPacker.packVolumeInfo(volInfo, replyBuf, tbuf.isUnicode()); 2239 break; 2240 2241 2243 case DiskInfoPacker.InfoFsVolume: 2244 2245 2247 volInfo = getVolumeInformation(disk, diskCtx); 2248 2249 2251 DiskInfoPacker.packFsVolumeInformation(volInfo, replyBuf, tbuf.isUnicode()); 2252 break; 2253 2254 2256 case DiskInfoPacker.InfoFsSize: 2257 2258 2260 diskInfo = getDiskInformation(disk, diskCtx); 2261 2262 2264 DiskInfoPacker.packFsSizeInformation(diskInfo, replyBuf); 2265 break; 2266 2267 2269 case DiskInfoPacker.InfoFsDevice: 2270 DiskInfoPacker.packFsDevice(0, 0, replyBuf); 2271 break; 2272 2273 2275 case DiskInfoPacker.InfoFsAttribute: 2276 DiskInfoPacker.packFsAttribute(0, 255, "JLAN", tbuf.isUnicode(), replyBuf); 2277 break; 2278 } 2279 2280 2282 if (replyBuf.getPosition() == dataPos) 2283 { 2284 m_sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv); 2285 return; 2286 } 2287 2288 int dataLen = replyBuf.getLength(); 2289 SMBSrvTransPacket.initTransactReply(outPkt, 0, prmPos, dataLen, dataPos); 2290 outPkt.setByteCount(replyBuf.getPosition() - outPkt.getByteOffset()); 2291 2292 2294 m_sess.sendResponseSMB(outPkt); 2295 } 2296 catch (InvalidDeviceInterfaceException ex) 2297 { 2298 2299 2301 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2302 return; 2303 } 2304 } 2305 2306 2314 protected final void procTrans2QueryPath(SrvTransactBuffer tbuf, SMBSrvPacket outPkt) throws java.io.IOException , 2315 SMBSrvException 2316 { 2317 2318 2320 int treeId = m_smbPkt.getTreeId(); 2321 TreeConnection conn = m_sess.findConnection(treeId); 2322 2323 if (conn == null) 2324 { 2325 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 2326 return; 2327 } 2328 2329 2331 if (conn.hasReadAccess() == false) 2332 { 2333 2334 2336 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 2337 return; 2338 } 2339 2340 2342 DataBuffer paramBuf = tbuf.getParameterBuffer(); 2343 2344 int infoLevl = paramBuf.getShort(); 2345 paramBuf.skipBytes(4); 2346 2347 String path = paramBuf.getString(tbuf.isUnicode()); 2348 2349 2351 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_INFO)) 2352 logger.debug("Query Path - level = 0x" + Integer.toHexString(infoLevl) + ", path = " + path); 2353 2354 2356 try 2357 { 2358 2359 2361 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 2362 2363 2365 outPkt.setParameterCount(10); 2366 2367 2369 byte[] buf = outPkt.getBuffer(); 2370 int prmPos = DataPacker.longwordAlign(outPkt.getByteOffset()); 2371 int dataPos = prmPos; 2373 2377 DataBuffer replyBuf = new DataBuffer(buf, dataPos, buf.length - dataPos); 2378 2379 2381 FileInfo fileInfo = disk.getFileInformation(m_sess, conn, path); 2382 2383 if (fileInfo == null) 2384 { 2385 m_sess.sendErrorResponseSMB(SMBStatus.NTObjectNotFound, SMBStatus.NTErr); 2386 return; 2387 } 2388 2389 2391 int dataLen = QueryInfoPacker.packInfo(fileInfo, replyBuf, infoLevl, true); 2392 2393 2395 if (dataLen == 0) 2396 { 2397 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 2398 return; 2399 } 2400 2401 SMBSrvTransPacket.initTransactReply(outPkt, 0, prmPos, dataLen, dataPos); 2402 outPkt.setByteCount(replyBuf.getPosition() - outPkt.getByteOffset()); 2403 2404 2406 m_sess.sendResponseSMB(outPkt); 2407 } 2408 catch (FileNotFoundException ex) 2409 { 2410 2411 2413 m_sess.sendErrorResponseSMB(SMBStatus.NTObjectNotFound, SMBStatus.NTErr); 2414 return; 2415 } 2416 catch (InvalidDeviceInterfaceException ex) 2417 { 2418 2419 2421 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 2422 return; 2423 } 2424 catch (UnsupportedInfoLevelException ex) 2425 { 2426 2427 2429 m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.NTErr); 2430 return; 2431 } 2432 } 2433 2434 2442 2443 protected void procTreeConnectAndX(SMBSrvPacket outPkt) throws SMBSrvException, TooManyConnectionsException, 2444 java.io.IOException 2445 { 2446 2447 2449 if (m_smbPkt.checkPacketIsValid(4, 3) == false) 2450 { 2451 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 2452 return; 2453 } 2454 2455 2457 int flags = m_smbPkt.getParameter(2); 2458 int pwdLen = m_smbPkt.getParameter(3); 2459 2460 2462 int dataPos = m_smbPkt.getByteOffset(); 2463 int dataLen = m_smbPkt.getByteCount(); 2464 byte[] buf = m_smbPkt.getBuffer(); 2465 2466 2468 String pwd = null; 2469 2470 if (pwdLen > 0) 2471 { 2472 pwd = new String (buf, dataPos, pwdLen); 2473 dataPos += pwdLen; 2474 dataLen -= pwdLen; 2475 } 2476 2477 2479 String uncPath = DataPacker.getString(buf, dataPos, dataLen); 2480 if (uncPath == null) 2481 { 2482 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2483 return; 2484 } 2485 2486 2488 dataPos += uncPath.length() + 1; dataLen -= uncPath.length() + 1; 2491 String service = DataPacker.getString(buf, dataPos, dataLen); 2492 if (service == null) 2493 { 2494 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2495 return; 2496 } 2497 2498 2501 int servType = ShareType.ServiceAsType(service); 2502 if (servType == ShareType.UNKNOWN && service.compareTo("?????") != 0) 2503 { 2504 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2505 return; 2506 } 2507 2508 2510 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TREE)) 2511 logger.debug("Tree Connect AndX - " + uncPath + ", " + service); 2512 2513 2515 PCShare share = null; 2516 2517 try 2518 { 2519 share = new PCShare(uncPath); 2520 } 2521 catch (InvalidUNCPathException ex) 2522 { 2523 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2524 return; 2525 } 2526 2527 2529 if (servType == ShareType.NAMEDPIPE && share.getShareName().compareTo("IPC$") == 0) 2530 servType = ShareType.ADMINPIPE; 2531 2532 2534 SharedDevice shareDev = null; 2535 2536 try 2537 { 2538 2539 2541 shareDev = m_sess.getSMBServer().findShare(share.getNodeName(), share.getShareName(), servType, 2542 getSession(), true); 2543 } 2544 catch (InvalidUserException ex) 2545 { 2546 2547 2549 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 2550 return; 2551 } 2552 catch (Exception ex) 2553 { 2554 2555 2557 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidNetworkName, SMBStatus.ErrSrv); 2558 return; 2559 } 2560 2561 2563 if (shareDev == null || (servType != ShareType.UNKNOWN && shareDev.getType() != servType)) 2564 { 2565 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos); 2566 return; 2567 } 2568 2569 2572 SrvAuthenticator auth = getSession().getSMBServer().getAuthenticator(); 2573 int filePerm = FileAccess.Writeable; 2574 2575 if (auth != null) 2576 { 2577 2578 2580 filePerm = auth.authenticateShareConnect(m_sess.getClientInformation(), shareDev, pwd, m_sess); 2581 if (filePerm < 0) 2582 { 2583 2584 2586 m_sess.sendErrorResponseSMB(SMBStatus.SRVNoAccessRights, SMBStatus.ErrSrv); 2587 return; 2588 } 2589 } 2590 2591 2593 int treeId = m_sess.addConnection(shareDev); 2594 outPkt.setTreeId(treeId); 2595 2596 2598 TreeConnection tree = m_sess.findConnection(treeId); 2599 tree.setPermission(filePerm); 2600 2601 2603 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TREE)) 2604 logger.debug("Tree Connect AndX - Allocated Tree Id = " + treeId + ", Permission = " 2605 + FileAccess.asString(filePerm)); 2606 2607 2609 outPkt.setParameterCount(3); 2610 outPkt.setAndXCommand(0xFF); outPkt.setParameter(1, 0); 2612 outPkt.setParameter(2, 0); 2613 2614 2616 int pos = outPkt.getByteOffset(); 2617 pos = DataPacker.putString(ShareType.TypeAsService(shareDev.getType()), buf, pos, true); 2618 outPkt.setByteCount(pos - outPkt.getByteOffset()); 2619 2620 2622 m_sess.sendResponseSMB(outPkt); 2623 2624 2626 if (tree.getInterface() != null) 2627 tree.getInterface().treeOpened(m_sess, tree); 2628 } 2629 2630 2635 protected final void procWriteAndX(SMBSrvPacket outPkt) throws java.io.IOException , SMBSrvException 2636 { 2637 2638 2640 if (m_smbPkt.checkPacketIsValid(12, 0) == false) 2641 { 2642 m_sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv); 2643 return; 2644 } 2645 2646 2648 int treeId = m_smbPkt.getTreeId(); 2649 TreeConnection conn = m_sess.findConnection(treeId); 2650 2651 if (conn == null) 2652 { 2653 m_sess.sendErrorResponseSMB(SMBStatus.SRVInvalidTID, SMBStatus.ErrSrv); 2654 return; 2655 } 2656 2657 2659 if (conn.hasWriteAccess() == false) 2660 { 2661 2662 2664 m_sess.sendErrorResponseSMB(SMBStatus.DOSAccessDenied, SMBStatus.ErrDos); 2665 return; 2666 } 2667 2668 2671 if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 2672 { 2673 2674 2676 IPCHandler.processIPCRequest(m_sess, outPkt); 2677 return; 2678 } 2679 2680 2682 int fid = m_smbPkt.getParameter(2); 2683 int offset = m_smbPkt.getParameterLong(3); 2684 int dataLen = m_smbPkt.getParameter(10); 2685 int dataPos = m_smbPkt.getParameter(11) + RFCNetBIOSProtocol.HEADER_LEN; 2686 2687 NetworkFile netFile = conn.findFile(fid); 2688 2689 if (netFile == null) 2690 { 2691 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos); 2692 return; 2693 } 2694 2695 2697 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_FILEIO)) 2698 logger.debug("File Write AndX [" + netFile.getFileId() + "] : Size=" + dataLen + " ,Pos=" + offset); 2699 2700 2702 byte[] buf = m_smbPkt.getBuffer(); 2703 int wrtlen = 0; 2704 2705 2707 try 2708 { 2709 2710 2712 DiskInterface disk = (DiskInterface) conn.getSharedDevice().getInterface(); 2713 2714 2716 wrtlen = disk.writeFile(m_sess, conn, netFile, buf, dataPos, dataLen, offset); 2717 } 2718 catch (InvalidDeviceInterfaceException ex) 2719 { 2720 2721 2723 m_sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos); 2724 return; 2725 } 2726 catch (java.io.IOException ex) 2727 { 2728 2729 2731 logger.error("File Write Error [" + netFile.getFileId() + "] : ", ex); 2732 2733 2735 m_sess.sendErrorResponseSMB(SMBStatus.HRDWriteFault, SMBStatus.ErrHrd); 2736 return; 2737 } 2738 2739 2741 outPkt.setParameterCount(6); 2742 outPkt.setAndXCommand(0xFF); 2743 outPkt.setParameter(1, 0); 2744 outPkt.setParameter(2, wrtlen); 2745 outPkt.setParameter(3, 0); outPkt.setParameter(4, 0); outPkt.setParameter(5, 0); outPkt.setByteCount(0); 2749 2750 2752 m_sess.sendResponseSMB(outPkt); 2753 } 2754 2755 2758 public boolean runProtocol() throws java.io.IOException , SMBSrvException, TooManyConnectionsException 2759 { 2760 2761 2763 if (m_smbPkt == null) 2764 m_smbPkt = m_sess.getReceivePacket(); 2765 2766 2768 if (m_smbPkt.checkPacketSignature() == false) 2769 throw new IOException ("Invalid SMB signature"); 2770 2771 2775 SMBSrvPacket outPkt = m_smbPkt; 2776 boolean chainedCmd = hasChainedCommand(m_smbPkt); 2777 2778 if (chainedCmd) 2779 { 2780 2781 2783 if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_STATE)) 2784 logger.debug("AndX Command = 0x" + Integer.toHexString(m_smbPkt.getAndXCommand())); 2785 2786 2788 outPkt = new SMBSrvPacket(m_smbPkt); 2789 } 2790 2791 2793 m_smbPkt.resetBytePointer(); 2794 2795 2797 boolean handledOK = true; 2798 2799 switch (m_smbPkt.getCommand()) 2800 { 2801 2802 2804 case PacketType.SessionSetupAndX: 2805 procSessionSetup(outPkt); 2806 break; 2807 2808 2810 case PacketType.TreeConnectAndX: 2811 procTreeConnectAndX(outPkt); 2812 break; 2813 2814 2816 case PacketType.Transaction2: 2817 case PacketType.Transaction: 2818 procTransact2(outPkt); 2819 break; 2820 2821 2823 case PacketType.TransactionSecond: 2824 case PacketType.Transaction2Second: 2825 procTransact2Secondary(outPkt); 2826 break; 2827 2828 2830 case PacketType.FindClose2: 2831 procFindClose(outPkt); 2832 break; 2833 2834 2836 case PacketType.OpenAndX: 2837 procOpenAndX(outPkt); 2838 break; 2839 2840 2842 case PacketType.ReadAndX: 2843 procReadAndX(outPkt); 2844 break; 2845 2846 2848 case PacketType.WriteAndX: 2849 procWriteAndX(outPkt); 2850 break; 2851 2852 2854 case PacketType.TreeDisconnect: 2855 procTreeDisconnect(outPkt); 2856 break; 2857 2858 2860 case PacketType.LockingAndX: 2861 procLockingAndX(outPkt); 2862 break; 2863 2864 2866 case PacketType.LogoffAndX: 2867 procLogoffAndX(outPkt); 2868 break; 2869 2870 2872 case PacketType.TreeConnect: 2873 super.runProtocol(); 2874 break; 2875 2876 2878 case PacketType.RenameFile: 2879 procRenameFile(outPkt); 2880 break; 2881 2882 2884 case PacketType.Echo: 2885 super.procEcho(outPkt); 2886 break; 2887 2888 2890 default: 2891 2892 2896 int treeId = m_smbPkt.getTreeId(); 2897 TreeConnection conn = null; 2898 if (treeId != -1) 2899 conn = m_sess.findConnection(treeId); 2900 2901 if (conn != null) 2902 { 2903 2904 2907 if (conn.getSharedDevice().getType() == ShareType.DISK 2908 || conn.getSharedDevice().getType() == ShareType.PRINTER) 2909 { 2910 2911 2913 handledOK = super.runProtocol(); 2914 } 2915 else if (conn.getSharedDevice().getType() == ShareType.ADMINPIPE) 2916 { 2917 2918 2920 IPCHandler.processIPCRequest(m_sess, outPkt); 2921 handledOK = true; 2922 } 2923 } 2924 break; 2925 } 2926 2927 2929 return handledOK; 2930 } 2931} | Popular Tags |