KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > dcerpc > server > WkssvcDCEHandler


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.dcerpc.server;
18
19 import java.io.IOException JavaDoc;
20
21 import org.alfresco.filesys.server.config.ServerConfiguration;
22 import org.alfresco.filesys.smb.Dialect;
23 import org.alfresco.filesys.smb.SMBStatus;
24 import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
25 import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
26 import org.alfresco.filesys.smb.dcerpc.Wkssvc;
27 import org.alfresco.filesys.smb.dcerpc.info.ServerInfo;
28 import org.alfresco.filesys.smb.dcerpc.info.WorkstationInfo;
29 import org.alfresco.filesys.smb.server.SMBServer;
30 import org.alfresco.filesys.smb.server.SMBSrvException;
31 import org.alfresco.filesys.smb.server.SMBSrvSession;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 /**
36  * Wkssvc DCE/RPC Handler Class
37  */

38 public class WkssvcDCEHandler implements DCEHandler
39 {
40
41     // Debug logging
42

43     private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol");
44
45     /**
46      * Process a WksSvc DCE/RPC request
47      *
48      * @param sess SMBSrvSession
49      * @param inBuf DCEBuffer
50      * @param pipeFile DCEPipeFile
51      * @exception IOException
52      * @exception SMBSrvException
53      */

54     public void processRequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile) throws IOException JavaDoc,
55             SMBSrvException
56     {
57
58         // Get the operation code and move the buffer pointer to the start of the request data
59

60         int opNum = inBuf.getHeaderValue(DCEBuffer.HDR_OPCODE);
61         try
62         {
63             inBuf.skipBytes(DCEBuffer.OPERATIONDATA);
64         }
65         catch (DCEBufferException ex)
66         {
67         }
68
69         // Debug
70

71         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
72             logger.debug("DCE/RPC WksSvc request=" + Wkssvc.getOpcodeName(opNum));
73
74         // Create the output DCE buffer and add the response header
75

76         DCEBuffer outBuf = new DCEBuffer();
77         outBuf.putResponseHeader(inBuf.getHeaderValue(DCEBuffer.HDR_CALLID), 0);
78
79         // Process the request
80

81         boolean processed = false;
82
83         switch (opNum)
84         {
85
86         // Get workstation information
87

88         case Wkssvc.NetWkstaGetInfo:
89             processed = netWkstaGetInfo(sess, inBuf, outBuf);
90             break;
91
92         // Unsupported function
93

94         default:
95             break;
96         }
97
98         // Return an error status if the request was not processed
99

100         if (processed == false)
101         {
102             sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
103             return;
104         }
105
106         // Set the allocation hint for the response
107

108         outBuf.setHeaderValue(DCEBuffer.HDR_ALLOCHINT, outBuf.getLength());
109
110         // Attach the output buffer to the pipe file
111

112         pipeFile.setBufferedData(outBuf);
113     }
114
115     /**
116      * Get workstation infomation
117      *
118      * @param sess SMBSrvSession
119      * @param inBuf DCEPacket
120      * @param outBuf DCEPacket
121      * @return boolean
122      */

123     protected final boolean netWkstaGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf)
124     {
125
126         // Decode the request
127

128         String JavaDoc srvName = null;
129         int infoLevel = 0;
130
131         try
132         {
133             inBuf.skipPointer();
134             srvName = inBuf.getString(DCEBuffer.ALIGN_INT);
135             infoLevel = inBuf.getInt();
136         }
137         catch (DCEBufferException ex)
138         {
139             return false;
140         }
141
142         // Debug
143

144         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
145             logger.debug("NetWkstaGetInfo srvName=" + srvName + ", infoLevel=" + infoLevel);
146
147         // Create the workstation information and set the common values
148

149         WorkstationInfo wkstaInfo = new WorkstationInfo(infoLevel);
150
151         SMBServer srv = sess.getSMBServer();
152         wkstaInfo.setWorkstationName(srv.getServerName());
153         wkstaInfo.setDomain(srv.getConfiguration().getDomainName());
154
155         // Determine if the server is using the NT SMB dialect and set the platofmr id accordingly
156

157         ServerConfiguration srvConfig = sess.getServer().getConfiguration();
158         if (srvConfig != null && srvConfig.getEnabledDialects().hasDialect(Dialect.NT) == true)
159         {
160             wkstaInfo.setPlatformId(ServerInfo.PLATFORM_NT);
161             wkstaInfo.setVersion(5, 1);
162         }
163         else
164         {
165             wkstaInfo.setPlatformId(ServerInfo.PLATFORM_OS2);
166             wkstaInfo.setVersion(4, 0);
167         }
168
169         // Write the server information to the DCE response
170

171         wkstaInfo.writeObject(outBuf, outBuf);
172         outBuf.putInt(0);
173
174         // Indicate that the request was processed successfully
175

176         return true;
177     }
178 }
179
Popular Tags