1 17 package org.alfresco.filesys.smb.server; 18 19 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 20 import org.alfresco.filesys.smb.PacketType; 21 import org.alfresco.filesys.util.DataPacker; 22 23 26 public class NTTransPacket extends SMBSrvPacket 27 { 28 29 31 private static final int StandardParams = 19; 32 private static final int ParameterBytes = 36; 35 37 private static final int ReplyParams = 18; 38 39 41 private static final int NTMaxSetupCount = SMBPacket.PARAMWORDS; 42 private static final int NTParams = SMBPacket.PARAMWORDS + 3; 43 private static final int NTSetupCount = NTParams + 32; 44 private static final int NTFunction = NTSetupCount + 1; 45 46 48 private static final int DefaultReturnParams = 4; 49 private static final int DefaultReturnData = 1024; 50 51 54 public NTTransPacket() 55 { 56 super(); 57 } 58 59 64 public NTTransPacket(byte[] buf) 65 { 66 super(buf); 67 } 68 69 74 public NTTransPacket(NTTransPacket pkt) 75 { 76 super(pkt); 77 } 78 79 84 public final int getDataLength() 85 { 86 return getNTParameter(6); 87 } 88 89 94 public final int getDataOffset() 95 { 96 return getNTParameter(7) + RFCNetBIOSProtocol.HEADER_LEN; 97 } 98 99 104 public final int[] getParameterBlock() 105 { 106 107 109 int prmcnt = getParameterBlockCount() / 4; if (prmcnt <= 0) 111 return null; 112 int[] prmblk = new int[prmcnt]; 113 114 117 int pos = getParameterBlockOffset(); 118 119 121 setBytePointer(pos, getByteCount()); 122 123 for (int idx = 0; idx < prmcnt; idx++) 124 { 125 126 128 prmblk[idx] = unpackInt(); 129 } 130 131 133 return prmblk; 134 } 135 136 141 public final int getTotalParameterCount() 142 { 143 return getNTParameter(0); 144 } 145 146 151 public final int getTotalDataCount() 152 { 153 return getNTParameter(1); 154 } 155 156 161 public final int getMaximumParameterReturn() 162 { 163 return getNTParameter(2); 164 } 165 166 171 public final int getMaximumDataReturn() 172 { 173 return getNTParameter(3); 174 } 175 176 181 public final int getParameterBlockCount() 182 { 183 return getNTParameter(getCommand() == PacketType.NTTransact ? 4 : 2); 184 } 185 186 191 public final int getParameterBlockOffset() 192 { 193 return getNTParameter(getCommand() == PacketType.NTTransact ? 5 : 3) + RFCNetBIOSProtocol.HEADER_LEN; 194 } 195 196 201 public final int getParameterBlockDisplacement() 202 { 203 return getNTParameter(4); 204 } 205 206 211 public final int getDataBlockCount() 212 { 213 return getNTParameter(getCommand() == PacketType.NTTransact ? 6 : 5); 214 } 215 216 221 public final int getDataBlockOffset() 222 { 223 return getNTParameter(getCommand() == PacketType.NTTransact ? 7 : 6) + RFCNetBIOSProtocol.HEADER_LEN; 224 } 225 226 231 public final int getDataBlockDisplacement() 232 { 233 return getNTParameter(7); 234 } 235 236 242 protected final int getNTParameter(int idx) 243 { 244 int pos = NTParams + (4 * idx); 245 return DataPacker.getIntelInt(getBuffer(), pos); 246 } 247 248 253 public final int getSetupCount() 254 { 255 byte[] buf = getBuffer(); 256 return (int) buf[NTSetupCount] & 0xFF; 257 } 258 259 264 public final int getSetupOffset() 265 { 266 return NTFunction + 2; 267 } 268 269 274 public final int getNTFunction() 275 { 276 byte[] buf = getBuffer(); 277 return DataPacker.getIntelShort(buf, NTFunction); 278 } 279 280 290 public final void initTransact(int func, byte[] paramblk, int plen, byte[] datablk, int dlen, int setupcnt) 291 { 292 initTransact(func, paramblk, plen, datablk, dlen, setupcnt, DefaultReturnParams, DefaultReturnData); 293 } 294 295 307 public final void initTransact(int func, byte[] paramblk, int plen, byte[] datablk, int dlen, int setupcnt, 308 int maxPrm, int maxData) 309 { 310 311 313 setCommand(PacketType.NTTransact); 314 setParameterCount(StandardParams + setupcnt); 315 316 318 setTotalParameterCount(plen); 319 setTotalDataCount(dlen); 320 setMaximumParameterReturn(maxPrm); 321 setMaximumDataReturn(maxData); 322 setParameterCount(plen); 323 setParameterBlockOffset(0); 324 setDataBlockCount(dlen); 325 setDataBlockOffset(0); 326 327 setSetupCount(setupcnt); 328 setNTFunction(func); 329 330 resetBytePointerAlign(); 331 332 334 if (paramblk != null) 335 { 336 337 339 setParameterBlockOffset(getPosition()); 340 341 343 packBytes(paramblk, plen); 344 } 345 346 348 if (datablk != null) 349 { 350 351 353 alignBytePointer(); 354 setDataBlockOffset(getPosition()); 355 356 358 packBytes(datablk, dlen); 359 } 360 361 363 setByteCount(); 364 } 365 366 374 public final void initTransactReply(byte[] paramblk, int plen, byte[] datablk, int dlen) 375 { 376 377 379 setParameterCount(ReplyParams); 380 setSetupCount(0); 381 382 384 setTotalParameterCount(plen); 385 setTotalDataCount(dlen); 386 387 setReplyParameterCount(plen); 388 setReplyParameterOffset(0); 389 setReplyParameterDisplacement(0); 390 391 setReplyDataCount(dlen); 392 setDataBlockOffset(0); 393 setReplyDataDisplacement(0); 394 395 setSetupCount(0); 396 397 resetBytePointerAlign(); 398 399 401 if (paramblk != null) 402 { 403 404 406 setReplyParameterOffset(getPosition() - 4); 407 408 410 packBytes(paramblk, plen); 411 } 412 413 415 if (datablk != null) 416 { 417 418 420 alignBytePointer(); 421 setReplyDataOffset(getPosition() - 4); 422 423 425 packBytes(datablk, dlen); 426 } 427 428 430 setByteCount(); 431 } 432 433 442 public final void initTransactReply(byte[] paramblk, int plen, byte[] datablk, int dlen, int setupCnt) 443 { 444 445 447 setParameterCount(ReplyParams + setupCnt); 448 setSetupCount(setupCnt); 449 450 452 setTotalParameterCount(plen); 453 setTotalDataCount(dlen); 454 455 setReplyParameterCount(plen); 456 setReplyParameterOffset(0); 457 setReplyParameterDisplacement(0); 458 459 setReplyDataCount(dlen); 460 setDataBlockOffset(0); 461 setReplyDataDisplacement(0); 462 463 setSetupCount(setupCnt); 464 465 resetBytePointerAlign(); 466 467 469 if (paramblk != null) 470 { 471 472 474 setReplyParameterOffset(getPosition() - 4); 475 476 478 packBytes(paramblk, plen); 479 } 480 481 483 if (datablk != null) 484 { 485 486 488 alignBytePointer(); 489 setReplyDataOffset(getPosition() - 4); 490 491 493 packBytes(datablk, dlen); 494 } 495 496 498 setByteCount(); 499 } 500 501 506 public final void setTotalParameterCount(int cnt) 507 { 508 setNTParameter(0, cnt); 509 } 510 511 516 public final void setTotalDataCount(int cnt) 517 { 518 setNTParameter(1, cnt); 519 } 520 521 526 public final void setMaximumParameterReturn(int cnt) 527 { 528 setNTParameter(2, cnt); 529 } 530 531 536 public final void setMaximumDataReturn(int cnt) 537 { 538 setNTParameter(3, cnt); 539 } 540 541 546 public final void setTransactParameterCount(int cnt) 547 { 548 setNTParameter(4, cnt); 549 } 550 551 556 public final void setReplyParameterCount(int cnt) 557 { 558 setNTParameter(2, cnt); 559 } 560 561 566 public final void setReplyParameterOffset(int off) 567 { 568 setNTParameter(3, off); 569 } 570 571 576 public final void setReplyParameterDisplacement(int disp) 577 { 578 setNTParameter(4, disp); 579 } 580 581 586 public final void setReplyDataCount(int cnt) 587 { 588 setNTParameter(5, cnt); 589 } 590 591 596 public final void setReplyDataOffset(int off) 597 { 598 setNTParameter(6, off); 599 } 600 601 606 public final void setReplyDataDisplacement(int disp) 607 { 608 setNTParameter(7, disp); 609 } 610 611 616 public final void setParameterBlockOffset(int off) 617 { 618 setNTParameter(5, off != 0 ? off - RFCNetBIOSProtocol.HEADER_LEN : 0); 619 } 620 621 626 public final void setDataBlockCount(int cnt) 627 { 628 setNTParameter(6, cnt); 629 } 630 631 636 public final void setDataBlockOffset(int off) 637 { 638 setNTParameter(7, off != 0 ? off - RFCNetBIOSProtocol.HEADER_LEN : 0); 639 } 640 641 647 public final void setNTParameter(int idx, int val) 648 { 649 int pos = NTParams + (4 * idx); 650 DataPacker.putIntelInt(val, getBuffer(), pos); 651 } 652 653 658 public final void setMaximumSetupCount(int cnt) 659 { 660 byte[] buf = getBuffer(); 661 buf[NTMaxSetupCount] = (byte) cnt; 662 } 663 664 669 public final void setSetupCount(int cnt) 670 { 671 byte[] buf = getBuffer(); 672 buf[NTSetupCount] = (byte) cnt; 673 } 674 675 681 public final void setSetupParameter(int setupIdx, int setupVal) 682 { 683 int pos = NTSetupCount + 1 + (setupIdx * 2); 684 DataPacker.putIntelShort(setupVal, getBuffer(), pos); 685 } 686 687 692 public final void setNTFunction(int func) 693 { 694 byte[] buf = getBuffer(); 695 DataPacker.putIntelShort(func, buf, NTFunction); 696 } 697 698 702 public final void resetSetupPointer() 703 { 704 m_pos = NTFunction + 2; 705 m_endpos = m_pos; 706 } 707 708 711 public final void resetDataBlockPointer() 712 { 713 m_pos = getDataBlockOffset(); 714 m_endpos = m_pos; 715 } 716 717 720 public final void resetParameterBlockPointer() 721 { 722 m_pos = getParameterBlockOffset(); 723 m_endpos = m_pos; 724 } 725 } 726 | Popular Tags |