summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2007-01-18 21:50:24 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:43:44 -0500
commitfe5e7809b836e9dff7bb8bffaee852f1e6d4c7de (patch)
tree7881bdf4c66ed83fceda6d7f37d035a54297f979 /source4
parent2467451ddfb1b9a38c9cdfcd8c647dc5cc670448 (diff)
downloadsamba-fe5e7809b836e9dff7bb8bffaee852f1e6d4c7de.tar.gz
samba-fe5e7809b836e9dff7bb8bffaee852f1e6d4c7de.tar.bz2
samba-fe5e7809b836e9dff7bb8bffaee852f1e6d4c7de.zip
r20881: Sorting out NetUsrCtx methods. Still a couple of things left.
rafal (This used to be commit eebd00ba2bfdfe3bbbcc0a50b91e2e2b03371df6)
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/ejs/ejsnet/net_user.c175
1 files changed, 133 insertions, 42 deletions
diff --git a/source4/scripting/ejs/ejsnet/net_user.c b/source4/scripting/ejs/ejsnet/net_user.c
index e833787876..7563ef2e72 100644
--- a/source4/scripting/ejs/ejsnet/net_user.c
+++ b/source4/scripting/ejs/ejsnet/net_user.c
@@ -37,7 +37,7 @@ static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv);
/*
Usage:
- usrCtx = net.UserMgr(domain);
+ usrCtx = net.UserMgr(domain = <default from credentials>);
*/
int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -46,68 +46,102 @@ int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv)
const char *userman_domain = NULL;
struct MprVar *obj = NULL;
- ctx = mprGetThisPtr(eid, "ctx");
- mem_ctx = talloc_new(mprMemCtx());
-
+ /* fetch the arguments: domain name */
if (argc == 0) {
+ /* default domain name is supplied in credentials */
userman_domain = cli_credentials_get_domain(ctx->cred);
} else if (argc == 1 && mprVarIsString(argv[0]->type)) {
+ /* domain name can also be specified explicitly
+ (e.g. to connect remote domain) */
userman_domain = talloc_strdup(ctx, mprToString(argv[0]));
} else {
ejsSetErrorMsg(eid, "too many arguments");
goto done;
}
+
+ /* libnet context */
+ ctx = mprGetThisPtr(eid, "ctx");
+ if (ctx == NULL) {
+ ejsSetErrorMsg(eid, "ctx property returns null pointer");
+ goto done;
+ }
- if (!userman_domain) {
+ mem_ctx = talloc_new(mprMemCtx());
+
+ /* any domain name must be specified anyway */
+ if (userman_domain == NULL) {
ejsSetErrorMsg(eid, "a domain must be specified for user management");
goto done;
}
-
+
+ /* create 'net user' subcontext */
obj = mprInitObject(eid, "NetUsrCtx", argc, argv);
+
+ /* add properties */
mprSetPtrChild(obj, "ctx", ctx);
mprSetPtrChild(obj, "domain", userman_domain);
+ /* add methods */
mprSetStringCFunction(obj, "Create", ejs_net_createuser);
mprSetStringCFunction(obj, "Delete", ejs_net_deleteuser);
mprSetStringCFunction(obj, "Info", ejs_net_userinfo);
mprSetCFunction(obj, "List", ejs_net_userlist);
- return 0;
done:
talloc_free(mem_ctx);
- return -1;
+ return 0;
}
+/*
+ Usage:
+ NTSTATUS = NetUsrCtx.Create(Username)
+*/
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;
+ const char *username = NULL;
struct libnet_CreateUser req;
- if (argc != 1) {
- ejsSetErrorMsg(eid, "argument 1 must be a string");
- return -1;
+ mem_ctx = talloc_new(mprMemCtx());
+ if (mem_ctx == NULL) {
+ ejsSetErrorMsg(eid, "could not create memory context - out of memory");
+ goto done;
}
+ /* fetch the arguments: username */
+ if (argc == 0) {
+ ejsSetErrorMsg(eid, "too little arguments");
+ goto done;
+
+ } else if (argc == 1) {
+ username = argv[0];
+
+ } else {
+ ejsSetErrorMsg(eid, "too many arguments");
+ goto done;
+ }
+
+ /* libnet context */
ctx = mprGetThisPtr(eid, "ctx");
- if (!ctx) {
+ if (ctx == NULL) {
ejsSetErrorMsg(eid, "ctx property returns null pointer");
- return -1;
+ goto done;
}
+ /* domain where the account is to be created */
userman_domain = mprGetThisPtr(eid, "domain");
- if (!userman_domain) {
+ if (userman_domain == NULL) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
- return -1;
+ goto done;
}
- mem_ctx = talloc_new(mprMemCtx());
-
+ /* call the libnet function */
req.in.domain_name = userman_domain;
req.in.user_name = argv[0];
@@ -116,83 +150,125 @@ static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv)
ejsSetErrorMsg(eid, "%s", req.out.error_string);
}
+done:
talloc_free(mem_ctx);
mpr_Return(eid, mprNTSTATUS(status));
return 0;
}
+/*
+ Usage:
+ NTSTATUS = NetUsrCtx.Delete(Username)
+*/
static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
TALLOC_CTX *mem_ctx;
struct libnet_context *ctx;
const char *userman_domain = NULL;
+ const char *username = NULL;
struct libnet_DeleteUser req;
- if (argc != 1) {
- ejsSetErrorMsg(eid, "argument 1 must be a string");
- return -1;
+ mem_ctx = talloc_new(mprMemCtx());
+ if (mem_ctx == NULL) {
+ ejsSetErrorMsg(eid, "could not create memory context - out of memory");
+ goto done;
}
+ /* fetch the arguments: username */
+ if (argc == 0) {
+ ejsSetErrorMsg(eid, "too little arguments");
+ goto done;
+
+ } else if (argc == 1) {
+ username = argv[0];
+
+ } else {
+ ejsSetErrorMsg(eid, "too many arguments");
+ goto done;
+ }
+
+ /* libnet context */
ctx = mprGetThisPtr(eid, "ctx");
- if (!ctx) {
+ if (ctx == NULL) {
ejsSetErrorMsg(eid, "ctx property returns null pointer");
- return -1;
+ goto done;
}
-
+
+ /* domain where the account is to be deleted */
userman_domain = mprGetThisPtr(eid, "domain");
if (!userman_domain) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
- return -1;
+ goto done;
}
- mem_ctx = talloc_new(mprMemCtx());
-
+ /* call the libnet function */
req.in.domain_name = userman_domain;
- req.in.user_name = argv[0];
+ req.in.user_name = username;
status = libnet_DeleteUser(ctx, mem_ctx, &req);
if (!NT_STATUS_IS_OK(status)) {
ejsSetErrorMsg(eid, "%s", req.out.error_string);
}
+done:
talloc_free(mem_ctx);
mpr_Return(eid, mprNTSTATUS(status));
return 0;
}
+/*
+ Usage:
+ UserInfo = NetUsrCtx.Info(Username)
+*/
static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
TALLOC_CTX *mem_ctx;
struct libnet_context *ctx;
- const char *userman_domain;
+ const char *userman_domain = NULL;
+ const char *username = NULL;
struct libnet_UserInfo req;
struct MprVar mprUserInfo;
- if (argc != 1) {
- ejsSetErrorMsg(eid, "argument 1 must be a string");
- return -1;
+ mem_ctx = talloc_new(mprMemCtx());
+ if (mem_ctx == NULL) {
+ ejsSetErrorMsg(eid, "could not create memory context - out of memory");
+ goto done;
}
+
+ /* fetch the arguments: username */
+ if (argc == 0) {
+ ejsSetErrorMsg(eid, "too little arguments");
+ goto done;
+ } else if (argc == 1) {
+ username = argv[0];
+
+ } else {
+ ejsSetErrorMsg(eid, "too many arguments");
+ goto done;
+ }
+
+ /* libnet context */
ctx = mprGetThisPtr(eid, "ctx");
if (ctx == NULL) {
ejsSetErrorMsg(eid, "ctx property returns null pointer");
- return -1;
+ goto done;
}
-
+
+ /* domain where the user account is to be queried */
userman_domain = mprGetThisPtr(eid, "domain");
if (userman_domain == NULL) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
return -1;
}
- mem_ctx = talloc_new(mprMemCtx());
-
+ /* call the libnet function */
req.in.domain_name = userman_domain;
- req.in.user_name = argv[0];
+ req.in.user_name = username;
status = libnet_UserInfo(ctx, mem_ctx, &req);
if (!NT_STATUS_IS_OK(status)) {
@@ -213,19 +289,30 @@ done:
}
+/*
+ Usage:
+ UserListCtx = NetUsrCtx.List(UserListCtx)
+*/
static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv)
{
TALLOC_CTX *mem_ctx;
NTSTATUS status;
struct libnet_context *ctx;
const char *userlist_domain;
+ int page_size = 10; /* TODO: this should be specified in a nicer way */
struct libnet_UserList req;
struct MprVar mprListCtx, *mprInListCtx;
mem_ctx = talloc_new(mprMemCtx());
+ if (mem_ctx == NULL) {
+ ejsSetErrorMsg(eid, "could not create memory context - out of memory");
+ goto done;
+ }
+ /* fetch the arguments */
if (argc == 0) {
ejsSetErrorMsg(eid, "too little arguments");
+ goto done;
} else if (argc == 1) {
if (mprVarIsObject(argv[0]->type)) {
@@ -234,6 +321,7 @@ static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv)
req.in.resume_index = mprListGetResumeIndex(mprInListCtx);
} else {
+ /* this is a first call */
req.in.resume_index = 0;
}
@@ -242,20 +330,23 @@ static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv)
goto done;
}
+ /* libnet context */
ctx = mprGetThisPtr(eid, "ctx");
- if (!ctx) {
+ if (ctx == NULL) {
ejsSetErrorMsg(eid, "ctx property returns null pointer");
- return -1;
+ goto done;
}
-
+
+ /* domain where user accounts are to be enumerated */
userlist_domain = mprGetThisPtr(eid, "domain");
- if (!userlist_domain) {
+ if (userlist_domain == NULL) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
- return -1;
+ goto done;
}
+ /* call the libnet function */
req.in.domain_name = userlist_domain;
- req.in.page_size = 10; /* TODO: this should be specified in a nicer way */
+ req.in.page_size = page_size;
status = libnet_UserList(ctx, mem_ctx, &req);
if (!NT_STATUS_IS_OK(status) &&