r8452: allow for the ugly hack:
authorAndrew Tridgell <tridge@samba.org>
Thu, 14 Jul 2005 07:21:59 +0000 (07:21 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:23:05 +0000 (13:23 -0500)
#!/bin/sh
exec smbscript "$0" ${1+"$@"}

which is needed because bloody solaris puts 'env' in /bin instead of /usr/bin

also neaten up the #! handling code.
(This used to be commit 778bcd3738e42d8adfd4529f790c898f0d904363)

source4/scripting/ejs/smbscript.c

index dec9592c4632ec3c3685ec6ccb0dd01d712b9ace..d71d0847792fa79ed898251b73b4ed3057812053 100644 (file)
@@ -83,15 +83,15 @@ void ejs_exception(const char *reason)
        /* load the script and advance past interpreter line*/
        script = file_load(fname, &script_size, mem_ctx);
 
-       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--;
-               }
+       /* allow scriptable js */
+       if (strncmp(script, "#!", 2) == 0) {
+               script += strcspn(script, "\r\n");
+               script += strspn(script, "\r\n");
+       }
+       /* and this copes with the ugly exec hack */
+       if (strncmp(script, "exec ", 5) == 0) {
+               script += strcspn(script, "\r\n");
+               script += strspn(script, "\r\n");
        }
 
        /* run the script */