我可以自定义 sudo “此事件将被报告”消息吗?

Jul*_*les 20 sudo

是否可以在 Linux 或 BSD 系统上自定义sudo“将报告此事件”消息?我已经在man sudoman sudoers一个Ubuntu 16.04的机器,一台FreeBSD 10.2机器,并在Fedora 23的机器上,我还没有发现任何有用的东西。

Rah*_*hul 30

sudoers的手册下面是你被允许与须藤的conf配置的唯一消息。

badpass_message="Sorry, try again."
Run Code Online (Sandbox Code Playgroud)

但是,要回答您的问题,我们非常欢迎您编译自己的 sudo 副本。

将是您收到的消息。

  • 啊,开源之美。不喜欢什么?自己换吧! (12认同)
  • “换须藤!” *但我不知道怎么做!*“sudo 改变 sudo!” *好的。* (4认同)

meu*_*euh 14

从某种意义上说,这条消息已经是可定制的,因为对于 GNU/Linux 的许多部分来说,它sudo是国际化的,并且使用gettext 本地语言支持来查找大多数字符串以将它们替换为不同语言的区域设置版本。

例如,您可以在此处查看包含条目的法语文件:

msgid "%s is not in the sudoers file.  This incident will be reported.\n"
msgstr "%s n'apparaît pas dans le fichier sudoers. Cet événement sera signalé.\n"

msgid "%s is not allowed to run sudo on %s.  This incident will be reported.\n"
msgstr "%s n'est pas autorisé à exécuter sudo sur %s. Cet événement sera signalé.\n"
Run Code Online (Sandbox Code Playgroud)

那么,要更改您需要为哪种语言/区域设置指定的消息并编辑相应的 NLS 文件。但是,用户可能没有使用区域设置,因此这将不起作用。


或者,您可以使用二进制编辑器将 中出现的字符串替换为大小完全相同且参数数量相同/usr/libexec/sudo/sudoers.so的字符串。由于这将不再与翻译匹配,它将适用于所有语言环境。例如%sgettext

sed < /usr/libexec/sudo/sudoers.so 's/This incident will be reported/This incident WILL BE REPORTED/' >/tmp/sudoers.so
cmp -l /usr/libexec/sudo/sudoers.so /tmp/sudoers.so
Run Code Online (Sandbox Code Playgroud)

使用cmp,以确保你有没有损坏的文件。

  • 您可以通过填充 nul 字符来缩短消息,因为 C 使用以 nul 结尾的字符串。 (3认同)