patch: make net_join_domain return NTSTATUS

Michael Adam ma at sernet.de
Tue Aug 15 10:18:00 GMT 2006


Hi!

This small patch makes utils/net_ads.c:net_join_domain
hand the NTSTATUS code down to net_ads_join instead of just
returning 0 upon success and -1 otherwise.

Cheers, Michael

-------------- next part --------------
Index: utils/net_ads.c
===================================================================
--- utils/net_ads.c	(revision 17551)
+++ utils/net_ads.c	(working copy)
@@ -887,28 +887,27 @@
  Do the domain join
  ********************************************************************/
 
-static int net_join_domain( TALLOC_CTX *ctx, const char *servername, 
-                            struct in_addr *ip, DOM_SID **dom_sid, const char *password )
+static NTSTATUS net_join_domain(TALLOC_CTX *ctx, const char *servername, 
+				struct in_addr *ip, DOM_SID **dom_sid, 
+				const char *password)
 {
-	int ret = -1;
+	NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
 	struct cli_state *cli = NULL;
 
-	if ( !NT_STATUS_IS_OK(connect_to_ipc_krb5(&cli, ip, servername)) )
+	ret = connect_to_ipc_krb5(&cli, ip, servername);
+	if ( !NT_STATUS_IS_OK(ret) ) {
 		goto done;
+	}
 	
 	saf_store( cli->server_domain, cli->desthost );
 
-	if ( !NT_STATUS_IS_OK(netdom_get_domain_sid( ctx, cli, dom_sid )) )
+	ret = netdom_get_domain_sid( ctx, cli, dom_sid );
+	if ( !NT_STATUS_IS_OK(ret) ) {
 		goto done;
-
-	if ( !NT_STATUS_IS_OK(netdom_join_domain( ctx, cli, *dom_sid, 
-		password, ND_TYPE_AD )) )
-	{
-		goto done;
 	}
-	
-	ret = 0;
 
+	ret = netdom_join_domain( ctx, cli, *dom_sid, password, ND_TYPE_AD );
+
 done:
 	if ( cli ) 
 		cli_shutdown(cli);
@@ -1171,6 +1170,7 @@
 {
 	ADS_STRUCT *ads = NULL;
 	ADS_STATUS status;
+	NTSTATUS nt_status;
 	char *machine_account = NULL;
 	const char *short_domain_name = NULL;
 	char *tmp_password, *password;
@@ -1239,9 +1239,10 @@
 	tmp_password = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
 	password = talloc_strdup(ctx, tmp_password);
 	
-	if ( net_join_domain( ctx, ads->config.ldap_server_name, &ads->ldap_ip, &domain_sid, password ) != 0 ) {
-		/* There should be more detailed output here... */
-		d_fprintf(stderr, "call of net_join_domain failed\n");
+	nt_status = net_join_domain(ctx, ads->config.ldap_server_name, 
+				    &ads->ldap_ip, &domain_sid, password);
+	if ( !NT_STATUS_IS_OK(nt_status) ) {
+		d_fprintf(stderr, "call of net_join_domain failed: %s\n", nt_errstr(nt_status));
 		goto fail;
 	}
 	


More information about the samba-technical mailing list