diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-08-04 16:10:13 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:31:13 -0500 |
commit | 2a533ec684c8297f893fdd23e919937d92c58c15 (patch) | |
tree | 3da0db04eb5d2b622604270e4d0d5a2a446c03b0 /source4 | |
parent | a0b29302c81bb68a9d083fb10f9d044891ed81a8 (diff) | |
download | samba-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')
-rw-r--r-- | source4/scripting/ejs/config.mk | 1 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls.c | 1 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_creds.c | 107 |
3 files changed, 109 insertions, 0 deletions
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 8eced504ed..191b139c66 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -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 diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 59e5b17034..4b03e2f404 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -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/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); +} |