summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2005-08-22 14:32:58 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:20 -0500
commit55e746ad560d4406821bc2d721cbb929b79a7a0a (patch)
treed9baa6d6d7651e3f95313699510335c714a2e681
parent5bd6a114711c0033403a656b42574380a6ebcd3d (diff)
downloadsamba-55e746ad560d4406821bc2d721cbb929b79a7a0a.tar.gz
samba-55e746ad560d4406821bc2d721cbb929b79a7a0a.tar.bz2
samba-55e746ad560d4406821bc2d721cbb929b79a7a0a.zip
r9477: Convert popt options to an ejs object. Doesn't seem to break anything
except of popt help (-h) option (unexpected ?). rafal (This used to be commit 1990793b23d6198a85ce1bdf6ad43e12015db203)
-rwxr-xr-xsource4/scripting/bin/smbstatus4
-rw-r--r--source4/scripting/ejs/smbcalls_auth.c11
-rw-r--r--source4/scripting/ejs/smbcalls_creds.c37
-rw-r--r--source4/scripting/ejs/smbcalls_options.c20
-rwxr-xr-xsource4/setup/newuser6
-rwxr-xr-xsource4/setup/provision8
6 files changed, 53 insertions, 33 deletions
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus
index 38f2ab06a9..d5610023d6 100755
--- a/source4/scripting/bin/smbstatus
+++ b/source4/scripting/bin/smbstatus
@@ -11,12 +11,12 @@ libinclude("management.js");
var options = new Object();
-ok = GetOptions(ARGV, options,
+options = GetOptions(ARGV,
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
"nbt");
-if (ok == false) {
+if (options == undefined) {
println("Failed to parse options: " + options.ERROR);
return -1;
}
diff --git a/source4/scripting/ejs/smbcalls_auth.c b/source4/scripting/ejs/smbcalls_auth.c
index 4b3534b4cc..37ac9543cc 100644
--- a/source4/scripting/ejs/smbcalls_auth.c
+++ b/source4/scripting/ejs/smbcalls_auth.c
@@ -105,16 +105,19 @@ static int ejs_userAuth(MprVarHandle eid, int argc, struct MprVar **argv)
const char *password;
const char *domain;
const char *remote_host;
- struct MprVar auth;
+ struct MprVar auth, *creds_obj;
+ struct cli_credentials *creds;
if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {
ejsSetErrorMsg(eid, "userAuth invalid arguments, this function requires an object.");
return -1;
}
- username = mprToString(mprGetProperty(argv[0], "username", NULL));
- password = mprToString(mprGetProperty(argv[0], "password", NULL));
- domain = mprToString(mprGetProperty(argv[0], "domain", NULL));
+ /* get credential values from credentials object */
+ creds = mprGetPtr(argv[0], "creds");
+ username = cli_credentials_get_username(creds);
+ password = cli_credentials_get_password(creds);
+ domain = cli_credentials_get_domain(creds);
remote_host = mprToString(mprGetProperty(argv[0], "rhost", NULL));
if (username == NULL || password == NULL || domain == NULL) {
diff --git a/source4/scripting/ejs/smbcalls_creds.c b/source4/scripting/ejs/smbcalls_creds.c
index 61a5139cda..45da5895e4 100644
--- a/source4/scripting/ejs/smbcalls_creds.c
+++ b/source4/scripting/ejs/smbcalls_creds.c
@@ -23,6 +23,7 @@
#include "includes.h"
#include "scripting/ejs/smbcalls.h"
#include "lib/appweb/ejs/ejs.h"
+#include "lib/cmdline/popt_common.h"
/*
helper function to get the local objects credentials ptr
@@ -184,19 +185,9 @@ static int ejs_creds_get_workstation(MprVarHandle eid, int argc, struct MprVar *
/*
initialise credentials ejs object
*/
-static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
+static int ejs_credentials_obj(MprVarHandle eid, int argc, struct MprVar **argv, struct cli_credentials *creds)
{
struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv);
- struct cli_credentials *creds;
-
- creds = cli_credentials_init(mprMemCtx());
- if (creds == NULL) {
- return -1;
- }
-
- cli_credentials_guess(creds);
- cli_credentials_set_username(creds, "", CRED_GUESSED);
- cli_credentials_set_password(creds, "", CRED_GUESSED);
mprSetPtrChild(obj, "creds", creds);
@@ -217,6 +208,30 @@ static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv
/*
+ initialise credentials ejs object
+*/
+static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct cli_credentials *creds;
+
+ creds = cli_credentials_init(mprMemCtx());
+ if (creds == NULL) {
+ return -1;
+ }
+
+ return ejs_credentials_obj(eid, argc, argv, creds);
+}
+
+/*
+ initialise cmdline credentials ejs object
+*/
+int ejs_credentials_cmdline(int eid, int argc, struct MprVar **argv)
+{
+ return ejs_credentials_obj(eid, argc, argv, cmdline_credentials);
+}
+
+
+/*
setup C functions that be called from ejs
*/
void smb_setup_ejs_credentials(void)
diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c
index 9fbfd312a9..8eca9ebcaa 100644
--- a/source4/scripting/ejs/smbcalls_options.c
+++ b/source4/scripting/ejs/smbcalls_options.c
@@ -28,8 +28,7 @@
/*
usage:
- var options = new Object();
- result = GetOptions(argv, options,
+ options = GetOptions(argv,
"realm=s",
"enablexx",
"myint=i");
@@ -41,6 +40,7 @@
additional command line arguments are placed in options.ARGV
*/
+
static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv)
{
poptContext pc;
@@ -52,13 +52,15 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv)
} tables[] = {
{ "POPT_AUTOHELP", poptHelpOptions, "Help options:" },
{ "POPT_COMMON_SAMBA", popt_common_samba, "Common Samba options:" },
- { "POPT_COMMON_CONNECTION", popt_common_connection, "Connection options:" },
+ { "POPT_COMMON_CONNECTION", popt_common_connection, "Connection options:" },
{ "POPT_COMMON_CREDENTIALS", popt_common_credentials, "Authentication options:" },
{ "POPT_COMMON_VERSION", popt_common_version, "Common Samba options:" }
};
+
+ struct MprVar *options = mprInitObject(eid, "options", 0, NULL);
+
TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
struct poptOption *long_options = NULL;
- struct MprVar *options;
int i, num_options = 0;
int opt_argc;
const char **opt_argv;
@@ -66,15 +68,12 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv)
const int BASE_OPTNUM = 0x100000;
/* validate arguments */
- if (argc < 2 ||
- argv[0]->type != MPR_TYPE_OBJECT ||
- argv[1]->type != MPR_TYPE_OBJECT) {
+ if (argc < 1 || argv[0]->type != MPR_TYPE_OBJECT) {
ejsSetErrorMsg(eid, "GetOptions invalid arguments");
return -1;
}
opt_argv = mprToArray(tmp_ctx, argv[0]);
- options = argv[1];
opt_argc = str_list_length(opt_argv);
long_options = talloc_array(tmp_ctx, struct poptOption, 1);
@@ -178,7 +177,10 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv)
poptFreeContext(pc);
talloc_free(tmp_ctx);
- mpr_Return(eid, mprCreateBoolVar(1));
+
+ /* setup methods */
+ mprSetCFunction(options, "get_credentials", ejs_credentials_cmdline);
+
return 0;
}
diff --git a/source4/setup/newuser b/source4/setup/newuser
index f5015611b9..cf2c7b8382 100755
--- a/source4/setup/newuser
+++ b/source4/setup/newuser
@@ -6,8 +6,7 @@ exec smbscript "$0" ${1+"$@"}
Released under the GNU GPL v2 or later
*/
-options = new Object();
-ok = GetOptions(ARGV, options,
+options = GetOptions(ARGV,
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
@@ -15,7 +14,8 @@ ok = GetOptions(ARGV, options,
'unixname=s',
'password=s',
'quiet');
-if (ok == false) {
+
+if (options == undefined) {
println("Failed to parse options: " + options.ERROR);
return -1;
}
diff --git a/source4/setup/provision b/source4/setup/provision
index a9bbfa6a26..35c9d64f80 100755
--- a/source4/setup/provision
+++ b/source4/setup/provision
@@ -6,8 +6,7 @@ exec smbscript "$0" ${1+"$@"}
Released under the GNU GPL v2 or later
*/
-options = new Object();
-ok = GetOptions(ARGV, options,
+options = GetOptions(ARGV,
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
@@ -29,8 +28,9 @@ ok = GetOptions(ARGV, options,
'users=s',
'quiet',
'blank');
-if (ok == false) {
- println("Failed to parse options: " + options.ERROR);
+
+if (options == undefined) {
+ println("Failed to parse options: ", options.ERROR);
return -1;
}