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