summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-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));