summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs/smbcalls_creds.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-08-04 16:10:13 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:31:13 -0500
commit2a533ec684c8297f893fdd23e919937d92c58c15 (patch)
tree3da0db04eb5d2b622604270e4d0d5a2a446c03b0 /source4/scripting/ejs/smbcalls_creds.c
parenta0b29302c81bb68a9d083fb10f9d044891ed81a8 (diff)
downloadsamba-2a533ec684c8297f893fdd23e919937d92c58c15.tar.gz
samba-2a533ec684c8297f893fdd23e919937d92c58c15.tar.bz2
samba-2a533ec684c8297f893fdd23e919937d92c58c15.zip
r9059: add a basic credentials object for mimir
(This used to be commit 36a9277e878d4db599fcfc02b96d2aaeac0b74dd)
Diffstat (limited to 'source4/scripting/ejs/smbcalls_creds.c')
-rw-r--r--source4/scripting/ejs/smbcalls_creds.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls_creds.c b/source4/scripting/ejs/smbcalls_creds.c
new file mode 100644
index 0000000000..eb937aebb6
--- /dev/null
+++ b/source4/scripting/ejs/smbcalls_creds.c
@@ -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);
+}