r11586: Further work on ejs interface for libnet. The idea is to split libnet
authorRafal Szczesniak <mimir@samba.org>
Tue, 8 Nov 2005 23:22:21 +0000 (23:22 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:45:54 +0000 (13:45 -0500)
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

source/scripting/ejs/ejsnet.c
source/scripting/ejs/ejsnet.h

index bed660aceb035b6e77d4d9f62a2795142ee3bfa9..4dc52f577102abd39d46683f58d3b4bdd6e52d45 100644 (file)
@@ -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);
index 4ea64df36bec32e848e9dc4bb6ee98bb8f204aa3..50978c648d372f6c39265a4798bd6e4fc20fd5d6 100644 (file)
@@ -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**);