1 char rcsid[] = "$Header: perly.c,v 3.0.1.9 90/11/10 01:53:26 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 3.0.1.9 90/11/10 01:53:26 lwall
10 * patch38: random cleanup
11 * patch38: more msdos/os2 upgrades
12 * patch38: references to $0 produced core dumps
13 * patch38: added hooks for unexec()
15 * Revision 3.0.1.8 90/10/16 10:14:20 lwall
16 * patch29: *foo now prints as *package'foo
17 * patch29: added waitpid
18 * patch29: the debugger now understands packages and evals
19 * patch29: added -M, -A and -C
20 * patch29: -w sometimes printed spurious warnings about ARGV and ENV
21 * patch29: require "./foo" didn't work right
22 * patch29: require error messages referred to wrong file
24 * Revision 3.0.1.7 90/08/13 22:22:22 lwall
25 * patch28: defined(@array) and defined(%array) didn't work right
27 * Revision 3.0.1.6 90/08/09 04:55:50 lwall
28 * patch19: added -x switch to extract script from input trash
29 * patch19: Added -c switch to do compilation only
30 * patch19: added numeric interpretation of $]
31 * patch19: added require operator
32 * patch19: $0, %ENV, @ARGV were wrong in dumped script
33 * patch19: . is now explicitly in @INC (and last)
35 * Revision 3.0.1.5 90/03/27 16:20:57 lwall
36 * patch16: MSDOS support
37 * patch16: do FILE inside eval blows up
39 * Revision 3.0.1.4 90/02/28 18:06:41 lwall
40 * patch9: perl can now start up other interpreters scripts
41 * patch9: nested evals clobbered their longjmp environment
42 * patch9: eval could mistakenly return undef in array context
44 * Revision 3.0.1.3 89/12/21 20:15:41 lwall
45 * patch7: ANSI strerror() is now supported
46 * patch7: errno may now be a macro with an lvalue
47 * patch7: allowed setuid scripts to have a space after #!
49 * Revision 3.0.1.2 89/11/17 15:34:42 lwall
50 * patch5: fixed possible confusion about current effective gid
52 * Revision 3.0.1.1 89/11/11 04:50:04 lwall
53 * patch2: moved yydebug to where its type didn't matter
55 * Revision 3.0 89/10/18 15:22:21 lwall
66 #include "patchlevel.h"
75 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
81 static char* moreswitches();
83 extern char **environ;
93 char *index(), *strcpy(), *getenv();
94 bool dosearch = FALSE;
99 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
102 fatal("suidperl is no longer needed since the kernel can now execute\n\
103 setuid perl scripts securely.\n");
110 euid = (int)geteuid();
112 egid = (int)getegid();
115 * There is no way we can refer to them from Perl so close them to save
116 * space. The other alternative would be to provide STDAUX and STDPRN
119 (void)fclose(stdaux);
120 (void)fclose(stdprn);
123 origfilename = savestr(argv[0]);
125 loop_ptr = -1; /* start label stack again */
128 (void)sprintf(index(rcsid,'#'), "%d\n", PATCHLEVEL);
129 linestr = Str_new(65,80);
130 str_nset(linestr,"",0);
131 str = str_make("",0); /* first used for -I flags */
132 curstash = defstash = hnew(0);
133 curstname = str_make("main",4);
134 stab_xhash(stabent("_main",TRUE)) = defstash;
135 defstash->tbl_name = "main";
136 incstab = hadd(aadd(stabent("INC",TRUE)));
137 incstab->str_pok |= SP_MULTI;
138 for (argc--,argv++; argc > 0; argc--,argv++) {
139 if (argv[0][0] != '-' || !argv[0][1])
143 validarg = " PHOOEY ";
161 if (s = moreswitches(s))
167 if (euid != uid || egid != gid)
168 fatal("No -e allowed in setuid scripts");
171 e_tmpname = savestr(TMPPATH);
172 (void)mktemp(e_tmpname);
173 e_fp = fopen(e_tmpname,"w");
175 fatal("Cannot open temporary file");
181 (void)putc('\n', e_fp);
185 if (euid != uid || egid != gid)
186 fatal("No -I allowed in setuid scripts");
192 (void)apush(stab_array(incstab),str_make(s,0));
195 (void)apush(stab_array(incstab),str_make(argv[1],0));
196 str_cat(str,argv[1]);
203 if (euid != uid || egid != gid)
204 fatal("No -P allowed in setuid scripts");
211 if (euid != uid || egid != gid)
212 fatal("No -s allowed in setuid scripts");
233 fatal("Unrecognized switch: -%s",s);
243 #define PRIVLIB "/usr/local/lib/perl"
245 (void)apush(stab_array(incstab),str_make(PRIVLIB,0));
246 (void)apush(stab_array(incstab),str_make(".",1));
249 str_set(&str_yes,Yes);
253 if (argv[0] == Nullch)
256 if ( isatty(fileno(stdin)) )
263 if (dosearch && !index(argv[0], '/') && (s = getenv("PATH"))) {
264 char *xfound = Nullch, *xfailed = Nullch;
267 bufend = s + strlen(s);
270 s = cpytill(tokenbuf,s,bufend,':',&len);
272 for (len = 0; *s && *s != ';'; tokenbuf[len++] = *s++);
273 tokenbuf[len] = '\0';
278 if (len && tokenbuf[len-1] != '/')
280 if (len && tokenbuf[len-1] != '\\')
282 (void)strcat(tokenbuf+len,"/");
283 (void)strcat(tokenbuf+len,argv[0]);
286 fprintf(stderr,"Looking for %s\n",tokenbuf);
288 if (stat(tokenbuf,&statbuf) < 0) /* not there? */
290 if ((statbuf.st_mode & S_IFMT) == S_IFREG
291 && cando(S_IREAD,TRUE,&statbuf) && cando(S_IEXEC,TRUE,&statbuf)) {
292 xfound = tokenbuf; /* bingo! */
296 xfailed = savestr(tokenbuf);
299 fatal("Can't execute %s", xfailed ? xfailed : argv[0] );
302 argv[0] = savestr(xfound);
305 fdpid = anew(Nullstab); /* for remembering popen pids by fd */
306 pidstatus = hnew(Nullstab); /* for remembering status of dead pids */
308 origfilename = savestr(argv[0]);
309 curcmd->c_filestab = fstab(origfilename);
310 if (strEQ(origfilename,"-"))
314 str_cat(str,PRIVLIB);
315 (void)sprintf(buf, "\
316 %ssed %s -e '/^[^#]/b' \
317 -e '/^#[ ]*include[ ]/b' \
318 -e '/^#[ ]*define[ ]/b' \
319 -e '/^#[ ]*if[ ]/b' \
320 -e '/^#[ ]*ifdef[ ]/b' \
321 -e '/^#[ ]*ifndef[ ]/b' \
323 -e '/^#[ ]*endif/b' \
331 (doextract ? "-e '1,/^#/d\n'" : ""),
332 argv[0], CPPSTDIN, str_get(str), CPPMINUS);
340 #ifdef IAMSUID /* actually, this is caught earlier */
341 if (euid != uid && !euid) /* if running suidperl */
343 (void)seteuid(uid); /* musn't stay setuid root */
346 (void)setreuid(-1, uid);
352 rsfp = mypopen(buf,"r");
357 rsfp = fopen(argv[0],"r");
358 if (rsfp == Nullfp) {
360 #ifndef IAMSUID /* in case script is not readable before setuid */
361 if (euid && stat(stab_val(curcmd->c_filestab)->str_ptr,&statbuf) >= 0 &&
362 statbuf.st_mode & (S_ISUID|S_ISGID)) {
363 (void)sprintf(buf, "%s/%s", BIN, "suidperl");
364 execv(buf, origargv); /* try again */
365 fatal("Can't do setuid\n");
369 fatal("Can't open perl script \"%s\": %s\n",
370 stab_val(curcmd->c_filestab)->str_ptr, strerror(errno));
372 str_free(str); /* free -I directories */
374 /* do we need to emulate setuid on scripts? */
376 /* This code is for those BSD systems that have setuid #! scripts disabled
377 * in the kernel because of a security problem. Merely defining DOSUID
378 * in perl will not fix that problem, but if you have disabled setuid
379 * scripts in the kernel, this will attempt to emulate setuid and setgid
380 * on scripts that have those now-otherwise-useless bits set. The setuid
381 * root version must be called suidperl. If regular perl discovers that
382 * it has opened a setuid script, it calls suidperl with the same argv
383 * that it had. If suidperl finds that the script it has just opened
384 * is NOT setuid root, it sets the effective uid back to the uid. We
385 * don't just make perl setuid root because that loses the effective
386 * uid we had before invoking perl, if it was different from the uid.
388 * DOSUID must be defined in both perl and suidperl, and IAMSUID must
389 * be defined in suidperl only. suidperl must be setuid root. The
390 * Configure script will set this up for you if you want it.
392 * There is also the possibility of have a script which is running
393 * set-id due to a C wrapper. We want to do the TAINT checks
394 * on these set-id scripts, but don't want to have the overhead of
395 * them in normal perl, and can't use suidperl because it will lose
396 * the effective uid info, so we have an additional non-setuid root
397 * version called taintperl that just does the TAINT checks.
401 if (fstat(fileno(rsfp),&statbuf) < 0) /* normal stat is insecure */
402 fatal("Can't stat script \"%s\"",origfilename);
403 if (statbuf.st_mode & (S_ISUID|S_ISGID)) {
408 /* On this access check to make sure the directories are readable,
409 * there is actually a small window that the user could use to make
410 * filename point to an accessible directory. So there is a faint
411 * chance that someone could execute a setuid script down in a
412 * non-accessible directory. I don't know what to do about that.
413 * But I don't think it's too important. The manual lies when
414 * it says access() is useful in setuid programs.
416 if (access(stab_val(curcmd->c_filestab)->str_ptr,1)) /*double check*/
417 fatal("Permission denied");
419 /* If we can swap euid and uid, then we can determine access rights
420 * with a simple stat of the file, and then compare device and
421 * inode to make sure we did stat() on the same file we opened.
422 * Then we just have to make sure he or she can execute it.
425 struct stat tmpstatbuf;
427 if (setreuid(euid,uid) < 0 || getuid() != euid || geteuid() != uid)
428 fatal("Can't swap uid and euid"); /* really paranoid */
429 if (stat(stab_val(curcmd->c_filestab)->str_ptr,&tmpstatbuf) < 0)
430 fatal("Permission denied"); /* testing full pathname here */
431 if (tmpstatbuf.st_dev != statbuf.st_dev ||
432 tmpstatbuf.st_ino != statbuf.st_ino) {
434 if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
436 "User %d tried to run dev %d ino %d in place of dev %d ino %d!\n\
437 (Filename of set-id script was %s, uid %d gid %d.)\n\nSincerely,\nperl\n",
438 uid,tmpstatbuf.st_dev, tmpstatbuf.st_ino,
439 statbuf.st_dev, statbuf.st_ino,
440 stab_val(curcmd->c_filestab)->str_ptr,
441 statbuf.st_uid, statbuf.st_gid);
442 (void)mypclose(rsfp);
444 fatal("Permission denied\n");
446 if (setreuid(uid,euid) < 0 || getuid() != uid || geteuid() != euid)
447 fatal("Can't reswap uid and euid");
448 if (!cando(S_IEXEC,FALSE,&statbuf)) /* can real uid exec? */
449 fatal("Permission denied\n");
451 #endif /* SETREUID */
454 if ((statbuf.st_mode & S_IFMT) != S_IFREG)
455 fatal("Permission denied");
456 if ((statbuf.st_mode >> 6) & S_IWRITE)
457 fatal("Setuid/gid script is writable by world");
458 doswitches = FALSE; /* -s is insecure in suid */
460 if (fgets(tokenbuf,sizeof tokenbuf, rsfp) == Nullch ||
461 strnNE(tokenbuf,"#!",2) ) /* required even on Sys V */
465 while (!isspace(*s)) s++;
466 if (strnNE(s-4,"perl",4)) /* sanity check */
467 fatal("Not a perl script");
468 while (*s == ' ' || *s == '\t') s++;
470 * #! arg must be what we saw above. They can invoke it by
471 * mentioning suidperl explicitly, but they may not add any strange
472 * arguments beyond what #! says if they do invoke suidperl that way.
474 len = strlen(validarg);
475 if (strEQ(validarg," PHOOEY ") ||
476 strnNE(s,validarg,len) || !isspace(s[len]))
477 fatal("Args must match #! line");
480 if (euid != uid && (statbuf.st_mode & S_ISUID) &&
481 euid == statbuf.st_uid)
483 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
484 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
487 if (euid) { /* oops, we're not the setuid root perl */
490 (void)sprintf(buf, "%s/%s", BIN, "suidperl");
491 execv(buf, origargv); /* try again */
493 fatal("Can't do setuid\n");
496 if (statbuf.st_mode & S_ISGID && statbuf.st_gid != egid)
498 (void)setegid(statbuf.st_gid);
501 (void)setregid((GIDTYPE)-1,statbuf.st_gid);
503 setgid(statbuf.st_gid);
506 if (statbuf.st_mode & S_ISUID) {
507 if (statbuf.st_uid != euid)
509 (void)seteuid(statbuf.st_uid); /* all that for this */
512 (void)setreuid((UIDTYPE)-1,statbuf.st_uid);
514 setuid(statbuf.st_uid);
518 else if (uid) /* oops, mustn't run as root */
520 (void)seteuid((UIDTYPE)uid);
523 (void)setreuid((UIDTYPE)-1,(UIDTYPE)uid);
525 setuid((UIDTYPE)uid);
529 euid = (int)geteuid();
531 egid = (int)getegid();
532 if (!cando(S_IEXEC,TRUE,&statbuf))
533 fatal("Permission denied\n"); /* they can't do this */
537 fatal("-P not allowed for setuid/setgid script\n");
539 fatal("Script is not setuid/setgid in suidperl\n");
541 #ifndef TAINT /* we aren't taintperl or suidperl */
542 /* script has a wrapper--can't run suidperl or we lose euid */
543 else if (euid != uid || egid != gid) {
545 (void)sprintf(buf, "%s/%s", BIN, "taintperl");
546 execv(buf, origargv); /* try again */
547 fatal("Can't run setuid script with taint checks");
552 #ifndef TAINT /* we aren't taintperl or suidperl */
553 if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
554 #ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
555 fstat(fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
556 if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
558 (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
561 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
562 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
563 #endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
564 /* not set-id, must be wrapped */
566 (void)sprintf(buf, "%s/%s", BIN, "taintperl");
567 execv(buf, origargv); /* try again */
568 fatal("Can't run setuid script with taint checks");
573 #if !defined(IAMSUID) && !defined(TAINT)
575 /* skip forward in input to the real script? */
578 if ((s = str_gets(linestr, rsfp, 0)) == Nullch)
579 fatal("No Perl script found in input\n");
580 if (*s == '#' && s[1] == '!' && instr(s,"perl")) {
581 ungetc('\n',rsfp); /* to keep line count right */
583 if (s = instr(s,"perl -")) {
585 while (s = moreswitches(s)) ;
587 if (cddir && chdir(cddir) < 0)
588 fatal("Can't chdir to %s",cddir);
591 #endif /* !defined(IAMSUID) && !defined(TAINT) */
593 defstab = stabent("_",TRUE);
597 stab_xhash(stabent("_DB",TRUE)) = debstash;
599 dbargs = stab_xarray(aadd((tmpstab = stabent("args",TRUE))));
600 tmpstab->str_pok |= SP_MULTI;
601 dbargs->ary_flags = 0;
602 subname = str_make("main",4);
603 DBstab = stabent("DB",TRUE);
604 DBstab->str_pok |= SP_MULTI;
605 DBline = stabent("dbline",TRUE);
606 DBline->str_pok |= SP_MULTI;
607 DBsub = hadd(tmpstab = stabent("sub",TRUE));
608 tmpstab->str_pok |= SP_MULTI;
609 DBsingle = stab_val((tmpstab = stabent("single",TRUE)));
610 tmpstab->str_pok |= SP_MULTI;
611 DBtrace = stab_val((tmpstab = stabent("trace",TRUE)));
612 tmpstab->str_pok |= SP_MULTI;
613 DBsignal = stab_val((tmpstab = stabent("signal",TRUE)));
614 tmpstab->str_pok |= SP_MULTI;
620 bufend = bufptr = str_get(linestr);
622 savestack = anew(Nullstab); /* for saving non-local values */
623 stack = anew(Nullstab); /* for saving non-local values */
624 stack->ary_flags = 0; /* not a real array */
625 afill(stack,63); afill(stack,-1); /* preextend stack */
626 afill(savestack,63); afill(savestack,-1);
628 /* now parse the script */
631 if (yyparse() || error_count) {
633 fatal("%s had compilation errors.\n", origfilename);
635 fatal("Execution of %s aborted due to compilation errors.\n",
640 New(50,loop_stack,128,struct loop);
643 New(51,debname,128,char);
644 New(52,debdelim,128,char);
652 (void)UNLINK(e_tmpname);
655 /* initialize everything that won't change if we undump */
657 if (sigstab = stabent("SIG",allstabs)) {
658 sigstab->str_pok |= SP_MULTI;
662 magicalize("!#?^~=-%123456789.+&*()<>,\\/[|`':\024");
663 userinit(); /* in case linked C routines want magical variables */
665 amperstab = stabent("&",allstabs);
666 leftstab = stabent("`",allstabs);
667 rightstab = stabent("'",allstabs);
668 sawampersand = (amperstab || leftstab || rightstab);
669 if (tmpstab = stabent(":",allstabs))
670 str_set(STAB_STR(tmpstab),chopset);
671 if (tmpstab = stabent("\024",allstabs))
674 /* these aren't necessarily magical */
675 if (tmpstab = stabent(";",allstabs))
676 str_set(STAB_STR(tmpstab),"\034");
677 if (tmpstab = stabent("]",allstabs)) {
678 str = STAB_STR(tmpstab);
680 strncpy(tokenbuf,rcsid+19,3);
681 sprintf(tokenbuf+3,"%2.2d",PATCHLEVEL);
682 str->str_u.str_nval = atof(tokenbuf);
685 str_nset(stab_val(stabent("\"", TRUE)), " ", 1);
687 stdinstab = stabent("STDIN",TRUE);
688 stdinstab->str_pok |= SP_MULTI;
689 stab_io(stdinstab) = stio_new();
690 stab_io(stdinstab)->ifp = stdin;
691 tmpstab = stabent("stdin",TRUE);
692 stab_io(tmpstab) = stab_io(stdinstab);
693 tmpstab->str_pok |= SP_MULTI;
695 tmpstab = stabent("STDOUT",TRUE);
696 tmpstab->str_pok |= SP_MULTI;
697 stab_io(tmpstab) = stio_new();
698 stab_io(tmpstab)->ofp = stab_io(tmpstab)->ifp = stdout;
699 defoutstab = tmpstab;
700 tmpstab = stabent("stdout",TRUE);
701 stab_io(tmpstab) = stab_io(defoutstab);
702 tmpstab->str_pok |= SP_MULTI;
704 curoutstab = stabent("STDERR",TRUE);
705 curoutstab->str_pok |= SP_MULTI;
706 stab_io(curoutstab) = stio_new();
707 stab_io(curoutstab)->ofp = stab_io(curoutstab)->ifp = stderr;
708 tmpstab = stabent("stderr",TRUE);
709 stab_io(tmpstab) = stab_io(curoutstab);
710 tmpstab->str_pok |= SP_MULTI;
711 curoutstab = defoutstab; /* switch back to STDOUT */
713 statname = Str_new(66,0); /* last filename we did stat on */
718 just_doit: /* come here if running an undumped a.out */
719 argc--,argv++; /* skip name of script */
721 for (; argc > 0 && **argv == '-'; argc--,argv++) {
722 if (argv[0][1] == '-') {
726 str_numset(stab_val(stabent(argv[0]+1,TRUE)),(double)1.0);
732 if (tmpstab = stabent("0",allstabs))
733 str_set(stab_val(tmpstab),origfilename);
734 if (argvstab = stabent("ARGV",allstabs)) {
735 argvstab->str_pok |= SP_MULTI;
736 (void)aadd(argvstab);
737 aclear(stab_array(argvstab));
738 for (; argc > 0; argc--,argv++) {
739 (void)apush(stab_array(argvstab),str_make(argv[0],0));
743 (void) stabent("ENV",TRUE); /* must test PATH and IFS */
745 if (envstab = stabent("ENV",allstabs)) {
746 envstab->str_pok |= SP_MULTI;
748 hclear(stab_hash(envstab), FALSE);
751 for (; *env; env++) {
752 if (!(s = index(*env,'=')))
755 str = str_make(s--,0);
756 str_magic(str, envstab, 'E', *env, s - *env);
757 (void)hstore(stab_hash(envstab), *env, s - *env, str, 0);
764 if (tmpstab = stabent("$",allstabs))
765 str_numset(STAB_STR(tmpstab),(double)getpid());
772 if (setjmp(top_env)) /* sets goto_targ on longjump */
773 loop_ptr = -1; /* start label stack again */
779 fprintf(stderr,"\nEXECUTING...\n\n");
783 fprintf(stderr,"%s syntax OK\n", origfilename);
789 (void) cmd_exec(main_root,G_SCALAR,-1);
792 fatal("Can't find label \"%s\"--aborting",goto_targ);
803 while (*sym = *list++)
804 magicname(sym, Nullch, 0);
808 magicname(sym,name,namlen)
815 if (stab = stabent(sym,allstabs)) {
816 stab_flags(stab) = SF_VMAGIC;
817 str_magic(stab_val(stab), stab, 0, name, namlen);
821 /* this routine is in perly.c by virtue of being sort of an alternate main() */
824 do_eval(str,optype,stash,gimme,arglast)
831 STR **st = stack->ary_array;
836 CMD * VOLATILE oldcurcmd = curcmd;
837 VOLATILE int oldtmps_base = tmps_base;
838 VOLATILE int oldsave = savestack->ary_fill;
839 VOLATILE int oldperldb = perldb;
840 SPAT * VOLATILE oldspat = curspat;
841 static char *last_eval = Nullch;
842 static CMD *last_root = Nullcmd;
843 VOLATILE int sp = arglast[0];
847 tmps_base = tmps_max;
848 if (curstash != stash) {
849 (void)savehptr(&curstash);
852 str_set(stab_val(stabent("@",TRUE)),"");
853 if (curcmd->c_line == 0) /* don't debug debugger... */
856 if (optype == O_EVAL) { /* normal eval */
857 curcmd->c_filestab = fstab("(eval)");
859 str_sset(linestr,str);
860 str_cat(linestr,";"); /* be kind to them */
863 if (last_root && !in_eval) {
868 specfilename = str_get(str);
870 if (optype == O_REQUIRE && &str_undef !=
871 hfetch(stab_hash(incstab), specfilename, strlen(specfilename), 0)) {
873 tmps_base = oldtmps_base;
878 tmpfilename = savestr(specfilename);
879 if (index("/.", *tmpfilename))
880 rsfp = fopen(tmpfilename,"r");
882 ar = stab_array(incstab);
883 for (i = 0; i <= ar->ary_fill; i++) {
884 (void)sprintf(buf, "%s/%s",
885 str_get(afetch(ar,i,TRUE)), specfilename);
886 rsfp = fopen(buf,"r");
890 if (*s == '.' && s[1] == '/')
892 Safefree(tmpfilename);
893 tmpfilename = savestr(s);
898 curcmd->c_filestab = fstab(tmpfilename);
899 Safefree(tmpfilename);
902 tmps_base = oldtmps_base;
903 if (optype == O_REQUIRE) {
904 sprintf(tokenbuf,"Can't locate %s in @INC", specfilename);
905 if (instr(tokenbuf,".h "))
906 strcat(tokenbuf," (change .h to .ph maybe?)");
907 if (instr(tokenbuf,".ph "))
908 strcat(tokenbuf," (did you run h2ph?)");
909 fatal("%s",tokenbuf);
911 if (gimme != G_ARRAY)
912 st[++sp] = &str_undef;
919 oldoldbufptr = oldbufptr = bufptr = str_get(linestr);
920 bufend = bufptr + linestr->str_cur;
921 if (++loop_ptr >= loop_max) {
923 Renew(loop_stack, loop_max, struct loop);
925 loop_stack[loop_ptr].loop_label = "_EVAL_";
926 loop_stack[loop_ptr].loop_sp = sp;
929 deb("(Pushing label #%d _EVAL_)\n", loop_ptr);
932 if (setjmp(loop_stack[loop_ptr].loop_env)) {
940 retval |= error_count;
942 else if (last_root && *bufptr == *last_eval && strEQ(bufptr,last_eval)){
944 eval_root = last_root; /* no point in reparsing */
946 else if (in_eval == 1) {
951 last_eval = savestr(bufptr);
954 retval |= error_count;
956 last_root = eval_root;
961 myroot = eval_root; /* in case cmd_exec does another eval! */
964 st = stack->ary_array;
966 if (gimme != G_ARRAY)
967 st[++sp] = &str_undef;
968 last_root = Nullcmd; /* can't free on error, for some reason */
975 sp = cmd_exec(eval_root,gimme,sp);
976 st = stack->ary_array;
977 for (i = arglast[0] + 1; i <= sp; i++)
978 st[i] = str_static(st[i]);
979 /* if we don't save result, free zaps it */
980 if (in_eval != 1 && myroot != last_root)
988 char *tmps = loop_stack[loop_ptr].loop_label;
989 deb("(Popping label #%d %s)\n",loop_ptr,
994 tmps_base = oldtmps_base;
996 if (savestack->ary_fill > oldsave) /* let them use local() */
997 restorelist(oldsave);
999 if (optype != O_EVAL) {
1001 if (optype == O_REQUIRE)
1002 fatal("%s", str_get(stab_val(stabent("@",TRUE))));
1006 if (gimme == G_SCALAR ? str_true(st[sp]) : sp > arglast[0]) {
1007 (void)hstore(stab_hash(incstab), specfilename,
1008 strlen(specfilename), str_smake(stab_val(curcmd->c_filestab)),
1011 else if (optype == O_REQUIRE)
1012 fatal("%s did not return a true value", specfilename);
1019 /* This routine handles any switches that can be given during run */
1037 if (euid != uid || egid != gid)
1038 fatal("No -d allowed in setuid scripts");
1046 if (euid != uid || egid != gid)
1047 fatal("No -D allowed in setuid scripts");
1051 warn("Recompile perl with -DDEBUGGING to use -D switch\n");
1055 inplace = savestr(s+1);
1056 for (s = inplace; *s && !isspace(*s); s++) ;
1058 argvoutstab = stabent("ARGVOUT",TRUE);
1062 if (euid != uid || egid != gid)
1063 fatal("No -I allowed in setuid scripts");
1066 (void)apush(stab_array(incstab),str_make(s,0));
1069 fatal("No space allowed after -I");
1088 fputs("\nThis is perl, version 3.0\n\n",stdout);
1089 fputs(rcsid,stdout);
1090 fputs("\nCopyright (c) 1989, 1990, Larry Wall\n",stdout);
1092 fputs("MS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis\n",
1095 fputs("OS/2 port Copyright (c) 1990, Raymond Chen, Kai Uwe Rommel\n",
1100 Perl may be copied only under the terms of the GNU General Public License,\n\
1101 a copy of which can be found with the Perl 3.0 distribution kit.\n",stdout);
1115 fatal("Switch meaningless after -x: -%s",s);
1120 /* compliments of Tom Christiansen */
1122 /* unexec() can be found in the Gnu emacs distribution */
1129 static char dumpname[BUFSIZ];
1130 static char perlpath[256];
1132 sprintf (dumpname, "%s.perldump", origfilename);
1133 sprintf (perlpath, "%s/perl", BIN);
1135 status = unexec(dumpname, perlpath, &etext, sbrk(0), 0);
1137 fprintf(stderr, "unexec of %s into %s failed!\n", perlpath, dumpname);
1140 abort(); /* for use with undump */