1 18 19 package com.knowgate.jcifs.smb; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 import com.knowgate.misc.Gadgets; 25 26 class SmbComNTCreateAndX extends AndXServerMessageBlock { 27 28 static final int FILE_READ_DATA = 0x00000001; static final int FILE_WRITE_DATA = 0x00000002; static final int FILE_APPEND_DATA = 0x00000004; static final int FILE_READ_EA = 0x00000008; static final int FILE_WRITE_EA = 0x00000010; static final int FILE_EXECUTE = 0x00000020; static final int FILE_DELETE = 0x00000040; static final int FILE_READ_ATTRIBUTES = 0x00000080; static final int FILE_WRITE_ATTRIBUTES = 0x00000100; static final int DELETE = 0x00010000; static final int READ_CONTROL = 0x00020000; static final int WRITE_DAC = 0x00040000; static final int WRITE_OWNER = 0x00080000; static final int SYNCHRONIZE = 0x00100000; static final int GENERIC_ALL = 0x10000000; static final int GENERIC_EXECUTE = 0x20000000; static final int GENERIC_WRITE = 0x40000000; static final int GENERIC_READ = 0x80000000; 48 50 52 54 55 static final int FILE_SUPERSEDE = 0x0; 56 57 60 61 static final int FILE_OPEN = 0x1; 62 63 66 67 static final int FILE_CREATE = 0x2; 68 69 72 73 static final int FILE_OPEN_IF = 0x3; 74 75 78 79 static final int FILE_OVERWRITE = 0x4; 80 81 84 85 static final int FILE_OVERWRITE_IF = 0x5; 86 87 88 static final int FILE_WRITE_THROUGH = 0x00000002; 90 static final int FILE_SEQUENTIAL_ONLY = 0x00000004; 91 static final int FILE_SYNCHRONOUS_IO_ALERT = 0x00000010; 92 static final int FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020; 93 94 static final int SECURITY_CONTEXT_TRACKING = 0x01; 96 static final int SECURITY_EFFECTIVE_ONLY = 0x02; 97 98 private int flags, 99 rootDirectoryFid, 100 desiredAccess, 101 extFileAttributes, 102 shareAccess, 103 createDisposition, 104 createOptions, 105 impersonationLevel; 106 private long allocationSize; 107 private byte securityFlags; 108 109 SmbComNTCreateAndX( String name, int flags, 110 int shareAccess, 111 int extFileAttributes, 112 int createOptions, 113 ServerMessageBlock andx ) { 114 super( andx ); 115 this.path = name; 116 command = SMB_COM_NT_CREATE_ANDX; 117 118 desiredAccess = ( flags >>> 16 ) & 0xFFFF; 120 desiredAccess |= FILE_READ_EA | FILE_READ_ATTRIBUTES; 121 122 this.extFileAttributes = extFileAttributes; 124 125 this.shareAccess = shareAccess; 127 128 if(( flags & SmbFile.O_TRUNC ) == SmbFile.O_TRUNC ) { 130 if(( flags & SmbFile.O_CREAT ) == SmbFile.O_CREAT ) { 132 createDisposition = FILE_OVERWRITE_IF; 134 } else { 135 createDisposition = FILE_OVERWRITE; 136 } 137 } else { 138 if(( flags & SmbFile.O_CREAT ) == SmbFile.O_CREAT ) { 140 if ((flags & SmbFile.O_EXCL ) == SmbFile.O_EXCL ) { 142 createDisposition = FILE_CREATE; 144 } else { 145 createDisposition = FILE_OPEN_IF; 146 } 147 } else { 148 createDisposition = FILE_OPEN; 149 } 150 } 151 152 if(( createOptions & 0x01 ) == 0 ) { 153 this.createOptions = createOptions | 0x0040; 154 } else { 155 this.createOptions = createOptions; 156 } 157 impersonationLevel = 0x02; securityFlags = (byte)0x03; } 160 161 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 162 int start = dstIndex; 163 164 dst[dstIndex++] = (byte)0x00; 165 writeInt2( ( useUnicode ? path.length() * 2 : path.length() ), dst, dstIndex ); 167 dstIndex += 2; 168 writeInt4( flags, dst, dstIndex ); 169 dstIndex += 4; 170 writeInt4( rootDirectoryFid, dst, dstIndex ); 171 dstIndex += 4; 172 writeInt4( desiredAccess, dst, dstIndex ); 173 dstIndex += 4; 174 writeInt8( allocationSize, dst, dstIndex ); 175 dstIndex += 8; 176 writeInt4( extFileAttributes, dst, dstIndex ); 177 dstIndex += 4; 178 writeInt4( shareAccess, dst, dstIndex ); 179 dstIndex += 4; 180 writeInt4( createDisposition, dst, dstIndex ); 181 dstIndex += 4; 182 writeInt4( createOptions, dst, dstIndex ); 183 dstIndex += 4; 184 writeInt4( impersonationLevel, dst, dstIndex ); 185 dstIndex += 4; 186 dst[dstIndex++] = securityFlags; 187 188 return dstIndex - start; 189 } 190 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 191 return writeString( path, dst, dstIndex ); 192 } 193 int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) { 194 return 0; 195 } 196 int readBytesWireFormat( byte[] buffer, int bufferIndex ) { 197 return 0; 198 } 199 int readBytesDirectWireFormat( InputStream in, int byteCount, 200 byte[] buffer, int bufferIndex ) throws IOException { 201 return 0; 202 } 203 public String toString() { 204 return new String ( "SmbComNTCreateAndX[" + 205 super.toString() + 206 ",flags=0x" + Gadgets.toHexString( flags, 2 ) + 207 ",rootDirectoryFid=" + rootDirectoryFid + 208 ",desiredAccess=0x" + Gadgets.toHexString( desiredAccess, 4 ) + 209 ",allocationSize=" + allocationSize + 210 ",extFileAttributes=0x" + Gadgets.toHexString( extFileAttributes, 4 ) + 211 ",shareAccess=0x" + Gadgets.toHexString( shareAccess, 4 ) + 212 ",createDisposition=0x" + Gadgets.toHexString( createDisposition, 4 ) + 213 ",createOptions=0x" + Gadgets.toHexString( createOptions, 8 ) + 214 ",impersonationLevel=0x" + Gadgets.toHexString( impersonationLevel, 4 ) + 215 ",securityFlags=0x" + Gadgets.toHexString( securityFlags, 2 ) + 216 ",name=" + path + "]" ); 217 } 218 } 219 | Popular Tags |