summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-07-21 21:47:36 +0200
committerStefan Metzmacher <metze@samba.org>2011-07-21 22:08:53 +0200
commitebe258dd4091c00cf2ca3d6648cf4d60cb682ee1 (patch)
tree489e2ef1d71b18fc3647b925087af92bfeb7fe5c /source3
parent04b740d18b5f7868bcded1b1bda504a95082425a (diff)
downloadsamba-ebe258dd4091c00cf2ca3d6648cf4d60cb682ee1.tar.gz
samba-ebe258dd4091c00cf2ca3d6648cf4d60cb682ee1.tar.bz2
samba-ebe258dd4091c00cf2ca3d6648cf4d60cb682ee1.zip
s3:libsmb: replace cli_initialise[_ex]() by cli_state_create()
This makes sure cli_state->src_ss and cli_state->dest_ss are always initialized. metze
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/cliconnect.c26
-rw-r--r--source3/libsmb/clientgen.c37
-rw-r--r--source3/libsmb/proto.h6
-rw-r--r--source3/winbindd/winbindd_cm.c9
4 files changed, 37 insertions, 41 deletions
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 5317c192bc..6a7931b786 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -2849,8 +2849,6 @@ NTSTATUS cli_connect_nb(const char *host, struct sockaddr_storage *pss,
int fd = -1;
char *desthost;
char *p;
- socklen_t length;
- int ret;
desthost = talloc_strdup(talloc_tos(), host);
if (desthost == NULL) {
@@ -2866,34 +2864,14 @@ NTSTATUS cli_connect_nb(const char *host, struct sockaddr_storage *pss,
}
}
- cli = cli_initialise_ex(signing_state);
- if (cli == NULL) {
- goto fail;
- }
- cli->desthost = talloc_move(cli, &desthost);
-
status = cli_connect_sock(host, name_type, pss, myname, port, 20, &fd,
&port);
if (!NT_STATUS_IS_OK(status)) {
- cli_shutdown(cli);
goto fail;
}
- cli->fd = fd;
- length = sizeof(cli->src_ss);
- ret = getsockname(fd, (struct sockaddr *)(void *)&cli->src_ss,
- &length);
- if (ret == -1) {
- status = map_nt_error_from_unix(errno);
- cli_shutdown(cli);
- goto fail;
- }
- length = sizeof(cli->dest_ss);
- ret = getpeername(fd, (struct sockaddr *)(void *)&cli->dest_ss,
- &length);
- if (ret == -1) {
- status = map_nt_error_from_unix(errno);
- cli_shutdown(cli);
+ cli = cli_state_create(NULL, fd, desthost, signing_state);
+ if (cli == NULL) {
goto fail;
}
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index be27f1e093..1ac5c2ec6c 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -161,11 +161,16 @@ NTSTATUS cli_init_creds(struct cli_state *cli, const char *username, const char
Set the signing state (used from the command line).
****************************************************************************/
-struct cli_state *cli_initialise_ex(int signing_state)
+struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
+ int fd,
+ const char *desthost,
+ int signing_state)
{
struct cli_state *cli = NULL;
bool allow_smb_signing = false;
bool mandatory_signing = false;
+ size_t length;
+ int ret;
/* Check the effective uid - make sure we are not setuid */
if (is_setuid_root()) {
@@ -173,7 +178,7 @@ struct cli_state *cli_initialise_ex(int signing_state)
return NULL;
}
- cli = talloc_zero(NULL, struct cli_state);
+ cli = talloc_zero(mem_ctx, struct cli_state);
if (!cli) {
return NULL;
}
@@ -234,7 +239,27 @@ struct cli_state *cli_initialise_ex(int signing_state)
}
cli->pending = NULL;
- cli->initialised = 1;
+ cli->desthost = talloc_strdup(cli, desthost);
+ if (cli->desthost == NULL) {
+ goto error;
+ }
+
+ cli->fd = fd;
+
+ length = sizeof(cli->src_ss);
+ ret = getsockname(fd,
+ (struct sockaddr *)(void *)&cli->src_ss,
+ &length);
+ if (ret == -1) {
+ goto error;
+ }
+ length = sizeof(cli->dest_ss);
+ ret = getpeername(fd,
+ (struct sockaddr *)(void *)&cli->dest_ss,
+ &length);
+ if (ret == -1) {
+ goto error;
+ }
cli->smb1.mid = 1;
cli->smb1.pid = (uint16_t)sys_getpid();
@@ -242,6 +267,7 @@ struct cli_state *cli_initialise_ex(int signing_state)
cli->smb1.tid = UINT16_MAX;
cli->smb1.uid = UID_FIELD_INVALID;
+ cli->initialised = 1;
return cli;
/* Clean up after malloc() error */
@@ -252,11 +278,6 @@ struct cli_state *cli_initialise_ex(int signing_state)
return NULL;
}
-struct cli_state *cli_initialise(void)
-{
- return cli_initialise_ex(Undefined);
-}
-
bool cli_state_encryption_on(struct cli_state *cli)
{
return common_encryption_on(cli->trans_enc_state);
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index d7a5612733..08d651f08c 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -159,8 +159,10 @@ NTSTATUS cli_set_domain(struct cli_state *cli, const char *domain);
NTSTATUS cli_set_username(struct cli_state *cli, const char *username);
NTSTATUS cli_set_password(struct cli_state *cli, const char *password);
NTSTATUS cli_init_creds(struct cli_state *cli, const char *username, const char *domain, const char *password);
-struct cli_state *cli_initialise(void);
-struct cli_state *cli_initialise_ex(int signing_state);
+struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
+ int fd,
+ const char *desthost,
+ int signing_state);
bool cli_state_encryption_on(struct cli_state *cli);
void cli_nt_pipes_close(struct cli_state *cli);
void cli_shutdown(struct cli_state *cli);
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 55e6e7b399..25f639872e 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -812,19 +812,14 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
goto done;
}
- if ((*cli = cli_initialise()) == NULL) {
+ *cli = cli_state_create(NULL, sockfd, controller, Undefined);
+ if (*cli == NULL) {
DEBUG(1, ("Could not cli_initialize\n"));
result = NT_STATUS_NO_MEMORY;
goto done;
}
(*cli)->timeout = 10000; /* 10 seconds */
- (*cli)->fd = sockfd;
- (*cli)->desthost = talloc_strdup((*cli), controller);
- if ((*cli)->desthost == NULL) {
- result = NT_STATUS_NO_MEMORY;
- goto done;
- }
(*cli)->use_kerberos = True;