r9724: Rewrite samba3dump in JS. The summary works now, but the full output
[sfrench/samba-autobuild/.git] / source4 / scripting / ejs / smbcalls_creds.c
index 546ae84d17297b5321dfe314775bf6676bbc9aaf..cc2ccf8c47455c9aa67519b01e635e6e89e1d8de 100644 (file)
@@ -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
@@ -124,22 +125,68 @@ static int ejs_creds_set_password(MprVarHandle eid, int argc, char **argv)
 
 
 /*
-  initialise credentials ejs object
+  set realm
 */
-static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
+static int ejs_creds_set_realm(MprVarHandle eid, int argc, char **argv)
 {
-       struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv);
-       struct cli_credentials *creds;
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+       if (argc != 1) {
+               ejsSetErrorMsg(eid, "bad arguments to set_realm");
+               return -1;
+       }
 
-       creds = cli_credentials_init(mprMemCtx());
-       if (creds == NULL) {
+       cli_credentials_set_realm(creds, argv[0], CRED_SPECIFIED);
+       mpr_Return(eid, mprCreateBoolVar(True));
+       return 0;
+}
+
+
+/*
+  get realm
+*/
+static int ejs_creds_get_realm(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+       
+       mpr_Return(eid, mprString(cli_credentials_get_realm(creds)));
+       return 0;
+}
+
+
+/*
+  set workstation
+*/
+static int ejs_creds_set_workstation(MprVarHandle eid, int argc, char **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+       if (argc != 1) {
+               ejsSetErrorMsg(eid, "bad arguments to set_workstation");
                return -1;
        }
+       
+       cli_credentials_set_workstation(creds, argv[0], CRED_SPECIFIED);
+       mpr_Return(eid, mprCreateBoolVar(True));
+       return 0;
+}
+
+
+/*
+  get workstation
+*/
+static int ejs_creds_get_workstation(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+       
+       mpr_Return(eid, mprString(cli_credentials_get_workstation(creds)));
+       return 0;
+}
 
-       cli_credentials_guess(creds);
-       cli_credentials_set_username(creds, "", CRED_GUESSED);
-       cli_credentials_set_password(creds, "", CRED_GUESSED);
 
+/*
+  initialise credentials ejs object
+*/
+static int ejs_credentials_obj(struct MprVar *obj, struct cli_credentials *creds)
+{
        mprSetPtrChild(obj, "creds", creds);
 
        /* setup our object methods */
@@ -149,11 +196,51 @@ static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv
        mprSetStringCFunction(obj, "set_username", ejs_creds_set_username);
        mprSetCFunction(obj, "get_password", ejs_creds_get_password);
        mprSetStringCFunction(obj, "set_password", ejs_creds_set_password);
+       mprSetCFunction(obj, "get_realm", ejs_creds_get_realm);
+       mprSetStringCFunction(obj, "set_realm", ejs_creds_set_realm);
+       mprSetCFunction(obj, "get_workstation", ejs_creds_get_workstation);
+       mprSetStringCFunction(obj, "set_workstation", ejs_creds_set_workstation);
 
        return 0;
 }
 
 
+struct MprVar mprCredentials(struct cli_credentials *creds)
+{
+       struct MprVar mpv = mprObject("credentials");
+
+       ejs_credentials_obj(&mpv, creds);
+       
+       return mpv;
+}
+
+
+/*
+  initialise credentials ejs object
+*/
+static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct cli_credentials *creds;
+       struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv);
+
+       creds = cli_credentials_init(mprMemCtx());
+       if (creds == NULL) {
+               return -1;
+       }
+
+       return ejs_credentials_obj(obj, creds);
+}
+
+/*
+  initialise cmdline credentials ejs object
+*/
+int ejs_credentials_cmdline(int eid, int argc, struct MprVar **argv)
+{
+       struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv);
+       return ejs_credentials_obj(obj, cmdline_credentials);
+}
+
+
 /*
   setup C functions that be called from ejs
 */