KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > DCERPCHandler


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.server;
18
19 import java.io.IOException JavaDoc;
20
21 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol;
22 import org.alfresco.filesys.server.filesys.TreeConnection;
23 import org.alfresco.filesys.smb.DataType;
24 import org.alfresco.filesys.smb.PacketType;
25 import org.alfresco.filesys.smb.SMBStatus;
26 import org.alfresco.filesys.smb.TransactBuffer;
27 import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
28 import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
29 import org.alfresco.filesys.smb.dcerpc.DCECommand;
30 import org.alfresco.filesys.smb.dcerpc.DCEDataPacker;
31 import org.alfresco.filesys.smb.dcerpc.DCEPipeType;
32 import org.alfresco.filesys.smb.dcerpc.UUID;
33 import org.alfresco.filesys.smb.dcerpc.server.DCEPipeFile;
34 import org.alfresco.filesys.smb.dcerpc.server.DCESrvPacket;
35 import org.alfresco.filesys.util.DataBuffer;
36 import org.alfresco.filesys.util.DataPacker;
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40 /**
41  * DCE/RPC Protocol Handler Class
42  */

43 public class DCERPCHandler
44 {
45     private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol");
46
47     /**
48      * Process a DCE/RPC request
49      *
50      * @param sess SMBSrvSession
51      * @param srvTrans SMBSrvTransPacket
52      * @param outPkt SMBSrvPacket
53      * @exception IOException
54      * @exception SMBSrvException
55      */

56     public static final void processDCERPCRequest(SMBSrvSession sess, SMBSrvTransPacket srvTrans, SMBSrvPacket outPkt)
57             throws IOException JavaDoc, SMBSrvException
58     {
59
60         // Get the tree id from the received packet and validate that it is a valid
61
// connection id.
62

63         int treeId = srvTrans.getTreeId();
64         TreeConnection conn = sess.findConnection(treeId);
65
66         if (conn == null)
67         {
68             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
69             return;
70         }
71
72         // Get the file id and validate
73

74         int fid = srvTrans.getSetupParameter(1);
75         int maxData = srvTrans.getParameter(3) - DCEBuffer.OPERATIONDATA;
76
77         // Get the IPC pipe file for the specified file id
78

79         DCEPipeFile pipeFile = (DCEPipeFile) conn.findFile(fid);
80         if (pipeFile == null)
81         {
82             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
83             return;
84         }
85
86         // Create a DCE/RPC buffer from the received data
87

88         DCEBuffer dceBuf = new DCEBuffer(srvTrans.getBuffer(), srvTrans.getParameter(10)
89                 + RFCNetBIOSProtocol.HEADER_LEN);
90
91         // Debug
92

93         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
94             logger.debug("TransactNmPipe pipeFile=" + pipeFile.getName() + ", fid=" + fid + ", dceCmd=0x"
95                     + Integer.toHexString(dceBuf.getHeaderValue(DCEBuffer.HDR_PDUTYPE)));
96
97         // Process the received DCE buffer
98

99         processDCEBuffer(sess, dceBuf, pipeFile);
100
101         // Check if there is a reply buffer to return to the caller
102

103         if (pipeFile.hasBufferedData() == false)
104             return;
105
106         DCEBuffer txBuf = pipeFile.getBufferedData();
107
108         // Initialize the reply
109

110         DCESrvPacket dcePkt = new DCESrvPacket(outPkt.getBuffer());
111
112         // Always only one fragment as the data either fits into the first reply fragment or the
113
// client will read the remaining data by issuing read requests on the pipe
114

115         int flags = DCESrvPacket.FLG_ONLYFRAG;
116
117         dcePkt.initializeDCEReply();
118         txBuf.setHeaderValue(DCEBuffer.HDR_FLAGS, flags);
119
120         // Build the reply data
121

122         byte[] buf = dcePkt.getBuffer();
123         int pos = DCEDataPacker.longwordAlign(dcePkt.getByteOffset());
124
125         // Set the DCE fragment size and send the reply DCE/RPC SMB
126

127         int dataLen = txBuf.getLength();
128         txBuf.setHeaderValue(DCEBuffer.HDR_FRAGLEN, dataLen);
129
130         // Copy the data from the DCE output buffer to the reply SMB packet
131

132         int len = txBuf.getLength();
133         int sts = SMBStatus.NTSuccess;
134
135         if (len > maxData)
136         {
137
138             // Write the maximum transmit fragment to the reply
139

140             len = maxData + DCEBuffer.OPERATIONDATA;
141             dataLen = maxData + DCEBuffer.OPERATIONDATA;
142
143             // Indicate a buffer overflow status
144

145             sts = SMBStatus.NTBufferOverflow;
146         }
147         else
148         {
149
150             // Clear the DCE/RPC pipe buffered data, the reply will fit into a single response
151
// packet
152

153             pipeFile.setBufferedData(null);
154         }
155
156         // Debug
157

158         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
159             logger.debug("Reply DCEbuf flags=0x" + Integer.toHexString(flags) + ", len=" + len + ", status=0x"
160                     + Integer.toHexString(sts));
161
162         // Copy the reply data to the reply packet
163

164         try
165         {
166             pos += txBuf.copyData(buf, pos, len);
167         }
168         catch (DCEBufferException ex)
169         {
170             sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
171             return;
172         }
173
174         // Set the SMB transaction data length
175

176         int byteLen = pos - dcePkt.getByteOffset();
177         dcePkt.setParameter(1, dataLen);
178         dcePkt.setParameter(6, dataLen);
179         dcePkt.setByteCount(byteLen);
180         dcePkt.setFlags2(SMBPacket.FLG2_LONGERRORCODE);
181         dcePkt.setLongErrorCode(sts);
182
183         sess.sendResponseSMB(dcePkt);
184     }
185
186     /**
187      * Process a DCE/RPC request
188      *
189      * @param sess SMBSrvSession
190      * @param tbuf TransactBuffer
191      * @param outPkt SMBSrvPacket
192      * @exception IOException
193      * @exception SMBSrvException
194      */

195     public static final void processDCERPCRequest(SMBSrvSession sess, TransactBuffer tbuf, SMBSrvPacket outPkt)
196             throws IOException JavaDoc, SMBSrvException
197     {
198
199         // Check if the transaction buffer has setup and data buffers
200

201         if (tbuf.hasSetupBuffer() == false || tbuf.hasDataBuffer() == false)
202         {
203             sess.sendErrorResponseSMB(SMBStatus.SRVUnrecognizedCommand, SMBStatus.ErrSrv);
204             return;
205         }
206
207         // Get the tree id from the received packet and validate that it is a valid
208
// connection id.
209

210         int treeId = tbuf.getTreeId();
211         TreeConnection conn = sess.findConnection(treeId);
212
213         if (conn == null)
214         {
215             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
216             return;
217         }
218
219         // Get the file id and validate
220

221         DataBuffer setupBuf = tbuf.getSetupBuffer();
222
223         setupBuf.skipBytes(2);
224         int fid = setupBuf.getShort();
225         int maxData = tbuf.getReturnDataLimit() - DCEBuffer.OPERATIONDATA;
226
227         // Get the IPC pipe file for the specified file id
228

229         DCEPipeFile pipeFile = (DCEPipeFile) conn.findFile(fid);
230         if (pipeFile == null)
231         {
232             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
233             return;
234         }
235
236         // Create a DCE/RPC buffer from the received transaction data
237

238         DCEBuffer dceBuf = new DCEBuffer(tbuf);
239
240         // Debug
241

242         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
243             logger.debug("TransactNmPipe pipeFile=" + pipeFile.getName() + ", fid=" + fid + ", dceCmd=0x"
244                     + Integer.toHexString(dceBuf.getHeaderValue(DCEBuffer.HDR_PDUTYPE)));
245
246         // Process the received DCE buffer
247

248         processDCEBuffer(sess, dceBuf, pipeFile);
249
250         // Check if there is a reply buffer to return to the caller
251

252         if (pipeFile.hasBufferedData() == false)
253             return;
254
255         DCEBuffer txBuf = pipeFile.getBufferedData();
256
257         // Initialize the reply
258

259         DCESrvPacket dcePkt = new DCESrvPacket(outPkt.getBuffer());
260
261         // Always only one fragment as the data either fits into the first reply fragment or the
262
// client will read the remaining data by issuing read requests on the pipe
263

264         int flags = DCESrvPacket.FLG_ONLYFRAG;
265
266         dcePkt.initializeDCEReply();
267         txBuf.setHeaderValue(DCEBuffer.HDR_FLAGS, flags);
268
269         // Build the reply data
270

271         byte[] buf = dcePkt.getBuffer();
272         int pos = DCEDataPacker.longwordAlign(dcePkt.getByteOffset());
273
274         // Set the DCE fragment size and send the reply DCE/RPC SMB
275

276         int dataLen = txBuf.getLength();
277         txBuf.setHeaderValue(DCEBuffer.HDR_FRAGLEN, dataLen);
278
279         // Copy the data from the DCE output buffer to the reply SMB packet
280

281         int len = txBuf.getLength();
282         int sts = SMBStatus.NTSuccess;
283
284         if (len > maxData)
285         {
286
287             // Write the maximum transmit fragment to the reply
288

289             len = maxData + DCEBuffer.OPERATIONDATA;
290             dataLen = maxData + DCEBuffer.OPERATIONDATA;
291
292             // Indicate a buffer overflow status
293

294             sts = SMBStatus.NTBufferOverflow;
295         }
296         else
297         {
298
299             // Clear the DCE/RPC pipe buffered data, the reply will fit into a single response
300
// packet
301

302             pipeFile.setBufferedData(null);
303         }
304
305         // Debug
306

307         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
308             logger.debug("Reply DCEbuf flags=0x" + Integer.toHexString(flags) + ", len=" + len + ", status=0x"
309                     + Integer.toHexString(sts));
310
311         // Copy the reply data to the reply packet
312

313         try
314         {
315             pos += txBuf.copyData(buf, pos, len);
316         }
317         catch (DCEBufferException ex)
318         {
319             sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
320             return;
321         }
322
323         // Set the SMB transaction data length
324

325         int byteLen = pos - dcePkt.getByteOffset();
326         dcePkt.setParameter(1, dataLen);
327         dcePkt.setParameter(6, dataLen);
328         dcePkt.setByteCount(byteLen);
329         dcePkt.setFlags2(SMBPacket.FLG2_LONGERRORCODE);
330         dcePkt.setLongErrorCode(sts);
331
332         sess.sendResponseSMB(dcePkt);
333     }
334
335     /**
336      * Process a DCE/RPC write request to the named pipe file
337      *
338      * @param sess SMBSrvSession
339      * @param inPkt SMBSrvPacket
340      * @param outPkt SMBSrvPacket
341      * @exception IOException
342      * @exception SMBSrvException
343      */

344     public static final void processDCERPCRequest(SMBSrvSession sess, SMBSrvPacket inPkt, SMBSrvPacket outPkt)
345             throws IOException JavaDoc, SMBSrvException
346     {
347
348         // Get the tree id from the received packet and validate that it is a valid
349
// connection id.
350

351         int treeId = inPkt.getTreeId();
352         TreeConnection conn = sess.findConnection(treeId);
353
354         if (conn == null)
355         {
356             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
357             return;
358         }
359
360         // Determine if this is a write or write andX request
361

362         int cmd = inPkt.getCommand();
363
364         // Get the file id and validate
365

366         int fid = -1;
367         if (cmd == PacketType.WriteFile)
368             fid = inPkt.getParameter(0);
369         else
370             fid = inPkt.getParameter(2);
371
372         // Get the IPC pipe file for the specified file id
373

374         DCEPipeFile pipeFile = (DCEPipeFile) conn.findFile(fid);
375         if (pipeFile == null)
376         {
377             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
378             return;
379         }
380
381         // Create a DCE buffer for the received data
382

383         DCEBuffer dceBuf = null;
384         byte[] buf = inPkt.getBuffer();
385         int pos = 0;
386         int len = 0;
387
388         if (cmd == PacketType.WriteFile)
389         {
390
391             // Get the data offset
392

393             pos = inPkt.getByteOffset();
394
395             // Check that the received data is valid
396

397             if (buf[pos++] != DataType.DataBlock)
398             {
399                 sess.sendErrorResponseSMB(SMBStatus.DOSInvalidData, SMBStatus.ErrDos);
400                 return;
401             }
402
403             len = DataPacker.getIntelShort(buf, pos);
404             pos += 2;
405
406         }
407         else
408         {
409
410             // Get the data offset and length
411

412             len = inPkt.getParameter(10);
413             pos = inPkt.getParameter(11) + RFCNetBIOSProtocol.HEADER_LEN;
414         }
415
416         // Create a DCE buffer mapped to the received packet
417

418         dceBuf = new DCEBuffer(buf, pos);
419
420         // Debug
421

422         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC))
423             logger.debug("Write pipeFile=" + pipeFile.getName() + ", fid=" + fid + ", dceCmd=0x"
424                     + Integer.toHexString(dceBuf.getHeaderValue(DCEBuffer.HDR_PDUTYPE)));
425
426         // Process the DCE buffer
427

