Split NetJoinDomain() into NetJoinDomainRemote() and the unsupported
authorGünther Deschner <gd@samba.org>
Tue, 11 Dec 2007 20:23:40 +0000 (21:23 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 21 Dec 2007 14:29:09 +0000 (15:29 +0100)
NetJoinDomainLocal().

Guenther
(This used to be commit d2f21ce6727ec9e4df67989db07b48470d0790a4)

source3/lib/netapi/joindomain.c

index 6da4548f054a3a22f221231657e050b6448d5dd2..1b951d7a5cf620bf031bf76592ca4f3e3e536a5a 100644 (file)
@@ -24,14 +24,25 @@ extern const char *opt_user_name;
 extern const char *opt_workgroup;
 extern const char *opt_password;
 
-WERROR NetJoinDomain(const char *server_name,
-                    const char *domain_name,
-                    const char *account_ou,
-                    const char *Account,
-                    const char *password,
-                    uint32_t join_flags)
+static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx,
+                                const char *server_name,
+                                const char *domain_name,
+                                const char *account_ou,
+                                const char *Account,
+                                const char *password,
+                                uint32_t join_flags)
+{
+       return WERR_NOT_SUPPORTED;
+}
+
+static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx,
+                                 const char *server_name,
+                                 const char *domain_name,
+                                 const char *account_ou,
+                                 const char *Account,
+                                 const char *password,
+                                 uint32_t join_flags)
 {
-       TALLOC_CTX *mem_ctx = NULL;
        struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
        struct wkssvc_PasswordBuffer encrypted_password;
@@ -41,22 +52,6 @@ WERROR NetJoinDomain(const char *server_name,
 
        ZERO_STRUCT(encrypted_password);
 
-       mem_ctx = talloc_init("NetJoinDomain");
-       if (!mem_ctx) {
-               werr = WERR_NOMEM;
-               goto done;
-       }
-
-       if (!server_name || is_myname_or_ipaddr(server_name)) {
-               werr = WERR_NOT_SUPPORTED;
-               goto done;
-       }
-
-       if (!domain_name) {
-               werr = WERR_INVALID_PARAM;
-               goto done;
-       }
-
        status = cli_full_connection(&cli, NULL, server_name,
                                     NULL, 0,
                                     "IPC$", "IPC",
@@ -101,6 +96,61 @@ WERROR NetJoinDomain(const char *server_name,
                cli_set_timeout(cli, old_timeout);
                cli_shutdown(cli);
        }
+
+       return werr;
+}
+
+WERROR NetJoinDomain(const char *server_name,
+                    const char *domain_name,
+                    const char *account_ou,
+                    const char *Account,
+                    const char *password,
+                    uint32_t join_flags)
+{
+       TALLOC_CTX *mem_ctx = NULL;
+       WERROR werr;
+
+       mem_ctx = talloc_init("NetJoinDomain");
+       if (!mem_ctx) {
+               werr = WERR_NOMEM;
+               goto done;
+       }
+
+       if (!domain_name) {
+               werr = WERR_INVALID_PARAM;
+               goto done;
+       }
+
+       if (!server_name || is_myname_or_ipaddr(server_name)) {
+
+               const char *dc = NULL;
+
+               /* FIXME: DsGetDcName */
+               if (server_name == NULL) {
+                       dc = domain_name;
+               } else {
+                       dc = domain_name;
+               }
+
+               werr = NetJoinDomainLocal(mem_ctx,
+                                         dc,
+                                         domain_name,
+                                         account_ou,
+                                         Account,
+                                         password,
+                                         join_flags);
+
+               goto done;
+       }
+
+       werr = NetJoinDomainRemote(mem_ctx,
+                                  server_name,
+                                  domain_name,
+                                  account_ou,
+                                  Account,
+                                  password,
+                                  join_flags);
+done:
        TALLOC_FREE(mem_ctx);
 
        return werr;