1 char rcsid[] = "$RCSfile: perl.c,v $$Revision: 4.0.1.3 $$Date: 91/06/07 11:40:18 $\nPatch level: ###\n";
3 * Copyright (c) 1991, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 * Revision 4.0.1.3 91/06/07 11:40:18 lwall
10 * patch4: changed old $^P to $^X
12 * Revision 4.0.1.2 91/06/07 11:26:16 lwall
13 * patch4: new copyright notice
14 * patch4: added $^P variable to control calling of perldb routines
15 * patch4: added $^F variable to specify maximum system fd, default 2
16 * patch4: debugger lost track of lines in eval
18 * Revision 4.0.1.1 91/04/11 17:49:05 lwall
19 * patch1: fixed undefined environ problem
21 * Revision 4.0 91/03/20 01:37:44 lwall
32 #include "patchlevel.h"
43 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
49 static char* moreswitches();
52 static char patchlevel[6];
53 static char *nrs = "\n";
54 static int nrschar = '\n'; /* final char of rs, or 0777 if none */
55 static int nrslen = 1;
65 bool dosearch = FALSE;
70 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
73 fatal("suidperl is no longer needed since the kernel can now execute\n\
74 setuid perl scripts securely.\n");
80 origenviron = environ;
82 euid = (int)geteuid();
84 egid = (int)getegid();
85 sprintf(patchlevel,"%3.3s%2.2d", index(rcsid,'4'), PATCHLEVEL);
88 * There is no way we can refer to them from Perl so close them to save
89 * space. The other alternative would be to provide STDAUX and STDPRN
96 origfilename = savestr(argv[0]);
98 loop_ptr = -1; /* start label stack again */
101 (void)sprintf(index(rcsid,'#'), "%d\n", PATCHLEVEL);
102 linestr = Str_new(65,80);
103 str_nset(linestr,"",0);
104 str = str_make("",0); /* first used for -I flags */
105 curstash = defstash = hnew(0);
106 curstname = str_make("main",4);
107 stab_xhash(stabent("_main",TRUE)) = defstash;
108 defstash->tbl_name = "main";
109 incstab = hadd(aadd(stabent("INC",TRUE)));
110 incstab->str_pok |= SP_MULTI;
111 for (argc--,argv++; argc > 0; argc--,argv++) {
112 if (argv[0][0] != '-' || !argv[0][1])
116 validarg = " PHOOEY ";
136 if (s = moreswitches(s))
142 if (euid != uid || egid != gid)
143 fatal("No -e allowed in setuid scripts");
146 e_tmpname = savestr(TMPPATH);
147 (void)mktemp(e_tmpname);
148 e_fp = fopen(e_tmpname,"w");
150 fatal("Cannot open temporary file");
156 (void)putc('\n', e_fp);
160 if (euid != uid || egid != gid)
161 fatal("No -I allowed in setuid scripts");
167 (void)apush(stab_array(incstab),str_make(s,0));
170 (void)apush(stab_array(incstab),str_make(argv[1],0));
171 str_cat(str,argv[1]);
178 if (euid != uid || egid != gid)
179 fatal("No -P allowed in setuid scripts");
186 if (euid != uid || egid != gid)
187 fatal("No -s allowed in setuid scripts");
208 fatal("Unrecognized switch: -%s",s);
219 #define PERLLIB_SEP ';'
221 #define PERLLIB_SEP ':'
223 #ifndef TAINT /* Can't allow arbitrary PERLLIB in setuid script */
225 char * s2 = getenv("PERLLIB");
228 /* Break at all separators */
230 /* First, skip any consecutive separators */
231 while ( *s2 == PERLLIB_SEP ) {
232 /* Uncomment the next line for PATH semantics */
233 /* (void)apush(stab_array(incstab),str_make(".",1)); */
236 if ( (s = index(s2,PERLLIB_SEP)) != Nullch ) {
237 (void)apush(stab_array(incstab),str_make(s2,(int)(s-s2)));
240 (void)apush(stab_array(incstab),str_make(s2,0));
249 #define PRIVLIB "/usr/local/lib/perl"
251 (void)apush(stab_array(incstab),str_make(PRIVLIB,0));
252 (void)apush(stab_array(incstab),str_make(".",1));
255 str_set(&str_yes,Yes);
259 if (argv[0] == Nullch)
262 if ( isatty(fileno(stdin)) )
269 if (dosearch && !index(argv[0], '/') && (s = getenv("PATH"))) {
270 char *xfound = Nullch, *xfailed = Nullch;
273 bufend = s + strlen(s);
276 s = cpytill(tokenbuf,s,bufend,':',&len);
278 for (len = 0; *s && *s != ';'; tokenbuf[len++] = *s++);
279 tokenbuf[len] = '\0';
284 if (len && tokenbuf[len-1] != '/')
286 if (len && tokenbuf[len-1] != '\\')
288 (void)strcat(tokenbuf+len,"/");
289 (void)strcat(tokenbuf+len,argv[0]);
292 fprintf(stderr,"Looking for %s\n",tokenbuf);
294 if (stat(tokenbuf,&statbuf) < 0) /* not there? */
296 if (S_ISREG(statbuf.st_mode)
297 && cando(S_IRUSR,TRUE,&statbuf) && cando(S_IXUSR,TRUE,&statbuf)) {
298 xfound = tokenbuf; /* bingo! */
302 xfailed = savestr(tokenbuf);
305 fatal("Can't execute %s", xfailed ? xfailed : argv[0] );
308 argv[0] = savestr(xfound);
311 fdpid = anew(Nullstab); /* for remembering popen pids by fd */
312 pidstatus = hnew(COEFFSIZE);/* for remembering status of dead pids */
314 origfilename = savestr(argv[0]);
315 curcmd->c_filestab = fstab(origfilename);
316 if (strEQ(origfilename,"-"))
320 str_cat(str,PRIVLIB);
321 (void)sprintf(buf, "\
322 %ssed %s -e '/^[^#]/b' \
323 -e '/^#[ ]*include[ ]/b' \
324 -e '/^#[ ]*define[ ]/b' \
325 -e '/^#[ ]*if[ ]/b' \
326 -e '/^#[ ]*ifdef[ ]/b' \
327 -e '/^#[ ]*ifndef[ ]/b' \
329 -e '/^#[ ]*endif/b' \
337 (doextract ? "-e '1,/^#/d\n'" : ""),
338 argv[0], CPPSTDIN, str_get(str), CPPMINUS);
346 #ifdef IAMSUID /* actually, this is caught earlier */
347 if (euid != uid && !euid) /* if running suidperl */
349 (void)seteuid(uid); /* musn't stay setuid root */
352 (void)setreuid(-1, uid);
358 rsfp = mypopen(buf,"r");
363 rsfp = fopen(argv[0],"r");
364 if (rsfp == Nullfp) {
366 #ifndef IAMSUID /* in case script is not readable before setuid */
367 if (euid && stat(stab_val(curcmd->c_filestab)->str_ptr,&statbuf) >= 0 &&
368 statbuf.st_mode & (S_ISUID|S_ISGID)) {
369 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
370 execv(buf, origargv); /* try again */
371 fatal("Can't do setuid\n");
375 fatal("Can't open perl script \"%s\": %s\n",
376 stab_val(curcmd->c_filestab)->str_ptr, strerror(errno));
378 str_free(str); /* free -I directories */
381 /* do we need to emulate setuid on scripts? */
383 /* This code is for those BSD systems that have setuid #! scripts disabled
384 * in the kernel because of a security problem. Merely defining DOSUID
385 * in perl will not fix that problem, but if you have disabled setuid
386 * scripts in the kernel, this will attempt to emulate setuid and setgid
387 * on scripts that have those now-otherwise-useless bits set. The setuid
388 * root version must be called suidperl or sperlN.NNN. If regular perl
389 * discovers that it has opened a setuid script, it calls suidperl with
390 * the same argv that it had. If suidperl finds that the script it has
391 * just opened is NOT setuid root, it sets the effective uid back to the
392 * uid. We don't just make perl setuid root because that loses the
393 * effective uid we had before invoking perl, if it was different from the
396 * DOSUID must be defined in both perl and suidperl, and IAMSUID must
397 * be defined in suidperl only. suidperl must be setuid root. The
398 * Configure script will set this up for you if you want it.
400 * There is also the possibility of have a script which is running
401 * set-id due to a C wrapper. We want to do the TAINT checks
402 * on these set-id scripts, but don't want to have the overhead of
403 * them in normal perl, and can't use suidperl because it will lose
404 * the effective uid info, so we have an additional non-setuid root
405 * version called taintperl or tperlN.NNN that just does the TAINT checks.
409 if (fstat(fileno(rsfp),&statbuf) < 0) /* normal stat is insecure */
410 fatal("Can't stat script \"%s\"",origfilename);
411 if (statbuf.st_mode & (S_ISUID|S_ISGID)) {
416 /* On this access check to make sure the directories are readable,
417 * there is actually a small window that the user could use to make
418 * filename point to an accessible directory. So there is a faint
419 * chance that someone could execute a setuid script down in a
420 * non-accessible directory. I don't know what to do about that.
421 * But I don't think it's too important. The manual lies when
422 * it says access() is useful in setuid programs.
424 if (access(stab_val(curcmd->c_filestab)->str_ptr,1)) /*double check*/
425 fatal("Permission denied");
427 /* If we can swap euid and uid, then we can determine access rights
428 * with a simple stat of the file, and then compare device and
429 * inode to make sure we did stat() on the same file we opened.
430 * Then we just have to make sure he or she can execute it.
433 struct stat tmpstatbuf;
435 if (setreuid(euid,uid) < 0 || getuid() != euid || geteuid() != uid)
436 fatal("Can't swap uid and euid"); /* really paranoid */
437 if (stat(stab_val(curcmd->c_filestab)->str_ptr,&tmpstatbuf) < 0)
438 fatal("Permission denied"); /* testing full pathname here */
439 if (tmpstatbuf.st_dev != statbuf.st_dev ||
440 tmpstatbuf.st_ino != statbuf.st_ino) {
442 if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
444 "User %d tried to run dev %d ino %d in place of dev %d ino %d!\n\
445 (Filename of set-id script was %s, uid %d gid %d.)\n\nSincerely,\nperl\n",
446 uid,tmpstatbuf.st_dev, tmpstatbuf.st_ino,
447 statbuf.st_dev, statbuf.st_ino,
448 stab_val(curcmd->c_filestab)->str_ptr,
449 statbuf.st_uid, statbuf.st_gid);
450 (void)mypclose(rsfp);
452 fatal("Permission denied\n");
454 if (setreuid(uid,euid) < 0 || getuid() != uid || geteuid() != euid)
455 fatal("Can't reswap uid and euid");
456 if (!cando(S_IXUSR,FALSE,&statbuf)) /* can real uid exec? */
457 fatal("Permission denied\n");
459 #endif /* HAS_SETREUID */
462 if (!S_ISREG(statbuf.st_mode))
463 fatal("Permission denied");
464 if (statbuf.st_mode & S_IWOTH)
465 fatal("Setuid/gid script is writable by world");
466 doswitches = FALSE; /* -s is insecure in suid */
468 if (fgets(tokenbuf,sizeof tokenbuf, rsfp) == Nullch ||
469 strnNE(tokenbuf,"#!",2) ) /* required even on Sys V */
473 while (!isspace(*s)) s++;
474 if (strnNE(s-4,"perl",4) && strnNE(s-9,"perl",4)) /* sanity check */
475 fatal("Not a perl script");
476 while (*s == ' ' || *s == '\t') s++;
478 * #! arg must be what we saw above. They can invoke it by
479 * mentioning suidperl explicitly, but they may not add any strange
480 * arguments beyond what #! says if they do invoke suidperl that way.
482 len = strlen(validarg);
483 if (strEQ(validarg," PHOOEY ") ||
484 strnNE(s,validarg,len) || !isspace(s[len]))
485 fatal("Args must match #! line");
488 if (euid != uid && (statbuf.st_mode & S_ISUID) &&
489 euid == statbuf.st_uid)
491 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
492 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
495 if (euid) { /* oops, we're not the setuid root perl */
498 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
499 execv(buf, origargv); /* try again */
501 fatal("Can't do setuid\n");
504 if (statbuf.st_mode & S_ISGID && statbuf.st_gid != egid)
506 (void)setegid(statbuf.st_gid);
509 (void)setregid((GIDTYPE)-1,statbuf.st_gid);
511 setgid(statbuf.st_gid);
514 if (statbuf.st_mode & S_ISUID) {
515 if (statbuf.st_uid != euid)
517 (void)seteuid(statbuf.st_uid); /* all that for this */
520 (void)setreuid((UIDTYPE)-1,statbuf.st_uid);
522 setuid(statbuf.st_uid);
526 else if (uid) /* oops, mustn't run as root */
528 (void)seteuid((UIDTYPE)uid);
531 (void)setreuid((UIDTYPE)-1,(UIDTYPE)uid);
533 setuid((UIDTYPE)uid);
537 euid = (int)geteuid();
539 egid = (int)getegid();
540 if (!cando(S_IXUSR,TRUE,&statbuf))
541 fatal("Permission denied\n"); /* they can't do this */
545 fatal("-P not allowed for setuid/setgid script\n");
547 fatal("Script is not setuid/setgid in suidperl\n");
549 #ifndef TAINT /* we aren't taintperl or suidperl */
550 /* script has a wrapper--can't run suidperl or we lose euid */
551 else if (euid != uid || egid != gid) {
553 (void)sprintf(buf, "%s/tperl%s", BIN, patchlevel);
554 execv(buf, origargv); /* try again */
555 fatal("Can't run setuid script with taint checks");
560 #ifndef TAINT /* we aren't taintperl or suidperl */
561 if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
562 #ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
563 fstat(fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
564 if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
566 (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
569 fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
570 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
571 #endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
572 /* not set-id, must be wrapped */
574 (void)sprintf(buf, "%s/tperl%s", BIN, patchlevel);
575 execv(buf, origargv); /* try again */
576 fatal("Can't run setuid script with taint checks");
581 #if !defined(IAMSUID) && !defined(TAINT)
583 /* skip forward in input to the real script? */
586 if ((s = str_gets(linestr, rsfp, 0)) == Nullch)
587 fatal("No Perl script found in input\n");
588 if (*s == '#' && s[1] == '!' && instr(s,"perl")) {
589 ungetc('\n',rsfp); /* to keep line count right */
591 if (s = instr(s,"perl -")) {
593 while (s = moreswitches(s)) ;
595 if (cddir && chdir(cddir) < 0)
596 fatal("Can't chdir to %s",cddir);
599 #endif /* !defined(IAMSUID) && !defined(TAINT) */
601 defstab = stabent("_",TRUE);
605 stab_xhash(stabent("_DB",TRUE)) = debstash;
607 dbargs = stab_xarray(aadd((tmpstab = stabent("args",TRUE))));
608 tmpstab->str_pok |= SP_MULTI;
609 dbargs->ary_flags = 0;
610 subname = str_make("main",4);
611 DBstab = stabent("DB",TRUE);
612 DBstab->str_pok |= SP_MULTI;
613 DBline = stabent("dbline",TRUE);
614 DBline->str_pok |= SP_MULTI;
615 DBsub = hadd(tmpstab = stabent("sub",TRUE));
616 tmpstab->str_pok |= SP_MULTI;
617 DBsingle = stab_val((tmpstab = stabent("single",TRUE)));
618 tmpstab->str_pok |= SP_MULTI;
619 DBtrace = stab_val((tmpstab = stabent("trace",TRUE)));
620 tmpstab->str_pok |= SP_MULTI;
621 DBsignal = stab_val((tmpstab = stabent("signal",TRUE)));
622 tmpstab->str_pok |= SP_MULTI;
628 bufend = bufptr = str_get(linestr);
630 savestack = anew(Nullstab); /* for saving non-local values */
631 stack = anew(Nullstab); /* for saving non-local values */
632 stack->ary_flags = 0; /* not a real array */
633 afill(stack,63); afill(stack,-1); /* preextend stack */
634 afill(savestack,63); afill(savestack,-1);
636 /* now parse the script */
639 if (yyparse() || error_count) {
641 fatal("%s had compilation errors.\n", origfilename);
643 fatal("Execution of %s aborted due to compilation errors.\n",
648 New(50,loop_stack,128,struct loop);
651 New(51,debname,128,char);
652 New(52,debdelim,128,char);
660 (void)UNLINK(e_tmpname);
663 /* initialize everything that won't change if we undump */
665 if (sigstab = stabent("SIG",allstabs)) {
666 sigstab->str_pok |= SP_MULTI;
670 magicalize("!#?^~=-%.+&*()<>,\\/[|`':\004\t\020\024\027\006");
671 userinit(); /* in case linked C routines want magical variables */
673 amperstab = stabent("&",allstabs);
674 leftstab = stabent("`",allstabs);
675 rightstab = stabent("'",allstabs);
676 sawampersand = (amperstab || leftstab || rightstab);
677 if (tmpstab = stabent(":",allstabs))
678 str_set(STAB_STR(tmpstab),chopset);
679 if (tmpstab = stabent("\024",allstabs))
682 /* these aren't necessarily magical */
683 if (tmpstab = stabent(";",allstabs))
684 str_set(STAB_STR(tmpstab),"\034");
685 if (tmpstab = stabent("]",allstabs)) {
686 str = STAB_STR(tmpstab);
688 str->str_u.str_nval = atof(patchlevel);
691 str_nset(stab_val(stabent("\"", TRUE)), " ", 1);
693 stdinstab = stabent("STDIN",TRUE);
694 stdinstab->str_pok |= SP_MULTI;
695 stab_io(stdinstab) = stio_new();
696 stab_io(stdinstab)->ifp = stdin;
697 tmpstab = stabent("stdin",TRUE);
698 stab_io(tmpstab) = stab_io(stdinstab);
699 tmpstab->str_pok |= SP_MULTI;
701 tmpstab = stabent("STDOUT",TRUE);
702 tmpstab->str_pok |= SP_MULTI;
703 stab_io(tmpstab) = stio_new();
704 stab_io(tmpstab)->ofp = stab_io(tmpstab)->ifp = stdout;
705 defoutstab = tmpstab;
706 tmpstab = stabent("stdout",TRUE);
707 stab_io(tmpstab) = stab_io(defoutstab);
708 tmpstab->str_pok |= SP_MULTI;
710 curoutstab = stabent("STDERR",TRUE);
711 curoutstab->str_pok |= SP_MULTI;
712 stab_io(curoutstab) = stio_new();
713 stab_io(curoutstab)->ofp = stab_io(curoutstab)->ifp = stderr;
714 tmpstab = stabent("stderr",TRUE);
715 stab_io(tmpstab) = stab_io(curoutstab);
716 tmpstab->str_pok |= SP_MULTI;
717 curoutstab = defoutstab; /* switch back to STDOUT */
719 statname = Str_new(66,0); /* last filename we did stat on */
721 /* now that script is parsed, we can modify record separator */
726 str_nset(stab_val(stabent("/", TRUE)), rs, rslen);
731 just_doit: /* come here if running an undumped a.out */
732 argc--,argv++; /* skip name of script */
734 for (; argc > 0 && **argv == '-'; argc--,argv++) {
735 if (argv[0][1] == '-') {
739 if (s = index(argv[0], '=')) {
741 str_set(stab_val(stabent(argv[0]+1,TRUE)),s);
744 str_numset(stab_val(stabent(argv[0]+1,TRUE)),(double)1.0);
750 if (tmpstab = stabent("0",allstabs)) {
751 str_set(stab_val(tmpstab),origfilename);
752 magicname("0", Nullch, 0);
754 if (tmpstab = stabent("\030",allstabs))
755 str_set(stab_val(tmpstab),origargv[0]);
756 if (argvstab = stabent("ARGV",allstabs)) {
757 argvstab->str_pok |= SP_MULTI;
758 (void)aadd(argvstab);
759 aclear(stab_array(argvstab));
760 for (; argc > 0; argc--,argv++) {
761 (void)apush(stab_array(argvstab),str_make(argv[0],0));
765 (void) stabent("ENV",TRUE); /* must test PATH and IFS */
767 if (envstab = stabent("ENV",allstabs)) {
768 envstab->str_pok |= SP_MULTI;
770 hclear(stab_hash(envstab), FALSE);
773 for (; *env; env++) {
774 if (!(s = index(*env,'=')))
777 str = str_make(s--,0);
778 str_magic(str, envstab, 'E', *env, s - *env);
779 (void)hstore(stab_hash(envstab), *env, s - *env, str, 0);
786 if (tmpstab = stabent("$",allstabs))
787 str_numset(STAB_STR(tmpstab),(double)getpid());
794 if (setjmp(top_env)) /* sets goto_targ on longjump */
795 loop_ptr = -1; /* start label stack again */
801 fprintf(stderr,"\nEXECUTING...\n\n");
805 fprintf(stderr,"%s syntax OK\n", origfilename);
811 (void) cmd_exec(main_root,G_SCALAR,-1);
814 fatal("Can't find label \"%s\"--aborting",goto_targ);
826 while (*sym = *list++)
827 magicname(sym, Nullch, 0);
831 magicname(sym,name,namlen)
838 if (stab = stabent(sym,allstabs)) {
839 stab_flags(stab) = SF_VMAGIC;
840 str_magic(stab_val(stab), stab, 0, name, namlen);
845 savelines(array, str)
849 register char *s = str->str_ptr;
850 register char *send = str->str_ptr + str->str_cur;
852 register int line = 1;
854 while (s && s < send) {
855 STR *tmpstr = Str_new(85,0);
863 str_nset(tmpstr, s, t - s);
864 astore(array, line++, tmpstr);
869 /* this routine is in perl.c by virtue of being sort of an alternate main() */
872 do_eval(str,optype,stash,gimme,arglast)
879 STR **st = stack->ary_array;
881 CMD *myroot = Nullcmd;
884 CMD * VOLATILE oldcurcmd = curcmd;
885 VOLATILE int oldtmps_base = tmps_base;
886 VOLATILE int oldsave = savestack->ary_fill;
887 VOLATILE int oldperldb = perldb;
888 SPAT * VOLATILE oldspat = curspat;
889 SPAT * VOLATILE oldlspat = lastspat;
890 static char *last_eval = Nullch;
891 static CMD *last_root = Nullcmd;
892 VOLATILE int sp = arglast[0];
897 tmps_base = tmps_max;
898 if (curstash != stash) {
899 (void)savehptr(&curstash);
902 str_set(stab_val(stabent("@",TRUE)),"");
903 if (curcmd->c_line == 0) /* don't debug debugger... */
906 if (optype == O_EVAL) { /* normal eval */
907 curcmd->c_filestab = fstab("(eval)");
909 str_sset(linestr,str);
910 str_cat(linestr,";\n"); /* be kind to them */
912 savelines(stab_xarray(curcmd->c_filestab), linestr);
915 if (last_root && !in_eval) {
921 specfilename = str_get(str);
923 if (optype == O_REQUIRE && &str_undef !=
924 hfetch(stab_hash(incstab), specfilename, strlen(specfilename), 0)) {
926 tmps_base = oldtmps_base;
931 tmpfilename = savestr(specfilename);
932 if (index("/.", *tmpfilename))
933 rsfp = fopen(tmpfilename,"r");
935 ar = stab_array(incstab);
936 for (i = 0; i <= ar->ary_fill; i++) {
937 (void)sprintf(buf, "%s/%s",
938 str_get(afetch(ar,i,TRUE)), specfilename);
939 rsfp = fopen(buf,"r");
943 if (*s == '.' && s[1] == '/')
945 Safefree(tmpfilename);
946 tmpfilename = savestr(s);
951 curcmd->c_filestab = fstab(tmpfilename);
952 Safefree(tmpfilename);
953 tmpfilename = Nullch;
956 tmps_base = oldtmps_base;
957 if (optype == O_REQUIRE) {
958 sprintf(tokenbuf,"Can't locate %s in @INC", specfilename);
959 if (instr(tokenbuf,".h "))
960 strcat(tokenbuf," (change .h to .ph maybe?)");
961 if (instr(tokenbuf,".ph "))
962 strcat(tokenbuf," (did you run h2ph?)");
963 fatal("%s",tokenbuf);
965 if (gimme != G_ARRAY)
966 st[++sp] = &str_undef;
973 oldoldbufptr = oldbufptr = bufptr = str_get(linestr);
974 bufend = bufptr + linestr->str_cur;
975 if (++loop_ptr >= loop_max) {
977 Renew(loop_stack, loop_max, struct loop);
979 loop_stack[loop_ptr].loop_label = "_EVAL_";
980 loop_stack[loop_ptr].loop_sp = sp;
983 deb("(Pushing label #%d _EVAL_)\n", loop_ptr);
987 if (setjmp(loop_stack[loop_ptr].loop_env)) {
994 retval |= error_count;
996 else if (last_root && *bufptr == *last_eval && strEQ(bufptr,last_eval)){
998 eval_root = last_root; /* no point in reparsing */
1000 else if (in_eval == 1) {
1002 Safefree(last_eval);
1004 cmd_free(last_root);
1006 last_root = Nullcmd;
1007 last_eval = savestr(bufptr);
1009 retval |= error_count;
1011 last_root = eval_root;
1013 Safefree(last_eval);
1020 myroot = eval_root; /* in case cmd_exec does another eval! */
1023 st = stack->ary_array;
1025 if (gimme != G_ARRAY)
1026 st[++sp] = &str_undef;
1028 #ifndef MANGLEDPARSE
1031 fprintf(stderr,"Freeing eval_root %lx\n",(long)eval_root);
1033 cmd_free(eval_root);
1035 if (eval_root == last_root)
1036 last_root = Nullcmd;
1037 eval_root = myroot = Nullcmd;
1046 sp = cmd_exec(eval_root,gimme,sp);
1047 st = stack->ary_array;
1048 for (i = arglast[0] + 1; i <= sp; i++)
1049 st[i] = str_mortal(st[i]);
1050 /* if we don't save result, free zaps it */
1051 if (in_eval != 1 && myroot != last_root)
1059 char *tmps = loop_stack[loop_ptr].loop_label;
1060 deb("(Popping label #%d %s)\n",loop_ptr,
1065 tmps_base = oldtmps_base;
1067 lastspat = oldlspat;
1068 if (savestack->ary_fill > oldsave) /* let them use local() */
1069 restorelist(oldsave);
1071 if (optype != O_EVAL) {
1073 if (optype == O_REQUIRE)
1074 fatal("%s", str_get(stab_val(stabent("@",TRUE))));
1078 if (gimme == G_SCALAR ? str_true(st[sp]) : sp > arglast[0]) {
1079 (void)hstore(stab_hash(incstab), specfilename,
1080 strlen(specfilename), str_smake(stab_val(curcmd->c_filestab)),
1083 else if (optype == O_REQUIRE)
1084 fatal("%s did not return a true value", specfilename);
1091 /* This routine handles any switches that can be given during run */
1102 nrschar = scanoct(s, 4, &numlen);
1103 nrs = nsavestr("\n",1);
1105 if (nrschar > 0377) {
1109 else if (!nrschar && numlen >= 2) {
1125 if (euid != uid || egid != gid)
1126 fatal("No -d allowed in setuid scripts");
1134 if (euid != uid || egid != gid)
1135 fatal("No -D allowed in setuid scripts");
1137 debug = atoi(s+1) | 32768;
1139 warn("Recompile perl with -DDEBUGGING to use -D switch\n");
1141 for (s++; isdigit(*s); s++) ;
1144 inplace = savestr(s+1);
1145 for (s = inplace; *s && !isspace(*s); s++) ;
1150 if (euid != uid || egid != gid)
1151 fatal("No -I allowed in setuid scripts");
1154 (void)apush(stab_array(incstab),str_make(s,0));
1157 fatal("No space allowed after -I");
1163 ors = savestr("\n");
1165 *ors = scanoct(s, 3 + (*s == '0'), &numlen);
1169 ors = nsavestr(nrs,nrslen);
1190 fputs("\nThis is perl, version 4.0\n\n",stdout);
1191 fputs(rcsid,stdout);
1192 fputs("\nCopyright (c) 1989, 1990, 1991, Larry Wall\n",stdout);
1194 fputs("MS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis\n",
1197 fputs("OS/2 port Copyright (c) 1990, Raymond Chen, Kai Uwe Rommel\n",
1202 Perl may be copied only under the terms of the GNU General Public License,\n\
1203 a copy of which can be found with the Perl 4.0 distribution kit.\n",stdout);
1217 fatal("Switch meaningless after -x: -%s",s);
1222 /* compliments of Tom Christiansen */
1224 /* unexec() can be found in the Gnu emacs distribution */
1231 static char dumpname[BUFSIZ];
1232 static char perlpath[256];
1234 sprintf (dumpname, "%s.perldump", origfilename);
1235 sprintf (perlpath, "%s/perl", BIN);
1237 status = unexec(dumpname, perlpath, &etext, sbrk(0), 0);
1239 fprintf(stderr, "unexec of %s into %s failed!\n", perlpath, dumpname);
1243 abort(); /* nothing else to do */
1246 # define SIGABRT SIGILL
1249 # define SIGILL 6 /* blech */
1251 kill(getpid(),SIGABRT); /* for use with undump */
1252 #endif /* ! MSDOS */