- uid = (int)getuid();
- euid = (int)geteuid();
- gid = (int)getgid();
- egid = (int)getegid();
- if (!cando(S_IEXEC,TRUE,&statbuf))
- fatal("Permission denied\n"); /* they can't do this */
- }
-#ifdef IAMSUID
- else if (preprocess)
- fatal("-P not allowed for setuid/setgid script\n");
- else
- fatal("Script is not setuid/setgid in suidperl\n");
-#else
-#ifndef TAINT /* we aren't taintperl or suidperl */
- /* script has a wrapper--can't run suidperl or we lose euid */
- else if (euid != uid || egid != gid) {
- (void)fclose(rsfp);
- (void)sprintf(buf, "%s/%s", BIN, "taintperl");
- execv(buf, origargv); /* try again */
- fatal("Can't run setuid script with taint checks");
- }
-#endif /* TAINT */
-#endif /* IAMSUID */
-#else /* !DOSUID */
-#ifndef TAINT /* we aren't taintperl or suidperl */
- if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
-#ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
- fstat(fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
- if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
- ||
- (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
- )
- if (!do_undump)
- fatal("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
-FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
-#endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
- /* not set-id, must be wrapped */
- (void)fclose(rsfp);
- (void)sprintf(buf, "%s/%s", BIN, "taintperl");
- execv(buf, origargv); /* try again */
- fatal("Can't run setuid script with taint checks");
- }
-#endif /* TAINT */
-#endif /* DOSUID */
-
-#if !defined(IAMSUID) && !defined(TAINT)
-
- /* skip forward in input to the real script? */
-
- while (doextract) {
- if ((s = str_gets(linestr, rsfp, 0)) == Nullch)
- fatal("No Perl script found in input\n");
- if (*s == '#' && s[1] == '!' && instr(s,"perl")) {
- ungetc('\n',rsfp); /* to keep line count right */
- doextract = FALSE;
- if (s = instr(s,"perl -")) {
- s += 6;
- while (s = moreswitches(s)) ;
- }
- if (cddir && chdir(cddir) < 0)
- fatal("Can't chdir to %s",cddir);
- }
- }
-#endif /* !defined(IAMSUID) && !defined(TAINT) */
-
- defstab = stabent("_",TRUE);
-
- if (perldb) {
- debstash = hnew(0);
- stab_xhash(stabent("_DB",TRUE)) = debstash;
- curstash = debstash;
- lineary = stab_xarray(aadd((tmpstab = stabent("line",TRUE))));
- tmpstab->str_pok |= SP_MULTI;
- subname = str_make("main",4);
- DBstab = stabent("DB",TRUE);
- DBstab->str_pok |= SP_MULTI;
- DBsub = hadd(tmpstab = stabent("sub",TRUE));
- tmpstab->str_pok |= SP_MULTI;
- DBsingle = stab_val((tmpstab = stabent("single",TRUE)));
- tmpstab->str_pok |= SP_MULTI;
- curstash = defstash;
- }