s3:libsmb: replace cli_initialise[_ex]() by cli_state_create()
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Jul 2011 19:47:36 +0000 (21:47 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 21 Jul 2011 20:08:53 +0000 (22:08 +0200)
This makes sure cli_state->src_ss and cli_state->dest_ss are always
initialized.

metze

source3/libsmb/cliconnect.c
source3/libsmb/clientgen.c
source3/libsmb/proto.h
source3/winbindd/winbindd_cm.c

index 5317c192bc6251433ce88e0111958747d3d2900c..6a7931b78618b7b60affe409688684f316866346 100644 (file)
@@ -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;
        }
 
index be27f1e093e5082f226a445bcc4cc4c786f38b19..1ac5c2ec6c6bfe2f9ac0710ecd78f88d2e227bb6 100644 (file)
@@ -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);
index d7a5612733d3e798027839dd32ab13ec399e9787..08d651f08c2a0d15329fa35a5101b0325d26eeff 100644 (file)
@@ -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);
index 55e6e7b399380b7ac497e87186a8341c8078d212..25f639872e421adf807ca78f746b25d568c5c6b8 100644 (file)
@@ -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;