📄 eval.c
字号:
case O_SHMCTL: case O_SHMREAD: case O_SHMWRITE: fatal("System V IPC is not implemented on this machine");#endif /* not SYSVIPC */ case O_RENAME: tmps = str_get(st[1]); tmps2 = str_get(st[2]);#ifdef TAINT taintproper("Insecure dependency in rename");#endif#ifdef HAS_RENAME value = (double)(rename(tmps,tmps2) >= 0);#else if (same_dirent(tmps2, tmps)) /* can always rename to same name */ anum = 1; else { if (euid || stat(tmps2,&statbuf) < 0 || !S_ISDIR(statbuf.st_mode)) (void)UNLINK(tmps2); if (!(anum = link(tmps,tmps2))) anum = UNLINK(tmps); } value = (double)(anum >= 0);#endif goto donumset; case O_LINK:#ifdef HAS_LINK tmps = str_get(st[1]); tmps2 = str_get(st[2]);#ifdef TAINT taintproper("Insecure dependency in link");#endif value = (double)(link(tmps,tmps2) >= 0); goto donumset;#else fatal("Unsupported function link"); break;#endif case O_MKDIR: tmps = str_get(st[1]); anum = (int)str_gnum(st[2]);#ifdef TAINT taintproper("Insecure dependency in mkdir");#endif#ifdef HAS_MKDIR value = (double)(mkdir(tmps,anum) >= 0); goto donumset;#else (void)strcpy(buf,"mkdir ");#endif#if !defined(HAS_MKDIR) || !defined(HAS_RMDIR) one_liner: for (tmps2 = buf+6; *tmps; ) { *tmps2++ = '\\'; *tmps2++ = *tmps++; } (void)strcpy(tmps2," 2>&1"); rsfp = mypopen(buf,"r"); if (rsfp) { *buf = '\0'; tmps2 = fgets(buf,sizeof buf,rsfp); (void)mypclose(rsfp); if (tmps2 != Nullch) { for (errno = 1; errno < sys_nerr; errno++) { if (instr(buf,sys_errlist[errno])) /* you don't see this */ goto say_zero; } errno = 0;#ifndef EACCES#define EACCES EPERM#endif if (instr(buf,"cannot make")) errno = EEXIST; else if (instr(buf,"existing file")) errno = EEXIST; else if (instr(buf,"ile exists")) errno = EEXIST; else if (instr(buf,"non-exist")) errno = ENOENT; else if (instr(buf,"does not exist")) errno = ENOENT; else if (instr(buf,"not empty")) errno = EBUSY; else if (instr(buf,"cannot access")) errno = EACCES; else errno = EPERM; goto say_zero; } else { /* some mkdirs return no failure indication */ tmps = str_get(st[1]); anum = (stat(tmps,&statbuf) >= 0); if (optype == O_RMDIR) anum = !anum; if (anum) errno = 0; else errno = EACCES; /* a guess */ value = (double)anum; } goto donumset; } else goto say_zero;#endif case O_RMDIR: if (maxarg < 1) tmps = str_get(stab_val(defstab)); else tmps = str_get(st[1]);#ifdef TAINT taintproper("Insecure dependency in rmdir");#endif#ifdef HAS_RMDIR value = (double)(rmdir(tmps) >= 0); goto donumset;#else (void)strcpy(buf,"rmdir "); goto one_liner; /* see above in HAS_MKDIR */#endif case O_GETPPID:#ifdef HAS_GETPPID value = (double)getppid(); goto donumset;#else fatal("Unsupported function getppid"); break;#endif case O_GETPGRP:#ifdef HAS_GETPGRP if (maxarg < 1) anum = 0; else anum = (int)str_gnum(st[1]);#ifdef _POSIX_SOURCE if (anum != 0) fatal("POSIX getpgrp can't take an argument"); value = (double)getpgrp();#else value = (double)getpgrp(anum);#endif goto donumset;#else fatal("The getpgrp() function is unimplemented on this machine"); break;#endif case O_SETPGRP:#ifdef HAS_SETPGRP argtype = (int)str_gnum(st[1]); anum = (int)str_gnum(st[2]);#ifdef TAINT taintproper("Insecure dependency in setpgrp");#endif value = (double)(setpgrp(argtype,anum) >= 0); goto donumset;#else fatal("The setpgrp() function is unimplemented on this machine"); break;#endif case O_GETPRIORITY:#ifdef HAS_GETPRIORITY argtype = (int)str_gnum(st[1]); anum = (int)str_gnum(st[2]); value = (double)getpriority(argtype,anum); goto donumset;#else fatal("The getpriority() function is unimplemented on this machine"); break;#endif case O_SETPRIORITY:#ifdef HAS_SETPRIORITY argtype = (int)str_gnum(st[1]); anum = (int)str_gnum(st[2]); optype = (int)str_gnum(st[3]);#ifdef TAINT taintproper("Insecure dependency in setpriority");#endif value = (double)(setpriority(argtype,anum,optype) >= 0); goto donumset;#else fatal("The setpriority() function is unimplemented on this machine"); break;#endif case O_CHROOT:#ifdef HAS_CHROOT if (maxarg < 1) tmps = str_get(stab_val(defstab)); else tmps = str_get(st[1]);#ifdef TAINT taintproper("Insecure dependency in chroot");#endif value = (double)(chroot(tmps) >= 0); goto donumset;#else fatal("Unsupported function chroot"); break;#endif case O_FCNTL: case O_IOCTL: if (maxarg <= 0) stab = last_in_stab; else if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE); argtype = U_I(str_gnum(st[2]));#ifdef TAINT taintproper("Insecure dependency in ioctl");#endif anum = do_ctl(optype,stab,argtype,st[3]); if (anum == -1) goto say_undef; if (anum != 0) { value = (double)anum; goto donumset; } str_set(str,"0 but true"); STABSET(str); break; case O_FLOCK:#ifdef HAS_FLOCK if (maxarg <= 0) stab = last_in_stab; else if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE); if (stab && stab_io(stab)) fp = stab_io(stab)->ifp; else fp = Nullfp; if (fp) { argtype = (int)str_gnum(st[2]); value = (double)(flock(fileno(fp),argtype) >= 0); } else value = 0; goto donumset;#else fatal("The flock() function is unimplemented on this machine"); break;#endif case O_UNSHIFT: ary = stab_array(arg[1].arg_ptr.arg_stab); if (arglast[2] - arglast[1] != 1) do_unshift(ary,arglast); else { STR *tmpstr = Str_new(52,0); /* must copy the STR */ str_sset(tmpstr,st[2]); aunshift(ary,1); (void)astore(ary,0,tmpstr); } value = (double)(ary->ary_fill + 1); goto donumset; case O_TRY: sp = do_try(arg[1].arg_ptr.arg_cmd, gimme,arglast); goto array_return; case O_EVALONCE: sp = do_eval(st[1], O_EVAL, curcmd->c_stash, TRUE, gimme,arglast); if (eval_root) { str_free(arg[1].arg_ptr.arg_str); arg[1].arg_ptr.arg_cmd = eval_root; arg[1].arg_type = (A_CMD|A_DONT); arg[0].arg_type = O_TRY; } goto array_return; case O_REQUIRE: case O_DOFILE: case O_EVAL: if (maxarg < 1) tmpstr = stab_val(defstab); else tmpstr = (arg[1].arg_type & A_MASK) != A_NULL ? st[1] : stab_val(defstab);#ifdef TAINT tainted |= tmpstr->str_tainted; taintproper("Insecure dependency in eval");#endif sp = do_eval(tmpstr, optype, curcmd->c_stash, FALSE, gimme,arglast); goto array_return; case O_FTRREAD: argtype = 0; anum = S_IRUSR; goto check_perm; case O_FTRWRITE: argtype = 0; anum = S_IWUSR; goto check_perm; case O_FTREXEC: argtype = 0; anum = S_IXUSR; goto check_perm; case O_FTEREAD: argtype = 1; anum = S_IRUSR; goto check_perm; case O_FTEWRITE: argtype = 1; anum = S_IWUSR; goto check_perm; case O_FTEEXEC: argtype = 1; anum = S_IXUSR; check_perm: if (mystat(arg,st[1]) < 0) goto say_undef; if (cando(anum,argtype,&statcache)) goto say_yes; goto say_no; case O_FTIS: if (mystat(arg,st[1]) < 0) goto say_undef; goto say_yes; case O_FTEOWNED: case O_FTROWNED: if (mystat(arg,st[1]) < 0) goto say_undef; if (statcache.st_uid == (optype == O_FTEOWNED ? euid : uid) ) goto say_yes; goto say_no; case O_FTZERO: if (mystat(arg,st[1]) < 0) goto say_undef; if (!statcache.st_size) goto say_yes; goto say_no; case O_FTSIZE: if (mystat(arg,st[1]) < 0) goto say_undef; value = (double)statcache.st_size; goto donumset; case O_FTMTIME: if (mystat(arg,st[1]) < 0) goto say_undef; value = (double)(basetime - statcache.st_mtime) / 86400.0; goto donumset; case O_FTATIME: if (mystat(arg,st[1]) < 0) goto say_undef; value = (double)(basetime - statcache.st_atime) / 86400.0; goto donumset; case O_FTCTIME: if (mystat(arg,st[1]) < 0) goto say_undef; value = (double)(basetime - statcache.st_ctime) / 86400.0; goto donumset; case O_FTSOCK: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISSOCK(statcache.st_mode)) goto say_yes; goto say_no; case O_FTCHR: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISCHR(statcache.st_mode)) goto say_yes; goto say_no; case O_FTBLK: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISBLK(statcache.st_mode)) goto say_yes; goto say_no; case O_FTFILE: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISREG(statcache.st_mode)) goto say_yes; goto say_no; case O_FTDIR: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISDIR(statcache.st_mode)) goto say_yes; goto say_no; case O_FTPIPE: if (mystat(arg,st[1]) < 0) goto say_undef; if (S_ISFIFO(statcache.st_mode)) goto say_yes; goto say_no; case O_FTLINK: if (mylstat(arg,st[1]) < 0) goto say_undef; if (S_ISLNK(statcache.st_mode)) goto say_yes; goto say_no; case O_SYMLINK:#ifdef HAS_SYMLINK tmps = str_get(st[1]); tmps2 = str_get(st[2]);#ifdef TAINT taintproper("Insecure dependency in symlink");#endif value = (double)(symlink(tmps,tmps2) >= 0); goto donumset;#else fatal("Unsupported function symlink");#endif case O_READLINK:#ifdef HAS_SYMLINK if (maxarg < 1) tmps = str_get(stab_val(defstab)); else tmps = str_get(st[1]); anum = readlink(tmps,buf,sizeof buf); if (anum < 0) goto say_undef; str_nset(str,buf,anum); break;#else goto say_undef; /* just pretend it's a normal file */#endif case O_FTSUID:#ifdef S_ISUID anum = S_ISUID; goto check_xid;#else goto say_no;#endif case O_FTSGID:#ifdef S_ISGID anum = S_ISGID; goto check_xid;#else goto say_no;#endif case O_FTSVTX:#ifdef S_ISVTX anum = S_ISVTX;#else goto say_no;#endif check_xid: if (mystat(arg,st[1]) < 0) goto say_undef; if (statcache.st_mode & anum) goto say_yes; goto say_no; case O_FTTTY: if (arg[1].arg_type & A_DONT) { stab = arg[1].arg_ptr.arg_stab; tmps = ""; } else stab = stabent(tmps = str_get(st[1]),FALSE); if (stab && stab_io(stab) && stab_io(stab)->ifp) anum = fileno(stab_io(stab)->ifp); else if (isDIGIT(*tmps)) anum = atoi(tmps); else goto say_undef; if (isatty(anum)) goto say_yes; goto say_no; case O_FTTEXT: case O_FTBINARY: str = do_fttext(arg,st[1]); break;#ifdef HAS_SOCKET case O_SOCKET: if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE);#ifndef lint value = (double)do_socket(stab,arglast);#else (void)do_socket(stab,arglast);#endif goto donumset; case O_BIND: if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE);#ifndef lint value = (double)do_bind(stab,arglast);#else (void)do_bind(stab,arglast);#endif goto donumset; case O_CONNECT: if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE);#ifndef lint value = (double)do_connect(stab,arglast);#else (void)do_connect(stab,arglast);#endif goto donumset; case O_LISTEN: if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE);#ifndef lint value = (double)do_listen(stab,arglast);#else (void)do_listen(stab,arglast);#endif goto donumset; case O_ACCEPT: if ((arg[1].arg_type & A_MASK) == A_WORD) stab = arg[1].arg_ptr.arg_stab; else stab = stabent(str_get(st[1]),TRUE); if ((arg[2].arg_type & A_MASK) == A_WORD) stab2 = arg[2].arg_ptr.arg_stab; else stab2 = stabent(str_get(st[2]),TRUE); do_accept(str,stab,stab2); STABSET(str); break; case O_GHBYNAME: if (maxarg < 1) goto say_undef; case O_GHBYADDR: case O_GHOSTENT: sp = do_ghent(optype, gimme,arglast); goto array_return; case O_GNBYNAME: if (maxarg < 1) goto say_undef; case O_GNBYADDR: case O_GNETENT: sp = do_gnent(optype, gimme,arglast); goto array_return; case O_GPBYNAME: if (maxarg < 1) goto say_undef; case O_GPBYNUMBER: case O_GPROTOEN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -