3

我想为 Linux 编写一个交互式程序,例如“less”命令。原因我不能在我的设置中使用 less,因为你可以在 less 提示符 '!cmd' 中执行 shell 命令,这对于任何生产机器来说都是一个主要的安全风险。

我的首选语言是 C,但是,由于我手头的时间,如果有人能推荐任何其他类似的程序也会很棒。

我知道一种选择是浏览较少的源代码,但看起来这在短时间内也不是很直接。

4

2 回答 2

9

太棒了,我在少本身的手册页中得到了答案。您可以使用其中一个变量禁用这些东西。

SECURITY 当环境变量 LESSSECURE 设置为 1 时,less 在“安全”模式下运行。这意味着这些功能被禁用:

          !      the shell command

          |      the pipe command

          :e     the examine command.

          v      the editing command

          s  -o  log files

          -k     use of lesskey files

          -t     use of tags files

                 metacharacters in filenames, such as *

                 filename completion (TAB, ^L)

   Less can also be compiled to be permanently in "secure" mode.
于 2014-04-02T14:57:22.897 回答
-2

'less' / 'more' 本身就是进程或程序。您读取了您运行的另一个命令的 o/p(可能您将使用管道 | 重定向),并像文件一样解析它们并每 10 行打印一次。

这可以通过简单地使用 python 或 C 来完成。但逻辑应该相同

于 2014-04-02T15:00:16.450 回答