summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-05-18 08:16:50 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:52:37 -0500
commit47e5c163d63ae04381a67cd4d5cc428f22374bb6 (patch)
tree35d75d44580a32dd8c110dd0edcb8eddc4906d80
parentd7e913d1931ddaa1f908b849b7f29629e1ddcee0 (diff)
downloadsamba-47e5c163d63ae04381a67cd4d5cc428f22374bb6.tar.gz
samba-47e5c163d63ae04381a67cd4d5cc428f22374bb6.tar.bz2
samba-47e5c163d63ae04381a67cd4d5cc428f22374bb6.zip
r22993: - make it possible to load a dsdb_schema from ldif via the ejs bindings
- make it possible to set ntds_objectGUID and ntds_invocationId via the ejy bindings metze (This used to be commit df7863ea1c964ec58feedd0bf72ef64456e3a3d1)
-rw-r--r--source4/scripting/ejs/config.mk1
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c125
2 files changed, 126 insertions, 0 deletions
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk
index d5ce2dd614..f1c17ad21d 100644
--- a/source4/scripting/ejs/config.mk
+++ b/source4/scripting/ejs/config.mk
@@ -15,6 +15,7 @@ INIT_FUNCTION = smb_setup_ejs_config
OBJ_FILES = smbcalls_ldb.o
SUBSYSTEM = smbcalls
INIT_FUNCTION = smb_setup_ejs_ldb
+PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR
[MODULE::smbcalls_nbt]
OBJ_FILES = smbcalls_nbt.o
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 3f970cea58..33f371cd4e 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -27,6 +27,8 @@
#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
#include "db_wrap.h"
+#include "dsdb/samdb/samdb.h"
+#include "librpc/ndr/libndr.h"
/*
get the connected db
@@ -566,6 +568,123 @@ static int ejs_ldbTransactionCommit(MprVarHandle eid, int argc, struct MprVar **
}
/*
+ commit a ldb attach a dsdb_schema from ldif files
+ usage:
+ ok = ldb.attach_dsdb_schema_from_ldif("prefixMap ldif content", "definition ldif content")
+*/
+static int ejs_ldb_attach_dsdb_schema_from_ldif(MprVarHandle eid, int argc, char **argv)
+{
+ struct ldb_context *ldb;
+ WERROR status;
+ char *pf_name;
+ char *df_name;
+ const char *pf;
+ const char *df;
+
+ if (argc != 2) {
+ ejsSetErrorMsg(eid, "ldb.attach_dsdb_schema_from_ldif invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ pf = argv[0];
+ df = argv[1];
+
+ status = dsdb_attach_schema_from_ldif_file(ldb, pf, df);
+
+ mpr_Return(eid, mprWERROR(status));
+ return 0;
+}
+
+/*
+ commit a ldb attach a dsdb_schema from ldif files
+ usage:
+ ok = ldb.set_ntds_invocationId("7729aa4b-f990-41ad-b81a-8b6a14090f41");
+*/
+static int ejs_ldb_set_ntds_invocationId(MprVarHandle eid, int argc, char **argv)
+{
+ struct ldb_context *ldb;
+ NTSTATUS status;
+ struct GUID guid;
+ char *guid_str;
+ bool ok;
+
+ if (argc != 1) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_invocationId invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ guid_str = argv[0];
+
+ status = GUID_from_string(guid_str, &guid);
+ if (!NT_STATUS_IS_OK(status)) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_invocationId - failed to parse GUID '%s' %s\n",
+ guid_str, nt_errstr(status));
+ return -1;
+ }
+
+ ok = samdb_set_ntds_invocation_id(ldb, &guid);
+ if (!ok) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_invocationId - failed to set cached ntds invocationId\n");
+ return -1;
+ }
+
+ mpr_Return(eid, mprCreateBoolVar(ok));
+ return 0;
+}
+
+/*
+ commit a ldb attach a dsdb_schema from ldif files
+ usage:
+ ok = ldb.get_ntds_objectGUID("7729aa4b-f990-41ad-b81a-8b6a14090f41");
+*/
+static int ejs_ldb_set_ntds_objectGUID(MprVarHandle eid, int argc, char **argv)
+{
+ struct ldb_context *ldb;
+ NTSTATUS status;
+ struct GUID guid;
+ char *guid_str;
+ bool ok;
+
+ if (argc != 1) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_objectGUID invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ guid_str = argv[0];
+
+ status = GUID_from_string(guid_str, &guid);
+ if (!NT_STATUS_IS_OK(status)) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_objectGUID - failed to parse GUID '%s' %s\n",
+ guid_str, nt_errstr(status));
+ return -1;
+ }
+
+ ok = samdb_set_ntds_invocation_id(ldb, &guid);
+ if (!ok) {
+ ejsSetErrorMsg(eid, "ldb.set_ntds_objectGUID - failed to set cached ntds invocationId\n");
+ return -1;
+ }
+
+ mpr_Return(eid, mprCreateBoolVar(ok));
+ return 0;
+}
+
+/*
initialise ldb ejs subsystem
*/
static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -586,6 +705,12 @@ static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
mprSetCFunction(ldb, "transaction_start", ejs_ldbTransactionStart);
mprSetCFunction(ldb, "transaction_cancel", ejs_ldbTransactionCancel);
mprSetCFunction(ldb, "transaction_commit", ejs_ldbTransactionCommit);
+ mprSetStringCFunction(ldb, "attach_dsdb_schema_from_ldif",
+ ejs_ldb_attach_dsdb_schema_from_ldif);
+ mprSetStringCFunction(ldb, "set_ntds_invocationId",
+ ejs_ldb_set_ntds_invocationId);
+ mprSetStringCFunction(ldb, "set_ntds_objectGUID",
+ ejs_ldb_set_ntds_objectGUID);
mprSetVar(ldb, "SCOPE_BASE", mprCreateNumberVar(LDB_SCOPE_BASE));
mprSetVar(ldb, "SCOPE_ONE", mprCreateNumberVar(LDB_SCOPE_ONELEVEL));
mprSetVar(ldb, "SCOPE_SUBTREE", mprCreateNumberVar(LDB_SCOPE_SUBTREE));