summaryrefslogtreecommitdiff
path: root/source4/dsdb/common
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-05-21 08:21:37 +1000
committerAndrew Bartlett <abartlet@samba.org>2010-05-24 23:08:11 +1000
commit20d2847492f9ccdb159df91315be9dcc142b5d83 (patch)
tree16ed4b48e289aa1c2dae2799464d405bfd71ef9f /source4/dsdb/common
parentfc04e565b08012e2e9926b055b6a8c5f5dccc080 (diff)
downloadsamba-20d2847492f9ccdb159df91315be9dcc142b5d83.tar.gz
samba-20d2847492f9ccdb159df91315be9dcc142b5d83.tar.bz2
samba-20d2847492f9ccdb159df91315be9dcc142b5d83.zip
s4:samr Move most of samr_CreateDomAlias into a helper function
This allows this logic to be shared, rather than copied, into a passdb wrapper. Andrew Bartlett
Diffstat (limited to 'source4/dsdb/common')
-rw-r--r--source4/dsdb/common/util_samr.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/source4/dsdb/common/util_samr.c b/source4/dsdb/common/util_samr.c
index 8b53bd784e..58d5b3fd21 100644
--- a/source4/dsdb/common/util_samr.c
+++ b/source4/dsdb/common/util_samr.c
@@ -326,3 +326,76 @@ NTSTATUS dsdb_add_domain_group(struct ldb_context *ldb,
return NT_STATUS_OK;
}
+NTSTATUS dsdb_add_domain_alias(struct ldb_context *ldb,
+ TALLOC_CTX *mem_ctx,
+ const char *alias_name,
+ struct dom_sid **sid,
+ struct ldb_dn **dn)
+{
+ const char *name;
+ struct ldb_message *msg;
+ struct dom_sid *alias_sid;
+ int ret;
+
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
+
+ /* Check if alias already exists */
+ name = samdb_search_string(ldb, tmp_ctx, NULL,
+ "sAMAccountName",
+ "(sAMAccountName=%s)(objectclass=group))",
+ ldb_binary_encode_string(mem_ctx, alias_name));
+
+ if (name != NULL) {
+ talloc_free(tmp_ctx);
+ return NT_STATUS_ALIAS_EXISTS;
+ }
+
+ msg = ldb_msg_new(tmp_ctx);
+ if (msg == NULL) {
+ talloc_free(tmp_ctx);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* add core elements to the ldb_message for the alias */
+ msg->dn = ldb_dn_copy(mem_ctx, ldb_get_default_basedn(ldb));
+ ldb_dn_add_child_fmt(msg->dn, "CN=%s,CN=Users", alias_name);
+ if (!msg->dn) {
+ talloc_free(tmp_ctx);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ samdb_msg_add_string(ldb, mem_ctx, msg, "sAMAccountName", alias_name);
+ samdb_msg_add_string(ldb, mem_ctx, msg, "objectClass", "group");
+ samdb_msg_add_int(ldb, mem_ctx, msg, "groupType", GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
+
+ /* create the alias */
+ ret = ldb_add(ldb, msg);
+ switch (ret) {
+ case LDB_SUCCESS:
+ break;
+ case LDB_ERR_ENTRY_ALREADY_EXISTS:
+ talloc_free(tmp_ctx);
+ return NT_STATUS_ALIAS_EXISTS;
+ case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
+ talloc_free(tmp_ctx);
+ return NT_STATUS_ACCESS_DENIED;
+ default:
+ DEBUG(0,("Failed to create alias record %s: %s\n",
+ ldb_dn_get_linearized(msg->dn),
+ ldb_errstring(ldb)));
+ talloc_free(tmp_ctx);
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ /* retrieve the sid for the alias just created */
+ alias_sid = samdb_search_dom_sid(ldb, tmp_ctx,
+ msg->dn, "objectSid", NULL);
+
+ *dn = talloc_steal(mem_ctx, msg->dn);
+ *sid = talloc_steal(mem_ctx, alias_sid);
+ talloc_free(tmp_ctx);
+
+ return NT_STATUS_OK;
+}
+