r25198: Change net_rpc_join_ok() to return NTSTATUS for better
authorMichael Adam <obnox@samba.org>
Mon, 17 Sep 2007 15:34:22 +0000 (15:34 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:50 +0000 (12:30 -0500)
error propagation.

Michael

source/utils/net_ads.c
source/utils/net_rpc_join.c

index 5646a0c8a82bf02db96f15e2a46a19b9b38814f1..4a4330666613bdb2d514272b09d9b7f0db0d33e7 100644 (file)
@@ -1600,8 +1600,12 @@ int net_ads_join(int argc, const char **argv)
 
        /* Verify that everything is ok */
 
-       if ( net_rpc_join_ok(short_domain_name, ads->config.ldap_server_name, &ads->ldap.ip) != 0 ) {
-               d_fprintf(stderr, "Failed to verify membership in domain!\n");
+       nt_status = net_rpc_join_ok(short_domain_name,
+                                   ads->config.ldap_server_name, &ads->ldap.ip);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               d_fprintf(stderr,
+                         "Failed to verify membership in domain: %s!\n",
+                         nt_errstr(nt_status));
                goto fail;
        }       
 
index 571d8016b9f69ba26390eb144d604b6e38eb2e69..b32fa27284fbdbef21477c98ff49e79f2056e3e5 100644 (file)
@@ -40,7 +40,8 @@
  * @return A shell status integer (0 for success)
  *
  **/
-int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
+NTSTATUS net_rpc_join_ok(const char *domain, const char *server,
+                        struct in_addr *ip)
 {
        enum security_types sec;
        unsigned int conn_flags = NET_FLAGS_PDC;
@@ -66,7 +67,7 @@ int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
        /* Connect to remote machine */
        ntret = net_make_ipc_connection_ex(domain, server, ip, conn_flags, &cli);
        if (!NT_STATUS_IS_OK(ntret)) {
-               return -1;
+               return ntret;
        }
 
        /* Setup the creds as though we're going to do schannel... */
@@ -78,13 +79,13 @@ int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
         if (!netlogon_pipe) {
                if (NT_STATUS_EQUAL(ntret, NT_STATUS_INVALID_NETWORK_RESPONSE)) {
                        cli_shutdown(cli);
-                       return 0;
+                       return NT_STATUS_OK;
                } else {
                        DEBUG(0,("net_rpc_join_ok: failed to get schannel session "
                                        "key from server %s for domain %s. Error was %s\n",
                                cli->desthost, domain, nt_errstr(ntret) ));
                        cli_shutdown(cli);
-                       return -1;
+                       return ntret;
                }
        }
 
@@ -92,7 +93,7 @@ int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
        if (!lp_client_schannel()) {
                cli_shutdown(cli);
                /* We're good... */
-               return 0;
+               return ntret;
        }
 
        pipe_hnd = cli_rpc_pipe_open_schannel_with_key(cli, PI_NETLOGON,
@@ -103,12 +104,14 @@ int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
                DEBUG(0,("net_rpc_join_ok: failed to open schannel session "
                                "on netlogon pipe to server %s for domain %s. Error was %s\n",
                        cli->desthost, domain, nt_errstr(ntret) ));
-               cli_shutdown(cli);
-               return -1;
+               /*
+                * Note: here, we have:
+                * (pipe_hnd != NULL) if and only if NT_STATUS_IS_OK(ntret)
+                */
        }
 
        cli_shutdown(cli);
-       return 0;
+       return ntret;
 }
 
 /**
@@ -422,8 +425,9 @@ int net_rpc_join_newstyle(int argc, const char **argv)
        }
 
        /* double-check, connection from scratch */
-       retval = net_rpc_join_ok(domain, cli->desthost, &cli->dest_ip);
-       
+       result = net_rpc_join_ok(domain, cli->desthost, &cli->dest_ip);
+       retval = NT_STATUS_IS_OK(result) ? 0 : -1;
+
 done:
 
        /* Display success or failure */
@@ -452,10 +456,13 @@ done:
 int net_rpc_testjoin(int argc, const char **argv) 
 {
        char *domain = smb_xstrdup(opt_target_workgroup);
+       NTSTATUS nt_status;
 
        /* Display success or failure */
-       if (net_rpc_join_ok(domain, NULL, NULL) != 0) {
-               fprintf(stderr,"Join to domain '%s' is not valid\n",domain);
+       nt_status = net_rpc_join_ok(domain, NULL, NULL);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               fprintf(stderr,"Join to domain '%s' is not valid: %s\n",
+                       nt_errstr(nt_status), domain);
                free(domain);
                return -1;
        }