【问题标题】:$(SUDO_USER) Variable inside debian package makefile$(SUDO_USER) debian 包 makefile 中的变量
【发布时间】:2012-01-20 18:02:52
【问题描述】:

所以我正在制作一个 debian 软件包,但是在复制所有文件后,我无法进行一些我想做的权限设置。它是一个网络应用程序并使用 libpcap。所以通常它需要root权限,但这是一个很大的安全问题。 (因为我的程序中的任何妥协都意味着对攻击者的完全 root 访问权限)所以相反,我们创建一个授予 pcap 权限的组,然后将安装用户添加到该组。

在makefile中它看起来像:

setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/myProgram
groupadd -f myGroup
usermod -a -G myGroup $(SUDO_USER)

如果您运行“sudo make install”,这完全可以正常工作。但是当我尝试在 debian 包中的 postinst 脚本中执行此操作时,我得到了这个:

var/lib/dpkg/info/myProgram-1.0.postinst: line 13: SUDO_USER: command not found
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -Z, --selinux-user            new SELinux user mapping for the user account

显然是因为 $(SUDO_USER) 变量为空。这还怎么做?我必须提示用户输入他/她的用户名吗?这听起来非常难看。 或者也许你只是不应该在 debian 包中进行这种配置?

(IE:Wireshark 在这里也有同样的问题,但他们似乎只是把它留给用户,根本不会在安装时弄乱权限。)

【问题讨论】:

    标签: debian packaging


    【解决方案1】:

    您说得对:您不应该知道“安装用户”的用户名,因为可能没有。假设你的包是由apt-cron 运行的,那么“安装用户”的整个概念就没有意义了。

    添加一个具有适当权限的系统范围的组,并在安装日志中留下一条消息,指出需要将用户添加到该组。或者,或者,使用可能适合您目的的预先存在的系统组。

    【讨论】:

      【解决方案2】:

      你肯定可以得到安装用户的用户名,只要去掉那些大括号,因为 bash 把它解释为一个函数

      #!/bin/sh
      # postinst script
      usermod -a -G myGroup $SUDO_USER
      # Do everythhing that you could imagine
      

      但你必须记住:

      1) 这在某些 GUI 应用程序中不起作用,例如 Ubuntu 软件中心

      2) 这绝对是一种不好的做法。所有软件包都必须在首次启动时设置其特定于用户的环境。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-22
        • 1970-01-01
        • 2017-03-17
        • 2016-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多