Add NetUnjoinDomain().
authorGünther Deschner <gd@samba.org>
Fri, 30 Nov 2007 18:57:08 +0000 (19:57 +0100)
committerVolker Lendecke <vl@sernet.de>
Fri, 30 Nov 2007 21:25:01 +0000 (22:25 +0100)
Guenther
(This used to be commit fd9d73ad44b0f0b3656a50a663b60aa26e7f7376)

source3/lib/netapi/joindomain.c

index 29766e59947f913fccab3933963be2f0d3081baa..66f0137cad12405f1257131ebc5b9036df722854 100644 (file)
@@ -100,3 +100,77 @@ WERROR NetJoinDomain(const char *server_name,
 
        return werr;
 }
+
+WERROR NetUnjoinDomain(const char *server_name,
+                      const char *account,
+                      const char *password,
+                      uint32_t unjoin_flags)
+{
+       TALLOC_CTX *mem_ctx = NULL;
+       struct cli_state *cli = NULL;
+       struct rpc_pipe_client *pipe_cli = NULL;
+       struct wkssvc_PasswordBuffer encrypted_password;
+       NTSTATUS status;
+       WERROR werr;
+       unsigned int old_timeout;
+
+       ZERO_STRUCT(encrypted_password);
+
+       mem_ctx = talloc_init("NetUnjoinDomain");
+       if (!mem_ctx) {
+               werr = WERR_NOMEM;
+               goto done;
+       }
+
+       if (!server_name || is_myname_or_ipaddr(server_name)) {
+               werr = WERR_NOT_SUPPORTED;
+               goto done;
+       }
+
+       status = net_make_ipc_connection_ex(NULL,
+                                           server_name,
+                                           NULL, 0, &cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       old_timeout = cli_set_timeout(cli, 60000);
+
+       pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
+                                           &status);
+       if (!pipe_cli) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       };
+
+       if (password) {
+               encode_wkssvc_join_password_buffer(mem_ctx,
+                                                  password,
+                                                  &cli->user_session_key,
+                                                  &encrypted_password);
+       }
+
+       old_timeout = cli_set_timeout(cli, 60000);
+
+       status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx,
+                                                server_name,
+                                                account,
+                                                &encrypted_password,
+                                                unjoin_flags);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       werr = WERR_OK;
+
+ done:
+       if (cli) {
+               cli_set_timeout(cli, old_timeout);
+               cli_shutdown(cli);
+       }
+       TALLOC_FREE(mem_ctx);
+
+       return werr;
+}