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

📄 dcerpc_connect.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
	NTSTATUS status = composite_wait(c);		talloc_free(c);	return status;}struct pipe_connect_state {	struct dcerpc_pipe *pipe;	struct dcerpc_binding *binding;	const struct ndr_interface_table *table;	struct cli_credentials *credentials;	struct loadparm_context *lp_ctx;};static void continue_map_binding(struct composite_context *ctx);static void continue_connect(struct composite_context *c, struct pipe_connect_state *s);static void continue_pipe_connect_ncacn_np_smb2(struct composite_context *ctx);static void continue_pipe_connect_ncacn_np_smb(struct composite_context *ctx);static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context *ctx);static void continue_pipe_connect_ncacn_unix(struct composite_context *ctx);static void continue_pipe_connect_ncalrpc(struct composite_context *ctx);static void continue_pipe_connect(struct composite_context *c, struct pipe_connect_state *s);static void continue_pipe_auth(struct composite_context *ctx);/*  Stage 2 of pipe_connect_b: Receive result of endpoint mapping*/static void continue_map_binding(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);		c->status = dcerpc_epm_map_binding_recv(ctx);	if (!composite_is_ok(c)) return;	DEBUG(2,("Mapped to DCERPC endpoint %s\n", s->binding->endpoint));		continue_connect(c, s);}/*  Stage 2 of pipe_connect_b: Continue connection after endpoint is known*/static void continue_connect(struct composite_context *c, struct pipe_connect_state *s){	struct dcerpc_pipe_connect pc;	/* potential exits to another stage by sending an async request */	struct composite_context *ncacn_np_smb2_req;	struct composite_context *ncacn_np_smb_req;	struct composite_context *ncacn_ip_tcp_req;	struct composite_context *ncacn_unix_req;	struct composite_context *ncalrpc_req;	/* dcerpc pipe connect input parameters */	pc.pipe         = s->pipe;	pc.binding      = s->binding;	pc.interface    = s->table;	pc.creds        = s->credentials;	pc.resolve_ctx  = lp_resolve_context(s->lp_ctx);	/* connect dcerpc pipe depending on required transport */	switch (s->binding->transport) {	case NCACN_NP:		if (pc.binding->flags & DCERPC_SMB2) {			/* new varient of SMB a.k.a. SMB2 */			ncacn_np_smb2_req = dcerpc_pipe_connect_ncacn_np_smb2_send(c, &pc, s->lp_ctx);			composite_continue(c, ncacn_np_smb2_req, continue_pipe_connect_ncacn_np_smb2, c);			return;		} else {			/* good old ordinary SMB */			ncacn_np_smb_req = dcerpc_pipe_connect_ncacn_np_smb_send(c, &pc, s->lp_ctx);			composite_continue(c, ncacn_np_smb_req, continue_pipe_connect_ncacn_np_smb, c);			return;		}		break;	case NCACN_IP_TCP:		ncacn_ip_tcp_req = dcerpc_pipe_connect_ncacn_ip_tcp_send(c, &pc);		composite_continue(c, ncacn_ip_tcp_req, continue_pipe_connect_ncacn_ip_tcp, c);		return;	case NCACN_UNIX_STREAM:		ncacn_unix_req = dcerpc_pipe_connect_ncacn_unix_stream_send(c, &pc);		composite_continue(c, ncacn_unix_req, continue_pipe_connect_ncacn_unix, c);		return;	case NCALRPC:		ncalrpc_req = dcerpc_pipe_connect_ncalrpc_send(c, &pc, s->lp_ctx);		composite_continue(c, ncalrpc_req, continue_pipe_connect_ncalrpc, c);		return;	default:		/* looks like a transport we don't support now */		composite_error(c, NT_STATUS_NOT_SUPPORTED);	}}/*  Stage 3 of pipe_connect_b: Receive result of pipe connect request on  named pipe on smb2*/static void continue_pipe_connect_ncacn_np_smb2(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);	c->status = dcerpc_pipe_connect_ncacn_np_smb2_recv(ctx);	if (!composite_is_ok(c)) return;	continue_pipe_connect(c, s);}/*  Stage 3 of pipe_connect_b: Receive result of pipe connect request on  named pipe on smb*/static void continue_pipe_connect_ncacn_np_smb(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);	c->status = dcerpc_pipe_connect_ncacn_np_smb_recv(ctx);	if (!composite_is_ok(c)) return;		continue_pipe_connect(c, s);}/*  Stage 3 of pipe_connect_b: Receive result of pipe connect request on tcp/ip*/static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);	c->status = dcerpc_pipe_connect_ncacn_ip_tcp_recv(ctx);	if (!composite_is_ok(c)) return;	continue_pipe_connect(c, s);}/*  Stage 3 of pipe_connect_b: Receive result of pipe connect request on unix socket*/static void continue_pipe_connect_ncacn_unix(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);		c->status = dcerpc_pipe_connect_ncacn_unix_stream_recv(ctx);	if (!composite_is_ok(c)) return;		continue_pipe_connect(c, s);}/*  Stage 3 of pipe_connect_b: Receive result of pipe connect request on local rpc*/static void continue_pipe_connect_ncalrpc(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data,						       struct pipe_connect_state);		c->status = dcerpc_pipe_connect_ncalrpc_recv(ctx);	if (!composite_is_ok(c)) return;	continue_pipe_connect(c, s);}/*  Stage 4 of pipe_connect_b: Start an authentication on connected dcerpc pipe  depending on credentials and binding flags passed.*/static void continue_pipe_connect(struct composite_context *c, struct pipe_connect_state *s){	struct composite_context *auth_bind_req;	s->pipe->binding = s->binding;	if (!talloc_reference(s->pipe, s->binding)) {		composite_error(c, NT_STATUS_NO_MEMORY);		return;	}	auth_bind_req = dcerpc_pipe_auth_send(s->pipe, s->binding, s->table,					      s->credentials, s->lp_ctx);	composite_continue(c, auth_bind_req, continue_pipe_auth, c);}/*  Stage 5 of pipe_connect_b: Receive result of pipe authentication request  and say if all went ok*/static void continue_pipe_auth(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_connect_state *s = talloc_get_type(c->private_data, struct pipe_connect_state);	c->status = dcerpc_pipe_auth_recv(ctx, s, &s->pipe);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  handle timeouts of a dcerpc connect*/static void dcerpc_connect_timeout_handler(struct event_context *ev, struct timed_event *te, 					   struct timeval t, void *private){	struct composite_context *c = talloc_get_type(private, struct composite_context);	composite_error(c, NT_STATUS_IO_TIMEOUT);}/*  start a request to open a rpc connection to a rpc pipe, using  specified binding structure to determine the endpoint and options*/_PUBLIC_ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,						     struct dcerpc_binding *binding,						     const struct ndr_interface_table *table,						     struct cli_credentials *credentials,						     struct event_context *ev,						     struct loadparm_context *lp_ctx){	struct composite_context *c;	struct pipe_connect_state *s;	struct event_context *new_ev = NULL;	/* composite context allocation and setup */	c = composite_create(parent_ctx, ev);	if (c == NULL) {		talloc_free(new_ev);		return NULL;	}	talloc_steal(c, new_ev);	s = talloc_zero(c, struct pipe_connect_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	/* initialise dcerpc pipe structure */	s->pipe = dcerpc_pipe_init(c, ev, lp_iconv_convenience(lp_ctx));	if (composite_nomem(s->pipe, c)) return c;	/* store parameters in state structure */	s->binding      = binding;	s->table        = table;	s->credentials  = credentials;	s->lp_ctx 	= lp_ctx;	event_add_timed(c->event_ctx, c,			timeval_current_ofs(DCERPC_REQUEST_TIMEOUT, 0),			dcerpc_connect_timeout_handler, c);		switch (s->binding->transport) {	case NCA_UNKNOWN: {		struct composite_context *binding_req;		binding_req = dcerpc_epm_map_binding_send(c, s->binding, s->table,							  s->pipe->conn->event_ctx,							  s->lp_ctx);		composite_continue(c, binding_req, continue_map_binding, c);		return c;		}	case NCACN_NP:	case NCACN_IP_TCP:	case NCALRPC:		if (!s->binding->endpoint) {			struct composite_context *binding_req;			binding_req = dcerpc_epm_map_binding_send(c, s->binding, s->table,								  s->pipe->conn->event_ctx,								  s->lp_ctx);			composite_continue(c, binding_req, continue_map_binding, c);			return c;		}	default:		break;	}	continue_connect(c, s);	return c;}/*  receive result of a request to open a rpc connection to a rpc pipe*/_PUBLIC_ NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,				    struct dcerpc_pipe **p){	NTSTATUS status;	struct pipe_connect_state *s;		status = composite_wait(c);		if (NT_STATUS_IS_OK(status)) {		s = talloc_get_type(c->private_data, struct pipe_connect_state);		talloc_steal(mem_ctx, s->pipe);		*p = s->pipe;	}	talloc_free(c);	return status;}/*  open a rpc connection to a rpc pipe, using the specified   binding structure to determine the endpoint and options - sync version*/_PUBLIC_ NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,			       struct dcerpc_pipe **pp,			       struct dcerpc_binding *binding,			       const struct ndr_interface_table *table,			       struct cli_credentials *credentials,			       struct event_context *ev,			       struct loadparm_context *lp_ctx){	struct composite_context *c;		c = dcerpc_pipe_connect_b_send(parent_ctx, binding, table,				       credentials, ev, lp_ctx);	return dcerpc_pipe_connect_b_recv(c, parent_ctx, pp);}struct pipe_conn_state {	struct dcerpc_pipe *pipe;};static void continue_pipe_connect_b(struct composite_context *ctx);/*  Initiate rpc connection to a rpc pipe, using the specified string  binding to determine the endpoint and options.  The string is to be parsed to a binding structure first.*/_PUBLIC_ struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,						   const char *binding,						   const struct ndr_interface_table *table,						   struct cli_credentials *credentials,						   struct event_context *ev, struct loadparm_context *lp_ctx){	struct composite_context *c;	struct pipe_conn_state *s;	struct dcerpc_binding *b;	struct composite_context *pipe_conn_req;	/* composite context allocation and setup */	c = composite_create(parent_ctx, ev);	if (c == NULL) {		return NULL;	}	s = talloc_zero(c, struct pipe_conn_state);	if (composite_nomem(s, c)) return c;	c->private_data = s;	/* parse binding string to the structure */	c->status = dcerpc_parse_binding(c, binding, &b);	if (!NT_STATUS_IS_OK(c->status)) {		DEBUG(0, ("Failed to parse dcerpc binding '%s'\n", binding));		composite_error(c, c->status);		return c;	}	DEBUG(3, ("Using binding %s\n", dcerpc_binding_string(c, b)));	/* 	   start connecting to a rpc pipe after binding structure	   is established	 */	pipe_conn_req = dcerpc_pipe_connect_b_send(c, b, table,						   credentials, ev, lp_ctx);	composite_continue(c, pipe_conn_req, continue_pipe_connect_b, c);	return c;}/*  Stage 2 of pipe_connect: Receive result of actual pipe connect request  and say if we're done ok*/static void continue_pipe_connect_b(struct composite_context *ctx){	struct composite_context *c = talloc_get_type(ctx->async.private_data,						      struct composite_context);	struct pipe_conn_state *s = talloc_get_type(c->private_data,						    struct pipe_conn_state);	c->status = dcerpc_pipe_connect_b_recv(ctx, c, &s->pipe);	talloc_steal(s, s->pipe);	if (!composite_is_ok(c)) return;	composite_done(c);}/*  Receive result of pipe connect (using binding string) request  and return connected pipe structure.*/NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,				  TALLOC_CTX *mem_ctx,				  struct dcerpc_pipe **pp){	NTSTATUS status;	struct pipe_conn_state *s;	status = composite_wait(c);	if (NT_STATUS_IS_OK(status)) {		s = talloc_get_type(c->private_data, struct pipe_conn_state);		*pp = talloc_steal(mem_ctx, s->pipe);	}	talloc_free(c);	return status;}/*  Open a rpc connection to a rpc pipe, using the specified string  binding to determine the endpoint and options - sync version*/_PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 			     struct dcerpc_pipe **pp, 			     const char *binding,			     const struct ndr_interface_table *table,			     struct cli_credentials *credentials,			     struct event_context *ev,			     struct loadparm_context *lp_ctx){	struct composite_context *c;	c = dcerpc_pipe_connect_send(parent_ctx, binding, 				     table, credentials, ev, lp_ctx);	return dcerpc_pipe_connect_recv(c, parent_ctx, pp);}

⌨️ 快捷键说明

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