428         processDCEBuffer(sess, dceBuf, pipeFile);
429
430         // Check if there is a valid reply buffered
431

432         int bufLen = 0;
433         if (pipeFile.hasBufferedData())
434             bufLen = pipeFile.getBufferedData().getLength();
435
436         // Send the write/write andX reply
437

438         if (cmd == PacketType.WriteFile)
439         {
440
441             // Build the write file reply
442

443             outPkt.setParameterCount(1);
444             outPkt.setParameter(0, len);
445             outPkt.setByteCount(0);
446         }
447         else
448         {
449
450             // Build the write andX reply
451

452             outPkt.setParameterCount(6);
453
454             outPkt.setAndXCommand(0xFF);
455             outPkt.setParameter(1, 0);
456             outPkt.setParameter(2, len);
457             outPkt.setParameter(3, bufLen);
458             outPkt.setParameter(4, 0);
459             outPkt.setParameter(5, 0);
460             outPkt.setByteCount(0);
461         }
462
463         // Send the write reply
464

465         outPkt.setFlags2(SMBPacket.FLG2_LONGERRORCODE);
466         sess.sendResponseSMB(outPkt);
467     }
468
469     /**
470      * Process a DCE/RPC pipe read request
471      *
472      * @param sess SMBSrvSession
473      * @param inPkt SMBSrvPacket
474      * @param outPkt SMBSrvPacket
475      * @exception IOException
476      * @exception SMBSrvException
477      */

