summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/cliconnect.c39
-rw-r--r--source3/libsmb/clidfs.c5
-rw-r--r--source3/libsmb/clientgen.c40
-rw-r--r--source3/libsmb/clikrb5.c2
-rw-r--r--source3/libsmb/clirap2.c2
-rw-r--r--source3/libsmb/libsmb_cache.c8
-rw-r--r--source3/libsmb/libsmbclient.c224
-rw-r--r--source3/libsmb/passchange.c108
-rw-r--r--source3/libsmb/trusts_util.c2
9 files changed, 210 insertions, 220 deletions
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 7f5b5d7fa5..4c3c4f4565 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -1394,8 +1394,9 @@ NTSTATUS cli_start_connection(struct cli_state **output_cli,
if (!my_name)
my_name = global_myname();
- if (!(cli = cli_initialise(NULL)))
+ if (!(cli = cli_initialise())) {
return NT_STATUS_NO_MEMORY;
+ }
make_nmb_name(&calling, my_name, 0x0);
make_nmb_name(&called , dest_host, 0x20);
@@ -1495,6 +1496,8 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
struct cli_state *cli = NULL;
int pw_len = password ? strlen(password)+1 : 0;
+ *output_cli = NULL;
+
if (password == NULL) {
password = "";
}
@@ -1513,8 +1516,9 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
nt_status = cli_nt_error(cli);
DEBUG(1,("failed session setup with %s\n", nt_errstr(nt_status)));
cli_shutdown(cli);
- if (NT_STATUS_IS_OK(nt_status))
+ if (NT_STATUS_IS_OK(nt_status)) {
nt_status = NT_STATUS_UNSUCCESSFUL;
+ }
return nt_status;
}
}
@@ -1541,7 +1545,7 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
Attempt a NetBIOS session request, falling back to *SMBSERVER if needed.
****************************************************************************/
-BOOL attempt_netbios_session_request(struct cli_state *cli, const char *srchost, const char *desthost,
+BOOL attempt_netbios_session_request(struct cli_state **ppcli, const char *srchost, const char *desthost,
struct in_addr *pdest_ip)
{
struct nmb_name calling, called;
@@ -1553,12 +1557,13 @@ BOOL attempt_netbios_session_request(struct cli_state *cli, const char *srchost,
* then use *SMBSERVER immediately.
*/
- if(is_ipaddress(desthost))
+ if(is_ipaddress(desthost)) {
make_nmb_name(&called, "*SMBSERVER", 0x20);
- else
+ } else {
make_nmb_name(&called, desthost, 0x20);
+ }
- if (!cli_session_request(cli, &calling, &called)) {
+ if (!cli_session_request(*ppcli, &calling, &called)) {
struct nmb_name smbservername;
make_nmb_name(&smbservername , "*SMBSERVER", 0x20);
@@ -1575,23 +1580,23 @@ BOOL attempt_netbios_session_request(struct cli_state *cli, const char *srchost,
*/
DEBUG(0,("attempt_netbios_session_request: %s rejected the session for name *SMBSERVER \
-with error %s.\n", desthost, cli_errstr(cli) ));
+with error %s.\n", desthost, cli_errstr(*ppcli) ));
return False;
}
- /*
- * We need to close the connection here but can't call cli_shutdown as
- * will free an allocated cli struct. cli_close_connection was invented
- * for this purpose. JRA. Based on work by "Kim R. Pedersen" <krp@filanet.dk>.
- */
+ /* Try again... */
+ cli_shutdown(*ppcli);
- cli_close_connection(cli);
+ *ppcli = cli_initialise();
+ if (!*ppcli) {
+ /* Out of memory... */
+ return False;
+ }
- if (!cli_initialise(cli) ||
- !cli_connect(cli, desthost, pdest_ip) ||
- !cli_session_request(cli, &calling, &smbservername)) {
+ if (!cli_connect(*ppcli, desthost, pdest_ip) ||
+ !cli_session_request(*ppcli, &calling, &smbservername)) {
DEBUG(0,("attempt_netbios_session_request: %s rejected the session for \
-name *SMBSERVER with error %s\n", desthost, cli_errstr(cli) ));
+name *SMBSERVER with error %s\n", desthost, cli_errstr(*ppcli) ));
return False;
}
}
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index e564bc4295..4280b0628e 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -51,7 +51,7 @@ static struct client_connection *connections;
static struct cli_state *do_connect( const char *server, const char *share,
BOOL show_sessetup )
{
- struct cli_state *c;
+ struct cli_state *c = NULL;
struct nmb_name called, calling;
const char *server_n;
struct in_addr ip;
@@ -83,7 +83,7 @@ static struct cli_state *do_connect( const char *server, const char *share,
ip = dest_ip;
/* have to open a new connection */
- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) != port) ||
+ if (!(c=cli_initialise()) || (cli_set_port(c, port) != port) ||
!cli_connect(c, server_n, &ip)) {
d_printf("Connection to %s failed\n", server_n);
return NULL;
@@ -99,6 +99,7 @@ static struct cli_state *do_connect( const char *server, const char *share,
d_printf("session request to %s failed (%s)\n",
called.name, cli_errstr(c));
cli_shutdown(c);
+ c = NULL;
if ((p=strchr_m(called.name, '.'))) {
*p = 0;
goto again;
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 8342df0f1d..4608d40d46 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -255,12 +255,12 @@ void cli_setup_signing_state(struct cli_state *cli, int signing_state)
}
/****************************************************************************
- Initialise a client structure.
+ Initialise a client structure. Always returns a malloc'ed struct.
****************************************************************************/
-struct cli_state *cli_initialise(struct cli_state *cli)
+struct cli_state *cli_initialise(void)
{
- BOOL alloced_cli = False;
+ struct cli_state *cli = NULL;
/* Check the effective uid - make sure we are not setuid */
if (is_setuid_root()) {
@@ -268,17 +268,11 @@ struct cli_state *cli_initialise(struct cli_state *cli)
return NULL;
}
+ cli = SMB_MALLOC_P(struct cli_state);
if (!cli) {
- cli = SMB_MALLOC_P(struct cli_state);
- if (!cli)
- return NULL;
- ZERO_STRUCTP(cli);
- alloced_cli = True;
+ return NULL;
}
- if (cli->initialised)
- cli_close_connection(cli);
-
ZERO_STRUCTP(cli);
cli->port = 0;
@@ -333,7 +327,6 @@ struct cli_state *cli_initialise(struct cli_state *cli)
cli_null_set_signing(cli);
cli->initialised = 1;
- cli->allocated = alloced_cli;
return cli;
@@ -343,10 +336,7 @@ struct cli_state *cli_initialise(struct cli_state *cli)
SAFE_FREE(cli->inbuf);
SAFE_FREE(cli->outbuf);
-
- if (alloced_cli)
- SAFE_FREE(cli);
-
+ SAFE_FREE(cli);
return NULL;
}
@@ -403,10 +393,10 @@ void cli_nt_pipes_close(struct cli_state *cli)
}
/****************************************************************************
- Close a client connection and free the memory without destroying cli itself.
+ Shutdown a client structure.
****************************************************************************/
-void cli_close_connection(struct cli_state *cli)
+void cli_shutdown(struct cli_state *cli)
{
cli_nt_pipes_close(cli);
@@ -443,20 +433,8 @@ void cli_close_connection(struct cli_state *cli)
}
cli->fd = -1;
cli->smb_rw_error = 0;
-}
-/****************************************************************************
- Shutdown a client structure.
-****************************************************************************/
-
-void cli_shutdown(struct cli_state *cli)
-{
- BOOL allocated = cli->allocated;
- cli_close_connection(cli);
- ZERO_STRUCTP(cli);
- if (allocated) {
- free(cli);
- }
+ SAFE_FREE(cli);
}
/****************************************************************************
diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c
index abb3843bac..d40fc31dc4 100644
--- a/source3/libsmb/clikrb5.c
+++ b/source3/libsmb/clikrb5.c
@@ -112,7 +112,7 @@ static krb5_error_code smb_krb5_parse_name_norealm_conv(krb5_context context,
#ifndef HAVE_KRB5_SET_REAL_TIME
/*
- * This function is not in the Heimdal mainline.
+ * Thir function is not in the Heimdal mainline.
*/
krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds)
{
diff --git a/source3/libsmb/clirap2.c b/source3/libsmb/clirap2.c
index 147683689d..3c23310f66 100644
--- a/source3/libsmb/clirap2.c
+++ b/source3/libsmb/clirap2.c
@@ -220,7 +220,7 @@ int cli_NetGroupAdd(struct cli_state *cli, RAP_GROUP_INFO_1 * grinfo )
/* Allocate data. */
data_size = MAX(soffset + strlen(grinfo->comment) + 1, 1024);
- data = SMB_MALLOC(data_size);
+ data = SMB_MALLOC_ARRAY(char, data_size);
if (!data) {
DEBUG (1, ("Malloc fail\n"));
return -1;
diff --git a/source3/libsmb/libsmb_cache.c b/source3/libsmb/libsmb_cache.c
index 5d948ea5e2..8c4fd7c89f 100644
--- a/source3/libsmb/libsmb_cache.c
+++ b/source3/libsmb/libsmb_cache.c
@@ -150,9 +150,10 @@ static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server,
* doesn't match the requested share, so
* disconnect from the current share.
*/
- if (! cli_tdis(&srv->server->cli)) {
+ if (! cli_tdis(srv->server->cli)) {
/* Sigh. Couldn't disconnect. */
- cli_shutdown(&srv->server->cli);
+ cli_shutdown(srv->server->cli);
+ srv->server->cli = NULL;
context->callbacks.remove_cached_srv_fn(context, srv->server);
continue;
}
@@ -166,7 +167,8 @@ static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server,
srv->share_name = SMB_STRDUP(share);
if (!srv->share_name) {
/* Out of memory. */
- cli_shutdown(&srv->server->cli);
+ cli_shutdown(srv->server->cli);
+ srv->server->cli = NULL;
context->callbacks.remove_cached_srv_fn(context, srv->server);
continue;
}
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index ca2624305e..db788f46e9 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -487,7 +487,7 @@ static int
smbc_check_server(SMBCCTX * context,
SMBCSRV * server)
{
- if ( send_keepalive(server->cli.fd) == False )
+ if ( send_keepalive(server->cli->fd) == False )
return 1;
/* connection is ok */
@@ -524,7 +524,8 @@ smbc_remove_unused_server(SMBCCTX * context,
DLIST_REMOVE(context->internal->_servers, srv);
- cli_shutdown(&srv->cli);
+ cli_shutdown(srv->cli);
+ srv->cli = NULL;
DEBUG(3, ("smbc_remove_usused_server: %p removed.\n", srv));
@@ -630,7 +631,7 @@ smbc_server(SMBCCTX *context,
fstring password)
{
SMBCSRV *srv=NULL;
- struct cli_state c;
+ struct cli_state *c;
struct nmb_name called, calling;
const char *server_n = server;
pstring ipenv;
@@ -666,7 +667,7 @@ smbc_server(SMBCCTX *context,
* disconnect if the requested share is not the same as the
* one that was already connected.
*/
- if (srv->cli.cnum == (uint16) -1) {
+ if (srv->cli->cnum == (uint16) -1) {
/* Ensure we have accurate auth info */
if (context->internal->_auth_fn_with_context != NULL) {
context->internal->_auth_fn_with_context(
@@ -683,11 +684,12 @@ smbc_server(SMBCCTX *context,
password, sizeof(fstring));
}
- if (! cli_send_tconX(&srv->cli, share, "?????",
+ if (! cli_send_tconX(srv->cli, share, "?????",
password, strlen(password)+1)) {
- errno = smbc_errno(context, &srv->cli);
- cli_shutdown(&srv->cli);
+ errno = smbc_errno(context, srv->cli);
+ cli_shutdown(srv->cli);
+ srv->cli = NULL;
context->callbacks.remove_cached_srv_fn(context,
srv);
srv = NULL;
@@ -730,19 +732,19 @@ smbc_server(SMBCCTX *context,
zero_ip(&ip);
/* have to open a new connection */
- if (!cli_initialise(&c)) {
+ if ((c = cli_initialise()) == NULL) {
errno = ENOMEM;
return NULL;
}
if (context->flags & SMB_CTX_FLAG_USE_KERBEROS) {
- c.use_kerberos = True;
+ c->use_kerberos = True;
}
if (context->flags & SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS) {
- c.fallback_after_kerberos = True;
+ c->fallback_after_kerberos = True;
}
- c.timeout = context->timeout;
+ c->timeout = context->timeout;
/*
* Force use of port 139 for first try if share is $IPC, empty, or
@@ -756,49 +758,47 @@ smbc_server(SMBCCTX *context,
port_try_next = 139;
}
- c.port = port_try_first;
+ c->port = port_try_first;
- if (!cli_connect(&c, server_n, &ip)) {
+ if (!cli_connect(c, server_n, &ip)) {
/* First connection attempt failed. Try alternate port. */
- c.port = port_try_next;
+ c->port = port_try_next;
- if (!cli_connect(&c, server_n, &ip)) {
- cli_shutdown(&c);
+ if (!cli_connect(c, server_n, &ip)) {
+ cli_shutdown(c);
errno = ETIMEDOUT;
return NULL;
}
}
- if (!cli_session_request(&c, &calling, &called)) {
- cli_shutdown(&c);
+ if (!cli_session_request(c, &calling, &called)) {
+ cli_shutdown(c);
if (strcmp(called.name, "*SMBSERVER")) {
make_nmb_name(&called , "*SMBSERVER", 0x20);
goto again;
- }
- else { /* Try one more time, but ensure we don't loop */
-
- /* Only try this if server is an IP address ... */
-
- if (is_ipaddress(server) && !tried_reverse) {
- fstring remote_name;
- struct in_addr rem_ip;
+ } else { /* Try one more time, but ensure we don't loop */
- if ((rem_ip.s_addr=inet_addr(server)) == INADDR_NONE) {
- DEBUG(4, ("Could not convert IP address %s to struct in_addr\n", server));
- errno = ETIMEDOUT;
- return NULL;
- }
+ /* Only try this if server is an IP address ... */
- tried_reverse++; /* Yuck */
+ if (is_ipaddress(server) && !tried_reverse) {
+ fstring remote_name;
+ struct in_addr rem_ip;
- if (name_status_find("*", 0, 0, rem_ip, remote_name)) {
- make_nmb_name(&called, remote_name, 0x20);
- goto again;
- }
+ if ((rem_ip.s_addr=inet_addr(server)) == INADDR_NONE) {
+ DEBUG(4, ("Could not convert IP address "
+ "%s to struct in_addr\n", server));
+ errno = ETIMEDOUT;
+ return NULL;
+ }
+ tried_reverse++; /* Yuck */
- }
+ if (name_status_find("*", 0, 0, rem_ip, remote_name)) {
+ make_nmb_name(&called, remote_name, 0x20);
+ goto again;
+ }
+ }
}
errno = ETIMEDOUT;
return NULL;
@@ -806,15 +806,15 @@ smbc_server(SMBCCTX *context,
DEBUG(4,(" session request ok\n"));
- if (!cli_negprot(&c)) {
- cli_shutdown(&c);
+ if (!cli_negprot(c)) {
+ cli_shutdown(c);
errno = ETIMEDOUT;
return NULL;
}
username_used = username;
- if (!cli_session_setup(&c, username_used,
+ if (!cli_session_setup(c, username_used,
password, strlen(password),
password, strlen(password),
workgroup)) {
@@ -823,12 +823,12 @@ smbc_server(SMBCCTX *context,
username_used = "";
if ((context->flags & SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON) ||
- !cli_session_setup(&c, username_used,
+ !cli_session_setup(c, username_used,
password, 1,
password, 0,
workgroup)) {
- cli_shutdown(&c);
+ cli_shutdown(c);
errno = EPERM;
return NULL;
}
@@ -836,10 +836,10 @@ smbc_server(SMBCCTX *context,
DEBUG(4,(" session setup ok\n"));
- if (!cli_send_tconX(&c, share, "?????",
+ if (!cli_send_tconX(c, share, "?????",
password, strlen(password)+1)) {
- errno = smbc_errno(context, &c);
- cli_shutdown(&c);
+ errno = smbc_errno(context, c);
+ cli_shutdown(c);
return NULL;
}
@@ -858,7 +858,6 @@ smbc_server(SMBCCTX *context,
ZERO_STRUCTP(srv);
srv->cli = c;
- srv->cli.allocated = False;
srv->dev = (dev_t)(str_checksum(server) ^ str_checksum(share));
srv->no_pathinfo = False;
srv->no_pathinfo2 = False;
@@ -884,8 +883,10 @@ smbc_server(SMBCCTX *context,
return srv;
failed:
- cli_shutdown(&c);
- if (!srv) return NULL;
+ cli_shutdown(c);
+ if (!srv) {
+ return NULL;
+ }
SAFE_FREE(srv);
return NULL;
@@ -960,19 +961,16 @@ smbc_attr_server(SMBCCTX *context,
}
ZERO_STRUCTP(ipc_srv);
- ipc_srv->cli = *ipc_cli;
- ipc_srv->cli.allocated = False;
-
- free(ipc_cli);
+ ipc_srv->cli = ipc_cli;
if (pol) {
- pipe_hnd = cli_rpc_pipe_open_noauth(&ipc_srv->cli,
+ pipe_hnd = cli_rpc_pipe_open_noauth(ipc_srv->cli,
PI_LSARPC,
&nt_status);
if (!pipe_hnd) {
DEBUG(1, ("cli_nt_session_open fail!\n"));
errno = ENOTSUP;
- cli_shutdown(&ipc_srv->cli);
+ cli_shutdown(ipc_srv->cli);
free(ipc_srv);
return NULL;
}
@@ -985,14 +983,14 @@ smbc_attr_server(SMBCCTX *context,
nt_status = rpccli_lsa_open_policy(
pipe_hnd,
- ipc_srv->cli.mem_ctx,
+ ipc_srv->cli->mem_ctx,
True,
GENERIC_EXECUTE_ACCESS,
pol);
if (!NT_STATUS_IS_OK(nt_status)) {
- errno = smbc_errno(context, &ipc_srv->cli);
- cli_shutdown(&ipc_srv->cli);
+ errno = smbc_errno(context, ipc_srv->cli);
+ cli_shutdown(ipc_srv->cli);
return NULL;
}
}
@@ -1009,7 +1007,7 @@ smbc_attr_server(SMBCCTX *context,
if (errno == 0) {
errno = ENOMEM;
}
- cli_shutdown(&ipc_srv->cli);
+ cli_shutdown(ipc_srv->cli);
free(ipc_srv);
return NULL;
}
@@ -1098,7 +1096,7 @@ smbc_open_ctx(SMBCCTX *context,
ZERO_STRUCTP(file);
/*d_printf(">>>open: resolving %s\n", path);*/
- if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath))
+ if (!cli_resolve_path( "", srv->cli, path, &targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
SAFE_FREE(file);
@@ -1172,7 +1170,7 @@ smbc_open_ctx(SMBCCTX *context,
if (fd == -1) {
int eno = 0;
- eno = smbc_errno(context, &srv->cli);
+ eno = smbc_errno(context, srv->cli);
file = context->opendir(context, fname);
if (!file) errno = eno;
return file;
@@ -1275,7 +1273,7 @@ smbc_read_ctx(SMBCCTX *context,
}
/*d_printf(">>>read: resolving %s\n", path);*/
- if (!cli_resolve_path("", &file->srv->cli, path,
+ if (!cli_resolve_path("", file->srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -1358,7 +1356,7 @@ smbc_write_ctx(SMBCCTX *context,
}
/*d_printf(">>>write: resolving %s\n", path);*/
- if (!cli_resolve_path("", &file->srv->cli, path,
+ if (!cli_resolve_path("", file->srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -1430,7 +1428,7 @@ smbc_close_ctx(SMBCCTX *context,
}
/*d_printf(">>>close: resolving %s\n", path);*/
- if (!cli_resolve_path("", &file->srv->cli, path,
+ if (!cli_resolve_path("", file->srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -1500,7 +1498,7 @@ smbc_getatr(SMBCCTX * context,
}
DEBUG(4,("smbc_getatr: sending qpathinfo\n"));
- if (!cli_resolve_path( "", &srv->cli, fixedpath, &targetcli, targetpath))
+ if (!cli_resolve_path( "", srv->cli, fixedpath, &targetcli, targetpath))
{
d_printf("Couldn't resolve %s\n", path);
return False;
@@ -1565,7 +1563,7 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
* attributes manipulated.
*/
if (srv->no_pathinfo ||
- ! cli_setpathinfo(&srv->cli, path, c_time, a_time, m_time, mode)) {
+ ! cli_setpathinfo(srv->cli, path, c_time, a_time, m_time, mode)) {
/*
* setpathinfo is not supported; go to plan B.
@@ -1581,9 +1579,9 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
srv->no_pathinfo = True;
/* Open the file */
- if ((fd = cli_open(&srv->cli, path, O_RDWR, DENY_NONE)) < 0) {
+ if ((fd = cli_open(srv->cli, path, O_RDWR, DENY_NONE)) < 0) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
return -1;
}
@@ -1592,7 +1590,7 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
* We'll need it in the set call
*/
if (c_time == 0) {
- ret = cli_getattrE(&srv->cli, fd,
+ ret = cli_getattrE(srv->cli, fd,
NULL, NULL,
&c_time, NULL, NULL);
} else {
@@ -1619,9 +1617,9 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
if (c_time > m_time) c_time = m_time;
/* Set the new attributes */
- ret = cli_setattrE(&srv->cli, fd,
+ ret = cli_setattrE(srv->cli, fd,
c_time, a_time, m_time);
- cli_close(&srv->cli, fd);
+ cli_close(srv->cli, fd);
}
/*
@@ -1631,11 +1629,11 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
* seems to work on win98.
*/
if (ret && mode != (uint16) -1) {
- ret = cli_setatr(&srv->cli, path, mode, 0);
+ ret = cli_setatr(srv->cli, path, mode, 0);
}
if (! ret) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
return False;
}
}
@@ -1695,7 +1693,7 @@ smbc_unlink_ctx(SMBCCTX *context,
}
/*d_printf(">>>unlink: resolving %s\n", path);*/
- if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath))
+ if (!cli_resolve_path( "", srv->cli, path, &targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
return -1;
@@ -1828,14 +1826,14 @@ smbc_rename_ctx(SMBCCTX *ocontext,
}
/*d_printf(">>>rename: resolving %s\n", path1);*/
- if (!cli_resolve_path( "", &srv->cli, path1, &targetcli1, targetpath1))
+ if (!cli_resolve_path( "", srv->cli, path1, &targetcli1, targetpath1))
{
d_printf("Could not resolve %s\n", path1);
return -1;
}
/*d_printf(">>>rename: resolved path as %s\n", targetpath1);*/
/*d_printf(">>>rename: resolving %s\n", path2);*/
- if (!cli_resolve_path( "", &srv->cli, path2, &targetcli2, targetpath2))
+ if (!cli_resolve_path( "", srv->cli, path2, &targetcli2, targetpath2))
{
d_printf("Could not resolve %s\n", path2);
return -1;
@@ -1930,7 +1928,7 @@ smbc_lseek_ctx(SMBCCTX *context,
}
/*d_printf(">>>lseek: resolving %s\n", path);*/
- if (!cli_resolve_path("", &file->srv->cli, path,
+ if (!cli_resolve_path("", file->srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -2099,7 +2097,7 @@ smbc_stat_ctx(SMBCCTX *context,
if (!smbc_getatr(context, srv, path, &mode, &size,
&c_time, &a_time, &m_time, &ino)) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
return -1;
}
@@ -2175,7 +2173,7 @@ smbc_fstat_ctx(SMBCCTX *context,
}
/*d_printf(">>>fstat: resolving %s\n", path);*/
- if (!cli_resolve_path("", &file->srv->cli, path,
+ if (!cli_resolve_path("", file->srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -2676,7 +2674,7 @@ smbc_opendir_ctx(SMBCCTX *context,
/* Now, list the stuff ... */
- if (!cli_NetServerEnum(&srv->cli,
+ if (!cli_NetServerEnum(srv->cli,
workgroup,
SV_TYPE_DOMAIN_ENUM,
list_unique_wg_fn,
@@ -2772,7 +2770,7 @@ smbc_opendir_ctx(SMBCCTX *context,
dir->srv = srv;
/* Now, list the servers ... */
- if (!cli_NetServerEnum(&srv->cli, server,
+ if (!cli_NetServerEnum(srv->cli, server,
0x0000FFFE, list_fn,
(void *)dir)) {
@@ -2808,15 +2806,15 @@ smbc_opendir_ctx(SMBCCTX *context,
/* List the shares ... */
if (net_share_enum_rpc(
- &srv->cli,
+ srv->cli,
list_fn,
(void *) dir) < 0 &&
cli_RNetShareEnum(
- &srv->cli,
+ srv->cli,
list_fn,
(void *)dir) < 0) {
- errno = cli_errno(&srv->cli);
+ errno = cli_errno(srv->cli);
if (dir) {
SAFE_FREE(dir->fname);
SAFE_FREE(dir);
@@ -2866,7 +2864,7 @@ smbc_opendir_ctx(SMBCCTX *context,
p = path + strlen(path);
pstrcat(path, "\\*");
- if (!cli_resolve_path("", &srv->cli, path,
+ if (!cli_resolve_path("", srv->cli, path,
&targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
@@ -3215,7 +3213,7 @@ smbc_mkdir_ctx(SMBCCTX *context,
}
/*d_printf(">>>mkdir: resolving %s\n", path);*/
- if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath))
+ if (!cli_resolve_path( "", srv->cli, path, &targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
return -1;
@@ -3312,7 +3310,7 @@ smbc_rmdir_ctx(SMBCCTX *context,
}
/*d_printf(">>>rmdir: resolving %s\n", path);*/
- if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath))
+ if (!cli_resolve_path( "", srv->cli, path, &targetcli, targetpath))
{
d_printf("Could not resolve %s\n", path);
return -1;
@@ -3568,8 +3566,8 @@ smbc_chmod_ctx(SMBCCTX *context,
if ((newmode & S_IXGRP) && lp_map_system(-1)) mode |= aSYSTEM;
if ((newmode & S_IXOTH) && lp_map_hidden(-1)) mode |= aHIDDEN;
- if (!cli_setatr(&srv->cli, path, mode, 0)) {
- errno = smbc_errno(context, &srv->cli);
+ if (!cli_setatr(srv->cli, path, mode, 0)) {
+ errno = smbc_errno(context, srv->cli);
return -1;
}
@@ -4098,7 +4096,7 @@ dos_attr_query(SMBCCTX *context,
&mode, &size,
&c_time, &a_time, &m_time, &inode)) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
return NULL;
@@ -4206,7 +4204,7 @@ cacl_get(SMBCCTX *context,
SMB_OFF_T size = 0;
uint16 mode = 0;
SMB_INO_T ino = 0;
- struct cli_state *cli = &srv->cli;
+ struct cli_state *cli = srv->cli;
/* Copy name so we can strip off exclusions (if any are specified) */
strncpy(name_sandbox, attr_name, sizeof(name_sandbox) - 1);
@@ -4551,7 +4549,7 @@ cacl_get(SMBCCTX *context,
if (!smbc_getatr(context, srv, filename, &mode, &size,
&c_time, &a_time, &m_time, &ino)) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
return -1;
}
@@ -5108,8 +5106,8 @@ smbc_setxattr_ctx(SMBCCTX *context,
}
if (ipc_srv) {
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
namevalue,
(*namevalue == '*'
? SMBC_XATTR_MODE_SET
@@ -5171,8 +5169,8 @@ smbc_setxattr_ctx(SMBCCTX *context,
errno = ENOMEM;
ret = -1;
} else {
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
namevalue,
(*namevalue == '*'
? SMBC_XATTR_MODE_SET
@@ -5202,8 +5200,8 @@ smbc_setxattr_ctx(SMBCCTX *context,
errno = ENOMEM;
ret = -1;
} else {
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
namevalue, SMBC_XATTR_MODE_CHOWN, 0);
}
talloc_destroy(ctx);
@@ -5229,8 +5227,8 @@ smbc_setxattr_ctx(SMBCCTX *context,
errno = ENOMEM;
ret = -1;
} else {
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
namevalue, SMBC_XATTR_MODE_CHOWN, 0);
}
talloc_destroy(ctx);
@@ -5388,12 +5386,12 @@ smbc_getxattr_ctx(SMBCCTX *context,
/* Yup. */
ret = cacl_get(context, ctx, srv,
- ipc_srv == NULL ? NULL : &ipc_srv->cli,
+ ipc_srv == NULL ? NULL : ipc_srv->cli,
&pol, path,
CONST_DISCARD(char *, name),
CONST_DISCARD(char *, value), size);
if (ret < 0 && errno == 0) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
}
talloc_destroy(ctx);
return ret;
@@ -5484,8 +5482,8 @@ smbc_removexattr_ctx(SMBCCTX *context,
StrCaseCmp(name, "system.nt_sec_desc.*+") == 0) {
/* Yup. */
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
NULL, SMBC_XATTR_MODE_REMOVE_ALL, 0);
talloc_destroy(ctx);
return ret;
@@ -5504,8 +5502,8 @@ smbc_removexattr_ctx(SMBCCTX *context,
StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0) {
/* Yup. */
- ret = cacl_set(ctx, &srv->cli,
- &ipc_srv->cli, &pol, path,
+ ret = cacl_set(ctx, srv->cli,
+ ipc_srv->cli, &pol, path,
name + 19, SMBC_XATTR_MODE_REMOVE, 0);
talloc_destroy(ctx);
return ret;
@@ -5755,10 +5753,10 @@ smbc_list_print_jobs_ctx(SMBCCTX *context,
}
- if (cli_print_queue(&srv->cli,
+ if (cli_print_queue(srv->cli,
(void (*)(struct print_job_info *))fn) < 0) {
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
return -1;
}
@@ -5825,10 +5823,10 @@ smbc_unlink_print_job_ctx(SMBCCTX *context,
}
- if ((err = cli_printjob_del(&srv->cli, id)) != 0) {
+ if ((err = cli_printjob_del(srv->cli, id)) != 0) {
if (err < 0)
- errno = smbc_errno(context, &srv->cli);
+ errno = smbc_errno(context, srv->cli);
else if (err == ERRnosuchprintjob)
errno = EINVAL;
return -1;
@@ -5947,8 +5945,8 @@ smbc_free_context(SMBCCTX *context,
s = context->internal->_servers;
while (s) {
DEBUG(1, ("Forced shutdown: %p (fd=%d)\n",
- s, s->cli.fd));
- cli_shutdown(&s->cli);
+ s, s->cli->fd));
+ cli_shutdown(s->cli);
context->callbacks.remove_cached_srv_fn(context,
s);
next = s->next;
@@ -6074,9 +6072,9 @@ smbc_option_get(SMBCCTX *context,
* Log to standard error instead of standard output.
*/
#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
- return (void *) (intptr_t) context->internal->_debug_stderr;
+ return (void *) (intptr_t) context->internal->_debug_stderr;
#else
- return (void *) context->internal->_debug_stderr;
+ return (void *) context->internal->_debug_stderr;
#endif
} else if (strcmp(option_name, "auth_function") == 0) {
/*
diff --git a/source3/libsmb/passchange.c b/source3/libsmb/passchange.c
index 673671d28d..0d3dcf4d75 100644
--- a/source3/libsmb/passchange.c
+++ b/source3/libsmb/passchange.c
@@ -29,7 +29,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
char *err_str, size_t err_str_len)
{
struct nmb_name calling, called;
- struct cli_state cli;
+ struct cli_state *cli;
struct rpc_pipe_client *pipe_hnd;
struct in_addr ip;
@@ -44,39 +44,45 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
return NT_STATUS_UNSUCCESSFUL;
}
- ZERO_STRUCT(cli);
-
- if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) {
+ cli = cli_initialise();
+ if (!cli) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (!cli_connect(cli, remote_machine, &ip)) {
slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- return NT_STATUS_UNSUCCESSFUL;
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
+ return result;
}
make_nmb_name(&calling, global_myname() , 0x0);
make_nmb_name(&called , remote_machine, 0x20);
- if (!cli_session_request(&cli, &calling, &called)) {
+ if (!cli_session_request(cli, &calling, &called)) {
slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- cli_shutdown(&cli);
- return NT_STATUS_UNSUCCESSFUL;
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
+ return result;
}
- cli.protocol = PROTOCOL_NT1;
+ cli->protocol = PROTOCOL_NT1;
- if (!cli_negprot(&cli)) {
+ if (!cli_negprot(cli)) {
slprintf(err_str, err_str_len-1, "machine %s rejected the negotiate protocol. Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
}
/* Given things like SMB signing, restrict anonymous and the like,
try an authenticated connection first */
- if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd)+1, old_passwd, strlen(old_passwd)+1, "")) {
+ if (!cli_session_setup(cli, user_name, old_passwd, strlen(old_passwd)+1, old_passwd, strlen(old_passwd)+1, "")) {
- result = cli_nt_error(&cli);
+ result = cli_nt_error(cli);
if (!NT_STATUS_IS_OK(result)) {
@@ -89,8 +95,8 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
NT_STATUS_PASSWORD_MUST_CHANGE)) {
slprintf(err_str, err_str_len-1, "Could not "
"connect to machine %s: %s\n",
- remote_machine, cli_errstr(&cli));
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli));
+ cli_shutdown(cli);
return result;
}
@@ -103,31 +109,31 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
* Thanks to <Nicholas.S.Jenkins@cdc.com> for this fix.
*/
- if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
+ if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
}
- cli_init_creds(&cli, "", "", NULL);
+ cli_init_creds(cli, "", "", NULL);
} else {
- cli_init_creds(&cli, user_name, "", old_passwd);
+ cli_init_creds(cli, user_name, "", old_passwd);
}
- if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
+ if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
slprintf(err_str, err_str_len-1, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
}
/* Try not to give the password away too easily */
if (!pass_must_change) {
- pipe_hnd = cli_rpc_pipe_open_ntlmssp(&cli,
+ pipe_hnd = cli_rpc_pipe_open_ntlmssp(cli,
PI_SAMR,
PIPE_AUTH_LEVEL_PRIVACY,
"", /* what domain... ? */
@@ -143,17 +149,17 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
* will just fail. So we do it anonymously, there's no other
* way.
*/
- pipe_hnd = cli_rpc_pipe_open_noauth(&cli, PI_SAMR, &result);
+ pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &result);
}
if (!pipe_hnd) {
if (lp_client_lanman_auth()) {
/* Use the old RAP method. */
- if (!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) {
+ if (!cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) {
slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
}
} else {
@@ -161,16 +167,16 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
"SAMR connection to machine %s failed. Error was %s, "
"but LANMAN password changed are disabled\n",
nt_errstr(result), remote_machine);
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
}
}
- if (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd, cli.mem_ctx, user_name,
+ if (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd, cli->mem_ctx, user_name,
new_passwd, old_passwd))) {
/* Great - it all worked! */
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return NT_STATUS_OK;
} else if (!(NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED)
@@ -179,7 +185,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
remote_machine, get_friendly_nt_error_msg(result));
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return result;
}
@@ -187,21 +193,21 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
cli_rpc_pipe_close(pipe_hnd);
/* Try anonymous NTLMSSP... */
- cli_init_creds(&cli, "", "", NULL);
+ cli_init_creds(cli, "", "", NULL);
result = NT_STATUS_UNSUCCESSFUL;
/* OK, this is ugly, but... try an anonymous pipe. */
- pipe_hnd = cli_rpc_pipe_open_noauth(&cli, PI_SAMR, &result);
+ pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &result);
if ( pipe_hnd &&
(NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd,
- cli.mem_ctx,
+ cli->mem_ctx,
user_name,
new_passwd,
old_passwd)))) {
/* Great - it all worked! */
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return NT_STATUS_OK;
} else {
if (!(NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED)
@@ -211,7 +217,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
slprintf(err_str, err_str_len-1,
"machine %s rejected the (anonymous) password change: Error was : %s.\n",
remote_machine, get_friendly_nt_error_msg(result));
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return result;
}
@@ -220,24 +226,24 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
if (lp_client_lanman_auth()) {
/* Use the old RAP method. */
- if (cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) {
+ if (cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) {
/* SAMR failed, but the old LanMan protocol worked! */
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return NT_STATUS_OK;
}
slprintf(err_str, err_str_len-1,
"machine %s rejected the password change: Error was : %s.\n",
- remote_machine, cli_errstr(&cli) );
- result = cli_nt_error(&cli);
- cli_shutdown(&cli);
+ remote_machine, cli_errstr(cli) );
+ result = cli_nt_error(cli);
+ cli_shutdown(cli);
return result;
} else {
slprintf(err_str, err_str_len-1,
"SAMR connection to machine %s failed. Error was %s, "
"but LANMAN password changed are disabled\n",
nt_errstr(result), remote_machine);
- cli_shutdown(&cli);
+ cli_shutdown(cli);
return NT_STATUS_UNSUCCESSFUL;
}
}
diff --git a/source3/libsmb/trusts_util.c b/source3/libsmb/trusts_util.c
index 55108bf72f..e4061883eb 100644
--- a/source3/libsmb/trusts_util.c
+++ b/source3/libsmb/trusts_util.c
@@ -99,7 +99,7 @@ NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *m
if (NT_STATUS_IS_OK(nt_status)) {
DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n",
- timestring(False)));
+ current_timestring(False)));
/*
* Return the result of trying to write the new password
* back into the trust account file.