summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-12 02:54:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:20:08 -0500
commit1bb2b0603126188e639d7adb6309166c64b5e9df (patch)
tree3526a48cb58c2451245faa155e50efc9ceb29d8a /source4/scripting/ejs
parent2dce83de0c4de67f15e95456d6a63864d2f6ad85 (diff)
downloadsamba-1bb2b0603126188e639d7adb6309166c64b5e9df.tar.gz
samba-1bb2b0603126188e639d7adb6309166c64b5e9df.tar.bz2
samba-1bb2b0603126188e639d7adb6309166c64b5e9df.zip
r8339: added ldbAdd(), ldbModify(), ldbDelete() and ldbRename() to ejs ldb functions
(This used to be commit 322c2137835ff2d76b3183901bf680780f164b5e)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 414251a31c..309271a29d 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -85,10 +85,154 @@ failed:
return -1;
}
+
+/*
+ perform an ldb add or modify
+*/
+static int ejs_ldbAddModify(MprVarHandle eid, int argc, char **argv,
+ int fn(struct ldb_context *, const struct ldb_message *))
+{
+ const char *ldifstring, *dbfile;
+ struct ldb_context *ldb;
+ struct ldb_ldif *ldif;
+ int ret;
+
+ if (argc != 2) {
+ ejsSetErrorMsg(eid, "ldbAddModify invalid arguments");
+ return -1;
+ }
+
+ dbfile = argv[0];
+ ldifstring = argv[1];
+
+ ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, NULL);
+ if (ldb == NULL) {
+ ejsSetErrorMsg(eid, "ldbAddModify failed to open %s", dbfile);
+ goto failed;
+ }
+
+ ldif = ldb_ldif_read_string(ldb, ldifstring);
+ if (ldif == NULL) {
+ ejsSetErrorMsg(eid, "ldbAddModify invalid ldif");
+ goto failed;
+ }
+ ret = fn(ldb, ldif->msg);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ talloc_free(ldb);
+ return 0;
+
+failed:
+ talloc_free(ldb);
+ return -1;
+}
+
+
+/*
+ perform an ldb delete
+ usage:
+ ok = ldbDelete(dbfile, dn);
+*/
+static int ejs_ldbDelete(MprVarHandle eid, int argc, char **argv)
+{
+ const char *dn, *dbfile;
+ struct ldb_context *ldb;
+ int ret;
+
+ if (argc != 2) {
+ ejsSetErrorMsg(eid, "ldbDelete invalid arguments");
+ return -1;
+ }
+
+ dbfile = argv[0];
+ dn = argv[1];
+
+ ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, NULL);
+ if (ldb == NULL) {
+ ejsSetErrorMsg(eid, "ldbDelete failed to open %s", dbfile);
+ goto failed;
+ }
+
+ ret = ldb_delete(ldb, dn);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ talloc_free(ldb);
+ return 0;
+
+failed:
+ talloc_free(ldb);
+ return -1;
+}
+
+/*
+ perform an ldb rename
+ usage:
+ ok = ldbRename(dbfile, dn1, dn2);
+*/
+static int ejs_ldbRename(MprVarHandle eid, int argc, char **argv)
+{
+ const char *dn1, *dn2, *dbfile;
+ struct ldb_context *ldb;
+ int ret;
+
+ if (argc != 3) {
+ ejsSetErrorMsg(eid, "ldbRename invalid arguments");
+ return -1;
+ }
+
+ dbfile = argv[0];
+ dn1 = argv[1];
+ dn2 = argv[2];
+
+ ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, NULL);
+ if (ldb == NULL) {
+ ejsSetErrorMsg(eid, "ldbRename failed to open %s", dbfile);
+ goto failed;
+ }
+
+ ret = ldb_rename(ldb, dn1, dn2);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ talloc_free(ldb);
+ return 0;
+
+failed:
+ talloc_free(ldb);
+ return -1;
+}
+
+/*
+ perform an ldb modify
+
+ syntax:
+ ok = ldbModify("dbfile", ldifstring);
+*/
+static int ejs_ldbAdd(MprVarHandle eid, int argc, char **argv)
+{
+ return ejs_ldbAddModify(eid, argc, argv, ldb_add);
+}
+
+/*
+ perform an ldb add
+
+ syntax:
+ ok = ldbAdd("dbfile", ldifstring);
+*/
+static int ejs_ldbModify(MprVarHandle eid, int argc, char **argv)
+{
+ return ejs_ldbAddModify(eid, argc, argv, ldb_modify);
+}
+
+
+
/*
setup C functions that be called from ejs
*/
void smb_setup_ejs_ldb(void)
{
ejsDefineCFunction(-1, "ldbSearch", ejs_ldbSearch, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineStringCFunction(-1, "ldbAdd", ejs_ldbAdd, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineStringCFunction(-1, "ldbModify", ejs_ldbModify, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineStringCFunction(-1, "ldbDelete", ejs_ldbDelete, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineStringCFunction(-1, "ldbRename", ejs_ldbRename, NULL, MPR_VAR_SCRIPT_HANDLE);
}