1 18 19 package jcifs.smb; 20 21 import java.util.Date ; 22 import jcifs.Config; 23 import jcifs.util.Hexdump; 24 25 class SmbComOpenAndX extends AndXServerMessageBlock { 26 27 private static final int FLAGS_RETURN_ADDITIONAL_INFO = 0x01; 29 private static final int FLAGS_REQUEST_OPLOCK = 0x02; 30 private static final int FLAGS_REQUEST_BATCH_OPLOCK = 0x04; 31 32 private static final int SHARING_COMPATIBILITY = 0x00; 34 private static final int SHARING_DENY_READ_WRITE_EXECUTE = 0x10; 35 private static final int SHARING_DENY_WRITE = 0x20; 36 private static final int SHARING_DENY_READ_EXECUTE = 0x30; 37 private static final int SHARING_DENY_NONE = 0x40; 38 39 private static final int DO_NOT_CACHE = 0x1000; private static final int WRITE_THROUGH = 0x4000; 42 private static final int OPEN_FN_CREATE = 0x10; 43 private static final int OPEN_FN_FAIL_IF_EXISTS = 0x00; 44 private static final int OPEN_FN_OPEN = 0x01; 45 private static final int OPEN_FN_TRUNC = 0x02; 46 47 private static final int BATCH_LIMIT = Config.getInt( "jcifs.smb.client.OpenAndX.ReadAndX", 1 ); 48 49 int flags, 50 desiredAccess, 51 searchAttributes, 52 fileAttributes, 53 creationTime, 54 openFunction, 55 allocationSize; 56 57 59 SmbComOpenAndX( String fileName, int flags, ServerMessageBlock andx ) { 60 super( andx ); 61 this.path = fileName; 62 command = SMB_COM_OPEN_ANDX; 63 64 desiredAccess = ( flags >>> 16 ) & 0x3; 66 if( desiredAccess == 0x3 ) { 67 desiredAccess = 0x2; 68 } 69 desiredAccess |= SHARING_DENY_NONE; 70 desiredAccess &= ~0x1; 72 searchAttributes = ATTR_DIRECTORY | ATTR_HIDDEN | ATTR_SYSTEM; 74 75 fileAttributes = 0; 77 78 if(( flags & SmbFile.O_TRUNC ) == SmbFile.O_TRUNC ) { 80 if(( flags & SmbFile.O_CREAT ) == SmbFile.O_CREAT ) { 82 openFunction = OPEN_FN_TRUNC | OPEN_FN_CREATE; 84 } else { 85 openFunction = OPEN_FN_TRUNC; 86 } 87 } else { 88 if(( flags & SmbFile.O_CREAT ) == SmbFile.O_CREAT ) { 90 if(( flags & SmbFile.O_EXCL ) == SmbFile.O_EXCL ) { 92 openFunction = OPEN_FN_CREATE | OPEN_FN_FAIL_IF_EXISTS; 94 } else { 95 openFunction = OPEN_FN_CREATE | OPEN_FN_OPEN; 96 } 97 } else { 98 openFunction = OPEN_FN_OPEN; 99 } 100 } 101 } 102 103 int getBatchLimit( byte command ) { 104 return command == SMB_COM_READ_ANDX ? BATCH_LIMIT : 0; 105 } 106 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 107 int start = dstIndex; 108 109 writeInt2( flags, dst, dstIndex ); 110 dstIndex += 2; 111 writeInt2( desiredAccess, dst, dstIndex ); 112 dstIndex += 2; 113 writeInt2( searchAttributes, dst, dstIndex ); 114 dstIndex += 2; 115 writeInt2( fileAttributes, dst, dstIndex ); 116 dstIndex += 2; 117 creationTime = 0; 118 writeInt4( creationTime, dst, dstIndex ); 119 dstIndex += 4; 120 writeInt2( openFunction, dst, dstIndex ); 121 dstIndex += 2; 122 writeInt4( allocationSize, dst, dstIndex ); 123 dstIndex += 4; 124 for( int i = 0; i < 8; i++ ) { 125 dst[dstIndex++] = 0x00; 126 } 127 128 return dstIndex - start; 129 } 130 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 131 int start = dstIndex; 132 133 if( useUnicode ) { 134 dst[dstIndex++] = (byte)'\0'; 135 } 136 dstIndex += writeString( path, dst, dstIndex ); 137 138 return dstIndex - start; 139 } 140 int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) { 141 return 0; 142 } 143 int readBytesWireFormat( byte[] buffer, int bufferIndex ) { 144 return 0; 145 } 146 public String toString() { 147 return new String ( "SmbComOpenAndX[" + 148 super.toString() + 149 ",flags=0x" + Hexdump.toHexString( flags, 2 ) + 150 ",desiredAccess=0x" + Hexdump.toHexString( desiredAccess, 4 ) + 151 ",searchAttributes=0x" + Hexdump.toHexString( searchAttributes, 4 ) + 152 ",fileAttributes=0x" + Hexdump.toHexString( fileAttributes, 4 ) + 153 ",creationTime=" + new Date ( creationTime ) + 154 ",openFunction=0x" + Hexdump.toHexString( openFunction, 2 ) + 155 ",allocationSize=" + allocationSize + 156 ",fileName=" + path + "]" ); 157 } 158 } 159 | Popular Tags |