return NT_STATUS_NO_LOGON_SERVERS;
/* Attempt connection */
- result = smbcli_full_connection(cli, lp_netbios_name(), remote_machine,
+ result = smbcli_full_connection(NULL, cli, lp_netbios_name(), remote_machine,
&dest_ip, 0, "IPC$", "IPC", "", "", "",0, retry);
if (!NT_STATUS_IS_OK(result)) {
again:
/* have to open a new connection */
- if (!(c=smbcli_state_init()) || !smbcli_socket_connect(c, server_n)) {
+ if (!(c=smbcli_state_init(NULL)) || !smbcli_socket_connect(c, server_n)) {
d_printf("Connection to %s failed\n", server_n);
return NULL;
}
server_name = dest_ip ? dest_ip : desthost;
- if (!(cli=smbcli_state_init()) || !smbcli_socket_connect(cli, server_name)) {
+ if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name)) {
d_printf("Connection to %s failed\n", server_name);
return 1;
}
myname = get_myname();
- nt_status = smbcli_full_connection(&c, myname, server, NULL, 0, share, "?????",
+ nt_status = smbcli_full_connection(NULL, &c, myname, server, NULL, 0, share, "?????",
username, workgroup, password, 0, NULL);
free(myname);
{
struct smbcli_socket *sock;
- sock = smbcli_sock_init();
+ sock = smbcli_sock_init(cli);
if (!sock) return False;
if (!smbcli_sock_connect_byname(sock, server, 0)) {
/*
easy way to get to a fully connected smbcli_state in one call
*/
-NTSTATUS smbcli_full_connection(struct smbcli_state **ret_cli,
- const char *myname,
- const char *host,
- struct in_addr *ip,
- const char *sharename,
- const char *devtype,
- const char *username,
- const char *domain,
- const char *password,
- uint_t flags,
- BOOL *retry)
+NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx,
+ struct smbcli_state **ret_cli,
+ const char *myname,
+ const char *host,
+ struct in_addr *ip,
+ const char *sharename,
+ const char *devtype,
+ const char *username,
+ const char *domain,
+ const char *password,
+ uint_t flags,
+ BOOL *retry)
{
struct smbcli_tree *tree;
NTSTATUS status;
username = talloc_strdup(mem_ctx, p+1);
}
- status = smbcli_tree_full_connection(&tree, myname, host, 0, sharename, devtype,
+ status = smbcli_tree_full_connection(parent_ctx,
+ &tree, myname, host, 0, sharename, devtype,
username, domain, password);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
- (*ret_cli) = smbcli_state_init();
+ (*ret_cli) = smbcli_state_init(parent_ctx);
- (*ret_cli)->tree = talloc_reference(*ret_cli, tree);
- talloc_free(tree);
+ (*ret_cli)->tree = tree;
(*ret_cli)->session = tree->session;
(*ret_cli)->transport = tree->session->transport;
-
+ talloc_steal(*ret_cli, tree->session->transport->socket);
+
done:
talloc_free(mem_ctx);
+
return status;
}
/****************************************************************************
Initialise a client state structure.
****************************************************************************/
-struct smbcli_state *smbcli_state_init(void)
+struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx)
{
struct smbcli_state *cli;
- cli = talloc_p(NULL, struct smbcli_state);
+ cli = talloc_p(mem_ctx, struct smbcli_state);
if (cli) {
ZERO_STRUCTP(cli);
}
return -1;
c = cluster->cli[i];
- if (NT_STATUS_IS_ERR(smbcli_full_connection(&c,
+ if (NT_STATUS_IS_ERR(smbcli_full_connection(NULL, &c,
NULL, host, NULL, 0,
share, "?????",
cluster->username, cluster->workgroup,
/*
create a smbcli_socket context
*/
-struct smbcli_socket *smbcli_sock_init(void)
+struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx)
{
struct smbcli_socket *sock;
- sock = talloc_p(NULL, struct smbcli_socket);
+ sock = talloc_p(mem_ctx, struct smbcli_socket);
if (!sock) {
return NULL;
}
a convenient function to establish a smbcli_tree from scratch, using reasonable default
parameters
*/
-NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
+NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
+ struct smbcli_tree **ret_tree,
const char *my_name,
const char *dest_host, int port,
const char *service, const char *service_type,
*ret_tree = NULL;
- sock = smbcli_sock_init();
+ sock = smbcli_sock_init(parent_ctx);
if (!sock) {
return NT_STATUS_NO_MEMORY;
}
c.close.in.fnum = smb->fnum;
c.close.in.write_time = 0;
smb_raw_close(smb->tree, &c);
+
talloc_free(smb);
return NT_STATUS_OK;
}
smb->fnum = io.ntcreatex.out.fnum;
- smb->tree = talloc_reference(smb, tree);
+ smb->tree = tree;
(*p)->transport.private = smb;
}
if (!username || !username[0]) {
- status = smbcli_full_connection(&cli, lp_netbios_name(),
+ status = smbcli_full_connection(NULL, &cli, lp_netbios_name(),
binding->host, NULL,
"ipc$", "?????",
"", "", NULL, 0, &retry);
} else {
- status = smbcli_full_connection(&cli, lp_netbios_name(),
+ status = smbcli_full_connection(NULL, &cli, lp_netbios_name(),
binding->host, NULL,
"ipc$", "?????",
username, domain,
/* this ensures that the reference count is decremented so
a pipe close will really close the link */
- talloc_free(cli->tree);
talloc_steal(*p, cli);
(*p)->flags = binding->flags;
ntvfs_set_private(req->tcon, depth, private);
- status = smbcli_tree_full_connection(&private->tree,
- "vfs_cifs",
- host,
- 0,
- remote_share, "?????",
- user, domain,
- pass);
+ status = smbcli_tree_full_connection(private,
+ &private->tree,
+ "vfs_cifs",
+ host,
+ 0,
+ remote_share, "?????",
+ user, domain,
+ pass);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/* a list of open pipes */
struct pipe_state {
struct pipe_state *next, *prev;
- TALLOC_CTX *mem_ctx;
const char *pipe_name;
uint16_t fnum;
struct dcesrv_connection *dce_conn;
*/
static void pipe_shutdown(struct ipc_private *private, struct pipe_state *p)
{
- TALLOC_CTX *mem_ctx = private->pipe_list->mem_ctx;
- dcesrv_endpoint_disconnect(private->pipe_list->dce_conn);
- DLIST_REMOVE(private->pipe_list, private->pipe_list);
- talloc_destroy(mem_ctx);
+ talloc_free(p->dce_conn);
+ DLIST_REMOVE(private->pipe_list, p);
+ talloc_destroy(p);
}
struct pipe_state **ps)
{
struct pipe_state *p;
- TALLOC_CTX *mem_ctx;
NTSTATUS status;
struct dcesrv_ep_description ep_description;
struct auth_session_info *session_info = NULL;
NTVFS_GET_PRIVATE(ipc_private, private, req);
- mem_ctx = talloc_init("ipc_open '%s'", fname);
- if (!mem_ctx) {
- return NT_STATUS_NO_MEMORY;
- }
-
- p = talloc(mem_ctx, sizeof(struct pipe_state));
+ p = talloc_p(private, struct pipe_state);
if (!p) {
- talloc_destroy(mem_ctx);
return NT_STATUS_NO_MEMORY;
}
- p->mem_ctx = mem_ctx;
- p->pipe_name = talloc_strdup(mem_ctx, fname);
+ p->pipe_name = talloc_strdup(p, fname);
if (!p->pipe_name) {
- talloc_destroy(mem_ctx);
+ talloc_free(p);
return NT_STATUS_NO_MEMORY;
}
p->fnum = find_next_fnum(private);
if (p->fnum == 0) {
- talloc_destroy(mem_ctx);
+ talloc_free(p);
return NT_STATUS_TOO_MANY_OPENED_FILES;
}
session_info,
&p->dce_conn);
if (!NT_STATUS_IS_OK(status)) {
- talloc_destroy(mem_ctx);
+ talloc_free(p);
return status;
}
}
+/*
+ destroy a link to an endpoint
+*/
+static int dcesrv_endpoint_destructor(void *ptr)
+{
+ struct dcesrv_connection *p = ptr;
+ if (p->iface) {
+ p->iface->unbind(p, p->iface);
+ }
+
+ /* destroy any handles */
+ while (p->handles) {
+ dcesrv_handle_destroy(p, p->handles);
+ }
+
+ if (p->auth_state.gensec_security) {
+ gensec_end(&p->auth_state.gensec_security);
+ }
+
+ return 0;
+}
+
+
/*
connect to a dcerpc endpoint
*/
(*p)->auth_state.session_key = dcesrv_generic_session_key;
(*p)->srv_conn = NULL;
+ talloc_set_destructor(*p, dcesrv_endpoint_destructor);
+
return NT_STATUS_OK;
}
}
-/*
- disconnect a link to an endpoint
-*/
-void dcesrv_endpoint_disconnect(struct dcesrv_connection *p)
-{
- if (p->iface) {
- p->iface->unbind(p, p->iface);
- }
-
- /* destroy any handles */
- while (p->handles) {
- dcesrv_handle_destroy(p, p->handles);
- }
-
- if (p->auth_state.gensec_security) {
- gensec_end(&p->auth_state.gensec_security);
- }
-
- talloc_free(p);
-}
-
static void dcesrv_init_hdr(struct dcerpc_packet *pkt)
{
pkt->rpc_vers = 5;
printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
servers[i].server_name, servers[i].share_name,
servers[i].username, j);
- status = smbcli_full_connection(&servers[i].cli[j],
+ status = smbcli_full_connection(NULL, &servers[i].cli[j],
"gentest",
servers[i].server_name, NULL,
servers[i].share_name, "?????",
slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), snum);
do {
- status = smbcli_full_connection(&c, myname,
+ status = smbcli_full_connection(NULL, &c, myname,
server, NULL,
share, "?????",
servers[snum].username, lp_workgroup(),
slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
- nt_status = smbcli_full_connection(&c, myname, server_n, NULL, 0, share, "?????",
- username, lp_workgroup(), password, 0,
- NULL);
+ nt_status = smbcli_full_connection(NULL,
+ &c, myname, server_n, NULL, 0, share, "?????",
+ username, lp_workgroup(), password, 0,
+ NULL);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0, ("smbcli_full_connection failed with error %s\n", nt_errstr(nt_status)));
*share = 0;
share++;
- status = smbcli_full_connection(&c, "masktest",
+ status = smbcli_full_connection(NULL, &c, "masktest",
server, NULL,
share, "?????",
username, lp_workgroup(),
printf("logoff the new vuid\n");
status = smb_raw_ulogoff(session);
CHECK_STATUS(status, NT_STATUS_OK);
- talloc_free(session);
printf("the new vuid should not now be accessible\n");
status = smb_raw_write(tree, &wr);
status = smb_raw_close(cli->tree, &cl);
CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
- /* close down the new tree, which will also close the session
- as the reference count will be 0 */
talloc_free(tree);
+ talloc_free(session);
done:
return ret;
struct samr_Connect4 r4;
struct samr_Connect5 r5;
union samr_ConnectInfo info;
- BOOL ret = True;
+ struct policy_handle h;
+ BOOL ret = True, got_handle = False;
printf("testing samr_Connect\n");
r.in.system_name = 0;
r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
- r.out.connect_handle = handle;
+ r.out.connect_handle = &h;
status = dcerpc_samr_Connect(p, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("Connect failed - %s\n", nt_errstr(status));
ret = False;
+ } else {
+ got_handle = True;
+ *handle = h;
}
printf("testing samr_Connect2\n");
r2.in.system_name = NULL;
r2.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
- r2.out.connect_handle = handle;
+ r2.out.connect_handle = &h;
status = dcerpc_samr_Connect2(p, mem_ctx, &r2);
if (!NT_STATUS_IS_OK(status)) {
printf("Connect2 failed - %s\n", nt_errstr(status));
ret = False;
+ } else {
+ if (got_handle) {
+ test_Close(p, mem_ctx, handle);
+ }
+ got_handle = True;
+ *handle = h;
}
printf("testing samr_Connect3\n");
r3.in.system_name = NULL;
r3.in.unknown = 0;
r3.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
- r3.out.connect_handle = handle;
+ r3.out.connect_handle = &h;
status = dcerpc_samr_Connect3(p, mem_ctx, &r3);
if (!NT_STATUS_IS_OK(status)) {
printf("Connect3 failed - %s\n", nt_errstr(status));
ret = False;
+ } else {
+ if (got_handle) {
+ test_Close(p, mem_ctx, handle);
+ }
+ got_handle = True;
+ *handle = h;
}
printf("testing samr_Connect4\n");
r4.in.system_name = "";
r4.in.unknown = 0;
r4.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
- r4.out.connect_handle = handle;
+ r4.out.connect_handle = &h;
status = dcerpc_samr_Connect4(p, mem_ctx, &r4);
if (!NT_STATUS_IS_OK(status)) {
printf("Connect4 failed - %s\n", nt_errstr(status));
ret = False;
+ } else {
+ if (got_handle) {
+ test_Close(p, mem_ctx, handle);
+ }
+ got_handle = True;
+ *handle = h;
}
printf("testing samr_Connect5\n");
r5.in.level = 1;
r5.in.info = &info;
r5.out.info = &info;
- r5.out.connect_handle = handle;
+ r5.out.connect_handle = &h;
status = dcerpc_samr_Connect5(p, mem_ctx, &r5);
if (!NT_STATUS_IS_OK(status)) {
printf("Connect5 failed - %s\n", nt_errstr(status));
ret = False;
+ } else {
+ if (got_handle) {
+ test_Close(p, mem_ctx, handle);
+ }
+ got_handle = True;
+ *handle = h;
}
return ret;
make_nmb_name(&calling, lp_netbios_name(), 0x0);
choose_called_name(&called, host, 0x20);
- cli = smbcli_state_init();
+ cli = smbcli_state_init(NULL);
if (!cli) {
printf("Failed initialize smbcli_struct to connect with %s\n", host);
return NULL;
if (use_kerberos)
flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
- status = smbcli_full_connection(c, lp_netbios_name(),
+ status = smbcli_full_connection(NULL,
+ c, lp_netbios_name(),
hostname, NULL,
sharename, "?????",
username, username[0]?userdomain:"",
const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
const char *password = lp_parm_string(-1, "torture", "password");
- status = smbcli_full_connection(&cli1, lp_netbios_name(),
+ status = smbcli_full_connection(NULL,
+ &cli1, lp_netbios_name(),
host, NULL,
share, "?????",
username, userdomain,