1 19 20 package jcifs.dcerpc; 21 22 import java.net.*; 23 import java.io.*; 24 25 import jcifs.dcerpc.ndr.NdrBuffer; 26 import jcifs.smb.*; 27 import jcifs.util.*; 28 29 public class DcerpcPipeHandle extends DcerpcHandle { 30 31 SmbNamedPipe pipe; 32 SmbFileInputStream in = null; 33 SmbFileOutputStream out = null; 34 boolean isStart = true; 35 36 public DcerpcPipeHandle(String url, 37 NtlmPasswordAuthentication auth) 38 throws UnknownHostException, MalformedURLException, DcerpcException { 39 binding = DcerpcHandle.parseBinding(url); 40 url = "smb://" + binding.server + "/IPC$/" + binding.endpoint.substring(6); 41 pipe = new SmbNamedPipe(url, 42 43 (0x2019F << 16) | SmbNamedPipe.PIPE_TYPE_RDWR | SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT, 44 auth); 45 } 46 47 protected void doSendFragment(byte[] buf, 48 int off, 49 int length, 50 boolean isDirect) throws IOException { 51 if (in == null) 52 in = (SmbFileInputStream)pipe.getNamedPipeInputStream(); 53 if (out == null) 54 out = (SmbFileOutputStream)pipe.getNamedPipeOutputStream(); 55 if (isDirect) { 56 out.writeDirect( buf, off, length, 1 ); 57 return; 58 } 59 out.write(buf, off, length); 60 } 61 protected void doReceiveFragment(byte[] buf, boolean isDirect) throws IOException { 62 int off, flags, length; 63 64 if (buf.length < max_recv) 65 throw new IllegalArgumentException ("buffer too small"); 66 67 if (isStart && !isDirect) { off = in.read(buf, 0, 1024); 69 } else { 70 off = in.readDirect(buf, 0, buf.length); 71 } 72 73 if (buf[0] != 5 && buf[1] != 0) 74 throw new IOException("Unexpected DCERPC PDU header"); 75 76 flags = buf[3] & 0xFF; 77 isStart = (flags & DCERPC_LAST_FRAG) == DCERPC_LAST_FRAG; 79 80 length = Encdec.dec_uint16le(buf, 8); 81 if (length > max_recv) 82 throw new IOException("Unexpected fragment length: " + length); 83 84 while (off < length) { 85 off += in.readDirect(buf, off, length - off); 86 } 87 } 88 public void close() throws IOException { 89 if (out != null) 90 out.close(); 91 } 92 } 93 94 | Popular Tags |