NTSTATUS net_make_ipc_connection_ex(struct net_context *c ,const char *domain, const char *server, struct sockaddr_storage *pss, unsigned flags, struct cli_state **pcli) { char *server_name = NULL; struct sockaddr_storage server_ss; struct cli_state *cli = NULL; NTSTATUS nt_status; if ( !server || !pss ) { if (!net_find_server(c, domain, flags, &server_ss, &server_name)) { d_fprintf(stderr, _("Unable to find a suitable server " "for domain %s\n"), domain); nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } } else { server_name = SMB_STRDUP( server ); server_ss = *pss; } if (flags & NET_FLAGS_ANONYMOUS) { nt_status = connect_to_ipc_anonymous(c, &cli, &server_ss, server_name); } else { nt_status = connect_to_ipc(c, &cli, &server_ss, server_name); } /* store the server in the affinity cache if it was a PDC */ if ( (flags & NET_FLAGS_PDC) && NT_STATUS_IS_OK(nt_status) ) saf_store( cli->server_domain, cli->desthost ); SAFE_FREE(server_name); if (!NT_STATUS_IS_OK(nt_status)) { d_fprintf(stderr, _("Connection failed: %s\n"), nt_errstr(nt_status)); cli = NULL; } else if (c->opt_request_timeout) { cli_set_timeout(cli, c->opt_request_timeout * 1000); } done: if (pcli != NULL) { *pcli = cli; } return nt_status; }
struct cli_state *net_make_ipc_connection_ex( const char *domain, const char *server, struct in_addr *ip, unsigned flags) { char *server_name = NULL; struct in_addr server_ip; struct cli_state *cli = NULL; NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; if ( !server || !ip ) { if (!net_find_server(domain, flags, &server_ip, &server_name)) { d_fprintf(stderr, "Unable to find a suitable server\n"); return NULL; } } else { server_name = SMB_STRDUP( server ); server_ip = *ip; } if (opt_user_name) { nt_status = connect_to_ipc(&cli, &server_ip, server_name); if (NT_STATUS_IS_OK(nt_status)) { goto connected; } } if (flags & NET_FLAGS_ANONYMOUS) { nt_status = connect_to_ipc_anonymous(&cli, &server_ip, server_name); if (NT_STATUS_IS_OK(nt_status)) { goto connected; } } SAFE_FREE(server_name); d_fprintf(stderr, "Connection failed: %s\n", nt_errstr(nt_status)); return NULL; connected: /* store the server in the affinity cache if it was a PDC */ if ( (flags & NET_FLAGS_PDC) && NT_STATUS_IS_OK(nt_status) ) saf_store( cli->server_domain, cli->desthost ); return cli; }
/** * Connect a server and open a given pipe * * @param cli_dst A cli_state * @param pipe The pipe to open * @param got_pipe boolean that stores if we got a pipe * * @return Normal NTSTATUS return. **/ NTSTATUS connect_dst_pipe(struct net_context *c, struct cli_state **cli_dst, struct rpc_pipe_client **pp_pipe_hnd, const struct ndr_syntax_id *interface) { NTSTATUS nt_status; char *server_name = SMB_STRDUP("127.0.0.1"); struct cli_state *cli_tmp = NULL; struct rpc_pipe_client *pipe_hnd = NULL; if (server_name == NULL) { return NT_STATUS_NO_MEMORY; } if (c->opt_destination) { SAFE_FREE(server_name); if ((server_name = SMB_STRDUP(c->opt_destination)) == NULL) { return NT_STATUS_NO_MEMORY; } } /* make a connection to a named pipe */ nt_status = connect_to_ipc(c, &cli_tmp, NULL, server_name); if (!NT_STATUS_IS_OK(nt_status)) { SAFE_FREE(server_name); return nt_status; } nt_status = cli_rpc_pipe_open_noauth(cli_tmp, interface, &pipe_hnd); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0, ("couldn't not initialize pipe\n")); cli_shutdown(cli_tmp); SAFE_FREE(server_name); return nt_status; } *cli_dst = cli_tmp; *pp_pipe_hnd = pipe_hnd; SAFE_FREE(server_name); return nt_status; }
/** * Connect a server and open a given pipe * * @param cli_dst A cli_state * @param pipe The pipe to open * @param got_pipe boolean that stores if we got a pipe * * @return Normal NTSTATUS return. **/ NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **pp_pipe_hnd, int pipe_num) { NTSTATUS nt_status; char *server_name = SMB_STRDUP("127.0.0.1"); struct cli_state *cli_tmp = NULL; struct rpc_pipe_client *pipe_hnd = NULL; if (server_name == NULL) { return NT_STATUS_NO_MEMORY; } if (opt_destination) { SAFE_FREE(server_name); if ((server_name = SMB_STRDUP(opt_destination)) == NULL) { return NT_STATUS_NO_MEMORY; } } /* make a connection to a named pipe */ nt_status = connect_to_ipc(&cli_tmp, NULL, server_name); if (!NT_STATUS_IS_OK(nt_status)) { SAFE_FREE(server_name); return nt_status; } pipe_hnd = cli_rpc_pipe_open_noauth(cli_tmp, pipe_num, &nt_status); if (!pipe_hnd) { DEBUG(1, ("couldn't not initialize pipe\n")); cli_shutdown(cli_tmp); SAFE_FREE(server_name); return nt_status; } *cli_dst = cli_tmp; *pp_pipe_hnd = pipe_hnd; SAFE_FREE(server_name); return nt_status; }