Robustness-fixes for NetJoinDomain().
authorGünther Deschner <gd@samba.org>
Fri, 30 Nov 2007 18:56:41 +0000 (19:56 +0100)
committerVolker Lendecke <vl@sernet.de>
Fri, 30 Nov 2007 21:25:01 +0000 (22:25 +0100)
Guenther
(This used to be commit 2d5236cc37fe015ce9098a0ebe99cdc0ca3537ae)

source3/lib/netapi/joindomain.c

index 7c71276de6f5f21782a72965ec85cf7d62364dd6..29766e59947f913fccab3933963be2f0d3081baa 100644 (file)
@@ -35,6 +35,8 @@ WERROR NetJoinDomain(const char *server_name,
        WERROR werr;
        unsigned int old_timeout;
 
+       ZERO_STRUCT(encrypted_password);
+
        mem_ctx = talloc_init("NetJoinDomain");
        if (!mem_ctx) {
                werr = WERR_NOMEM;
@@ -68,10 +70,12 @@ WERROR NetJoinDomain(const char *server_name,
                goto done;
        };
 
-       encode_wkssvc_join_password_buffer(mem_ctx,
-                                          password,
-                                          &cli->user_session_key,
-                                          &encrypted_password);
+       if (password) {
+               encode_wkssvc_join_password_buffer(mem_ctx,
+                                                  password,
+                                                  &cli->user_session_key,
+                                                  &encrypted_password);
+       }
 
        old_timeout = cli_set_timeout(cli, 60000);
 
@@ -82,13 +86,16 @@ WERROR NetJoinDomain(const char *server_name,
                                               join_flags);
        if (!NT_STATUS_IS_OK(status)) {
                werr = ntstatus_to_werror(status);
+               goto done;
        }
 
        werr = WERR_OK;
 
  done:
-       cli_set_timeout(cli, old_timeout);
-       cli_shutdown(cli);
+       if (cli) {
+               cli_set_timeout(cli, old_timeout);
+               cli_shutdown(cli);
+       }
        TALLOC_FREE(mem_ctx);
 
        return werr;