登录时显示 pam_exec 环境中的对话框?

登录时显示 pam_exec 环境中的对话框?

我用来pam_exec做一些根任务。它们需要一些时间,我想告诉用户稍等一下。

我正在那里执行任务,而不是稍后,因为我需要:

  • 根权限
  • 之前从服务器重新同步主文件任何事物加载到桌面上

我的问题是:我无法显示显示任何内容的窗口。我正在加载此脚本来pam_exec测试这是$DISPLAY问题还是用户问题:

#!/bin/bash

case "$PAM_TYPE" in

    'open_session')

    echo Plain exec &> /tmp/pamexec_output
    yad &>> /tmp/pamexec_output
    echo Set display &>> /tmp/pamexec_output
    DISPLAY=:0 yad &>> /tmp/pamexec_output
    echo Set user lightdm &>> /tmp/pamexec_output
        sudo -u lightdm yad &>> /tmp/pamexec_output
    echo Set user $PAM_USER &>> /tmp/pamexec_output
        sudo -u $PAM_USER yad &>> /tmp/pamexec_output
    echo Set user lightdm and display &>> /tmp/pamexec_output
    DISPLAY=:0 sudo -u lightdm yad &>> /tmp/pamexec_output
    echo Set user $PAM_USER and display &>> /tmp/pamexec_output
    DISPLAY=:0 sudo -u $PAM_USER yad &>> /tmp/pamexec_output
    echo PS AUX &>> /tmp/pamexec_output
    ps aux &>> /tmp/pamexec_output

    ;;

esac

我无法得到答案没有显示任何窗口,并且输出:

Plain exec
No protocol specified
No protocol specified

(yad:25314): Gtk-WARNING **: cannot open display: :0
Set display
No protocol specified
No protocol specified

(yad:25317): Gtk-WARNING **: cannot open display: :0
Set user lightdm
No protocol specified
No protocol specified

(yad:25321): Gtk-WARNING **: cannot open display: :0
Set user jorge.suarez
No protocol specified
No protocol specified

(yad:25325): Gtk-WARNING **: cannot open display: :0
Set user lightdm and display
No protocol specified
No protocol specified

(yad:25328): Gtk-WARNING **: cannot open display: :0
Set user jorge.suarez and display
No protocol specified
No protocol specified

(yad:25331): Gtk-WARNING **: cannot open display: :0

作为奖励,这是最终输出,来自ps aux.也许这会有所帮助:

