1 17 package org.alfresco.filesys.smb.server; 18 19 import java.io.IOException ; 20 import java.util.Enumeration ; 21 22 import org.alfresco.filesys.server.core.ShareType; 23 import org.alfresco.filesys.server.core.SharedDevice; 24 import org.alfresco.filesys.server.core.SharedDeviceList; 25 import org.alfresco.filesys.smb.PacketType; 26 import org.alfresco.filesys.smb.SMBStatus; 27 import org.alfresco.filesys.smb.TransactBuffer; 28 import org.alfresco.filesys.util.DataBuffer; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 35 class PipeLanmanHandler 36 { 37 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 38 39 41 public static final int WorkStation = 0x00000001; 42 public static final int Server = 0x00000002; 43 public static final int SQLServer = 0x00000004; 44 public static final int DomainCtrl = 0x00000008; 45 public static final int DomainBakCtrl = 0x00000010; 46 public static final int TimeSource = 0x00000020; 47 public static final int AFPServer = 0x00000040; 48 public static final int NovellServer = 0x00000080; 49 public static final int DomainMember = 0x00000100; 50 public static final int PrintServer = 0x00000200; 51 public static final int DialinServer = 0x00000400; 52 public static final int UnixServer = 0x00000800; 53 public static final int NTServer = 0x00001000; 54 public static final int WfwServer = 0x00002000; 55 public static final int MFPNServer = 0x00004000; 56 public static final int NTNonDCServer = 0x00008000; 57 public static final int PotentialBrowse = 0x00010000; 58 public static final int BackupBrowser = 0x00020000; 59 public static final int MasterBrowser = 0x00040000; 60 public static final int DomainMaster = 0x00080000; 61 public static final int OSFServer = 0x00100000; 62 public static final int VMSServer = 0x00200000; 63 public static final int Win95Plus = 0x00400000; 64 public static final int DFSRoot = 0x00800000; 65 public static final int NTCluster = 0x01000000; 66 public static final int TerminalServer = 0x02000000; 67 public static final int DCEServer = 0x10000000; 68 public static final int AlternateXport = 0x20000000; 69 public static final int LocalListOnly = 0x40000000; 70 public static final int DomainEnum = 0x80000000; 71 72 82 public final static boolean processRequest(TransactBuffer tbuf, SMBSrvSession sess, SMBSrvPacket trans) 83 throws IOException , SMBSrvException 84 { 85 86 88 SMBSrvTransPacket tpkt = new SMBSrvTransPacket(trans.getBuffer()); 89 90 93 DataBuffer paramBuf = tbuf.getParameterBuffer(); 94 95 int cmd = paramBuf.getShort(); 96 String prmDesc = paramBuf.getString(false); 97 String dataDesc = paramBuf.getString(false); 98 99 101 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 102 logger.debug("\\PIPE\\LANMAN\\ transact request, cmd=" + cmd + ", prm=" + prmDesc + ", data=" + dataDesc); 103 104 106 boolean processed = false; 107 108 switch (cmd) 109 { 110 111 113 case PacketType.RAPShareEnum: 114 processed = procNetShareEnum(sess, tbuf, prmDesc, dataDesc, tpkt); 115 break; 116 117 119 case PacketType.RAPShareGetInfo: 120 processed = procNetShareGetInfo(sess, tbuf, prmDesc, dataDesc, tpkt); 121 break; 122 123 125 case PacketType.RAPWkstaGetInfo: 126 processed = procNetWkstaGetInfo(sess, tbuf, prmDesc, dataDesc, tpkt); 127 break; 128 129 131 case PacketType.RAPServerGetInfo: 132 processed = procNetServerGetInfo(sess, tbuf, prmDesc, dataDesc, tpkt); 133 break; 134 135 137 case PacketType.NetPrintQGetInfo: 138 processed = procNetPrintQGetInfo(sess, tbuf, prmDesc, dataDesc, tpkt); 139 break; 140 141 143 default: 144 145 147 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 148 logger.debug("No handler for \\PIPE\\LANMAN\\ request, cmd=" + cmd + ", prm=" + prmDesc + ", data=" 149 + dataDesc); 150 break; 151 } 152 153 155 return processed; 156 } 157 158 168 protected final static boolean procNetServerGetInfo(SMBSrvSession sess, TransactBuffer tbuf, String prmDesc, 169 String dataDesc, SMBSrvTransPacket tpkt) throws IOException , SMBSrvException 170 { 171 172 174 if (prmDesc.compareTo("WrLh") != 0) 175 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 176 177 179 DataBuffer paramBuf = tbuf.getParameterBuffer(); 180 181 int infoLevel = paramBuf.getShort(); 182 int bufSize = paramBuf.getShort(); 183 184 186 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 187 logger.debug("NetServerGetInfo infoLevel=" + infoLevel); 188 189 191 if (infoLevel == 1 && dataDesc.compareTo("B16BBDz") == 0) 192 { 193 194 196 TransactBuffer replyBuf = new TransactBuffer(tbuf.isType(), 0, 6, 1024); 197 198 200 paramBuf = replyBuf.getParameterBuffer(); 201 202 paramBuf.putShort(0); paramBuf.putShort(0); paramBuf.putShort(1); 206 208 DataBuffer dataBuf = replyBuf.getDataBuffer(); 209 int strPos = SMBSrvTransPacket.CalculateDataItemSize("B16BBDz"); 210 211 213 dataBuf.putStringPointer(strPos); 214 strPos = dataBuf.putFixedStringAt(sess.getServerName(), 16, strPos); 215 216 218 dataBuf.putByte(1); 219 dataBuf.putByte(0); 220 221 223 dataBuf.putInt(sess.getSMBServer().getServerType()); 224 225 227 String srvComment = sess.getSMBServer().getComment(); 228 if (srvComment == null) 229 srvComment = ""; 230 231 dataBuf.putStringPointer(strPos); 232 strPos = dataBuf.putStringAt(srvComment, strPos, false, true); 233 234 236 dataBuf.setLength(strPos); 237 238 240 tpkt.doTransactionResponse(sess, replyBuf); 241 } 242 else 243 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 244 245 247 return true; 248 } 249 250 260 protected final static boolean procNetShareEnum(SMBSrvSession sess, TransactBuffer tbuf, String prmDesc, 261 String dataDesc, SMBSrvTransPacket tpkt) throws IOException , SMBSrvException 262 { 263 264 266 if (prmDesc.compareTo("WrLeh") != 0) 267 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 268 269 271 DataBuffer paramBuf = tbuf.getParameterBuffer(); 272 273 int infoLevel = paramBuf.getShort(); 274 int bufSize = paramBuf.getShort(); 275 276 278 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 279 logger.debug("NetShareEnum infoLevel=" + infoLevel); 280 281 283 if (infoLevel == 1 && dataDesc.compareTo("B13BWz") == 0) 284 { 285 286 288 SharedDeviceList shrList = sess.getSMBServer().getShareList(null, sess); 289 int shrCount = 0; 290 int strPos = 0; 291 292 if (shrList != null) 293 { 294 295 297 shrCount = shrList.numberOfShares(); 298 strPos = SMBSrvTransPacket.CalculateDataItemSize("B13BWz") * shrCount; 299 } 300 301 303 TransactBuffer replyBuf = new TransactBuffer(tbuf.isType(), 0, 6, bufSize); 304 305 307 paramBuf = replyBuf.getParameterBuffer(); 308 309 paramBuf.putShort(0); paramBuf.putShort(0); paramBuf.putShort(shrCount); paramBuf.putShort(shrCount); 314 316 DataBuffer dataBuf = replyBuf.getDataBuffer(); 317 Enumeration <SharedDevice> enm = shrList.enumerateShares(); 318 319 while (enm.hasMoreElements()) 320 { 321 322 324 SharedDevice shrDev = enm.nextElement(); 325 326 328 dataBuf.putFixedString(shrDev.getName(), 13); 329 dataBuf.putByte(0); 330 dataBuf.putShort(ShareType.asShareInfoType(shrDev.getType())); 331 dataBuf.putStringPointer(strPos); 332 333 if (shrDev.getComment() != null) 334 strPos = dataBuf.putStringAt(shrDev.getComment(), strPos, false, true); 335 else 336 strPos = dataBuf.putStringAt("", strPos, false, true); 337 } 338 339 341 dataBuf.setLength(strPos); 342 343 345 tpkt.doTransactionResponse(sess, replyBuf); 346 } 347 else 348 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 349 350 352 return true; 353 } 354 355 365 protected final static boolean procNetShareGetInfo(SMBSrvSession sess, TransactBuffer tbuf, String prmDesc, 366 String dataDesc, SMBSrvTransPacket tpkt) throws IOException , SMBSrvException 367 { 368 369 371 if (prmDesc.compareTo("zWrLh") != 0) 372 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 373 374 376 DataBuffer paramBuf = tbuf.getParameterBuffer(); 377 378 String shareName = paramBuf.getString(32, false); 379 int infoLevel = paramBuf.getShort(); 380 int bufSize = paramBuf.getShort(); 381 382 384 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 385 logger.debug("NetShareGetInfo - " + shareName + ", infoLevel=" + infoLevel); 386 387 389 if (infoLevel == 1 && dataDesc.compareTo("B13BWz") == 0) 390 { 391 392 394 SharedDevice share = null; 395 396 try 397 { 398 399 401 share = sess.getSMBServer().findShare(null, shareName, ShareType.UNKNOWN, sess, false); 402 } 403 catch (Exception ex) 404 { 405 } 406 407 if (share == null) 408 { 409 sess.sendErrorResponseSMB(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 410 return true; 411 } 412 413 415 TransactBuffer replyBuf = new TransactBuffer(tbuf.isType(), 0, 6, 1024); 416 417 419 paramBuf = replyBuf.getParameterBuffer(); 420 421 paramBuf.putShort(0); paramBuf.putShort(0); paramBuf.putShort(1); 425 427 DataBuffer dataBuf = replyBuf.getDataBuffer(); 428 int strPos = SMBSrvTransPacket.CalculateDataItemSize("B13BWz"); 429 430 432 dataBuf.putStringPointer(strPos); 433 strPos = dataBuf.putFixedStringAt(share.getName(), 13, strPos); 434 435 437 dataBuf.putByte(0); 438 439 441 dataBuf.putShort(share.getType()); 442 443 445 dataBuf.putStringPointer(strPos); 446 447 if (share.getComment() != null) 448 strPos = dataBuf.putStringAt(share.getComment(), strPos, false, true); 449 else 450 strPos = dataBuf.putStringAt("", strPos, false, true); 451 452 454 dataBuf.setLength(strPos); 455 456 458 tpkt.doTransactionResponse(sess, replyBuf); 459 } 460 else 461 { 462 463 465 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 466 logger.debug("NetShareGetInfo - UNSUPPORTED " + shareName + ", infoLevel=" + infoLevel + ", dataDesc=" 467 + dataDesc); 468 469 471 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 472 } 473 474 476 return true; 477 } 478 479 489 protected final static boolean procNetWkstaGetInfo(SMBSrvSession sess, TransactBuffer tbuf, String prmDesc, 490 String dataDesc, SMBSrvTransPacket tpkt) throws IOException , SMBSrvException 491 { 492 493 495 if (prmDesc.compareTo("WrLh") != 0) 496 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 497 498 500 DataBuffer paramBuf = tbuf.getParameterBuffer(); 501 502 int infoLevel = paramBuf.getShort(); 503 int bufSize = paramBuf.getShort(); 504 505 507 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 508 logger.debug("NetWkstaGetInfo infoLevel=" + infoLevel); 509 510 512 if ((infoLevel == 1 && dataDesc.compareTo("zzzBBzzz") == 0) 513 || (infoLevel == 10 && dataDesc.compareTo("zzzBBzz") == 0)) 514 { 515 516 518 TransactBuffer replyBuf = new TransactBuffer(tbuf.isType(), 0, 6, 1024); 519 520 522 DataBuffer dataBuf = replyBuf.getDataBuffer(); 523 int strPos = SMBSrvTransPacket.CalculateDataItemSize(dataDesc); 524 525 527 dataBuf.putStringPointer(strPos); 528 strPos = dataBuf.putStringAt(sess.getServerName(), strPos, false, true); 529 530 532 dataBuf.putStringPointer(strPos); 533 strPos = dataBuf.putStringAt("", strPos, false, true); 534 535 537 dataBuf.putStringPointer(strPos); 538 539 String domain = sess.getServer().getConfiguration().getDomainName(); 540 if (domain == null) 541 domain = ""; 542 strPos = dataBuf.putStringAt(domain, strPos, false, true); 543 544 546 dataBuf.putByte(4); 547 dataBuf.putByte(2); 548 549 551 dataBuf.putStringPointer(strPos); 552 strPos = dataBuf.putStringAt("", strPos, false, true); 553 554 556 if (infoLevel == 1 && dataDesc.compareTo("zzzBBzzz") == 0) 557 { 558 559 561 dataBuf.putStringPointer(strPos); 562 strPos = dataBuf.putStringAt("", strPos, false, true); 563 } 564 565 567 dataBuf.setLength(strPos); 568 569 571 paramBuf = replyBuf.getParameterBuffer(); 572 573 paramBuf.putShort(0); paramBuf.putShort(0); paramBuf.putShort(dataBuf.getLength()); 576 paramBuf.putShort(0); 578 580 tpkt.doTransactionResponse(sess, replyBuf); 581 } 582 else 583 { 584 585 587 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 588 logger.debug("NetWkstaGetInfo UNSUPPORTED infoLevel=" + infoLevel + ", dataDesc=" + dataDesc); 589 590 592 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 593 } 594 595 597 return true; 598 } 599 600 610 protected final static boolean procNetPrintQGetInfo(SMBSrvSession sess, TransactBuffer tbuf, String prmDesc, 611 String dataDesc, SMBSrvTransPacket tpkt) throws IOException , SMBSrvException 612 { 613 614 616 if (prmDesc.compareTo("zWrLh") != 0) 617 throw new SMBSrvException(SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv); 618 619 621 DataBuffer paramBuf = tbuf.getParameterBuffer(); 622 623 String shareName = paramBuf.getString(32, false); 624 int infoLevel = paramBuf.getShort(); 625 int bufSize = paramBuf.getShort(); 626 627 629 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC)) 630 logger.debug("NetPrintQGetInfo - " + shareName + ", infoLevel=" + infoLevel); 631 632 634 return false; 635 } 636 } | Popular Tags |