Author: mimir Date: 2005-11-08 23:22:21 +0000 (Tue, 08 Nov 2005) New Revision: 11586
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11586 Log: 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 Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h Changeset: Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c =================================================================== --- branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c 2005-11-08 20:13:26 UTC (rev 11585) +++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c 2005-11-08 23:22:21 UTC (rev 11586) @@ -76,10 +76,10 @@ } 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 @@ } +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 @@ } ctx = mprGetThisPtr(eid, "ctx"); + 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; + } + mem_ctx = talloc_init(NULL); - - req.in.domain_name = cli_credentials_get_domain(ctx->cred); + + req.in.domain_name = userman_domain; req.in.user_name = argv[0]; status = libnet_CreateUser(ctx, mem_ctx, &req); Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h =================================================================== --- branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h 2005-11-08 20:13:26 UTC (rev 11585) +++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h 2005-11-08 23:22:21 UTC (rev 11586) @@ -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**);