PS AUX
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  26684  2488 ?        Ss   Jan24   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [kworker/u:0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         8  0.0  0.0      0     0 ?        S<   Jan24   0:00 [cpuset]
root         9  0.0  0.0      0     0 ?        S<   Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [kdevtmpfs]
root        11  0.0  0.0      0     0 ?        S<   Jan24   0:00 [netns]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [sync_supers]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [bdi-default]
root        14  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kintegrityd]
root        15  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kblockd]
root        16  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ata_sff]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [khubd]
root        18  0.0  0.0      0     0 ?        S<   Jan24   0:00 [md]
root        21  0.0  0.0      0     0 ?        S    Jan24   0:00 [khungtaskd]
root        22  0.0  0.0      0     0 ?        S    Jan24   0:00 [kswapd0]
root        23  0.0  0.0      0     0 ?        SN   Jan24   0:00 [ksmd]
root        24  0.0  0.0      0     0 ?        SN   Jan24   0:00 [khugepaged]
root        25  0.0  0.0      0     0 ?        S    Jan24   0:00 [fsnotify_mark]
root        26  0.0  0.0      0     0 ?        S    Jan24   0:00 [ecryptfs-kthrea]
root        27  0.0  0.0      0     0 ?        S<   Jan24   0:00 [crypto]
root        35  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kthrotld]
root        36  0.0  0.0      0     0 ?        S    Jan24   0:00 [scsi_eh_0]
root        37  0.0  0.0      0     0 ?        S    Jan24   0:08 [scsi_eh_1]
root        38  0.0  0.0      0     0 ?        S    Jan24   0:00 [kworker/u:2]
root        59  0.0  0.0      0     0 ?        S<   Jan24   0:00 [devfreq_wq]
root       206  0.0  0.0      0     0 ?        S    Jan24   0:02 [jbd2/vda5-8]
root       207  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       227  0.0  0.1  30844  1256 ?        S    Jan24   0:00 mountall --daemon
root       302  0.0  0.0  17224   640 ?        S    Jan24   0:00 upstart-udev-bridge --daemon
root       305  0.0  0.2  24524  2172 ?        Ss   Jan24   0:00 /sbin/udevd --daemon
root       431  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kpsmoused]
root       504  0.0  0.1  19192  1032 ?        Ss   Jan24   0:00 rpcbind -w
root       513  0.0  0.0      0     0 ?        S    Jan24   0:00 [jbd2/vda6-8]
root       514  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       532  0.0  0.0  15180   404 ?        S    Jan24   0:00 upstart-socket-bridge --daemon
root       570  0.0  0.0      0     0 ?        S    Jan24   0:00 [jbd2/vda7-8]
root       573  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       655  0.0  0.0      0     0 ?        S<   Jan24   0:00 [rpciod]
root       658  0.0  0.0      0     0 ?        S<   Jan24   0:00 [nfsiod]
root       669  0.0  0.2  49948  2716 ?        Ss   Jan24   0:00 /usr/sbin/sshd -D
102        679  0.0  0.2  27184  2536 ?        Ss   Jan24   0:17 dbus-daemon --system --fork --activation=upstart
root       709  0.0  0.3  79036  3096 ?        Ss   Jan24   0:00 /usr/sbin/modem-manager
root       717  0.0  0.1  21180  1692 ?        Ss   Jan24   0:00 /usr/sbin/bluetoothd
syslog     733  0.0  0.1 249464  1404 ?        Sl   Jan24   0:02 rsyslogd -c5
root       738  0.0  0.5 229848  5260 ?        Ssl  Jan24   0:05 NetworkManager
root       746  0.0  0.0      0     0 ?        S<   Jan24   0:00 [krfcommd]
root       756  0.0  0.6 188336  5844 ?        Sl   Jan24   0:23 /usr/lib/policykit-1/polkitd --no-debug
statd      773  0.0  0.1  21496  1312 ?        Ss   Jan24   0:00 rpc.statd -L
avahi      780  0.0  0.1  34396  1716 ?        S    Jan24   0:00 avahi-daemon: registering [ctdeskxyy.local]
avahi      781  0.0  0.0  34268   472 ?        S    Jan24   0:00 avahi-daemon: chroot helper
root       787  0.0  0.1   7256  1508 ?        S    Jan24   0:00 /sbin/dhclient -d -4 -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /var/run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/dhcp/dhclient-05584152-142d-425d-b5b9-1e63697e0637-eth0.lease -cf /var/run/nm-dhclient-eth0.conf eth0
colord     808  0.0  1.2 491876 11588 ?        Sl   Jan24   0:01 /usr/lib/x86_64-linux-gnu/colord/colord
root       938  0.0  0.0  19980   932 tty4     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty4
root       948  0.0  0.0  19980   940 tty5     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty5
root       961  0.0  0.2  69768  1904 tty3     Ss   Jan24   0:00 /bin/login --             
root       964  0.0  0.0  19980   936 tty6     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty6
root       983  0.0  0.0   4452   812 ?        Ss   Jan24   0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
root       984  0.0  0.1  19104  1024 ?        Ss   Jan24   0:00 cron
daemon     985  0.0  0.0  16900   372 ?        Ss   Jan24   0:00 atd
root       991  0.0  0.3 262560  3396 ?        Ssl  Jan24   0:01 lightdm
whoopsie   993  0.0  0.5 202176  5024 ?        Ssl  Jan24   0:01 whoopsie
nobody    1001  0.0  0.1  33016  1252 ?        S    Jan24   0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.0.1 --conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=0 --proxy-dnssec
root      1023  0.0  0.1 701376  1192 ?        Ssl  Jan24   0:00 /usr/sbin/nscd
nslcd     1111  0.0  0.2 443796  1916 ?        Ssl  Jan24   0:00 /usr/sbin/nslcd
root      1254  0.0  0.4 586496  4152 ?        Sl   Jan24   0:08 /usr/sbin/console-kit-daemon --no-daemon
root      1362  0.0  0.0      0     0 ?        S    Jan24   0:01 [flush-253:0]
root      1534  0.0  0.2  76052  2032 tty1     Ss   Jan24   0:00 /bin/login --              
root      1536  0.0  0.4 219940  4272 ?        Sl   Jan24   0:01 /usr/lib/upower/upowerd
rtkit     1567  0.0  0.1 160644  1136 ?        SNl  Jan24   0:00 /usr/lib/rtkit/rtkit-daemon
1000      1782  0.0  0.4  19556  4676 tty1     S    Jan24   0:00 -bash
root      1930  0.0  0.2  66712  1904 tty1     S    Jan24   0:00 sudo su
root      1931  0.0  0.1  66472  1816 tty1     S    Jan24   0:00 su
root      1941  0.0  0.2  17260  2324 tty1     S+   Jan24   0:01 bash
root      1965  0.0  0.0      0     0 ?        S    Jan24   0:00 [lockd]
root      2505  0.0  0.3 193524  3628 ?        Sl   Jan24   0:01 /usr/lib/udisks/udisks-daemon
root      2506  0.0  0.0  45512   804 ?        S    Jan24   0:00 udisks-daemon: not polling any devices
root      5436  0.0  0.4  98476  4256 ?        Ss   08:01   0:00 /usr/sbin/cupsd -F
root     11778  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfs_mru_cache]
root     11779  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfslogd]
root     11780  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfsdatad]
root     11781  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfsconvertd]
root     11784  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsIO]
root     11785  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsCommit]
root     11786  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsSync]
root     13718  0.0  0.0      0     0 ?        Z    Jan24   0:00 [lightdm] <defunct>
root     14197  0.0  0.1  24520  1640 ?        S    08:03   0:00 /sbin/udevd --daemon
root     14198  0.0  0.0      0     0 ?        S<   08:03   0:00 [iprt]
root     16911  0.0  0.2  69768  1904 tty2     Ss   Jan24   0:00 /bin/login --             
root     18750  0.0  0.3 124052  3712 ?        Sl   09:12   0:00 /usr/lib/accountsservice/accounts-daemon
root     21715  0.0  0.0      0     0 ?        Z    09:20   0:00 [lightdm] <defunct>
4004     23593  0.0  0.3 207504  3592 ?        Sl   09:35   0:00 /usr/lib/deja-dup/deja-dup/deja-dup-monitor
root     24087  0.0  0.0      0     0 ?        S    09:42   0:00 [kworker/0:1]
root     24355  0.0  0.0      0     0 ?        S    09:47   0:00 [kworker/0:2]
root     24581  0.1  2.6 122056 24912 ?        SN   09:48   0:00 /usr/bin/python /usr/sbin/aptd
root     25026  0.1  0.0      0     0 ?        S    09:52   0:00 [kworker/0:0]
root     25134  1.8  2.6 148396 25280 tty7     Ss+  09:53   0:00 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root     25226  0.0  0.3 155028  3136 ?        Sl   09:53   0:00 lightdm --session-child 12 385
lightdm  25258  0.1  0.5 344020  5200 ?        S<l  09:53   0:00 /usr/bin/pulseaudio --start --log-target=syslog
lightdm  25263  0.0  0.3  95984  3240 ?        S    09:53   0:00 /usr/lib/pulseaudio/pulse/gconf-helper
root     25313  0.0  0.1  16516  1376 ?        Ss   09:54   0:00 /bin/bash /usr/local/lib/puppet-files/gestion-sesiones.sh log=/tmp/cosaaaa
root     25334  0.0  0.1  14144  1020 ?        R    09:54   0:00 ps aux
4004     26833  0.0  0.5 362740  5676 ?        S<l  Jan24   0:01 /usr/bin/pulseaudio --start --log-target=syslog
4004     26836  0.0  0.3  95968  3256 ?        S    Jan24   0:00 /usr/lib/pulseaudio/pulse/gconf-helper
root     28396  0.0  0.0      0     0 ?        Z    Jan24   0:00 [lightdm] <defunct>
4004     29073  0.0  0.4  19536  4660 tty2     S+   Jan24   0:00 -bash
4004     29256  0.0  0.4  19488  4468 tty3     S+   Jan24   0:00 -bash

另一个有趣的发现。这个脚本:

#!/bin/bash

case "$PAM_TYPE" in

    'open_session')

    (
         sleep 5
         yad &> /tmp/pam_output
    ) &

    ;;

esac

它可以工作,但窗口是在桌面加载后显示的。所以这没有帮助。

它也可以在注销时使用,没有问题。

关于如何解决这个问题有什么想法吗?

答案1

您可以将 pam_exec 写入文件(就像使用 /tmp/pam_output 一样),并在用户登录之前由 lightdm 执行一个单独的守护进程,该守护进程监视 /tmp/pam_output 和当看到新输出时会弹出一条注释。 lightdm 运行的后台进程已经设置了 X 环境和 X11 cookie,并且将在 lightdm 用户而不是 root 的上下文中运行,无论如何,这更安全。看本文档当欢迎程序启动时启动脚本。

相关内容