]> git.samba.org - samba.git/commitdiff
r9059: add a basic credentials object for mimir
authorAndrew Tridgell <tridge@samba.org>
Thu, 4 Aug 2005 16:10:13 +0000 (16:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:31:13 +0000 (13:31 -0500)
source/scripting/ejs/config.mk
source/scripting/ejs/smbcalls.c
source/scripting/ejs/smbcalls_creds.c [new file with mode: 0644]

index 8eced504ed5f140634eff0b18b44b5e6c9ea9953..191b139c6640483af458f1118504def5a2a92adf 100644 (file)
@@ -24,6 +24,7 @@ OBJ_FILES = \
                scripting/ejs/smbcalls_string.o \
                scripting/ejs/smbcalls_rand.o \
                scripting/ejs/smbcalls_sys.o \
+               scripting/ejs/smbcalls_creds.o \
                scripting/ejs/mprutil.o
 REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC EJSRPC MESSAGING
 # End SUBSYSTEM SMBCALLS
index 59e5b170341ce73f5558952ad1d51eb28f655657..4b03e2f4047690d18b2fcaba3823c1cdbbf67c41 100644 (file)
@@ -127,6 +127,7 @@ void smb_setup_ejs_functions(void)
        smb_setup_ejs_string();
        smb_setup_ejs_random();
        smb_setup_ejs_system();
+       smb_setup_ejs_credentials();
 
        ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
        ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
diff --git a/source/scripting/ejs/smbcalls_creds.c b/source/scripting/ejs/smbcalls_creds.c
new file mode 100644 (file)
index 0000000..eb937ae
--- /dev/null
@@ -0,0 +1,107 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   provide hooks credentials calls
+
+   Copyright (C) Andrew Tridgell 2005
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "scripting/ejs/smbcalls.h"
+#include "lib/appweb/ejs/ejs.h"
+
+/*
+  helper function to get the local objects credentials ptr
+*/
+static struct cli_credentials *ejs_creds_get_credentials(int eid)
+{
+       struct cli_credentials *creds = mprGetThisPtr(eid, "creds");
+       if (creds == NULL) {
+               ejsSetErrorMsg(eid, "NULL ejs credentials");
+       }
+       return creds;
+}
+
+/*
+  get a domain
+*/
+static int ejs_creds_get_domain(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+
+       mpr_Return(eid, mprString(cli_credentials_get_domain(creds)));
+       return 0;
+}
+
+
+static int ejs_creds_get_username(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+
+       mpr_Return(eid, mprString(cli_credentials_get_username(creds)));
+       return 0;
+}
+
+static int ejs_creds_set_username(MprVarHandle eid, int argc, char **argv)
+{
+       struct cli_credentials *creds = ejs_creds_get_credentials(eid);
+       if (argc != 1) {
+               ejsSetErrorMsg(eid, "bad arguments to set_username");
+               return -1;
+       }
+
+       cli_credentials_set_username(creds, argv[0], CRED_SPECIFIED);
+       mpr_Return(eid, mprCreateBoolVar(True));
+       return 0;
+}
+
+
+/*
+  initialise credentials ejs object
+*/
+static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       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);
+
+       /* setup our object methods */
+       mprSetCFunction(obj, "get_domain", ejs_creds_get_domain);
+       mprSetCFunction(obj, "get_username", ejs_creds_get_username);
+       mprSetStringCFunction(obj, "set_username", ejs_creds_set_username);
+
+       return 0;
+}
+
+
+/*
+  setup C functions that be called from ejs
+*/
+void smb_setup_ejs_credentials(void)
+{
+       ejsDefineCFunction(-1, "credentials_init", ejs_credentials_init, NULL, MPR_VAR_SCRIPT_HANDLE);
+}