From f52a74021512aace67f7ecba33ed130102f47533 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 00:13:10 +0000 Subject: r7061: A ejs scripting client. This should allow javascript to be run in a command line environment instead of inside the web server. It doesn't work yet though, rather an exception is thrown when trying to call ejsDefineStringCFunction(). (This used to be commit 3444cd5429dfef5a67d5bf7818ae08e4e8cc5ccc) --- source4/scripting/ejs/smbscript.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 source4/scripting/ejs/smbscript.c (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c new file mode 100644 index 0000000000..f1c3f0b46d --- /dev/null +++ b/source4/scripting/ejs/smbscript.c @@ -0,0 +1,62 @@ +/* + Unix SMB/CIFS implementation. + + Standalone client for ESP scripting. + + Copyright (C) Tim Potter 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 "web_server/ejs/ejs.h" + +void http_exception(const char *reason) +{ + fprintf(stderr, "smbscript exception: %s", reason); + exit(1); +} + +extern void ejsDefineStringCFunction(EjsId eid, const char *functionName, + MprStringCFunction fn, void *thisPtr, int flags); + +static int writeProc(MprVarHandle userHandle, int argc, char **argv) +{ + int i; + + mprAssert(argv); + for (i = 0; i < argc; i++) { + printf("%s", argv[i]); + } + return 0; +} + + int main(int argc, const char *argv[]) +{ + EjsId eid; + EjsHandle primary, alternate; + MprVar result; + char *emsg; + + ejsOpen(0, 0, 0); + eid = ejsOpenEngine(primary, alternate); + ejsDefineStringCFunction(eid, "write", writeProc, NULL, 0); + ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg); + ejsClose(); + + printf("emsg = %s\n", emsg); + + return 0; +} -- cgit From e95c8f19116813dd03cce957c3367254782915fd Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 03:25:21 +0000 Subject: r7063: Do error checking on the ejs functions. Tridge says there is a bug in defining per-engine CFunction's so move calls to ejsDefineStringCFunction() above the ejsOpenEngine() call. Test script now works! (This used to be commit 5e2458ae6c863ff29b85fff3d093f7f4fa9dc2be) --- source4/scripting/ejs/smbscript.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index f1c3f0b46d..85064d3b44 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -29,9 +29,6 @@ void http_exception(const char *reason) exit(1); } -extern void ejsDefineStringCFunction(EjsId eid, const char *functionName, - MprStringCFunction fn, void *thisPtr, int flags); - static int writeProc(MprVarHandle userHandle, int argc, char **argv) { int i; @@ -50,13 +47,26 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) MprVar result; char *emsg; - ejsOpen(0, 0, 0); - eid = ejsOpenEngine(primary, alternate); - ejsDefineStringCFunction(eid, "write", writeProc, NULL, 0); - ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg); - ejsClose(); + if (ejsOpen(0, 0, 0) != 0) { + fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " + "EJ subsystem\n"); + exit(1); + } - printf("emsg = %s\n", emsg); + ejsDefineStringCFunction(-1, "write", writeProc, NULL, 0); + + if ((eid = ejsOpenEngine(primary, alternate)) == (EjsId)-1) { + fprintf(stderr, "smbscript: ejsOpenEngine(): unable to " + "initialise an EJS engine\n"); + exit(1); + } + + if (ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg) == -1) { + fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); + exit(1); + } + + ejsClose(); return 0; } -- cgit From de850cb754f8ea49acc80e4303a9835578768154 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 03:29:10 +0000 Subject: r7064: Clean up handle parameter passing after peeking at tridge's ejstest.c (This used to be commit 805b6c7cf0f1e05fbb690bdfc93938747e13e6cd) --- source4/scripting/ejs/smbscript.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 85064d3b44..1c823a4d8e 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -43,11 +43,11 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) int main(int argc, const char *argv[]) { EjsId eid; - EjsHandle primary, alternate; + EjsHandle handle; MprVar result; char *emsg; - if (ejsOpen(0, 0, 0) != 0) { + if (ejsOpen(NULL, NULL, NULL) != 0) { fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " "EJ subsystem\n"); exit(1); @@ -55,13 +55,13 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) ejsDefineStringCFunction(-1, "write", writeProc, NULL, 0); - if ((eid = ejsOpenEngine(primary, alternate)) == (EjsId)-1) { + if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) { fprintf(stderr, "smbscript: ejsOpenEngine(): unable to " "initialise an EJS engine\n"); exit(1); } - if (ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg) == -1) { + if (ejsEvalScript(eid, "write(\"hello\n\");", &result, &emsg) == -1) { fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); exit(1); } -- cgit From 14ade23914b328fcb5924488c2416dfa7748e4ab Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 03:53:36 +0000 Subject: r7065: Move ejs from web_server to lib so it can be shared with smbscript. (This used to be commit b83dc8fbfb9ffe30654bc4869398f50dd9ccccb7) --- source4/scripting/ejs/smbscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 1c823a4d8e..f1ff03ae49 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -21,7 +21,7 @@ */ #include "includes.h" -#include "web_server/ejs/ejs.h" +#include "lib/ejs/ejs.h" void http_exception(const char *reason) { -- cgit From 7756b990f38495bf98e335b56bdc510659c34bdb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 04:10:22 +0000 Subject: r7066: Rename http_exception to ejs_exception. (This used to be commit f2e59d3adfd7813c3c2090350f8ff2a99a5533e9) --- source4/scripting/ejs/smbscript.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index f1ff03ae49..0b0a446839 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -23,7 +23,7 @@ #include "includes.h" #include "lib/ejs/ejs.h" -void http_exception(const char *reason) +void ejs_exception(const char *reason) { fprintf(stderr, "smbscript exception: %s", reason); exit(1); @@ -61,7 +61,7 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) exit(1); } - if (ejsEvalScript(eid, "write(\"hello\n\");", &result, &emsg) == -1) { + if (ejsEvalFile(eid, (char *)argv[1], &result, &emsg) == -1) { fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); exit(1); } -- cgit From 21f3a3921c03777beb7e3072152ae33956b38807 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 29 May 2005 08:12:16 +0000 Subject: r7069: Add a little usage message to smbscript and fix a compiler warning. My compiler still complains about "handle" (scripting/ejs/smbscrip.c:46) possibly not being initialized and to me this looks true. Running smbscript with the trivial write("Hello, world\n"); also leaves some memory around. Volker (This used to be commit 06d27a19213dc8fe6dfc948a5e8cbafa74db7a29) --- source4/scripting/ejs/smbscript.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 0b0a446839..57f42688d6 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -47,6 +47,11 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) MprVar result; char *emsg; + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + if (ejsOpen(NULL, NULL, NULL) != 0) { fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " "EJ subsystem\n"); @@ -61,7 +66,8 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) exit(1); } - if (ejsEvalFile(eid, (char *)argv[1], &result, &emsg) == -1) { + if (ejsEvalFile(eid, discard_const_p(char, argv[1]), &result, + &emsg) == -1) { fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); exit(1); } -- cgit From 8754c793bfe79e87febb026e5915e054c23cfede Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 May 2005 11:35:56 +0000 Subject: r7072: moved the esp hooks calls to the ejs level, so we can call them from both esp scripts and ejs scripts. This allows the smbscript program to call all the existing extension calls like lpGet() and ldbSearch() Also fixed smbscript to load smb.conf, and setup logging for DEBUG() I left the unixAuth() routine in web_server/calls.c at the moment, as that is really only useful for esp scripts. I imagine that as we extend esp/ejs, we will put some functions in scripting/ejs/ for use in both ejs and esp, and some functions in web_server/ where they will only be accessed by esp web scripts (This used to be commit e59ae64f60d388a5634559e4e0887e4676b70871) --- source4/scripting/ejs/smbscript.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 57f42688d6..593d3b0cf5 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "dynconfig.h" #include "lib/ejs/ejs.h" void ejs_exception(const char *reason) @@ -29,36 +30,36 @@ void ejs_exception(const char *reason) exit(1); } -static int writeProc(MprVarHandle userHandle, int argc, char **argv) -{ - int i; - - mprAssert(argv); - for (i = 0; i < argc; i++) { - printf("%s", argv[i]); - } - return 0; -} - int main(int argc, const char *argv[]) { EjsId eid; EjsHandle handle; MprVar result; char *emsg; + TALLOC_CTX *mem_ctx = talloc_new(NULL); if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } + setup_logging(argv[0],DEBUG_STDOUT); + + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", + argv[0], dyn_CONFIGFILE); + exit(1); + } + + mprSetCtx(mem_ctx); + if (ejsOpen(NULL, NULL, NULL) != 0) { fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " "EJ subsystem\n"); exit(1); } - ejsDefineStringCFunction(-1, "write", writeProc, NULL, 0); + smb_setup_ejs_functions(); if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) { fprintf(stderr, "smbscript: ejsOpenEngine(): unable to " @@ -74,5 +75,7 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) ejsClose(); + talloc_free(mem_ctx); + return 0; } -- cgit From 8f84f7cdecf12396eb5c1723e5e1ccf813cd9a51 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 May 2005 11:43:52 +0000 Subject: r7074: we should load all shares in smbscript (This used to be commit 92f85507df2bce5e246484860a43748321f2291e) --- source4/scripting/ejs/smbscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 593d3b0cf5..c6b1b7a192 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -45,7 +45,7 @@ void ejs_exception(const char *reason) setup_logging(argv[0],DEBUG_STDOUT); - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + if (!lp_load(dyn_CONFIGFILE, False, False, False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", argv[0], dyn_CONFIGFILE); exit(1); -- cgit From f477a741293673adad784c55a749031a290bd072 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 May 2005 11:58:14 +0000 Subject: r7075: added support for ARGV[] in ejs scripts (This used to be commit 3db568eb6bb383c4c1e1fd0c7f043a9914dcc3cc) --- source4/scripting/ejs/smbscript.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index c6b1b7a192..3378885147 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -37,8 +37,11 @@ void ejs_exception(const char *reason) MprVar result; char *emsg; TALLOC_CTX *mem_ctx = talloc_new(NULL); + const char **argv_list = NULL; + struct MprVar v; + int i; - if (argc != 2) { + if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } @@ -67,6 +70,14 @@ void ejs_exception(const char *reason) exit(1); } + /* setup ARGV[] in the ejs environment */ + for (i=2;i Date: Sun, 29 May 2005 12:41:59 +0000 Subject: r7078: - fix an uninitialised variable in smbscript - fixed handle passing in the smb/ejs interface calls, so they can be called safely from esp (This used to be commit 45ea1b64413de577366939b2106f657f6c47b1bd) --- source4/scripting/ejs/smbscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 3378885147..021dafa4ae 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -33,7 +33,7 @@ void ejs_exception(const char *reason) int main(int argc, const char *argv[]) { EjsId eid; - EjsHandle handle; + EjsHandle handle = 0; MprVar result; char *emsg; TALLOC_CTX *mem_ctx = talloc_new(NULL); -- cgit From 0b2f972c8a5205f648ed747b04c5232c694afd30 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 21:45:38 +0000 Subject: r7080: Fix typo in error message. (This used to be commit fcf177c86e2bfbc993352b80824487e5df0a3f63) --- source4/scripting/ejs/smbscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 021dafa4ae..a15fce57b0 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -80,7 +80,7 @@ void ejs_exception(const char *reason) /* run the script */ if (ejsEvalFile(eid, discard_const_p(char, argv[1]), &result, &emsg) == -1) { - fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); + fprintf(stderr, "smbscript: ejsEvalFile(): %s\n", emsg); exit(1); } -- cgit From 520e2258c9949f9129a2e124035c0200c0c59b39 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 29 May 2005 22:11:32 +0000 Subject: r7082: Call load_interfaces() in smbscript initialisation. (This used to be commit 54051bf8bbb18653adafb37cc6181617ca60b781) --- source4/scripting/ejs/smbscript.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index a15fce57b0..754a49ccb1 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -54,6 +54,8 @@ void ejs_exception(const char *reason) exit(1); } + load_interfaces(); + mprSetCtx(mem_ctx); if (ejsOpen(NULL, NULL, NULL) != 0) { -- cgit From afeaf137c4cbcbde1d6e4c9921bb769a1d486aff Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 3 Jun 2005 08:00:42 +0000 Subject: r7215: Convert smbscript to use ejsEvalScript() and file_load() instead of ejsEvalFile(). Still need to add advancement of the script past the hash-bang line but it's home time now!! (This used to be commit 14a2053c045a2df1d68838900c833c2a15cb5a36) --- source4/scripting/ejs/smbscript.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 754a49ccb1..323e604f8d 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -35,7 +35,8 @@ void ejs_exception(const char *reason) EjsId eid; EjsHandle handle = 0; MprVar result; - char *emsg; + char *emsg, *script; + size_t script_size; TALLOC_CTX *mem_ctx = talloc_new(NULL); const char **argv_list = NULL; struct MprVar v; @@ -79,10 +80,12 @@ void ejs_exception(const char *reason) v = mprList("ARGV", argv_list); mprCreateProperty(ejsGetGlobalObject(eid), "ARGV", &v); + /* load the script and advance past interpreter line*/ + script = file_load(argv[1], &script_size); + /* run the script */ - if (ejsEvalFile(eid, discard_const_p(char, argv[1]), &result, - &emsg) == -1) { - fprintf(stderr, "smbscript: ejsEvalFile(): %s\n", emsg); + if (ejsEvalScript(eid, script, &result, &emsg) == -1) { + fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); exit(1); } -- cgit From c1b95bd467109793333c15ea44ec910ffe3e86b4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 3 Jun 2005 12:04:26 +0000 Subject: r7223: Advance script past interpreter line. (This used to be commit 31b9fadbed656f666f587a9dcb5a7627a2d388aa) --- source4/scripting/ejs/smbscript.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 323e604f8d..43a9377143 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -83,6 +83,17 @@ void ejs_exception(const char *reason) /* load the script and advance past interpreter line*/ script = file_load(argv[1], &script_size); + if ((script_size > 2) && script[0] == '#' && script[1] == '!') { + script += 2; + script_size -= 2; + while (script_size) { + if (*script == '\r' || *script == '\n') + break; + script++; + script_size--; + } + } + /* run the script */ if (ejsEvalScript(eid, script, &result, &emsg) == -1) { fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); -- cgit From d6555cadb7015d407a2a17538d8a1ccd073a41e6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 4 Jun 2005 03:35:38 +0000 Subject: r7262: Add a length property to ARGV array. (This used to be commit 4b775c619b7abed52d158ab70505320753a0c9cb) --- source4/scripting/ejs/smbscript.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 43a9377143..4bde40a955 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -78,6 +78,7 @@ void ejs_exception(const char *reason) argv_list = str_list_add(argv_list, argv[i]); } v = mprList("ARGV", argv_list); + mprSetPropertyValue(&v, "length", mprCreateIntegerVar(argc - 2)); mprCreateProperty(ejsGetGlobalObject(eid), "ARGV", &v); /* load the script and advance past interpreter line*/ -- cgit From 32f2e9806b267782125fed3a6162ea895e634eef Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 4 Jun 2005 03:51:38 +0000 Subject: r7263: Exit smbscript with the intepreter return value (defaults to 0). Change the exit value for an exception, usage error and other non-js errors to 127 which is kinda like the return value for the system(3) function. (This used to be commit c77a232b1152a27e2d8ffb719aefba6c6b2ba6df) --- source4/scripting/ejs/smbscript.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 4bde40a955..02a3aff28e 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. - Standalone client for ESP scripting. + Standalone client for ejs scripting. Copyright (C) Tim Potter 2005 @@ -27,7 +27,7 @@ void ejs_exception(const char *reason) { fprintf(stderr, "smbscript exception: %s", reason); - exit(1); + exit(127); } int main(int argc, const char *argv[]) @@ -39,12 +39,12 @@ void ejs_exception(const char *reason) size_t script_size; TALLOC_CTX *mem_ctx = talloc_new(NULL); const char **argv_list = NULL; - struct MprVar v; - int i; + struct MprVar v, *return_var; + int exit_status, i; if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); + exit(127); } setup_logging(argv[0],DEBUG_STDOUT); @@ -52,7 +52,7 @@ void ejs_exception(const char *reason) if (!lp_load(dyn_CONFIGFILE, False, False, False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", argv[0], dyn_CONFIGFILE); - exit(1); + exit(127); } load_interfaces(); @@ -62,7 +62,7 @@ void ejs_exception(const char *reason) if (ejsOpen(NULL, NULL, NULL) != 0) { fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " "EJ subsystem\n"); - exit(1); + exit(127); } smb_setup_ejs_functions(); @@ -70,7 +70,7 @@ void ejs_exception(const char *reason) if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) { fprintf(stderr, "smbscript: ejsOpenEngine(): unable to " "initialise an EJS engine\n"); - exit(1); + exit(127); } /* setup ARGV[] in the ejs environment */ @@ -98,12 +98,15 @@ void ejs_exception(const char *reason) /* run the script */ if (ejsEvalScript(eid, script, &result, &emsg) == -1) { fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); - exit(1); + exit(127); } + return_var = ejsGetReturnValue(eid); + exit_status = return_var->integer; + ejsClose(); talloc_free(mem_ctx); - return 0; + return exit_status; } -- cgit From 9e555f75e2b4982804f8effb4f2b4da689d714e8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 12 Jun 2005 06:37:25 +0000 Subject: r7500: Initialise module subsystems. (This used to be commit 564dfe14d00e80a0d373ab0fc17803ffaac0892e) --- source4/scripting/ejs/smbscript.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 02a3aff28e..68d94f6d2a 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -57,6 +57,8 @@ void ejs_exception(const char *reason) load_interfaces(); + smbscript_init_subsystems; + mprSetCtx(mem_ctx); if (ejsOpen(NULL, NULL, NULL) != 0) { -- cgit From 00e2b7c1b49b128488cf977b40b086b935fb605a Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 13 Jun 2005 10:01:11 +0000 Subject: r7530: Simply calling convention of lp_load(). This always loads all the services, as we now don't have an easy way to split out smbd. Andrew Bartlett (This used to be commit 990e061939c76b559c4f5914c5fc6ca1b13e19dd) --- source4/scripting/ejs/smbscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 68d94f6d2a..2795e4f127 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -49,7 +49,7 @@ void ejs_exception(const char *reason) setup_logging(argv[0],DEBUG_STDOUT); - if (!lp_load(dyn_CONFIGFILE, False, False, False)) { + if (!lp_load(dyn_CONFIGFILE)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", argv[0], dyn_CONFIGFILE); exit(127); -- cgit From 643e5d8239ba105a5ac99ecc513289a17402714b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 2 Jul 2005 05:21:17 +0000 Subject: r8069: the beginnings of code to allow rpc calls to be made from ejs tpot, note that this shows how you can modify passed in MprVar variables in C call (This used to be commit a782541db3de6ca3b599a220265cf9e6cb0c4d7b) --- source4/scripting/ejs/smbscript.c | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'source4/scripting/ejs/smbscript.c') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 2795e4f127..aa0fc42c48 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -4,6 +4,7 @@ Standalone client for ejs scripting. Copyright (C) Tim Potter 2005 + 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 @@ -21,6 +22,7 @@ */ #include "includes.h" +#include "lib/cmdline/popt_common.h" #include "dynconfig.h" #include "lib/ejs/ejs.h" @@ -30,7 +32,7 @@ void ejs_exception(const char *reason) exit(127); } - int main(int argc, const char *argv[]) + int main(int argc, const char **argv) { EjsId eid; EjsHandle handle = 0; @@ -39,28 +41,39 @@ void ejs_exception(const char *reason) size_t script_size; TALLOC_CTX *mem_ctx = talloc_new(NULL); const char **argv_list = NULL; + const char *fname; struct MprVar v, *return_var; int exit_status, i; + poptContext pc; + int opt; + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + POPT_COMMON_VERSION + POPT_TABLEEND + }; - if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(127); - } + popt_common_dont_ask(); - setup_logging(argv[0],DEBUG_STDOUT); + pc = poptGetContext("smbscript", argc, argv, long_options, 0); - if (!lp_load(dyn_CONFIGFILE)) { - fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", - argv[0], dyn_CONFIGFILE); - exit(127); - } + poptSetOtherOptionHelp(pc, "