c语言 - 用于'less' linux 命令/使'less'安全的备用程序



我想为Linux编写一个交互式程序,例如"less"命令。我不能在我的设置中使用更少的原因,因为您可以在较少提示的"!cmd"中执行 shell 命令,这对任何生产盒来说都是一个重大的安全风险。

我的首选语言是C,但是,如果有人可以建议任何其他类似的程序,由于我手里的时间,这些程序也会很棒。

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

太神奇了,我在 Man 页面中得到了 less 本身的答案。您可以使用其中一个变量禁用这些内容。

安全 当环境变量 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.

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

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