svn commit: samba r5595 - in trunk/source: rpc_client utils

jmcd at samba.org jmcd at samba.org
Mon Feb 28 11:25:32 GMT 2005


Author: jmcd
Date: 2005-02-28 11:25:32 +0000 (Mon, 28 Feb 2005)
New Revision: 5595

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=5595

Log:
Merge from 3.0, implement net rpc trustdom del, hopefully without
extraneous commits of rpcclient test code :-/

Modified:
   trunk/source/rpc_client/cli_samr.c
   trunk/source/utils/net_rpc.c


Changeset:
Modified: trunk/source/rpc_client/cli_samr.c
===================================================================
--- trunk/source/rpc_client/cli_samr.c	2005-02-28 11:17:13 UTC (rev 5594)
+++ trunk/source/rpc_client/cli_samr.c	2005-02-28 11:25:32 UTC (rev 5595)
@@ -2204,6 +2204,54 @@
 	return result;
 }
 
+/* Remove foreign SID */
+
+NTSTATUS cli_samr_remove_sid_foreign_domain(struct cli_state *cli, 
+					    TALLOC_CTX *mem_ctx, 
+					    POLICY_HND *user_pol,
+					    DOM_SID *sid)
+{
+	prs_struct qbuf, rbuf;
+	SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
+	SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
+	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+
+	DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
+
+	ZERO_STRUCT(q);
+	ZERO_STRUCT(r);
+
+	/* Initialise parse structures */
+
+	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+	/* Marshall data and send request */
+
+	init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
+
+	if (!samr_io_q_remove_sid_foreign_domain("", &q, &qbuf, 0) ||
+	    !rpc_api_pipe_req(cli, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN, &qbuf, &rbuf)) {
+		goto done;
+	}
+
+	/* Unmarshall response */
+
+	if (!samr_io_r_remove_sid_foreign_domain("", &r, &rbuf, 0)) {
+		goto done;
+	}
+
+	/* Return output parameters */
+
+	result = r.status;
+
+ done:
+	prs_mem_free(&qbuf);
+	prs_mem_free(&rbuf);
+
+	return result;
+}
+
 /* Query user security object */
 
 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,

Modified: trunk/source/utils/net_rpc.c
===================================================================
--- trunk/source/utils/net_rpc.c	2005-02-28 11:17:13 UTC (rev 5594)
+++ trunk/source/utils/net_rpc.c	2005-02-28 11:25:32 UTC (rev 5595)
@@ -4454,6 +4454,113 @@
 
 
 /**
+ * Remove interdomain trust account from the RPC server.
+ * All parameters (except for argc and argv) are passed by run_rpc_command
+ * function.
+ *
+ * @param domain_sid The domain sid acquired from the server
+ * @param cli A cli_state connected to the server.
+ * @param mem_ctx Talloc context, destoyed on completion of the function.
+ * @param argc  Standard main() style argc
+ * @param argc  Standard main() style argv.  Initial components are already
+ *              stripped
+ *
+ * @return normal NTSTATUS return code
+ */
+
+static NTSTATUS rpc_trustdom_del_internals(const DOM_SID *domain_sid, 
+					   const char *domain_name, 
+					   struct cli_state *cli, TALLOC_CTX *mem_ctx, 
+                                           int argc, const char **argv) {
+
+	POLICY_HND connect_pol, domain_pol, user_pol;
+	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+	char *acct_name;
+	DOM_SID trust_acct_sid;
+	uint32 *user_rids, num_rids, *name_types;
+	uint32 flags = 0x000003e8; /* Unknown */
+
+	if (argc != 1) {
+		d_printf("Usage: net rpc trustdom del <domain_name>\n");
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+
+	/* 
+	 * Make valid trusting domain account (ie. uppercased and with '$' appended)
+	 */
+	 
+	if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	strupper_m(acct_name);
+
+	/* Get samr policy handle */
+	result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
+				  &connect_pol);
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+	
+	/* Get domain policy handle */
+	result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+				      MAXIMUM_ALLOWED_ACCESS,
+				      domain_sid, &domain_pol);
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+
+	result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol, flags, 1,
+				       &acct_name, &num_rids, &user_rids,
+				       &name_types);
+	
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+
+	result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
+				    MAXIMUM_ALLOWED_ACCESS,
+				    user_rids[0], &user_pol);
+
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+
+	/* append the rid to the domain sid */
+	sid_copy(&trust_acct_sid, domain_sid);
+	if (!sid_append_rid(&trust_acct_sid, user_rids[0])) {
+		goto done;
+	}
+
+	/* remove the sid */
+
+	result = cli_samr_remove_sid_foreign_domain(cli, mem_ctx, &user_pol,
+						    &trust_acct_sid);
+
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+
+	/* Delete user */
+
+	result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
+
+	if (!NT_STATUS_IS_OK(result)) {
+		goto done;
+	}
+
+	if (!NT_STATUS_IS_OK(result)) {
+	  DEBUG(0,("Could not set trust account password: %s\n",
+		   nt_errstr(result)));
+	  goto done;
+	}
+
+ done:
+	SAFE_FREE(acct_name);
+	return result;
+}
+
+/**
  * Delete interdomain trust account for a remote domain.
  *
  * @param argc standard argc
@@ -4461,15 +4568,19 @@
  *
  * @return Integer status (0 means success)
  **/
- 
+
 static int rpc_trustdom_del(int argc, const char **argv)
 {
-	d_printf("Sorry, not yet implemented.\n");
-	d_printf("Use 'smbpasswd -x -i' instead.\n");
-	return -1;
+	if (argc > 0) {
+		return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_del_internals,
+		                       argc, argv);
+	} else {
+		d_printf("Usage: net rpc trustdom del <domain>\n");
+		return -1;
+	}
 }
+ 
 
- 
 /**
  * Establish trust relationship to a trusting domain.
  * Interdomain account must already be created on remote PDC.



More information about the samba-cvs mailing list