1 17 package org.alfresco.filesys.server.auth.passthru; 18 19 import java.io.IOException ; 20 21 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 22 import org.alfresco.filesys.server.auth.PasswordEncryptor; 23 import org.alfresco.filesys.server.auth.ntlm.NTLM; 24 import org.alfresco.filesys.server.auth.ntlm.Type1NTLMMessage; 25 import org.alfresco.filesys.server.auth.ntlm.Type2NTLMMessage; 26 import org.alfresco.filesys.server.auth.ntlm.Type3NTLMMessage; 27 import org.alfresco.filesys.smb.Capability; 28 import org.alfresco.filesys.smb.Dialect; 29 import org.alfresco.filesys.smb.NTTime; 30 import org.alfresco.filesys.smb.NetworkSession; 31 import org.alfresco.filesys.smb.PCShare; 32 import org.alfresco.filesys.smb.PacketType; 33 import org.alfresco.filesys.smb.SMBDate; 34 import org.alfresco.filesys.smb.SMBException; 35 import org.alfresco.filesys.smb.SMBStatus; 36 import org.alfresco.filesys.util.DataPacker; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 45 public class AuthenticateSession 46 { 47 48 50 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol.auth"); 51 52 54 private static final int DefaultPacketSize = 1024; 55 56 58 public static final int SecurityModeUser = 1; 59 public static final int SecurityModeShare = 2; 60 61 63 protected final static int Closed = -1; 64 65 67 public static final int DEFAULT_BUFSIZE = 4096; 68 69 71 private int m_dialect; 72 private String m_diaStr; 73 74 76 private NetworkSession m_netSession; 77 78 80 protected SMBPacket m_pkt; 81 82 84 private int m_defFlags = SMBPacket.FLG_CASELESS; 85 private int m_defFlags2 = SMBPacket.FLG2_LONGFILENAMES; 86 87 89 private PCShare m_remoteShr; 90 91 93 private String m_domain; 94 95 97 private String m_srvOS; 98 private String m_srvLM; 99 100 102 private int m_secMode; 103 104 106 private byte[] m_encryptKey; 107 108 110 private int m_sessIdx; 111 private int m_userId; 112 private int m_processId; 113 114 116 protected int m_treeid; 117 118 120 private int m_devtype; 121 122 124 private int m_maxPktSize; 125 126 128 private int m_sessCaps; 129 130 132 private int m_maxVCs; 133 private int m_maxMPX; 134 135 138 private boolean m_guest; 139 140 142 private boolean m_extendedSec; 143 144 146 private byte[] m_serverGUID; 147 148 150 private Type2NTLMMessage m_type2Msg; 151 152 154 private static int m_sessionIdx = 1; 155 156 158 private static int m_multiplexId = 1; 159 160 170 protected AuthenticateSession(PCShare shr, NetworkSession sess, int dialect, SMBPacket pkt) throws IOException , SMBException 171 { 172 173 175 m_dialect = dialect; 176 177 179 m_remoteShr = shr; 180 181 183 m_sessIdx = getNextSessionId(); 184 185 187 m_pkt = pkt; 188 if (pkt == null) 189 m_pkt = new SMBPacket(DEFAULT_BUFSIZE); 190 191 193 setSession(sess); 194 195 197 processNegotiateResponse(); 198 } 199 200 207 protected final SMBPacket allocatePacket(int pref) 208 { 209 210 213 if (pref > m_maxPktSize) 214 return new SMBPacket(m_maxPktSize + RFCNetBIOSProtocol.HEADER_LEN); 215 216 218 return new SMBPacket(pref + RFCNetBIOSProtocol.HEADER_LEN); 219 } 220 221 226 public final boolean supportsExtendedSecurity() 227 { 228 return (m_sessCaps & Capability.ExtendedSecurity) != 0 ? true : false; 229 } 230 231 236 public final boolean supportsRawMode() 237 { 238 return (m_sessCaps & Capability.RawMode) != 0 ? true : false; 239 } 240 241 246 public final boolean supportsUnicode() 247 { 248 return (m_sessCaps & Capability.Unicode) != 0 ? true : false; 249 } 250 251 256 public final boolean supportsLargeFiles() 257 { 258 return (m_sessCaps & Capability.LargeFiles) != 0 ? true : false; 259 } 260 261 266 public final boolean supportsNTSmbs() 267 { 268 return (m_sessCaps & Capability.NTSMBs) != 0 ? true : false; 269 } 270 271 276 public final boolean supportsRPCAPIs() 277 { 278 return (m_sessCaps & Capability.RemoteAPIs) != 0 ? true : false; 279 } 280 281 286 public final boolean supportsNTStatusCodes() 287 { 288 return (m_sessCaps & Capability.NTStatus) != 0 ? true : false; 289 } 290 291 296 public final boolean supportsLevel2Oplocks() 297 { 298 return (m_sessCaps & Capability.Level2Oplocks) != 0 ? true : false; 299 } 300 301 306 public final boolean supportsLockAndRead() 307 { 308 return (m_sessCaps & Capability.LockAndRead) != 0 ? true : false; 309 } 310 311 316 public final boolean supportsNTFind() 317 { 318 return (m_sessCaps & Capability.NTFind) != 0 ? true : false; 319 } 320 321 327 public void CloseSession() throws java.io.IOException , SMBException 328 { 329 330 332 if (isActive()) 333 { 334 335 337 m_netSession.Close(); 338 339 341 m_netSession = null; 342 } 343 } 344 345 350 public final int getDefaultFlags() 351 { 352 return m_defFlags; 353 } 354 355 360 public final int getDefaultFlags2() 361 { 362 return m_defFlags2; 363 } 364 365 370 public final int getDeviceType() 371 { 372 return m_devtype; 373 } 374 375 380 public final int getDialect() 381 { 382 return m_dialect; 383 } 384 385 390 public final String getDialectString() 391 { 392 return m_diaStr; 393 } 394 395 400 public final String getDomain() 401 { 402 return m_domain; 403 } 404 405 410 public final boolean hasEncryptionKey() 411 { 412 return m_encryptKey != null ? true : false; 413 } 414 415 420 public final byte[] getEncryptionKey() 421 { 422 return m_encryptKey; 423 } 424 425 430 public final String getLANManagerType() 431 { 432 return m_srvLM; 433 } 434 435 440 public final int getMaximumMultiplexedRequests() 441 { 442 return m_maxMPX; 443 } 444 445 450 public final int getMaximumPacketSize() 451 { 452 return m_maxPktSize; 453 } 454 455 460 public final int getMaximumVirtualCircuits() 461 { 462 return m_maxVCs; 463 } 464 465 470 public final synchronized int getNextMultiplexId() 471 { 472 return m_multiplexId++; 473 } 474 475 480 protected final synchronized int getNextSessionId() 481 { 482 return m_sessionIdx++; 483 } 484 485 490 public final String getOperatingSystem() 491 { 492 return m_srvOS; 493 } 494 495 500 public final String getPassword() 501 { 502 return m_remoteShr.getPassword(); 503 } 504 505 510 public final PCShare getPCShare() 511 { 512 return m_remoteShr; 513 } 514 515 520 public final int getSecurityMode() 521 { 522 return m_secMode; 523 } 524 525 530 public final String getServer() 531 { 532 return m_remoteShr.getNodeName(); 533 } 534 535 540 public final NetworkSession getSession() 541 { 542 return m_netSession; 543 } 544 545 550 public final boolean hasType2NTLMMessage() 551 { 552 return m_type2Msg != null ? true : false; 553 } 554 555 560 public final Type2NTLMMessage getType2NTLMMessage() 561 { 562 return m_type2Msg; 563 } 564 565 570 public final int getCapabilities() 571 { 572 return m_sessCaps; 573 } 574 575 580 public final int getProcessId() 581 { 582 return m_processId; 583 } 584 585 590 public final int getSessionId() 591 { 592 return m_sessIdx; 593 } 594 595 600 public final String getShareName() 601 { 602 return m_remoteShr.getShareName(); 603 } 604 605 610 public final int getTreeId() 611 { 612 return m_treeid; 613 } 614 615 620 public final int getUserId() 621 { 622 return m_userId; 623 } 624 625 630 public final String getUserName() 631 { 632 return m_remoteShr.getUserName(); 633 } 634 635 641 public final boolean hasDataAvailable() throws IOException 642 { 643 return m_netSession.hasData(); 644 } 645 646 651 public final boolean isActive() 652 { 653 return (m_netSession == null) ? false : true; 654 } 655 656 661 public final boolean isGuest() 662 { 663 return m_guest; 664 } 665 666 671 public final boolean isUnicode() 672 { 673 return (m_defFlags2 & SMBPacket.FLG2_UNICODE) != 0 ? true : false; 674 } 675 676 681 public final boolean isUsingExtendedSecurity() 682 { 683 return m_extendedSec; 684 } 685 686 692 public final void pingServer() throws java.io.IOException , SMBException 693 { 694 695 697 pingServer(1); 698 } 699 700 707 public final void pingServer(int cnt) throws java.io.IOException , SMBException 708 { 709 710 712 m_pkt.setCommand(PacketType.Echo); 713 m_pkt.setFlags(0); 714 m_pkt.setTreeId(getTreeId()); 715 m_pkt.setUserId(getUserId()); 716 m_pkt.setProcessId(getProcessId()); 717 m_pkt.setMultiplexId(1); 718 719 721 m_pkt.setParameterCount(1); 722 m_pkt.setParameter(0, cnt); String echoStr = "ECHO"; 724 m_pkt.setBytes(echoStr.getBytes()); 725 726 728 m_pkt.SendSMB(this); 729 730 732 while (cnt > 0) 733 { 734 735 737 m_pkt.ReceiveSMB(this); 738 739 741 cnt--; 742 } 743 } 744 745 750 protected final void setDefaultFlags(int flg) 751 { 752 m_defFlags = flg; 753 } 754 755 760 protected final void setDefaultFlags2(int flg2) 761 { 762 m_defFlags2 = flg2; 763 } 764 765 770 protected final void setDeviceType(int dev) 771 { 772 m_devtype = dev; 773 } 774 775 780 protected final void setDialect(int dia) 781 { 782 m_dialect = dia; 783 } 784 785 790 protected final void setDialectString(String dia) 791 { 792 m_diaStr = dia; 793 } 794 795 800 protected final void setDomain(String dom) 801 { 802 m_domain = dom; 803 } 804 805 810 public final void setEncryptionKey(byte[] key) 811 { 812 813 815 m_encryptKey = key; 816 } 817 818 823 protected final void setGuest(boolean sts) 824 { 825 m_guest = sts; 826 } 827 828 833 protected final void setLANManagerType(String lm) 834 { 835 m_srvLM = lm; 836 } 837 838 843 protected final void setMaximumMultiplexedRequests(int maxMulti) 844 { 845 m_maxMPX = maxMulti; 846 } 847 848 853 protected final void setMaximumPacketSize(int siz) 854 { 855 m_maxPktSize = siz; 856 } 857 858 863 protected final void setMaximumVirtualCircuits(int maxVC) 864 { 865 m_maxVCs = maxVC; 866 } 867 868 873 protected final void setOperatingSystem(String os) 874 { 875 m_srvOS = os; 876 } 877 878 883 protected final void setPassword(String pwd) 884 { 885 m_remoteShr.setPassword(pwd); 886 } 887 888 893 public final void setSecurityMode(int secMode) 894 { 895 m_secMode = secMode; 896 } 897 898 903 protected final void setServer(String srv) 904 { 905 m_remoteShr.setNodeName(srv); 906 } 907 908 913 protected final void setSession(NetworkSession netSess) 914 { 915 m_netSession = netSess; 916 } 917 918 923 protected final void setCapabilities(int caps) 924 { 925 m_sessCaps = caps; 926 } 927 928 933 protected final void setShareName(String shr) 934 { 935 m_remoteShr.setShareName(shr); 936 } 937 938 943 protected final void setProcessId(int id) 944 { 945 m_processId = id; 946 } 947 948 953 protected final void setTreeId(int id) 954 { 955 m_treeid = id; 956 } 957 958 963 protected final void setUserId(int uid) 964 { 965 m_userId = uid; 966 } 967 968 973 protected final void setUserName(String user) 974 { 975 m_remoteShr.setUserName(user); 976 } 977 978 983 public String toString() 984 { 985 StringBuffer str = new StringBuffer (); 986 987 str.append("[\\\\"); 988 str.append(getServer()); 989 str.append("\\"); 990 str.append(getShareName()); 991 str.append(":"); 992 str.append(Dialect.DialectTypeString(m_dialect)); 993 str.append(",UserId="); 994 str.append(getUserId()); 995 str.append("]"); 996 997 return str.toString(); 998 } 999 1000 1009 public final void doSessionSetup(String userName, byte[] ascPwd, byte[] uniPwd) throws IOException , SMBException 1010 { 1011 doSessionSetup(null, userName, null, ascPwd, uniPwd); 1012 } 1013 1014 1021 public final void doSessionSetup(Type3NTLMMessage type3Msg) throws IOException , SMBException 1022 { 1023 doSessionSetup(type3Msg.getDomain(), type3Msg.getUserName(), type3Msg.getWorkstation(), 1024 type3Msg.getLMHash(), type3Msg.getNTLMHash()); 1025 } 1026 1027 1038 public final void doSessionSetup(String domain, String userName, String wksName, 1039 byte[] ascPwd, byte[] uniPwd) throws IOException , SMBException 1040 { 1041 1043 if ( isUsingExtendedSecurity()) 1044 { 1045 1047 doExtendedSessionSetupPhase2(domain, userName, wksName, ascPwd, uniPwd); 1048 return; 1049 } 1050 1051 1053 SMBPacket pkt = new SMBPacket(); 1054 1055 pkt.setCommand(PacketType.SessionSetupAndX); 1056 1057 1059 if (getDialect() == Dialect.NT) 1060 { 1061 1062 1064 pkt.setParameterCount(13); 1065 pkt.setAndXCommand(0xFF); pkt.setParameter(1, 0); pkt.setParameter(2, DefaultPacketSize); 1068 pkt.setParameter(3, 1); 1069 pkt.setParameter(4, 0); pkt.setParameterLong(5, 0); 1072 1074 pkt.setParameter(7, ascPwd != null ? ascPwd.length : 0); pkt.setParameter(8, uniPwd != null ? uniPwd.length : 0); 1077 pkt.setParameter(9, 0); pkt.setParameter(10, 0); 1080 1082 int caps = Capability.LargeFiles + Capability.Unicode + Capability.NTSMBs + Capability.NTStatus 1083 + Capability.RemoteAPIs; 1084 1085 1087 pkt.setParameterLong(11, caps); 1088 1089 1091 int pos = pkt.getByteOffset(); 1092 pkt.setPosition(pos); 1093 1094 1096 if (ascPwd != null) 1097 pkt.packBytes(ascPwd, ascPwd.length); 1098 1099 1101 if (uniPwd != null) 1102 pkt.packBytes(uniPwd, uniPwd.length); 1103 1104 1106 pkt.packString(userName, false); 1107 1108 1110 if (getPCShare().hasDomain()) 1111 pkt.packString(getPCShare().getDomain(), false); 1112 else 1113 pkt.packString("?", false); 1114 1115 pkt.packString("Java VM", false); 1116 pkt.packString("JLAN", false); 1117 1118 1120 pkt.setByteCount(pkt.getPosition() - pos); 1121 } 1122 else 1123 { 1124 1125 1127 pkt.setUserId(1); 1128 1129 pkt.setParameterCount(10); 1130 pkt.setAndXCommand(0xFF); 1131 pkt.setParameter(1, 0); 1132 pkt.setParameter(2, DefaultPacketSize); 1133 pkt.setParameter(3, 1); 1134 pkt.setParameter(4, 0); 1135 pkt.setParameter(5, 0); 1136 pkt.setParameter(6, 0); 1137 pkt.setParameter(7, ascPwd != null ? ascPwd.length : 0); 1138 pkt.setParameter(8, 0); 1139 pkt.setParameter(9, 0); 1140 1141 1143 byte[] buf = pkt.getBuffer(); 1144 int pos = pkt.getByteOffset(); 1145 1146 if (ascPwd != null) 1147 { 1148 for (int i = 0; i < ascPwd.length; i++) 1149 buf[pos++] = ascPwd[i]; 1150 } 1151 1152 1154 StringBuffer clbuf = new StringBuffer (); 1155 1156 clbuf.append(getPCShare().getUserName()); 1157 clbuf.append((char) 0x00); 1158 1159 1161 if (getPCShare().hasDomain()) 1162 clbuf.append(getPCShare().getDomain()); 1163 else 1164 clbuf.append("?"); 1165 clbuf.append((char) 0x00); 1166 1167 clbuf.append("Java VM"); 1168 clbuf.append((char) 0x00); 1169 1170 clbuf.append("JLAN"); 1171 clbuf.append((char) 0x00); 1172 1173 1175 byte[] byts = clbuf.toString().getBytes(); 1176 for (int i = 0; i < byts.length; i++) 1177 buf[pos++] = byts[i]; 1178 1179 int pwdLen = ascPwd != null ? ascPwd.length : 0; 1180 pkt.setByteCount(pwdLen + byts.length); 1181 } 1182 1183 1185 pkt.ExchangeSMB(this, pkt, true); 1186 1187 1189 setUserId(pkt.getUserId()); 1190 1191 1193 if (pkt.getParameterCount() >= 3) 1194 { 1195 1196 1198 setGuest(pkt.getParameter(2) != 0 ? true : false); 1199 } 1200 1201 1204 if (pkt.getByteCount() > 0) 1205 { 1206 1207 1209 byte[] buf = pkt.getBuffer(); 1210 int offset = pkt.getByteOffset(); 1211 int maxlen = offset + pkt.getByteCount(); 1212 1213 1215 String srvOS = DataPacker.getString(buf, offset, maxlen); 1216 setOperatingSystem(srvOS); 1217 1218 offset += srvOS.length() + 1; 1219 maxlen -= srvOS.length() + 1; 1220 1221 1223 String lanman = DataPacker.getString(buf, offset, maxlen); 1224 setLANManagerType(lanman); 1225 1226 1228 if (getDomain() == null || getDomain().length() == 0) 1229 { 1230 1231 1233 offset += lanman.length() + 1; 1234 maxlen += lanman.length() + 1; 1235 1236 String dom = DataPacker.getString(buf, offset, maxlen); 1237 setDomain(dom); 1238 } 1239 } 1240 1241 1243 if (getDialect() == Dialect.Core || getDialect() == Dialect.CorePlus) 1244 { 1245 1246 1248 setMaximumPacketSize(pkt.getParameter(2)); 1249 } 1250 } 1251 1252 1258 private void processNegotiateResponse() throws IOException , SMBException 1259 { 1260 1261 1263 int keyLen = 0; 1264 boolean unicodeStr = false; 1265 int encAlgorithm = PasswordEncryptor.LANMAN; 1266 int defFlags2 = 0; 1267 1268 if (getDialect() == Dialect.NT) 1269 { 1270 1271 1273 m_pkt.resetParameterPointer(); 1274 m_pkt.skipBytes(2); 1276 setSecurityMode(m_pkt.unpackByte()); 1277 1278 1280 setMaximumMultiplexedRequests(m_pkt.unpackWord()); 1281 setMaximumVirtualCircuits(m_pkt.unpackWord()); 1282 1283 1285 setMaximumPacketSize(m_pkt.unpackInt()); 1286 1287 1289 m_pkt.skipBytes(8); 1290 1291 1293 setCapabilities(m_pkt.unpackInt()); 1294 1295 1297 if ( supportsExtendedSecurity()) 1298 m_extendedSec = true; 1299 1300 1302 SMBDate srvTime = NTTime.toSMBDate(m_pkt.unpackLong()); 1303 int tzone = m_pkt.unpackWord(); 1304 1305 1307 keyLen = m_pkt.unpackByte(); 1308 1309 1311 unicodeStr = true; 1312 1313 1315 encAlgorithm = PasswordEncryptor.NTLM1; 1316 1317 1319 defFlags2 = SMBPacket.FLG2_LONGFILENAMES + SMBPacket.FLG2_UNICODE + SMBPacket.FLG2_LONGERRORCODE; 1320 1321 if ( isUsingExtendedSecurity()) 1322 defFlags2 += SMBPacket.FLG2_EXTENDEDSECURITY; 1323 } 1324 else if (getDialect() > Dialect.CorePlus) 1325 { 1326 1327 1329 int secMode = m_pkt.getParameter(1); 1330 setSecurityMode((secMode & 0x01) != 0 ? SecurityModeUser : SecurityModeShare); 1331 1332 if (m_pkt.getParameterCount() >= 11) 1333 keyLen = m_pkt.getParameter(11) & 0xFF; 1335 1337 setMaximumMultiplexedRequests(m_pkt.getParameter(3)); 1338 setMaximumVirtualCircuits(m_pkt.getParameter(4)); 1339 1340 1342 if (m_pkt.isUnicode()) 1343 unicodeStr = true; 1344 1345 1347 defFlags2 = SMBPacket.FLG2_LONGFILENAMES; 1348 } 1349 1350 1352 setDefaultFlags2(defFlags2); 1353 1354 1356 if (m_pkt.getByteCount() > 0) 1357 { 1358 1359 1361 int bytsiz = m_pkt.getByteCount(); 1362 int bytpos = m_pkt.getByteOffset(); 1363 byte[] buf = m_pkt.getBuffer(); 1364 1365 1367 if ( isUsingExtendedSecurity() == false) 1368 { 1369 1371 if (keyLen > 0) 1372 { 1373 1374 1376 byte[] encryptKey = new byte[keyLen]; 1377 1378 1380 for (int keyIdx = 0; keyIdx < keyLen; keyIdx++) 1381 encryptKey[keyIdx] = buf[bytpos++]; 1382 1383 1385 setEncryptionKey(encryptKey); 1386 } 1387 1388 1390 String dom; 1391 1392 if (unicodeStr == false) 1393 dom = DataPacker.getString(buf, bytpos, bytsiz); 1394 else 1395 dom = DataPacker.getUnicodeString(buf, bytpos, bytsiz / 2); 1396 setDomain(dom); 1397 } 1398 else 1399 { 1400 1402 m_serverGUID = new byte[16]; 1403 System.arraycopy(buf, bytpos, m_serverGUID, 0, 16); 1404 1405 1408 doExtendedSessionSetupPhase1(); 1409 } 1410 } 1411 } 1412 1413 1419 private final void doExtendedSessionSetupPhase1() throws IOException , SMBException 1420 { 1421 1423 SMBPacket pkt = new SMBPacket(); 1424 1425 pkt.setCommand(PacketType.SessionSetupAndX); 1426 1427 pkt.setFlags(getDefaultFlags()); 1428 pkt.setFlags2(getDefaultFlags2()); 1429 1430 1432 pkt.setParameterCount(12); 1433 pkt.setAndXCommand(0xFF); pkt.setParameter(1, 0); pkt.setParameter(2, DefaultPacketSize); 1436 pkt.setParameter(3, 1); 1437 pkt.setParameter(4, 0); pkt.setParameterLong(5, 0); 1440 1442 pkt.setParameter(7, 0); pkt.setParameterLong(8, 0); 1445 1447 int caps = Capability.LargeFiles + Capability.Unicode + Capability.NTSMBs + Capability.NTStatus 1448 + Capability.RemoteAPIs + Capability.ExtendedSecurity; 1449 1450 1452 pkt.setParameterLong(10, caps); 1453 1454 1456 int pos = pkt.getByteOffset(); 1457 pkt.setPosition(pos); 1458 1459 1461 Type1NTLMMessage type1Msg = new Type1NTLMMessage(pkt.getBuffer(), pos, 0); 1462 1463 int type1Flags = getPCShare().getExtendedSecurityFlags(); 1464 if ( type1Flags == 0) 1465 type1Flags = NTLM.FlagNegotiateUnicode + NTLM.FlagNegotiateNTLM + NTLM.FlagRequestTarget; 1466 1467 type1Msg.buildType1(type1Flags, null, null); 1468 1469 1471 pkt.setPosition(pos + type1Msg.getLength()); 1472 1473 1475 pkt.setParameter(7, type1Msg.getLength()); 1476 1477 1479 pkt.packString("Java VM", true); 1480 pkt.packString("JLAN", true); 1481 1482 pkt.packString("", true); 1483 1484 1486 pkt.setByteCount(pkt.getPosition() - pos); 1487 1488 1490 pkt.ExchangeSMB(this, pkt, false); 1491 1492 1494 if ( pkt.isLongErrorCode() == false || pkt.getLongErrorCode() != SMBStatus.NTMoreProcessingRequired) 1495 pkt.checkForError(); 1496 1497 1499 setUserId(pkt.getUserId()); 1500 1501 1503 int type2Len = pkt.getParameter(3); 1504 if (pkt.getByteCount() > 0) 1505 { 1506 1507 1509 byte[] buf = pkt.getBuffer(); 1510 int offset = pkt.getByteOffset(); 1511 int maxlen = offset + pkt.getByteCount(); 1512 1513 1515 m_type2Msg = new Type2NTLMMessage(); 1516 m_type2Msg.copyFrom(buf, offset, type2Len); 1517 1518 1520 m_encryptKey = m_type2Msg.getChallenge(); 1521 1522 1524 offset = DataPacker.wordAlign(offset + type2Len); 1525 maxlen -= type2Len; 1526 1527 1529 String srvOS = DataPacker.getString(buf, offset, maxlen); 1530 setOperatingSystem(srvOS); 1531 1532 offset += srvOS.length() + 1; 1533 maxlen -= srvOS.length() + 1; 1534 1535 1537 String lanman = DataPacker.getString(buf, offset, maxlen); 1538 setLANManagerType(lanman); 1539 } 1540 } 1541 1542 1553 private final void doExtendedSessionSetupPhase2(String domain, String userName, String wksName, 1554 byte[] lmPwd, byte[] ntlmPwd) throws IOException , SMBException 1555 { 1556 1559 if ( domain == null) 1560 { 1561 if ( getPCShare().hasDomain() && getPCShare().getDomain().length() > 0) 1562 domain = getPCShare().getDomain(); 1563 else 1564 domain = m_type2Msg.getTarget(); 1565 } 1566 1567 1569 SMBPacket pkt = new SMBPacket(); 1570 1571 pkt.setCommand(PacketType.SessionSetupAndX); 1572 1573 pkt.setFlags(getDefaultFlags()); 1574 pkt.setFlags2(getDefaultFlags2()); 1575 1576 pkt.setUserId(getUserId()); 1577 1578 1580 pkt.setParameterCount(12); 1581 pkt.setAndXCommand(0xFF); pkt.setParameter(1, 0); pkt.setParameter(2, DefaultPacketSize); 1584 pkt.setParameter(3, 1); 1585 pkt.setParameter(4, 0); pkt.setParameterLong(5, 0); 1588 1590 pkt.setParameter(7, 0); pkt.setParameterLong(8, 0); 1593 1595 int caps = Capability.LargeFiles + Capability.Unicode + Capability.NTSMBs + Capability.NTStatus 1596 + Capability.RemoteAPIs + Capability.ExtendedSecurity; 1597 1598 1600 pkt.setParameterLong(10, caps); 1601 1602 1604 int pos = pkt.getByteOffset(); 1605 pkt.setPosition(pos); 1606 1607 1609 Type3NTLMMessage type3Msg = new Type3NTLMMessage(pkt.getBuffer(), pos, 0, true); 1610 1611 type3Msg.buildType3(lmPwd, ntlmPwd, domain, userName, wksName != null ? wksName : "", null, m_type2Msg.getFlags()); 1612 1613 1615 pkt.setPosition(pos + type3Msg.getLength()); 1616 1617 1619 pkt.setParameter(7, type3Msg.getLength()); 1620 1621 1623 pkt.packString("Java VM", true); 1624 pkt.packString("JLAN", true); 1625 1626 pkt.packString("", true); 1627 1628 1630 pkt.setByteCount(pkt.getPosition() - pos); 1631 1632 1634 pkt.ExchangeSMB(this, pkt, true); 1635 1636 1638 setGuest(pkt.getParameter(2) != 0 ? true : false); 1639 } 1640} 1641 | Popular Tags |