478     public static final void processDCERPCRead(SMBSrvSession sess, SMBSrvPacket inPkt, SMBSrvPacket outPkt)
479             throws IOException JavaDoc, SMBSrvException
480     {
481
482         // Get the tree id from the received packet and validate that it is a valid
483
// connection id.
484

485         int treeId = inPkt.getTreeId();
486         TreeConnection conn = sess.findConnection(treeId);
487
488         if (conn == null)
489         {
490             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
491             return;
492         }
493
494         // Determine if this is a read or read andX request
495

496         int cmd = inPkt.getCommand();
497
498         // Get the file id and read length, and validate
499

500         int fid = -1;
501         int rdLen = -1;
502
503         if (cmd == PacketType.ReadFile)
504         {
505             fid = inPkt.getParameter(0);
506             rdLen = inPkt.getParameter(1);
507         }
508         else
509         {
510             fid = inPkt.getParameter(2);
511             rdLen = inPkt.getParameter(5);
512         }
513
514         // Get the IPC pipe file for the specified file id
515

516         DCEPipeFile pipeFile = (DCEPipeFile) conn.findFile(fid);
517         if (pipeFile == null)
518         {
519             sess.sendErrorResponseSMB(SMBStatus.DOSInvalidHandle, SMBStatus.ErrDos);
520             return;
521         }
522
523         // Debug
524

525         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC))
526             logger.debug("Read pipeFile=" + pipeFile.getName() + ", fid=" + fid + ", rdLen=" + rdLen);
527
528         // Check if there is a valid reply buffered
529

