+
+/**
+ * compose a wbint_Principal and add it to talloc_dict
+ *
+ * NOTE: this has a side effect: *name needs to be talloc'd
+ * and it is talloc_move'd to mem_ctx.
+ */
+NTSTATUS add_wbint_Principal_to_dict(TALLOC_CTX *mem_ctx,
+ struct dom_sid *sid,
+ const char **name,
+ enum lsa_SidType type,
+ struct talloc_dict *dict)
+{
+ struct wbint_Principal *m;
+ DATA_BLOB key;
+ bool ok;
+
+ m = talloc(mem_ctx, struct wbint_Principal);
+ if (m == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ sid_copy(&m->sid, sid);
+ m->name = talloc_move(m, name);
+ m->type = type;
+
+ key = data_blob_const(&m->sid, sizeof(m->sid));
+
+ ok = talloc_dict_set(dict, key, &m);
+ if (!ok) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
+