1 17 package org.alfresco.filesys.smb.dcerpc.server; 18 19 import java.io.IOException ; 20 import java.util.Enumeration ; 21 import java.util.Vector ; 22 23 import org.alfresco.filesys.server.auth.acl.AccessControlManager; 24 import org.alfresco.filesys.server.config.ServerConfiguration; 25 import org.alfresco.filesys.server.core.ShareType; 26 import org.alfresco.filesys.server.core.SharedDevice; 27 import org.alfresco.filesys.server.core.SharedDeviceList; 28 import org.alfresco.filesys.smb.Dialect; 29 import org.alfresco.filesys.smb.SMBStatus; 30 import org.alfresco.filesys.smb.dcerpc.DCEBuffer; 31 import org.alfresco.filesys.smb.dcerpc.DCEBufferException; 32 import org.alfresco.filesys.smb.dcerpc.Srvsvc; 33 import org.alfresco.filesys.smb.dcerpc.info.ServerInfo; 34 import org.alfresco.filesys.smb.dcerpc.info.ShareInfo; 35 import org.alfresco.filesys.smb.dcerpc.info.ShareInfoList; 36 import org.alfresco.filesys.smb.server.SMBServer; 37 import org.alfresco.filesys.smb.server.SMBSrvException; 38 import org.alfresco.filesys.smb.server.SMBSrvSession; 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 45 public class SrvsvcDCEHandler implements DCEHandler 46 { 47 48 50 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 51 52 61 public void processRequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile) throws IOException , 62 SMBSrvException 63 { 64 65 67 int opNum = inBuf.getHeaderValue(DCEBuffer.HDR_OPCODE); 68 try 69 { 70 inBuf.skipBytes(DCEBuffer.OPERATIONDATA); 71 } 72 catch (DCEBufferException ex) 73 { 74 } 75 76 78 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC)) 79 logger.debug("DCE/RPC SrvSvc request=" + Srvsvc.getOpcodeName(opNum)); 80 81 83 DCEBuffer outBuf = new DCEBuffer(); 84 outBuf.putResponseHeader(inBuf.getHeaderValue(DCEBuffer.HDR_CALLID), 0); 85 86 88 boolean processed = false; 89 90 switch (opNum) 91 { 92 93 95 case Srvsvc.NetrShareEnum: 96 processed = netShareEnum(sess, inBuf, outBuf); 97 break; 98 99 101 case Srvsvc.NetrShareEnumSticky: 102 processed = netShareEnum(sess, inBuf, outBuf); 103 break; 104 105 107 case Srvsvc.NetrShareGetInfo: 108 processed = netShareGetInfo(sess, inBuf, outBuf); 109 break; 110 111 113 case Srvsvc.NetrServerGetInfo: 114 processed = netServerGetInfo(sess, inBuf, outBuf); 115 break; 116 117 119 default: 120 break; 121 } 122 123 125 if (processed == false) 126 { 127 sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv); 128 return; 129 } 130 131 133 outBuf.setHeaderValue(DCEBuffer.HDR_ALLOCHINT, outBuf.getLength()); 134 135 137 pipeFile.setBufferedData(outBuf); 138 } 139 140 148 protected final boolean netShareEnum(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf) 149 { 150 151 153 String srvName = null; 154 ShareInfoList shrInfo = null; 155 156 try 157 { 158 inBuf.skipPointer(); 159 srvName = inBuf.getString(DCEBuffer.ALIGN_INT); 160 shrInfo = new ShareInfoList(inBuf); 161 } 162 catch (DCEBufferException ex) 163 { 164 return false; 165 } 166 167 169 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC)) 170 logger.debug("NetShareEnum srvName=" + srvName + ", shrInfo=" + shrInfo.toString()); 171 172 174 SharedDeviceList shareList = sess.getServer().getShareMapper().getShareList(srvName, sess, false); 175 176 178 if (sess.getServer().hasAccessControlManager()) 179 { 180 181 183 AccessControlManager aclMgr = sess.getServer().getAccessControlManager(); 184 185 shareList = aclMgr.filterShareList(sess, shareList); 186 } 187 188 190 Vector infoList = new Vector (); 191 Enumeration <SharedDevice> enm = shareList.enumerateShares(); 192 193 while (enm.hasMoreElements()) 194 { 195 196 198 SharedDevice share = enm.nextElement(); 199 200 202 int shrTyp = ShareInfo.Disk; 203 204 if (share.getType() == ShareType.PRINTER) 205 shrTyp = ShareInfo.PrintQueue; 206 else if (share.getType() == ShareType.NAMEDPIPE) 207 shrTyp = ShareInfo.IPC; 208 else if (share.getType() == ShareType.ADMINPIPE) 209 shrTyp = ShareInfo.IPC + ShareInfo.Hidden; 210 211 213 ShareInfo info = new ShareInfo(shrInfo.getInformationLevel(), share.getName(), shrTyp, share.getComment()); 214 infoList.add(info); 215 216 218 switch (shrInfo.getInformationLevel()) 219 { 220 221 223 case 2: 224 if (share.getContext() != null) 225 info.setPath(share.getContext().getDeviceName()); 226 break; 227 228 230 case 502: 231 if (share.getContext() != null) 232 info.setPath(share.getContext().getDeviceName()); 233 break; 234 } 235 } 236 237 240 shrInfo.setShareList(infoList); 241 try 242 { 243 shrInfo.writeList(outBuf); 244 outBuf.putInt(0); } 246 catch (DCEBufferException ex) 247 { 248 } 249 250 252 return true; 253 } 254 255 263 protected final boolean netShareGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf) 264 { 265 266 268 String srvName = null; 269 String shrName = null; 270 int infoLevel = 0; 271 272 try 273 { 274 inBuf.skipPointer(); 275 srvName = inBuf.getString(DCEBuffer.ALIGN_INT); 276 shrName = inBuf.getString(DCEBuffer.ALIGN_INT); 277 infoLevel = inBuf.getInt(); 278 } 279 catch (DCEBufferException ex) 280 { 281 return false; 282 } 283 284 286 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC)) 287 logger.debug("netShareGetInfo srvname=" + srvName + ", share=" + shrName + ", infoLevel=" + infoLevel); 288 289 291 SharedDevice share = null; 292 293 try 294 { 295 296 298 share = sess.getServer().findShare(srvName, shrName, ShareType.UNKNOWN, sess, false); 299 } 300 catch (Exception ex) 301 { 302 } 303 304 306 if (share == null) 307 return false; 308 309 311 int shrTyp = ShareInfo.Disk; 312 313 if (share.getType() == ShareType.PRINTER) 314 shrTyp = ShareInfo.PrintQueue; 315 else if (share.getType() == ShareType.NAMEDPIPE) 316 shrTyp = ShareInfo.IPC; 317 else if (share.getType() == ShareType.ADMINPIPE) 318 shrTyp = ShareInfo.IPC + ShareInfo.Hidden; 319 320 322 ShareInfo shrInfo = new ShareInfo(infoLevel, share.getName(), shrTyp, share.getComment()); 323 324 326 outBuf.putInt(infoLevel); 327 outBuf.putPointer(true); 328 329 shrInfo.writeObject(outBuf, outBuf); 330 331 333 outBuf.putInt(0); 334 return true; 335 } 336 337 345 protected final boolean netServerGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf) 346 { 347 348 350 String srvName = null; 351 int infoLevel = 0; 352 353 try 354 { 355 inBuf.skipPointer(); 356 srvName = inBuf.getString(DCEBuffer.ALIGN_INT); 357 infoLevel = inBuf.getInt(); 358 } 359 catch (DCEBufferException ex) 360 { 361 return false; 362 } 363 364 366 if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC)) 367 logger.debug("netServerGetInfo srvname=" + srvName + ", infoLevel=" + infoLevel); 368 369 371 ServerInfo srvInfo = new ServerInfo(infoLevel); 372 373 SMBServer srv = sess.getSMBServer(); 374 srvInfo.setServerName(srv.getServerName()); 375 srvInfo.setComment(srv.getComment()); 376 srvInfo.setServerType(srv.getServerType()); 377 378 380 ServerConfiguration srvConfig = srv.getConfiguration(); 381 if (srvConfig != null && srvConfig.getEnabledDialects().hasDialect(Dialect.NT) == true) 382 { 383 srvInfo.setPlatformId(ServerInfo.PLATFORM_NT); 384 srvInfo.setVersion(5, 1); 385 } 386 else 387 { 388 srvInfo.setPlatformId(ServerInfo.PLATFORM_OS2); 389 srvInfo.setVersion(4, 0); 390 } 391 392 394 srvInfo.writeObject(outBuf, outBuf); 395 outBuf.putInt(0); 396 397 399 return true; 400 } 401 } 402 | Popular Tags |