1 char rcsid[] = "$Header: perl.c,v 4.0 91/03/20 01:37:44 lwall Locked $\nPatch level: ###\n";
3 * Copyright (c) 1989, Larry Wall
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 4.0 91/03/20 01:37:44 lwall
20 #include "patchlevel.h"
29 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
35 static char* moreswitches();
38 extern char **environ;
39 #endif /* ! __STDC__ */
41 static char patchlevel[6];
42 static char *nrs = "\n";
43 static int nrschar = '\n'; /* final char of rs, or 0777 if none */
44 static int nrslen = 1;
53 char *index(), *strcpy(), *getenv();
54 bool dosearch = FALSE;
59 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
62 fatal("suidperl is no longer needed since the kernel can now execute\n\
63 setuid perl scripts securely.\n");
69 origenviron = environ;
71 euid = (int)geteuid();
73 egid = (int)getegid();
74 sprintf(patchlevel,"%3.3s%2.2d", index(rcsid,'4'), PATCHLEVEL);
77 * There is no way we can refer to them from Perl so close them to save
78 * space. The other alternative would be to provide STDAUX and STDPRN
85 origfilename = savestr(argv[0]);
87 loop_ptr = -1; /* start label stack again */
90 (void)sprintf(index(rcsid,'#'), "%d\n", PATCHLEVEL);
91 linestr = Str_new(65,80);
92 str_nset(linestr,"",0);
93 str = str_make("",0); /* first used for -I flags */
94 curstash = defstash = hnew(0);
95 curstname = str_make("main",4);
96 stab_xhash(stabent("_main",TRUE)) = defstash;
97 defstash->tbl_name = "main";
98 incstab = hadd(aadd(stabent("INC",TRUE)));
99 incstab->str_pok |= SP_MULTI;
100 for (argc--,argv++; argc > 0; argc--,argv++) {
101 if (argv[0][0] != '-' || !argv[0][1])
105 validarg = " PHOOEY ";
125 if (s = moreswitches(s))
131 if (euid != uid || egid != gid)
132 fatal("No -e allowed in setuid scripts");
135 e_tmpname = savestr(TMPPATH);
136 (void)mktemp(e_tmpname);
137 e_fp = fopen(e_tmpname,"w");
139 fatal("Cannot open temporary file");
145 (void)putc('\n', e_fp);
149 if (euid != uid || egid != gid)
150 fatal("No -I allowed in setuid scripts");
156 (void)apush(stab_array(incstab),str_make(s,0));
159 (void)apush(stab_array(incstab),str_make(argv[1],0));
160 str_cat(str,argv[1]);
167 if (euid != uid || egid != gid)
168 fatal("No -P allowed in setuid scripts");
175 if (euid != uid || egid != gid)
176 fatal("No -s allowed in setuid scripts");
197 fatal("Unrecognized switch: -%s",s);
208 #define PERLLIB_SEP ';'
210 #define PERLLIB_SEP ':'
212 #ifndef TAINT /* Can't allow arbitrary PERLLIB in setuid script */
214 char * s2 = getenv("PERLLIB");
217 /* Break at all separators */
219 /* First, skip any consecutive separators */
220 while ( *s2 == PERLLIB_SEP ) {
221 /* Uncomment the next line for PATH semantics */
222 /* (void)apush(stab_array(incstab),str_make(".",1)); */
225 if ( (s = index(s2,PERLLIB_SEP)) != Nullch ) {
226 (void)apush(stab_array(incstab),str_make(s2,(int)(s-s2)));
229 (void)apush(stab_array(incstab),str_make(s2,0));
238 #define PRIVLIB "/usr/local/lib/perl"
240 (void)apush(stab_array(incstab),str_make(PRIVLIB,0));
241 (void)apush(stab_array(incstab),str_make(".",1));
244 str_set(&str_yes,Yes);
248 if (argv[0] == Nullch)
251 if ( isatty(fileno(stdin)) )
258 if (dosearch && !index(argv[0], '/') && (s = getenv("PATH"))) {
259 char *xfound = Nullch, *xfailed = Nullch;
262 bufend = s + strlen(s);
265 s = cpytill(tokenbuf,s,bufend,':',&len);
267 for (len = 0; *s && *s != ';'; tokenbuf[len++] = *s++);
268 tokenbuf[len] = '\0';
273 if (len && tokenbuf[len-1] != '/')
275 if (len && tokenbuf[len-1] != '\\')
277 (void)strcat(tokenbuf+len,"/");
278 (void)strcat(tokenbuf+len,argv[0]);
281 fprintf(stderr,"Looking for %s\n",tokenbuf);
283 if (stat(tokenbuf,&statbuf) < 0) /* not there? */
285 if (S_ISREG(statbuf.st_mode)
286 && cando(S_IRUSR,TRUE,&statbuf) && cando(S_IXUSR,TRUE,&statbuf)) {
287 xfound = tokenbuf; /* bingo! */
291 xfailed = savestr(tokenbuf);
294 fatal("Can't execute %s", xfailed ? xfailed : argv[0] );
297 argv[0] = savestr(xfound);
300 fdpid = anew(Nullstab); /* for remembering popen pids by fd */
301 pidstatus = hnew(COEFFSIZE);/* for remembering status of dead pids */
303 origfilename = savestr(argv[0]);
304 curcmd->c_filestab = fstab(origfilename);
305 if (strEQ(origfilename,"-"))
309 str_cat(str,PRIVLIB);
310 (void)sprintf(buf, "\
311 %ssed %s -e '/^[^#]/b' \
312 -e '/^#[ ]*include[ ]/b' \
313 -e '/^#[ ]*define[ ]/b' \
314 -e '/^#[ ]*if[ ]/b' \
315 -e '/^#[ ]*ifdef[ ]/b' \
316 -e '/^#[ ]*ifndef[ ]/b' \
318 -e '/^#[ ]*endif/b' \
326 (doextract ? "-e '1,/^#/d\n'" : ""),
327 argv[0], CPPSTDIN, str_get(str), CPPMINUS);
335 #ifdef IAMSUID /* actually, this is caught earlier */
336 if (euid != uid && !euid) /* if running suidperl */
338 (void)seteuid(uid); /* musn't stay setuid root */
341 (void)setreuid(-1, uid);
347 rsfp = mypopen(buf,"r");
352 rsfp = fopen(argv[0],"r");
353 if (rsfp == Nullfp) {
355 #ifndef IAMSUID /* in case script is not readable before setuid */
356 if (euid && stat(stab_val(curcmd->c_filestab)->str_ptr,&statbuf) >= 0 &&
357 statbuf.st_mode & (S_ISUID|S_ISGID)) {
358 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
359 execv(buf, origargv); /* try again */
360 fatal("Can't do setuid\n");
364 fatal("Can't open perl script \"%s\": %s\n",
365 stab_val(curcmd->c_filestab)->str_ptr, strerror(errno));
367 str_free(str); /* free -I directories */
370 /* do we need to emulate setuid on scripts? */
372 /* This code is for those BSD systems that have setuid #! scripts disabled
373 * in the kernel because of a security problem. Merely defining DOSUID
374 * in perl will not fix that problem, but if you have disabled setuid
375 * scripts in the kernel, this will attempt to emulate setuid and setgid
376 * on scripts that have those now-otherwise-useless bits set. The setuid
377 * root version must be called suidperl or sperlN.NNN. If regular perl
378 * discovers that it has opened a setuid script, it calls suidperl with
379 * the same argv that it had. If suidperl finds that the script it has
380 * just opened is NOT setuid root, it sets the effective uid back to the
381 * uid. We don't just make perl setuid root because that loses the
382 * effective uid we had before invoking perl, if it was different from the
385 * DOSUID must be defined in both perl and suidperl, and IAMSUID must
386 * be defined in suidperl only. suidperl must be setuid root. The
387 * Configure script will set this up for you if you want it.
389 * There is also the possibility of have a script which is running
390 * set-id due to a C wrapper. We want to do the TAINT checks
391 * on these set-id scripts, but don't want to have the overhead of
392 * them in normal perl, and can't use suidperl because it will lose
393 * the effective uid info, so we have an additional non-setuid root
394 * version called taintperl or tperlN.NNN that just does the TAINT checks.
398 if (fstat(fileno(rsfp),&statbuf) < 0) /* normal stat is insecure */
399 fatal("Can't stat script \"%s\"",origfilename);
400 if (statbuf.st_mode & (S_ISUID|S_ISGID)) {
405 /* On this access check to make sure the directories are readable,
406 * there is actually a small window that the user could use to make
407 * filename point to an accessible directory. So there is a faint
408 * chance that someone could execute a setuid script down in a
409 * non-accessible directory. I don't know what to do about that.
410 * But I don't think it's too important. The manual lies when
411 * it says access() is useful in setuid programs.
413 if (access(stab_val(curcmd->c_filestab)->str_ptr,1)) /*double check*/
414 fatal("Permission denied");
416 /* If we can swap euid and uid, then we can determine access rights
417 * with a simple stat of the file, and then compare device and
418 * inode to make sure we did stat() on the same file we opened.
419 * Then we just have to make sure he or she can execute it.
422 struct stat tmpstatbuf;
424 if (setreuid(euid,uid) < 0 || getuid() != euid || geteuid() != uid)
425 fatal("Can't swap uid and euid"); /* really paranoid */
426 if (stat(stab_val(curcmd->c_filestab)->str_ptr,&tmpstatbuf) < 0)
427 fatal("Permission denied"); /* testing full pathname here */
428 if (tmpstatbuf.st_dev != statbuf.st_dev ||
429 tmpstatbuf.st_ino != statbuf.st_ino) {
431 if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
433 "User %d tried to run dev %d ino %d in place of dev %d ino %d!\n\
434 (Filename of set-id script was %s, uid %d gid %d.)\n\nSincerely,\nperl\n",
435 uid,tmpstatbuf.st_dev, tmpstatbuf.st_ino,
436 statbuf.st_dev, statbuf.st_ino,
437 stab_val(curcmd->c_filestab)->str_ptr,
438 statbuf.st_uid, statbuf.st_gid);
439 (void)mypclose(rsfp);
441 fatal("Permission denied\n");
443 if (setreuid(uid,euid) < 0 || getuid() != uid || geteuid() != euid)
444 fatal("Can't reswap uid and euid");
445 if (!cando(S_IXUSR,FALSE,&statbuf)) /* can real uid exec? */
446 fatal("Permission denied\n");
448 #endif /* HAS_SETREUID */
451 if (!S_ISREG(statbuf.st_mode))
452 fatal("Permission denied");
453 if (statbuf.st_mode & S_IWOTH)
454 fatal("Setuid/gid script is writable by world");
455 doswitches = FALSE; /* -s is insecure in suid */
457 if (fgets(tokenbuf,sizeof tokenbuf, rsfp) == Nullch ||
458 strnNE(tokenbuf,"#!",2) ) /* required even on Sys V */
462 while (!isspace(*s)) s++;
463 if (strnNE(s-4,"perl",4) && strnNE(s-9,"perl",4)) /* sanity check */
464 fatal("Not a perl script");
465 while (*s == ' ' || *s == '\t') s++;
467 * #! arg must be what we saw above. They can invoke it by
468 * mentioning suidperl explicitly, but they may not add any strange
469 * arguments beyond what #! says if they do invoke suidperl that way.
471 len = strlen(validarg);
472 if (strEQ(validarg," PHOOEY ") ||
473 strnNE(s,validarg,len) || !isspace(s[len]))
474 fatal("Args must match #! line");
477 if (euid != uid && (statbuf.st_mode & S_ISUID) &&
478 euid == statbuf.st_uid)
480 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
481 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
484 if (euid) { /* oops, we're not the setuid root perl */
487 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
488 execv(buf, origargv); /* try again */
490 fatal("Can't do setuid\n");
493 if (statbuf.st_mode & S_ISGID && statbuf.st_gid != egid)
495 (void)setegid(statbuf.st_gid);
498 (void)setregid((GIDTYPE)-1,statbuf.st_gid);
500 setgid(statbuf.st_gid);
503 if (statbuf.st_mode & S_ISUID) {
504 if (statbuf.st_uid != euid)
506 (void)seteuid(statbuf.st_uid); /* all that for this */
509 (void)setreuid((UIDTYPE)-1,statbuf.st_uid);
511 setuid(statbuf.st_uid);
515 else if (uid) /* oops, mustn't run as root */
517 (void)seteuid((UIDTYPE)uid);
520 (void)setreuid((UIDTYPE)-1,(UIDTYPE)uid);
522 setuid((UIDTYPE)uid);
526 euid = (int)geteuid();
528 egid = (int)getegid();
529 if (!cando(S_IXUSR,TRUE,&statbuf))
530 fatal("Permission denied\n"); /* they can't do this */
534 fatal("-P not allowed for setuid/setgid script\n");
536 fatal("Script is not setuid/setgid in suidperl\n");
538 #ifndef TAINT /* we aren't taintperl or suidperl */
539 /* script has a wrapper--can't run suidperl or we lose euid */
540 else if (euid != uid || egid != gid) {
542 (void)sprintf(buf, "%s/tperl%s", BIN, patchlevel);
543 execv(buf, origargv); /* try again */
544 fatal("Can't run setuid script with taint checks");
549 #ifndef TAINT /* we aren't taintperl or suidperl */
550 if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
551 #ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
552 fstat(fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
553 if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
555 (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
558 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
559 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
560 #endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
561 /* not set-id, must be wrapped */
563 (void)sprintf(buf, "%s/tperl%s", BIN, patchlevel);
564 execv(buf, origargv); /* try again */
565 fatal("Can't run setuid script with taint checks");
570 #if !defined(IAMSUID) && !defined(TAINT)
572 /* skip forward in input to the real script? */
575 if ((s = str_gets(linestr, rsfp, 0)) == Nullch)
576 fatal("No Perl script found in input\n");
577 if (*s == '#' && s[1] == '!' && instr(s,"perl")) {
578 ungetc('\n',rsfp); /* to keep line count right */
580 if (s = instr(s,"perl -")) {
582 while (s = moreswitches(s)) ;
584 if (cddir && chdir(cddir) < 0)
585 fatal("Can't chdir to %s",cddir);
588 #endif /* !defined(IAMSUID) && !defined(TAINT) */
590 defstab = stabent("_",TRUE);
594 stab_xhash(stabent("_DB",TRUE)) = debstash;
596 dbargs = stab_xarray(aadd((tmpstab = stabent("args",TRUE))));
597 tmpstab->str_pok |= SP_MULTI;
598 dbargs->ary_flags = 0;
599 subname = str_make("main",4);
600 DBstab = stabent("DB",TRUE);
601 DBstab->str_pok |= SP_MULTI;
602 DBline = stabent("dbline",TRUE);
603 DBline->str_pok |= SP_MULTI;
604 DBsub = hadd(tmpstab = stabent("sub",TRUE));
605 tmpstab->str_pok |= SP_MULTI;
606 DBsingle = stab_val((tmpstab = stabent("single",TRUE)));
607 tmpstab->str_pok |= SP_MULTI;
608 DBtrace = stab_val((tmpstab = stabent("trace",TRUE)));
609 tmpstab->str_pok |= SP_MULTI;
610 DBsignal = stab_val((tmpstab = stabent("signal",TRUE)));
611 tmpstab->str_pok |= SP_MULTI;
617 bufend = bufptr = str_get(linestr);
619 savestack = anew(Nullstab); /* for saving non-local values */
620 stack = anew(Nullstab); /* for saving non-local values */
621 stack->ary_flags = 0; /* not a real array */
622 afill(stack,63); afill(stack,-1); /* preextend stack */
623 afill(savestack,63); afill(savestack,-1);
625 /* now parse the script */
628 if (yyparse() || error_count) {
630 fatal("%s had compilation errors.\n", origfilename);
632 fatal("Execution of %s aborted due to compilation errors.\n",
637 New(50,loop_stack,128,struct loop);
640 New(51,debname,128,char);
641 New(52,debdelim,128,char);
649 (void)UNLINK(e_tmpname);
652 /* initialize everything that won't change if we undump */
654 if (sigstab = stabent("SIG",allstabs)) {
655 sigstab->str_pok |= SP_MULTI;
659 magicalize("!#?^~=-%.+&*()<>,\\/[|`':\004\t\024\027");
660 userinit(); /* in case linked C routines want magical variables */
662 amperstab = stabent("&",allstabs);
663 leftstab = stabent("`",allstabs);
664 rightstab = stabent("'",allstabs);
665 sawampersand = (amperstab || leftstab || rightstab);
666 if (tmpstab = stabent(":",allstabs))
667 str_set(STAB_STR(tmpstab),chopset);
668 if (tmpstab = stabent("\024",allstabs))
671 /* these aren't necessarily magical */
672 if (tmpstab = stabent(";",allstabs))
673 str_set(STAB_STR(tmpstab),"\034");
674 if (tmpstab = stabent("]",allstabs)) {
675 str = STAB_STR(tmpstab);
677 str->str_u.str_nval = atof(patchlevel);
680 str_nset(stab_val(stabent("\"", TRUE)), " ", 1);
682 stdinstab = stabent("STDIN",TRUE);
683 stdinstab->str_pok |= SP_MULTI;
684 stab_io(stdinstab) = stio_new();
685 stab_io(stdinstab)->ifp = stdin;
686 tmpstab = stabent("stdin",TRUE);
687 stab_io(tmpstab) = stab_io(stdinstab);
688 tmpstab->str_pok |= SP_MULTI;
690 tmpstab = stabent("STDOUT",TRUE);
691 tmpstab->str_pok |= SP_MULTI;
692 stab_io(tmpstab) = stio_new();
693 stab_io(tmpstab)->ofp = stab_io(tmpstab)->ifp = stdout;
694 defoutstab = tmpstab;
695 tmpstab = stabent("stdout",TRUE);
696 stab_io(tmpstab) = stab_io(defoutstab);
697 tmpstab->str_pok |= SP_MULTI;
699 curoutstab = stabent("STDERR",TRUE);
700 curoutstab->str_pok |= SP_MULTI;
701 stab_io(curoutstab) = stio_new();
702 stab_io(curoutstab)->ofp = stab_io(curoutstab)->ifp = stderr;
703 tmpstab = stabent("stderr",TRUE);
704 stab_io(tmpstab) = stab_io(curoutstab);
705 tmpstab->str_pok |= SP_MULTI;
706 curoutstab = defoutstab; /* switch back to STDOUT */
708 statname = Str_new(66,0); /* last filename we did stat on */
710 /* now that script is parsed, we can modify record separator */
715 str_nset(stab_val(stabent("/", TRUE)), rs, rslen);
720 just_doit: /* come here if running an undumped a.out */
721 argc--,argv++; /* skip name of script */
723 for (; argc > 0 && **argv == '-'; argc--,argv++) {
724 if (argv[0][1] == '-') {
728 if (s = index(argv[0], '=')) {
730 str_set(stab_val(stabent(argv[0]+1,TRUE)),s);
733 str_numset(stab_val(stabent(argv[0]+1,TRUE)),(double)1.0);
739 if (tmpstab = stabent("0",allstabs)) {
740 str_set(stab_val(tmpstab),origfilename);
741 magicname("0", Nullch, 0);
743 if (tmpstab = stabent("\020",allstabs))
744 str_set(stab_val(tmpstab),origargv[0]);
745 if (argvstab = stabent("ARGV",allstabs)) {
746 argvstab->str_pok |= SP_MULTI;
747 (void)aadd(argvstab);
748 aclear(stab_array(argvstab));
749 for (; argc > 0; argc--,argv++) {
750 (void)apush(stab_array(argvstab),str_make(argv[0],0));
754 (void) stabent("ENV",TRUE); /* must test PATH and IFS */
756 if (envstab = stabent("ENV",allstabs)) {
757 envstab->str_pok |= SP_MULTI;
759 hclear(stab_hash(envstab), FALSE);
762 for (; *env; env++) {
763 if (!(s = index(*env,'=')))
766 str = str_make(s--,0);
767 str_magic(str, envstab, 'E', *env, s - *env);
768 (void)hstore(stab_hash(envstab), *env, s - *env, str, 0);
775 if (tmpstab = stabent("$",allstabs))
776 str_numset(STAB_STR(tmpstab),(double)getpid());
783 if (setjmp(top_env)) /* sets goto_targ on longjump */
784 loop_ptr = -1; /* start label stack again */
790 fprintf(stderr,"\nEXECUTING...\n\n");
794 fprintf(stderr,"%s syntax OK\n", origfilename);
800 (void) cmd_exec(main_root,G_SCALAR,-1);
803 fatal("Can't find label \"%s\"--aborting",goto_targ);
815 while (*sym = *list++)
816 magicname(sym, Nullch, 0);
820 magicname(sym,name,namlen)
827 if (stab = stabent(sym,allstabs)) {
828 stab_flags(stab) = SF_VMAGIC;
829 str_magic(stab_val(stab), stab, 0, name, namlen);
833 /* this routine is in perl.c by virtue of being sort of an alternate main() */
836 do_eval(str,optype,stash,gimme,arglast)
843 STR **st = stack->ary_array;
845 CMD *myroot = Nullcmd;
848 CMD * VOLATILE oldcurcmd = curcmd;
849 VOLATILE int oldtmps_base = tmps_base;
850 VOLATILE int oldsave = savestack->ary_fill;
851 VOLATILE int oldperldb = perldb;
852 SPAT * VOLATILE oldspat = curspat;
853 SPAT * VOLATILE oldlspat = lastspat;
854 static char *last_eval = Nullch;
855 static CMD *last_root = Nullcmd;
856 VOLATILE int sp = arglast[0];
861 tmps_base = tmps_max;
862 if (curstash != stash) {
863 (void)savehptr(&curstash);
866 str_set(stab_val(stabent("@",TRUE)),"");
867 if (curcmd->c_line == 0) /* don't debug debugger... */
870 if (optype == O_EVAL) { /* normal eval */
871 curcmd->c_filestab = fstab("(eval)");
873 str_sset(linestr,str);
874 str_cat(linestr,";"); /* be kind to them */
877 if (last_root && !in_eval) {
883 specfilename = str_get(str);
885 if (optype == O_REQUIRE && &str_undef !=
886 hfetch(stab_hash(incstab), specfilename, strlen(specfilename), 0)) {
888 tmps_base = oldtmps_base;
893 tmpfilename = savestr(specfilename);
894 if (index("/.", *tmpfilename))
895 rsfp = fopen(tmpfilename,"r");
897 ar = stab_array(incstab);
898 for (i = 0; i <= ar->ary_fill; i++) {
899 (void)sprintf(buf, "%s/%s",
900 str_get(afetch(ar,i,TRUE)), specfilename);
901 rsfp = fopen(buf,"r");
905 if (*s == '.' && s[1] == '/')
907 Safefree(tmpfilename);
908 tmpfilename = savestr(s);
913 curcmd->c_filestab = fstab(tmpfilename);
914 Safefree(tmpfilename);
915 tmpfilename = Nullch;
918 tmps_base = oldtmps_base;
919 if (optype == O_REQUIRE) {
920 sprintf(tokenbuf,"Can't locate %s in @INC", specfilename);
921 if (instr(tokenbuf,".h "))
922 strcat(tokenbuf," (change .h to .ph maybe?)");
923 if (instr(tokenbuf,".ph "))
924 strcat(tokenbuf," (did you run h2ph?)");
925 fatal("%s",tokenbuf);
927 if (gimme != G_ARRAY)
928 st[++sp] = &str_undef;
935 oldoldbufptr = oldbufptr = bufptr = str_get(linestr);
936 bufend = bufptr + linestr->str_cur;
937 if (++loop_ptr >= loop_max) {
939 Renew(loop_stack, loop_max, struct loop);
941 loop_stack[loop_ptr].loop_label = "_EVAL_";
942 loop_stack[loop_ptr].loop_sp = sp;
945 deb("(Pushing label #%d _EVAL_)\n", loop_ptr);
949 if (setjmp(loop_stack[loop_ptr].loop_env)) {
956 retval |= error_count;
958 else if (last_root && *bufptr == *last_eval && strEQ(bufptr,last_eval)){
960 eval_root = last_root; /* no point in reparsing */
962 else if (in_eval == 1) {
969 last_eval = savestr(bufptr);
971 retval |= error_count;
973 last_root = eval_root;
982 myroot = eval_root; /* in case cmd_exec does another eval! */
985 st = stack->ary_array;
987 if (gimme != G_ARRAY)
988 st[++sp] = &str_undef;
993 fprintf(stderr,"Freeing eval_root %lx\n",(long)eval_root);
997 if (eval_root == last_root)
999 eval_root = myroot = Nullcmd;
1008 sp = cmd_exec(eval_root,gimme,sp);
1009 st = stack->ary_array;
1010 for (i = arglast[0] + 1; i <= sp; i++)
1011 st[i] = str_mortal(st[i]);
1012 /* if we don't save result, free zaps it */
1013 if (in_eval != 1 && myroot != last_root)
1021 char *tmps = loop_stack[loop_ptr].loop_label;
1022 deb("(Popping label #%d %s)\n",loop_ptr,
1027 tmps_base = oldtmps_base;
1029 lastspat = oldlspat;
1030 if (savestack->ary_fill > oldsave) /* let them use local() */
1031 restorelist(oldsave);
1033 if (optype != O_EVAL) {
1035 if (optype == O_REQUIRE)
1036 fatal("%s", str_get(stab_val(stabent("@",TRUE))));
1040 if (gimme == G_SCALAR ? str_true(st[sp]) : sp > arglast[0]) {
1041 (void)hstore(stab_hash(incstab), specfilename,
1042 strlen(specfilename), str_smake(stab_val(curcmd->c_filestab)),
1045 else if (optype == O_REQUIRE)
1046 fatal("%s did not return a true value", specfilename);
1053 /* This routine handles any switches that can be given during run */
1064 nrschar = scanoct(s, 4, &numlen);
1065 nrs = nsavestr("\n",1);
1067 if (nrschar > 0377) {
1071 else if (!nrschar && numlen >= 2) {
1087 if (euid != uid || egid != gid)
1088 fatal("No -d allowed in setuid scripts");
1096 if (euid != uid || egid != gid)
1097 fatal("No -D allowed in setuid scripts");
1099 debug = atoi(s+1) | 32768;
1101 warn("Recompile perl with -DDEBUGGING to use -D switch\n");
1103 for (s++; isdigit(*s); s++) ;
1106 inplace = savestr(s+1);
1107 for (s = inplace; *s && !isspace(*s); s++) ;
1112 if (euid != uid || egid != gid)
1113 fatal("No -I allowed in setuid scripts");
1116 (void)apush(stab_array(incstab),str_make(s,0));
1119 fatal("No space allowed after -I");
1125 ors = savestr("\n");
1127 *ors = scanoct(s, 3 + (*s == '0'), &numlen);
1131 ors = nsavestr(nrs,nrslen);
1152 fputs("\nThis is perl, version 4.0\n\n",stdout);
1153 fputs(rcsid,stdout);
1154 fputs("\nCopyright (c) 1989, 1990, 1991, Larry Wall\n",stdout);
1156 fputs("MS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis\n",
1159 fputs("OS/2 port Copyright (c) 1990, Raymond Chen, Kai Uwe Rommel\n",
1164 Perl may be copied only under the terms of the GNU General Public License,\n\
1165 a copy of which can be found with the Perl 4.0 distribution kit.\n",stdout);
1179 fatal("Switch meaningless after -x: -%s",s);
1184 /* compliments of Tom Christiansen */
1186 /* unexec() can be found in the Gnu emacs distribution */
1193 static char dumpname[BUFSIZ];
1194 static char perlpath[256];
1196 sprintf (dumpname, "%s.perldump", origfilename);
1197 sprintf (perlpath, "%s/perl", BIN);
1199 status = unexec(dumpname, perlpath, &etext, sbrk(0), 0);
1201 fprintf(stderr, "unexec of %s into %s failed!\n", perlpath, dumpname);
1205 # define SIGABRT SIGILL
1208 # define SIGILL 6 /* blech */
1210 kill(getpid(),SIGABRT); /* for use with undump */