530         if (pipeFile.hasBufferedData())
531         {
532
533             // Get the buffered data
534

535             DCEBuffer bufData = pipeFile.getBufferedData();
536             int bufLen = bufData.getAvailableLength();
537
538             // Debug
539

540             if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC))
541                 logger.debug(" Buffered data available=" + bufLen);
542
543             // Check if there is less data than the read size
544

545             if (rdLen > bufLen)
546                 rdLen = bufLen;
547
548             // Build the read response
549

550             if (cmd == PacketType.ReadFile)
551             {
552
553                 // Build the read response
554

555                 outPkt.setParameterCount(5);
556                 outPkt.setParameter(0, rdLen);
557                 for (int i = 1; i < 5; i++)
558                     outPkt.setParameter(i, 0);
559                 outPkt.setByteCount(rdLen + 3);
560
561                 // Copy the data to the response
562

563                 byte[] buf = outPkt.getBuffer();
564                 int pos = outPkt.getByteOffset();
565
566                 buf[pos++] = (byte) DataType.DataBlock;
567                 DataPacker.putIntelShort(rdLen, buf, pos);
568                 pos += 2;
569
570                 try
571                 {
572                     bufData.copyData(buf, pos, rdLen);
573                 }
574                 catch (DCEBufferException ex)
575                 {
576                     logger.error("DCR/RPC read", ex);
577                 }
578             }
579             else
580             {
581
582                 // Build the read andX response
583

584                 outPkt.setParameterCount(12);
585                 outPkt.setAndXCommand(0xFF);
586                 for (int i = 1; i < 12; i++)
587                     outPkt.setParameter(i, 0);
588
589                 // Copy the data to the response
590

591                 byte[] buf = outPkt.getBuffer();
592                 int pos = DCEDataPacker.longwordAlign(outPkt.getByteOffset());
593
594                 outPkt.setParameter(5, rdLen);
595                 outPkt.setParameter(6, pos - RFCNetBIOSProtocol.HEADER_LEN);
596                 outPkt.setByteCount((pos + rdLen) - outPkt.getByteOffset());
597
598                 try
599                 {
600                     bufData.copyData(buf, pos, rdLen);
601                 }
602                 catch (DCEBufferException ex)
603                 {
604                     logger.error("DCE/RPC error", ex);
605                 }
606             }
607         }
608         else
609         {
610
611             // Debug
612

613             if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_IPC))
614                 logger.debug(" No buffered data available");
615
616             // Return a zero length read response
617

