1 17 package org.alfresco.filesys.smb.dcerpc.server; 18 19 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 20 import org.alfresco.filesys.smb.PacketType; 21 import org.alfresco.filesys.smb.dcerpc.DCECommand; 22 import org.alfresco.filesys.smb.dcerpc.DCEDataPacker; 23 import org.alfresco.filesys.smb.server.SMBTransPacket; 24 import org.alfresco.filesys.util.DataPacker; 25 26 29 public class DCESrvPacket extends SMBTransPacket 30 { 31 32 34 private static final int VERSIONMAJOR = 0; 35 private static final int VERSIONMINOR = 1; 36 private static final int PDUTYPE = 2; 37 private static final int HEADERFLAGS = 3; 38 private static final int PACKEDDATAREP = 4; 39 private static final int FRAGMENTLEN = 8; 40 private static final int AUTHLEN = 10; 41 private static final int CALLID = 12; 42 private static final int DCEDATA = 16; 43 44 46 private static final int ALLOCATIONHINT = 16; 47 private static final int PRESENTIDENT = 20; 48 private static final int OPERATIONID = 22; 49 private static final int OPERATIONDATA = 24; 50 51 53 public static final int FLG_FIRSTFRAG = 0x01; 54 public static final int FLG_LASTFRAG = 0x02; 55 public static final int FLG_ONLYFRAG = 0x03; 56 57 59 private static final byte HDR_VERSIONMAJOR = 5; 60 private static final byte HDR_VERSIONMINOR = 0; 61 private static final int HDR_PACKEDDATAREP = 0x00000010; 62 63 65 private int m_offset; 66 67 72 public DCESrvPacket(byte[] buf) 73 { 74 super(buf); 75 } 77 78 83 public DCESrvPacket(int siz) 84 { 85 super(siz); 86 87 89 setMultiplexId(getNextMultiplexId()); 90 } 91 92 97 public final int getMajorVersion() 98 { 99 return (int) (getBuffer()[m_offset + VERSIONMAJOR] & 0xFF); 100 } 101 102 107 public final int getMinorVersion() 108 { 109 return (int) (getBuffer()[m_offset + VERSIONMINOR] & 0xFF); 110 } 111 112 117 public final int getPDUType() 118 { 119 return (int) (getBuffer()[m_offset + PDUTYPE] & 0xFF); 120 } 121 122 127 public final int getHeaderFlags() 128 { 129 return (int) (getBuffer()[m_offset + HEADERFLAGS] & 0xFF); 130 } 131 132 137 public final int getPackedDataRepresentation() 138 { 139 return DataPacker.getIntelInt(getBuffer(), m_offset + PACKEDDATAREP); 140 } 141 142 147 public final int getFragmentLength() 148 { 149 return DataPacker.getIntelShort(getBuffer(), m_offset + FRAGMENTLEN); 150 } 151 152 157 public final void setFragmentLength(int len) 158 { 159 160 162 DataPacker.putIntelShort(len, getBuffer(), m_offset + FRAGMENTLEN); 163 } 164 165 170 public final int getAuthenticationLength() 171 { 172 return DataPacker.getIntelShort(getBuffer(), m_offset + AUTHLEN); 173 } 174 175 180 public final int getCallId() 181 { 182 return DataPacker.getIntelInt(getBuffer(), m_offset + CALLID); 183 } 184 185 190 public final boolean isFirstFragment() 191 { 192 if ((getHeaderFlags() & FLG_FIRSTFRAG) != 0) 193 return true; 194 return false; 195 } 196 197 202 public final boolean isLastFragment() 203 { 204 if ((getHeaderFlags() & FLG_LASTFRAG) != 0) 205 return true; 206 return false; 207 } 208 209 214 public final boolean isOnlyFragment() 215 { 216 if ((getHeaderFlags() & FLG_ONLYFRAG) == FLG_ONLYFRAG) 217 return true; 218 return false; 219 } 220 221 226 public final int getDCEDataOffset() 227 { 228 229 231 int dataOff = -1; 232 switch (getPDUType()) 233 { 234 235 237 case DCECommand.BIND: 238 case DCECommand.BINDACK: 239 dataOff = m_offset + DCEDATA; 240 break; 241 242 244 case DCECommand.REQUEST: 245 case DCECommand.RESPONSE: 246 dataOff = m_offset + OPERATIONDATA; 247 break; 248 } 249 250 252 return dataOff; 253 } 254 255 260 public final int getAllocationHint() 261 { 262 return DataPacker.getIntelInt(getBuffer(), m_offset + ALLOCATIONHINT); 263 } 264 265 270 public final void setAllocationHint(int alloc) 271 { 272 DataPacker.putIntelInt(alloc, getBuffer(), m_offset + ALLOCATIONHINT); 273 } 274 275 280 public final int getPresentationIdentifier() 281 { 282 return DataPacker.getIntelShort(getBuffer(), m_offset + PRESENTIDENT); 283 } 284 285 290 public final void setPresentationIdentifier(int ident) 291 { 292 DataPacker.putIntelShort(ident, getBuffer(), m_offset + PRESENTIDENT); 293 } 294 295 300 public final int getOperationId() 301 { 302 return DataPacker.getIntelShort(getBuffer(), m_offset + OPERATIONID); 303 } 304 305 314 public final void initializeDCERequest(int handle, byte typ, int flags, int callId) 315 { 316 317 319 InitializeTransact(16, null, 0, null, 0); 320 321 323 int bytPos = DCEDataPacker.longwordAlign(getByteOffset()); 324 325 setParameter(3, 0); 326 setParameter(4, bytPos - RFCNetBIOSProtocol.HEADER_LEN); 327 328 330 setParameter(5, 0); 331 332 334 setParameter(6, 0); 335 setParameter(7, bytPos - RFCNetBIOSProtocol.HEADER_LEN); 336 337 339 setParameter(8, 0); 340 341 343 setParameter(9, 0); 344 345 347 setSetupParameter(0, PacketType.TransactNmPipe); 348 setSetupParameter(1, handle); 349 350 352 m_offset = bytPos; 353 354 356 byte[] buf = getBuffer(); 357 DataPacker.putZeros(buf, m_offset, 24); 358 359 buf[m_offset + VERSIONMAJOR] = HDR_VERSIONMAJOR; 360 buf[m_offset + VERSIONMINOR] = HDR_VERSIONMINOR; 361 buf[m_offset + PDUTYPE] = typ; 362 buf[m_offset + HEADERFLAGS] = (byte) (flags & 0xFF); 363 DataPacker.putIntelInt(HDR_PACKEDDATAREP, buf, m_offset + PACKEDDATAREP); 364 DataPacker.putIntelInt(0, buf, m_offset + AUTHLEN); 365 DataPacker.putIntelInt(callId, buf, m_offset + CALLID); 366 } 367 368 372 public final void initializeDCEReply() 373 { 374 375 377 setParameterCount(10); 378 379 381 setParameter(0, 0); 382 setParameter(1, 0); 383 384 386 int bytPos = DCEDataPacker.longwordAlign(getByteOffset()); 387 388 setParameter(3, 0); 389 setParameter(4, bytPos - RFCNetBIOSProtocol.HEADER_LEN); 390 391 393 setParameter(5, 0); 394 395 397 setParameter(6, 0); 398 setParameter(7, bytPos - RFCNetBIOSProtocol.HEADER_LEN); 399 400 402 setParameter(8, 0); 403 404 406 setParameter(9, 0); 407 } 408 409 412 public final void DumpHeader() 413 { 414 415 417 System.out.println("** DCE/RPC Header - PDU Type = " + DCECommand.getCommandString(getPDUType())); 418 System.out.println(" Version : " + getMajorVersion() + "." + getMinorVersion()); 419 System.out.println(" Flags : 0x" + getHeaderFlags()); 420 System.out.println(" Packed Data Rep : 0x" + getPackedDataRepresentation()); 421 System.out.println(" Fragment Length : " + getFragmentLength()); 422 System.out.println(" Auth Length : " + getAuthenticationLength()); 423 System.out.println(" Call ID : " + getCallId()); 424 } 425 } 426 | Popular Tags |