Use libnetapi_open_ipc_connection in libnetapi.
authorGünther Deschner <gd@samba.org>
Thu, 10 Apr 2008 20:04:04 +0000 (22:04 +0200)
committerGünther Deschner <gd@samba.org>
Thu, 10 Apr 2008 20:04:04 +0000 (22:04 +0200)
Guenther
(This used to be commit d9f19fc61586d606393368799dee9757c169d602)

source3/lib/netapi/getdc.c
source3/lib/netapi/joindomain.c
source3/lib/netapi/netapi.c
source3/lib/netapi/serverinfo.c
source3/lib/netapi/user.c

index 944cfb24f35666295fe98257d0a7c48856692b58..8f882941b3786115df743051527a411018524762 100644 (file)
@@ -45,19 +45,8 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
        NTSTATUS status;
        WERROR werr;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS |
-                                    CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -74,9 +63,6 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
                                       (const char **)r->out.buffer,
                                       &werr);
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
 
        return werr;
 }
@@ -101,19 +87,8 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
        NTSTATUS status;
        WERROR werr;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS |
-                                    CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -133,9 +108,6 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
                goto done;
        }
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
 
        return werr;
 
@@ -175,19 +147,8 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
        struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS |
-                                    CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -213,9 +174,5 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
-
        return werr;
 }
index 96c2f3d1fc443f084e9e7dc5bb0b7b1436be949d..056d8d27e252f9a2f2a9b666038993eab9ea806f 100644 (file)
@@ -103,18 +103,8 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx,
        WERROR werr;
        unsigned int old_timeout = 0;
 
-       status = cli_full_connection(&cli, NULL, r->in.server,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -152,7 +142,6 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx,
                if (old_timeout) {
                        cli_set_timeout(cli, old_timeout);
                }
-               cli_shutdown(cli);
        }
 
        return werr;
@@ -245,18 +234,8 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx,
        WERROR werr;
        unsigned int old_timeout = 0;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -289,8 +268,9 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx,
 
  done:
        if (cli) {
-               cli_set_timeout(cli, old_timeout);
-               cli_shutdown(cli);
+               if (old_timeout) {
+                       cli_set_timeout(cli, old_timeout);
+               }
        }
 
        return werr;
@@ -307,18 +287,8 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx,
        NTSTATUS status;
        WERROR werr;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -340,10 +310,6 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
-
        return werr;
 }
 
@@ -451,18 +417,8 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx,
        NTSTATUS status;
        WERROR werr;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
index fbec2757f0f16f28c9af48a977a10c40005a52ce..2478a8dda113813d838ea178ce3b7f53eeceb3c0 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "lib/netapi/netapi.h"
+#include "lib/netapi/netapi_private.h"
 
 extern bool AllowDebugChange;
 
@@ -113,6 +114,7 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
 
 NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
 {
+       libnetapi_shutdown_cm(ctx);
 
        if (ctx->krb5_cc_env) {
                char *env = getenv(KRB5_ENV_CCNAME);
index fb5d9402cfdedc74425f27191075a442be876581..238b9ca30802bd721b5354d97370ac6f561bbc57 100644 (file)
@@ -70,18 +70,8 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
        WERROR werr;
        union srvsvc_NetSrvInfo info;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -109,10 +99,6 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
-
        return werr;
 }
 
@@ -186,18 +172,8 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
        WERROR werr;
        union srvsvc_NetSrvInfo info;
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -229,9 +205,5 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (cli) {
-               cli_shutdown(cli);
-       }
-
        return werr;
 }
index 54157a8f8260147264b49ffafbfa816e792ea084..d9505bc06796a7c9e54c5726c6fc8c1aded2b2e7 100644 (file)
@@ -180,18 +180,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx,
                        goto done;
        }
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -353,8 +343,6 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx,
                rpccli_samr_Close(pipe_cli, ctx, &connect_handle);
        }
 
-       cli_shutdown(cli);
-
        return werr;
 }
 
@@ -385,18 +373,8 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx,
        ZERO_STRUCT(domain_handle);
        ZERO_STRUCT(user_handle);
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -534,8 +512,6 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx,
                rpccli_samr_Close(pipe_cli, ctx, &connect_handle);
        }
 
-       cli_shutdown(cli);
-
        return werr;
 }
 
@@ -621,18 +597,8 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
                        return WERR_NOT_SUPPORTED;
        }
 
-       status = cli_full_connection(&cli, NULL, r->in.server_name,
-                                    NULL, 0,
-                                    "IPC$", "IPC",
-                                    ctx->username,
-                                    ctx->workgroup,
-                                    ctx->password,
-                                    CLI_FULL_CONNECTION_USE_KERBEROS |
-                                    CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-                                    Undefined, NULL);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               werr = ntstatus_to_werror(status);
+       werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+       if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
 
@@ -721,6 +687,10 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
                                                         r->out.buffer);
 
  done:
+       if (!cli) {
+               return werr;
+       }
+
        if (is_valid_policy_hnd(&domain_handle)) {
                rpccli_samr_Close(pipe_cli, ctx, &domain_handle);
        }
@@ -728,10 +698,6 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
                rpccli_samr_Close(pipe_cli, ctx, &connect_handle);
        }
 
-       if (cli) {
-               cli_shutdown(cli);
-       }
-
        return werr;
 }