summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2005-11-08 23:22:21 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:54 -0500
commit2a006a7e6bf4a8813b1c5d9b07643082d98a4988 (patch)
treebd0365d365170a1354aeae248eea4046938475e9 /source4/scripting/ejs
parent9a9604b26c7639e3ebf989e6c9195bcca008d65c (diff)
downloadsamba-2a006a7e6bf4a8813b1c5d9b07643082d98a4988.tar.gz
samba-2a006a7e6bf4a8813b1c5d9b07643082d98a4988.tar.bz2
samba-2a006a7e6bf4a8813b1c5d9b07643082d98a4988.zip
r11586: Further work on ejs interface for libnet. The idea is to split libnet
functionalities into groups of subcontexts of net subcontext just the way it's done in net tool. This way we can pass common arguments when creating subcontext. Also, this may allow easier writing net tool completely as a script. At the moment there's a name resolve code segfault to be fixed. rafal (This used to be commit 25310d05927dab69d37248977f974bcaedbd081b)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/ejsnet.c60
-rw-r--r--source4/scripting/ejs/ejsnet.h1
2 files changed, 57 insertions, 4 deletions
diff --git a/source4/scripting/ejs/ejsnet.c b/source4/scripting/ejs/ejsnet.c
index bed660aceb..4dc52f5771 100644
--- a/source4/scripting/ejs/ejsnet.c
+++ b/source4/scripting/ejs/ejsnet.c
@@ -76,10 +76,10 @@ static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
}
obj = mprInitObject(eid, "NetCtx", argc, argv);
-
- mprSetStringCFunction(obj, "CreateUser", ejs_net_createuser);
mprSetPtrChild(obj, "ctx", ctx);
+ mprSetCFunction(obj, "UserMgr", ejs_net_userman);
+
return 0;
done:
talloc_free(ctx);
@@ -87,11 +87,52 @@ done:
}
+static int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ TALLOC_CTX *mem_ctx;
+ struct libnet_context *ctx;
+ const char *userman_domain = NULL;
+ struct MprVar *obj = NULL;
+
+ ctx = mprGetThisPtr(eid, "ctx");
+ mem_ctx = talloc_init(NULL);
+
+ if (argc == 0) {
+ userman_domain = cli_credentials_get_domain(ctx->cred);
+
+ } else if (argc == 1 && mprVarIsString(argv[0]->type)) {
+ userman_domain = talloc_strdup(ctx, mprToString(argv[0]));
+
+ } else {
+ ejsSetErrorMsg(eid, "too many arguments");
+ goto done;
+ }
+
+ if (!userman_domain) {
+ ejsSetErrorMsg(eid, "a domain must be specified for user management");
+ goto done;
+ }
+
+ obj = mprInitObject(eid, "NetUsrCtx", argc, argv);
+ mprSetPtrChild(obj, "ctx", ctx);
+ mprSetPtrChild(obj, "domain", userman_domain);
+
+ mprSetStringCFunction(obj, "Create", ejs_net_createuser);
+
+ return 0;
+done:
+ talloc_free(mem_ctx);
+ return -1;
+}
+
+
static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
TALLOC_CTX *mem_ctx;
struct libnet_context *ctx;
+ const char *userman_domain = NULL;
struct libnet_CreateUser req;
if (argc != 1) {
@@ -100,9 +141,20 @@ static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv)
}
ctx = mprGetThisPtr(eid, "ctx");
- mem_ctx = talloc_init(NULL);
+ if (!ctx) {
+ ejsSetErrorMsg(eid, "ctx property returns null pointer");
+ goto done;
+ }
+
+ userman_domain = mprGetThisPtr(eid, "domain");
+ if (!userman_domain) {
+ ejsSetErrorMsg(eid, "domain property returns null pointer");
+ goto done;
+ }
- req.in.domain_name = cli_credentials_get_domain(ctx->cred);
+ mem_ctx = talloc_init(NULL);
+
+ req.in.domain_name = userman_domain;
req.in.user_name = argv[0];
status = libnet_CreateUser(ctx, mem_ctx, &req);
diff --git a/source4/scripting/ejs/ejsnet.h b/source4/scripting/ejs/ejsnet.h
index 4ea64df36b..50978c648d 100644
--- a/source4/scripting/ejs/ejsnet.h
+++ b/source4/scripting/ejs/ejsnet.h
@@ -24,4 +24,5 @@
void ejsnet_setup(void);
+static int ejs_net_userman(MprVarHandle, int, struct MprVar**);
static int ejs_net_createuser(MprVarHandle, int, char**);