618             if (cmd == PacketType.ReadFile)
619             {
620
621                 // Initialize the read response
622

623                 outPkt.setParameterCount(5);
624                 for (int i = 0; i < 5; i++)
625                     outPkt.setParameter(i, 0);
626                 outPkt.setByteCount(0);
627             }
628             else
629             {
630
631                 // Return a zero length read andX response
632

633                 outPkt.setParameterCount(12);
634
635                 outPkt.setAndXCommand(0xFF);
636                 for (int i = 1; i < 12; i++)
637                     outPkt.setParameter(i, 0);
638                 outPkt.setByteCount(0);
639             }
640         }
641
642         // Clear the status code
643

644         outPkt.setLongErrorCode(SMBStatus.NTSuccess);
645
646         // Send the read reply
647

648         outPkt.setFlags2(SMBPacket.FLG2_LONGERRORCODE);
649         sess.sendResponseSMB(outPkt);
650     }
651
652     /**
653      * Process the DCE/RPC request buffer
654      *
655      * @param sess SMBSrvSession
656      * @param buf DCEBuffer
657      * @param pipeFile DCEPipeFile
658      * @exception IOException
659      * @exception SMBSrvException
660      */

661     public static final void processDCEBuffer(SMBSrvSession sess, DCEBuffer dceBuf, DCEPipeFile pipeFile)
662             throws IOException JavaDoc, SMBSrvException
663     {
664
665         // Process the DCE/RPC request
666

667         switch (dceBuf.getHeaderValue(DCEBuffer.HDR_PDUTYPE))
668         {
669
670         // DCE Bind
671

672         case DCECommand.BIND:
673             procDCEBind(sess, dceBuf, pipeFile);
674             break;
675
676         // DCE Request
677

678         case DCECommand.REQUEST:
679             procDCERequest(sess, dceBuf, pipeFile);
680             break;
681
682         default:
683             sess.sendErrorResponseSMB(SMBStatus.SRVNoAccessRights, SMBStatus.ErrSrv);
684             break;
685         }
686     }
687
688     /**
689      * Process a DCE bind request
690      *
691      * @param sess SMBSrvSession
692      * @param dceBuf DCEBuffer
693      * @param pipeFile DCEPipeFile
694      * @exception IOException
695      * @exception SMBSrvException
696      */

