⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dcerpc_connect.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Unix SMB/CIFS implementation.   dcerpc connect functions   Copyright (C) Andrew Tridgell 2003   Copyright (C) Jelmer Vernooij 2004   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-2007   Copyright (C) Rafal Szczesniak  2005      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program.  If not, see <http://www.gnu.org/licenses/>.*/#include "includes.h"#include "libcli/composite/composite.h"#include "libcli/smb_composite/smb_composite.h"#include "lib/events/events.h"#include "libcli/smb2/smb2.h"#include "libcli/smb2/smb2_calls.h"#include "librpc/rpc/dcerpc.h"#include "librpc/rpc/dcerpc_proto.h"#include "auth/credentials/credentials.h"#include "param/param.h"#include "libcli/resolve/resolve.h"struct pipe_np_smb_state {	struct smb_composite_connect conn;	struct smbcli_tree *tree;	struct dcerpc_pipe_connect io;};/*  Stage 3 of ncacn_np_smb: Named pipe opened (or not)*/static void continue_pipe_open_smb(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	/* receive result of named pipe open request on smb */	c->status = dcerpc_pipe_open_smb_recv(ctx);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  Stage 2 of ncacn_np_smb: Open a named pipe after successful smb connection*/static void continue_smb_connect(struct composite_context *ctx){	struct composite_context *open_ctx;	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_np_smb_state *s = talloc_get_type(c->private_data,						      struct pipe_np_smb_state);		/* receive result of smb connect request */	c->status = smb_composite_connect_recv(ctx, c);	if (!composite_is_ok(c)) return;	/* prepare named pipe open parameters */	s->tree         = s->conn.out.tree;	s->io.pipe_name = s->io.binding->endpoint;	/* send named pipe open request */	open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe, s->tree, s->io.pipe_name);	if (composite_nomem(open_ctx, c)) return;	composite_continue(c, open_ctx, continue_pipe_open_smb, c);}/*  Initiate async open of a rpc connection to a rpc pipe on SMB using  the binding structure to determine the endpoint and options*/static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *mem_ctx, struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx){	struct composite_context *c;	struct pipe_np_smb_state *s;	struct composite_context *conn_req;	struct smb_composite_connect *conn;	/* composite context allocation and setup */	c = composite_create(mem_ctx, io->pipe->conn->event_ctx);	if (c == NULL) return NULL;	s = talloc_zero(c, struct pipe_np_smb_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	s->io  = *io;	conn   = &s->conn;	/* prepare smb connection parameters: we're connecting to IPC$ share on	   remote rpc server */	conn->in.dest_host              = s->io.binding->host;	conn->in.dest_ports                  = lp_smb_ports(lp_ctx);	if (s->io.binding->target_hostname == NULL)		conn->in.called_name = "*SMBSERVER"; /* FIXME: This is invalid */	else		conn->in.called_name            = s->io.binding->target_hostname;	conn->in.service                = "IPC$";	conn->in.service_type           = NULL;	conn->in.workgroup		= lp_workgroup(lp_ctx);	lp_smbcli_options(lp_ctx, &conn->in.options);	/*	 * provide proper credentials - user supplied, but allow a	 * fallback to anonymous if this is an schannel connection	 * (might be NT4 not allowing machine logins at session	 * setup).	 */	s->conn.in.credentials = s->io.creds;	if (s->io.binding->flags & DCERPC_SCHANNEL) {		conn->in.fallback_to_anonymous  = true;	} else {		conn->in.fallback_to_anonymous  = false;	}	/* send smb connect request */	conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, 					      lp_resolve_context(lp_ctx), 					      s->io.pipe->conn->event_ctx);	if (composite_nomem(conn_req, c)) return c;	composite_continue(c, conn_req, continue_smb_connect, c);	return c;}/*  Receive result of a rpc connection to a rpc pipe on SMB*/static NTSTATUS dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context *c){	NTSTATUS status = composite_wait(c);	talloc_free(c);	return status;}struct pipe_np_smb2_state {	struct smb2_tree *tree;	struct dcerpc_pipe_connect io;};/*  Stage 3 of ncacn_np_smb: Named pipe opened (or not)*/static void continue_pipe_open_smb2(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	/* receive result of named pipe open request on smb2 */	c->status = dcerpc_pipe_open_smb2_recv(ctx);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  Stage 2 of ncacn_np_smb2: Open a named pipe after successful smb2 connection*/static void continue_smb2_connect(struct composite_context *ctx){	struct composite_context *open_req;	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,						       struct pipe_np_smb2_state);	/* receive result of smb2 connect request */	c->status = smb2_connect_recv(ctx, c, &s->tree);	if (!composite_is_ok(c)) return;	/* prepare named pipe open parameters */	s->io.pipe_name = s->io.binding->endpoint;	/* send named pipe open request */	open_req = dcerpc_pipe_open_smb2_send(s->io.pipe, s->tree, s->io.pipe_name);	if (composite_nomem(open_req, c)) return;	composite_continue(c, open_req, continue_pipe_open_smb2, c);}/*    Initiate async open of a rpc connection request on SMB2 using   the binding structure to determine the endpoint and options*/static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(					TALLOC_CTX *mem_ctx,					struct dcerpc_pipe_connect *io,					struct loadparm_context *lp_ctx){	struct composite_context *c;	struct pipe_np_smb2_state *s;	struct composite_context *conn_req;	struct smbcli_options options;	/* composite context allocation and setup */	c = composite_create(mem_ctx, io->pipe->conn->event_ctx);	if (c == NULL) return NULL;	s = talloc_zero(c, struct pipe_np_smb2_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	s->io = *io;	/*	 * provide proper credentials - user supplied or anonymous in case this is	 * schannel connection	 */	if (s->io.binding->flags & DCERPC_SCHANNEL) {		s->io.creds = cli_credentials_init(mem_ctx);		if (composite_nomem(s->io.creds, c)) return c;		cli_credentials_guess(s->io.creds, lp_ctx);	}	lp_smbcli_options(lp_ctx, &options);	/* send smb2 connect request */	conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, "IPC$", 				     s->io.resolve_ctx,				     s->io.creds,				     c->event_ctx,				     &options);	composite_continue(c, conn_req, continue_smb2_connect, c);	return c;}/*  Receive result of a rpc connection to a rpc pipe on SMB2*/static NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context *c){	NTSTATUS status = composite_wait(c);		talloc_free(c);	return status;}struct pipe_ip_tcp_state {	struct dcerpc_pipe_connect io;	const char *host;	const char *target_hostname;	uint32_t port;};/*  Stage 2 of ncacn_ip_tcp: rpc pipe opened (or not)*/static void continue_pipe_open_ncacn_ip_tcp(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	/* receive result of named pipe open request on tcp/ip */	c->status = dcerpc_pipe_open_tcp_recv(ctx);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  Initiate async open of a rpc connection to a rpc pipe on TCP/IP using  the binding structure to determine the endpoint and options*/static struct composite_context* dcerpc_pipe_connect_ncacn_ip_tcp_send(TALLOC_CTX *mem_ctx,								       struct dcerpc_pipe_connect *io){	struct composite_context *c;	struct pipe_ip_tcp_state *s;	struct composite_context *pipe_req;	/* composite context allocation and setup */	c = composite_create(mem_ctx, io->pipe->conn->event_ctx);	if (c == NULL) return NULL;	s = talloc_zero(c, struct pipe_ip_tcp_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	/* store input parameters in state structure */	s->io               = *io;	s->host             = talloc_reference(c, io->binding->host);	s->target_hostname  = talloc_reference(c, io->binding->target_hostname);                             /* port number is a binding endpoint here */	s->port             = atoi(io->binding->endpoint);   	/* send pipe open request on tcp/ip */	pipe_req = dcerpc_pipe_open_tcp_send(s->io.pipe->conn, s->host, s->target_hostname, 					     s->port, io->resolve_ctx);	composite_continue(c, pipe_req, continue_pipe_open_ncacn_ip_tcp, c);	return c;}/*  Receive result of a rpc connection to a rpc pipe on TCP/IP*/static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp_recv(struct composite_context *c){	NTSTATUS status = composite_wait(c);		talloc_free(c);	return status;}struct pipe_unix_state {	struct dcerpc_pipe_connect io;	const char *path;};/*  Stage 2 of ncacn_unix: rpc pipe opened (or not)*/static void continue_pipe_open_ncacn_unix_stream(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	/* receive result of pipe open request on unix socket */	c->status = dcerpc_pipe_open_unix_stream_recv(ctx);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  Initiate async open of a rpc connection to a rpc pipe on unix socket using  the binding structure to determine the endpoint and options*/static struct composite_context* dcerpc_pipe_connect_ncacn_unix_stream_send(TALLOC_CTX *mem_ctx,									    struct dcerpc_pipe_connect *io){	struct composite_context *c;	struct pipe_unix_state *s;	struct composite_context *pipe_req;	/* composite context allocation and setup */	c = composite_create(mem_ctx, io->pipe->conn->event_ctx);	if (c == NULL) return NULL;	s = talloc_zero(c, struct pipe_unix_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	/* prepare pipe open parameters and store them in state structure	   also, verify whether biding endpoint is not null */	s->io = *io;		if (!io->binding->endpoint) {		DEBUG(0, ("Path to unix socket not specified\n"));		composite_error(c, NT_STATUS_INVALID_PARAMETER);		return c;	}	s->path  = talloc_strdup(c, io->binding->endpoint);  /* path is a binding endpoint here */	if (composite_nomem(s->path, c)) return c;	/* send pipe open request on unix socket */	pipe_req = dcerpc_pipe_open_unix_stream_send(s->io.pipe->conn, s->path);	composite_continue(c, pipe_req, continue_pipe_open_ncacn_unix_stream, c);	return c;}/*  Receive result of a rpc connection to a pipe on unix socket*/static NTSTATUS dcerpc_pipe_connect_ncacn_unix_stream_recv(struct composite_context *c){	NTSTATUS status = composite_wait(c);	talloc_free(c);	return status;}struct pipe_ncalrpc_state {	struct dcerpc_pipe_connect io;};static NTSTATUS dcerpc_pipe_connect_ncalrpc_recv(struct composite_context *c);/*  Stage 2 of ncalrpc: rpc pipe opened (or not)*/static void continue_pipe_open_ncalrpc(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	/* receive result of pipe open request on ncalrpc */	c->status = dcerpc_pipe_connect_ncalrpc_recv(ctx);	if (!composite_is_ok(c)) return;	composite_done(c);}/*    Initiate async open of a rpc connection request on NCALRPC using   the binding structure to determine the endpoint and options*/static struct composite_context* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX *mem_ctx,								  struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx){	struct composite_context *c;	struct pipe_ncalrpc_state *s;	struct composite_context *pipe_req;	/* composite context allocation and setup */	c = composite_create(mem_ctx, io->pipe->conn->event_ctx);	if (c == NULL) return NULL;	s = talloc_zero(c, struct pipe_ncalrpc_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;		/* store input parameters in state structure */	s->io  = *io;	/* send pipe open request */	pipe_req = dcerpc_pipe_open_pipe_send(s->io.pipe->conn, lp_ncalrpc_dir(lp_ctx), 					      s->io.binding->endpoint);	composite_continue(c, pipe_req, continue_pipe_open_ncalrpc, c);	return c;}/*  Receive result of a rpc connection to a rpc pipe on NCALRPC*/static NTSTATUS dcerpc_pipe_connect_ncalrpc_recv(struct composite_context *c){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -