FileEntry[] doMsrpcShareEnum() throws IOException { MsrpcShareEnum rpc; DcerpcHandle handle; rpc = new MsrpcShareEnum(url.getHost()); /* JCIFS will build a composite list of shares if the target host has * multiple IP addresses such as when domain-based DFS is in play. Because * of this, to ensure that we query each IP individually without re-resolving * the hostname and getting a different IP, we must use the current addresses * IP rather than just url.getHost() like we were using prior to 1.2.16. */ handle = DcerpcHandle.getHandle("ncacn_np:" + getAddress().getHostAddress() + "[\\PIPE\\srvsvc]", auth); try { handle.sendrecv(rpc); if (rpc.retval != 0) throw new SmbException(rpc.retval, true); return rpc.getEntries(); } finally { try { handle.close(); } catch(IOException ioe) { if (log.level >= 4) ioe.printStackTrace(log); } } } FileEntry[] doNetShareEnum() throws SmbException {
private String init(String url) throws UnknownHostException, MalformedURLException, DcerpcException { binding = DcerpcHandle.parseBinding(url); url = "smb://" + binding.server + "/IPC$/" + binding.endpoint.substring(6); String params = "", server, address; server = (String)binding.getOption("server"); if (server != null) params += "&server=" + server; address = (String)binding.getOption("address"); if (server != null) params += "&address=" + address; if (params.length() > 0) url += "?" + params.substring(1); return url; }
static void resolveSids0(String authorityServerName, NtlmPasswordAuthentication auth, SID[] sids) throws IOException { DcerpcHandle handle = null; LsaPolicyHandle policyHandle = null; try { handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\lsarpc]", auth); String server = authorityServerName; int dot = server.indexOf('.'); if (dot > 0 && Character.isDigit(server.charAt(0)) == false) server = server.substring(0, dot); policyHandle = new LsaPolicyHandle(handle, "\\\\" + server, 0x00000800); SID.resolveSids(handle, policyHandle, sids); } finally { if (handle != null) { if (policyHandle != null) { policyHandle.close(); } handle.close(); } } }
static FileEntry[] doMsrpcShareEnum ( CIFSContext ctx, SmbResourceLocator loc, Address address ) throws IOException { try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + getRPCTarget(ctx, loc, address) + "[\\PIPE\\srvsvc]", ctx) ) { MsrpcShareEnum rpc = new MsrpcShareEnum(loc.getServer()); handle.sendrecv(rpc); if ( rpc.retval != 0 ) { throw new SmbException(rpc.retval, true); } return rpc.getEntries(); } }
bind(); doSendFragment(stub, off, n, isDirect); off += n; doReceiveFragment(stub, isDirect); buf.reset(); buf.setIndex(8); doReceiveFragment(frag, isDirect); fbuf.reset(); fbuf.setIndex(8);
public void bind() throws DcerpcException, IOException { synchronized (this) { try { state = 1; DcerpcMessage bind = new DcerpcBind(binding, this); sendrecv(bind); } catch (IOException ioe) { state = 0; throw ioe; } } }
aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x0002000c, rid); rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray); handle.sendrecv(rpc); if (rpc.retval != 0) throw new SmbException(rpc.retval, false); SID[] sids = new SID[rpc.sids.num_sids]; String origin_server = handle.getServer(); NtlmPasswordAuthentication origin_auth = (NtlmPasswordAuthentication)handle.getPrincipal();
try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]", tc) ) { SamrPolicyHandle policyHandle = new SamrPolicyHandle(handle, authorityServerName, 0x00000030); SamrDomainHandle domainHandle = new SamrDomainHandle(handle, policyHandle, 0x00000200, domsid.unwrap(sid_t.class)); try ( SamrAliasHandle aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x0002000c, rid) ) { rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray); handle.sendrecv(rpc); if ( rpc.retval != 0 ) throw new SmbException(rpc.retval, false); SID[] sids = new SID[rpc.sids.num_sids]; String origin_server = handle.getServer(); CIFSContext origin_ctx = handle.getTransportContext();
bind(); NdrBuffer buf = encodeMessage(msg, out); int off = sendFragments(msg, out, buf); int have = doSendReceiveFragment(out, off, msg.length, inB); setupReceivedFragment(buf); buf.setIndex(0); msg.decode_header(buf); msgBuf = new NdrBuffer(receiveMoreFragments(msg, inB), 0);
/** * Get a handle to a service * * @param url * @param tc * context to use * @return a DCERPC handle for the given url * @throws MalformedURLException * @throws DcerpcException */ public static DcerpcHandle getHandle ( String url, CIFSContext tc ) throws MalformedURLException, DcerpcException { return getHandle(url, tc, false); }
NdrBuffer fragBuf = new NdrBuffer(fragBytes, 0); while ( !msg.isFlagSet(DCERPC_LAST_FRAG) ) { doReceiveFragment(fragBytes); setupReceivedFragment(fragBuf); fragBuf.reset(); msg.decode_header(fragBuf);
@Override public void close () throws IOException { super.close(); try { this.handle.close(); } finally { this.pipe.close(); } } }
doSendFragment(out, off, msg.length); off += fragSize;
static FileEntry[] doDfsRootEnum ( CIFSContext ctx, SmbResourceLocator loc, Address address ) throws IOException { try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + getRPCTarget(ctx, loc, address) + "[\\PIPE\\netdfs]", ctx) ) { MsrpcDfsRootEnum rpc = new MsrpcDfsRootEnum(loc.getServer()); handle.sendrecv(rpc); if ( rpc.retval != 0 ) { throw new SmbException(rpc.retval, true); } return rpc.getEntries(); } }
bind(); doSendFragment(stub, off, msg.length, isDirect); off += n; doReceiveFragment(stub, isDirect); buf.reset(); buf.setIndex(8); doReceiveFragment(frag, isDirect); fbuf.reset(); fbuf.setIndex(8);
public void bind() throws DcerpcException, IOException { synchronized (this) { try { state = 1; DcerpcMessage bind = new DcerpcBind(binding, this); sendrecv(bind); } catch (IOException ioe) { state = 0; throw ioe; } } } public void sendrecv(DcerpcMessage msg) throws DcerpcException, IOException {
static void resolveSids0(String authorityServerName, NtlmPasswordAuthentication auth, SID[] sids) throws IOException { DcerpcHandle handle = null; LsaPolicyHandle policyHandle = null; synchronized (sid_cache) { try { handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\lsarpc]", auth); String server = authorityServerName; int dot = server.indexOf('.'); if (dot > 0 && Character.isDigit(server.charAt(0)) == false) server = server.substring(0, dot); policyHandle = new LsaPolicyHandle(handle, "\\\\" + server, 0x00000800); SID.resolveSids(handle, policyHandle, sids); } finally { if (handle != null) { if (policyHandle != null) { policyHandle.close(); } handle.close(); } } } }
aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x0002000c, rid); rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray); handle.sendrecv(rpc); if (rpc.retval != 0) throw new SmbException(rpc.retval, false); SID[] sids = new SID[rpc.sids.num_sids]; String origin_server = handle.getServer(); NtlmPasswordAuthentication origin_auth = (NtlmPasswordAuthentication)handle.getPrincipal();
try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]", tc) ) { SamrPolicyHandle policyHandle = new SamrPolicyHandle(handle, authorityServerName, 0x00000030); SamrDomainHandle domainHandle = new SamrDomainHandle(handle, policyHandle, 0x00000200, domsid.unwrap(sid_t.class)); try ( SamrAliasHandle aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x0002000c, rid) ) { rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray); handle.sendrecv(rpc); if ( rpc.retval != 0 ) throw new SmbException(rpc.retval, false); SID[] sids = new SID[rpc.sids.num_sids]; String origin_server = handle.getServer(); CIFSContext origin_ctx = handle.getTransportContext();
bind(); NdrBuffer buf = encodeMessage(msg, out); int off = sendFragments(msg, out, buf); int have = doSendReceiveFragment(out, off, msg.length, inB); setupReceivedFragment(buf); buf.setIndex(0); msg.decode_header(buf); msgBuf = new NdrBuffer(receiveMoreFragments(msg, inB), 0);