697     public static final void procDCEBind(SMBSrvSession sess, DCEBuffer dceBuf, DCEPipeFile pipeFile)
698             throws IOException JavaDoc, SMBSrvException
699     {
700
701         try
702         {
703
704             // DEBUG
705

706             if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
707                 logger.debug("DCE Bind");
708
709             // Get the call id and skip the DCE header
710

711             int callId = dceBuf.getHeaderValue(DCEBuffer.HDR_CALLID);
712             dceBuf.skipBytes(DCEBuffer.DCEDATA);
713
714             // Unpack the bind request
715

716             int maxTxSize = dceBuf.getShort();
717             int maxRxSize = dceBuf.getShort();
718             int groupId = dceBuf.getInt();
719             int ctxElems = dceBuf.getByte(DCEBuffer.ALIGN_INT);
720             int presCtxId = dceBuf.getByte(DCEBuffer.ALIGN_SHORT);
721             int trfSyntax = dceBuf.getByte(DCEBuffer.ALIGN_SHORT);
722
723             UUID uuid1 = dceBuf.getUUID(true);
724             UUID uuid2 = dceBuf.getUUID(true);
725
726             // Debug
727

728             if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
729             {
730                 logger.debug("Bind: maxTx=" + maxTxSize + ", maxRx=" + maxRxSize + ", groupId=" + groupId
731                         + ", ctxElems=" + ctxElems + ", presCtxId=" + presCtxId + ", trfSyntax=" + trfSyntax);
732                 logger.debug(" uuid1=" + uuid1.toString());
733                 logger.debug(" uuid2=" + uuid2.toString());
734             }
735
736             // Update the IPC pipe file
737

738             pipeFile.setMaxTransmitFragmentSize(maxTxSize);
739             pipeFile.setMaxReceiveFragmentSize(maxRxSize);
740
741             // Create an output DCE buffer for the reply and add the bind acknowledge header
742

743             DCEBuffer txBuf = new DCEBuffer();
744             txBuf.putBindAckHeader(dceBuf.getHeaderValue(DCEBuffer.HDR_CALLID));
745             txBuf.setHeaderValue(DCEBuffer.HDR_FLAGS, DCEBuffer.FLG_ONLYFRAG);
746
747             // Pack the bind acknowledge DCE reply
748

749             txBuf.putShort(maxTxSize);
750             txBuf.putShort(maxRxSize);
751             txBuf.putInt(0x53F0);
752
753             String JavaDoc srvPipeName = DCEPipeType.getServerPipeName(pipeFile.getPipeId());
754             txBuf.putShort(srvPipeName.length() + 1);
755             txBuf.putASCIIString(srvPipeName, true, DCEBuffer.ALIGN_INT);
756             txBuf.putInt(1);
757             txBuf.putShort(0);
758             txBuf.putShort(0);
759             txBuf.putUUID(uuid2, true);
760
761             txBuf.setHeaderValue(DCEBuffer.HDR_FRAGLEN, txBuf.getLength());
762
763             // Attach the reply buffer to the pipe file
764

765             pipeFile.setBufferedData(txBuf);
766         }
767         catch (DCEBufferException ex)
768         {
769             sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
770             return;
771         }
772     }
773
774     /**
775      * Process a DCE request
776      *
777      * @param sess SMBSrvSession
778      * @param dceBuf DCEBuffer
779      * @param pipeFile DCEPipeFile
780      * @exception IOException
781      * @exception SMBSrvException
782      */

783     public static final void procDCERequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile)
784             throws IOException JavaDoc, SMBSrvException
785     {
786
787         // Debug
788

789         if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
790             logger.debug("DCE Request opNum=0x" + Integer.toHexString(inBuf.getHeaderValue(DCEBuffer.HDR_OPCODE)));
791
792         // Pass the request to the DCE pipe request handler
793

794         if (pipeFile.hasRequestHandler())
795             pipeFile.getRequestHandler().processRequest(sess, inBuf, pipeFile);
796         else
797             sess.sendErrorResponseSMB(SMBStatus.SRVNoAccessRights, SMBStatus.ErrSrv);
798     }
799 }
800
Popular Tags