mirror of
https://github.com/samba-team/samba.git
synced 2025-10-23 11:33:16 +03:00
r22323: - add credentials property to NetContext object
- change a comment (matches the idea better) rafal
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
63b89ccbeb
commit
4e8d9d3f60
@@ -43,7 +43,7 @@ static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
|
|||||||
TALLOC_CTX *event_mem_ctx = talloc_new(mprMemCtx());
|
TALLOC_CTX *event_mem_ctx = talloc_new(mprMemCtx());
|
||||||
struct cli_credentials *creds;
|
struct cli_credentials *creds;
|
||||||
struct libnet_context *ctx;
|
struct libnet_context *ctx;
|
||||||
struct MprVar obj;
|
struct MprVar obj, mprCreds;
|
||||||
struct event_context *ev;
|
struct event_context *ev;
|
||||||
|
|
||||||
if (!event_mem_ctx) {
|
if (!event_mem_ctx) {
|
||||||
@@ -59,6 +59,9 @@ static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
|
|||||||
talloc_steal(ctx, event_mem_ctx);
|
talloc_steal(ctx, event_mem_ctx);
|
||||||
|
|
||||||
if (argc == 0 || (argc == 1 && argv[0]->type == MPR_TYPE_NULL)) {
|
if (argc == 0 || (argc == 1 && argv[0]->type == MPR_TYPE_NULL)) {
|
||||||
|
/*
|
||||||
|
create the default credentials
|
||||||
|
*/
|
||||||
creds = cli_credentials_init(ctx);
|
creds = cli_credentials_init(ctx);
|
||||||
if (creds == NULL) {
|
if (creds == NULL) {
|
||||||
ejsSetErrorMsg(eid, "cli_credential_init() failed");
|
ejsSetErrorMsg(eid, "cli_credential_init() failed");
|
||||||
@@ -68,11 +71,16 @@ static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
|
|||||||
cli_credentials_set_conf(creds);
|
cli_credentials_set_conf(creds);
|
||||||
cli_credentials_set_anonymous(creds);
|
cli_credentials_set_anonymous(creds);
|
||||||
|
|
||||||
|
mprCreds = mprCredentials(creds);
|
||||||
|
|
||||||
} else if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) {
|
} else if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) {
|
||||||
/* get credential values from credentials object */
|
/*
|
||||||
creds = mprGetPtr(argv[0], "creds");
|
get credential values from credentials object
|
||||||
|
*/
|
||||||
|
mprCreds = *(argv[0]);
|
||||||
|
creds = mprGetPtr(&mprCreds, "creds");
|
||||||
if (creds == NULL) {
|
if (creds == NULL) {
|
||||||
ejsSetErrorMsg(eid, "userAuth requires a 'creds' first parameter");
|
ejsSetErrorMsg(eid, "invalid credentials parameter");
|
||||||
talloc_free(ctx);
|
talloc_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -82,15 +90,25 @@ static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
|
|||||||
talloc_free(ctx);
|
talloc_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* setup libnet_context credentials */
|
||||||
ctx->cred = creds;
|
ctx->cred = creds;
|
||||||
|
|
||||||
obj = mprObject("NetCtx");
|
/* create the NetContext object */
|
||||||
|
obj = mprObject("NetContext");
|
||||||
|
|
||||||
|
/* add internal libnet_context pointer to the NetContext object */
|
||||||
mprSetPtrChild(&obj, "ctx", ctx);
|
mprSetPtrChild(&obj, "ctx", ctx);
|
||||||
|
|
||||||
|
/* add properties publicly available from js code */
|
||||||
|
mprCreateProperty(&obj, "credentials", &mprCreds);
|
||||||
|
|
||||||
|
/* add methods to the object */
|
||||||
mprSetCFunction(&obj, "UserMgr", ejs_net_userman);
|
mprSetCFunction(&obj, "UserMgr", ejs_net_userman);
|
||||||
mprSetCFunction(&obj, "JoinDomain", ejs_net_join_domain);
|
mprSetCFunction(&obj, "JoinDomain", ejs_net_join_domain);
|
||||||
mprSetCFunction(&obj, "SamSyncLdb", ejs_net_samsync_ldb);
|
mprSetCFunction(&obj, "SamSyncLdb", ejs_net_samsync_ldb);
|
||||||
|
|
||||||
|
/* return the object */
|
||||||
mpr_Return(eid, obj);
|
mpr_Return(eid, obj);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -59,7 +59,7 @@ int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv)
|
|||||||
|
|
||||||
} else if (argc == 1 && mprVarIsString(argv[0]->type)) {
|
} else if (argc == 1 && mprVarIsString(argv[0]->type)) {
|
||||||
/* domain name can also be specified explicitly
|
/* domain name can also be specified explicitly
|
||||||
(e.g. to connect remote domain) */
|
(e.g. to connect BUILTIN domain) */
|
||||||
userman_domain = mprToString(argv[0]);
|
userman_domain = mprToString(argv[0]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user