mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
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
This commit is contained in:
parent
04b740d18b
commit
ebe258dd40
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user