2 Unix SMB/CIFS implementation.
4 provide hooks credentials calls
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "scripting/ejs/smbcalls.h"
25 #include "lib/appweb/ejs/ejs.h"
28 helper function to get the local objects credentials ptr
30 static struct cli_credentials *ejs_creds_get_credentials(int eid)
32 struct cli_credentials *creds = mprGetThisPtr(eid, "creds");
34 ejsSetErrorMsg(eid, "NULL ejs credentials");
42 static int ejs_creds_get_domain(MprVarHandle eid, int argc, struct MprVar **argv)
44 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
46 mpr_Return(eid, mprString(cli_credentials_get_domain(creds)));
54 static int ejs_creds_set_domain(MprVarHandle eid, int argc, char **argv)
56 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
58 ejsSetErrorMsg(eid, "bad arguments to set_domain");
62 cli_credentials_set_domain(creds, argv[0], CRED_SPECIFIED);
63 mpr_Return(eid, mprCreateBoolVar(True));
71 static int ejs_creds_get_username(MprVarHandle eid, int argc, struct MprVar **argv)
73 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
75 mpr_Return(eid, mprString(cli_credentials_get_username(creds)));
83 static int ejs_creds_set_username(MprVarHandle eid, int argc, char **argv)
85 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
87 ejsSetErrorMsg(eid, "bad arguments to set_username");
91 cli_credentials_set_username(creds, argv[0], CRED_SPECIFIED);
92 mpr_Return(eid, mprCreateBoolVar(True));
100 static int ejs_creds_get_password(MprVarHandle eid, int argc, struct MprVar **argv)
102 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
104 mpr_Return(eid, mprString(cli_credentials_get_password(creds)));
112 static int ejs_creds_set_password(MprVarHandle eid, int argc, char **argv)
114 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
116 ejsSetErrorMsg(eid, "bad arguments to set_password");
120 cli_credentials_set_password(creds, argv[0], CRED_SPECIFIED);
121 mpr_Return(eid, mprCreateBoolVar(True));
129 static int ejs_creds_set_realm(MprVarHandle eid, int argc, char **argv)
131 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
133 ejsSetErrorMsg(eid, "bad arguments to set_realm");
137 cli_credentials_set_realm(creds, argv[0], CRED_SPECIFIED);
138 mpr_Return(eid, mprCreateBoolVar(True));
146 static int ejs_creds_get_realm(MprVarHandle eid, int argc, struct MprVar **argv)
148 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
150 mpr_Return(eid, mprString(cli_credentials_get_realm(creds)));
158 static int ejs_creds_set_workstation(MprVarHandle eid, int argc, char **argv)
160 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
162 ejsSetErrorMsg(eid, "bad arguments to set_workstation");
166 cli_credentials_set_workstation(creds, argv[0], CRED_SPECIFIED);
167 mpr_Return(eid, mprCreateBoolVar(True));
175 static int ejs_creds_get_workstation(MprVarHandle eid, int argc, struct MprVar **argv)
177 struct cli_credentials *creds = ejs_creds_get_credentials(eid);
179 mpr_Return(eid, mprString(cli_credentials_get_workstation(creds)));
185 initialise credentials ejs object
187 static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv)
189 struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv);
190 struct cli_credentials *creds;
192 creds = cli_credentials_init(mprMemCtx());
197 cli_credentials_guess(creds);
198 cli_credentials_set_username(creds, "", CRED_GUESSED);
199 cli_credentials_set_password(creds, "", CRED_GUESSED);
201 mprSetPtrChild(obj, "creds", creds);
203 /* setup our object methods */
204 mprSetCFunction(obj, "get_domain", ejs_creds_get_domain);
205 mprSetStringCFunction(obj, "set_domain", ejs_creds_set_domain);
206 mprSetCFunction(obj, "get_username", ejs_creds_get_username);
207 mprSetStringCFunction(obj, "set_username", ejs_creds_set_username);
208 mprSetCFunction(obj, "get_password", ejs_creds_get_password);
209 mprSetStringCFunction(obj, "set_password", ejs_creds_set_password);
210 mprSetCFunction(obj, "get_realm", ejs_creds_get_realm);
211 mprSetStringCFunction(obj, "set_realm", ejs_creds_set_realm);
212 mprSetCFunction(obj, "get_workstation", ejs_creds_get_workstation);
213 mprSetStringCFunction(obj, "set_workstation", ejs_creds_set_workstation);
220 setup C functions that be called from ejs
222 void smb_setup_ejs_credentials(void)
224 ejsDefineCFunction(-1, "credentials_init", ejs_credentials_init, NULL, MPR_VAR_SCRIPT_HANDLE);