大网数据广告活动
服务器运维问答

How to create conditional behaviour with pam_exec and PAM_TYPE?

· 52CE 我爱测

I want to implement conditions for PAM_TYPE open_session and close_session. With this I can trigger different actions at different times for login and logout. I have a script which tests for the variable PAM_TYPE and give appropr…

问题原文

原帖链接 · h___m · CC BY-SA 4.0

I want to implement conditions for PAM_TYPE open_session and close_session. With this I can trigger different actions at different times for login and logout.

I have a script which tests for the variable PAM_TYPE and give appropriate exit codes: exit 0 for success and exit 1 otherwise.

But I get weird problems with the assembly; pam_exec don't get the right exit codes from the script.

Here is my implementation for testing:

In /etc/pam.d/common-session I have added:

session [success=ignore default=1] pam_exec.so debug seteuid /usr/sbin/test.sh logout
session optional        pam_exec.so debug log=/tmp/test_pam.txt /bin/echo "logout reached"
session [success=1 default=ignore] pam_exec.so debug seteuid /usr/sbin/test.sh logout
session optional        pam_exec.so  debug log=/tmp/test_pam.txt /bin/echo "login reached"

The script /usr/sbin/test.sh is

#!/bin/bash
# some actions
# invocted by pam_exec.so

echo $PAM_TYPE
case $1 in
logout)
  if [ $PAM_TYPE == "close_session" ]; then echo $PAM_TYPE; exit 0; else exit 1; fi
  ;;
esac

When I make a su to an user and immediately a logout I get in the log-file

$ cat /tmp/test_pam.txt 
*** Mon Jun  3 12:14:07 2019
"login reached"
*** Mon Jun  3 12:15:00 2019
"login reached"

This behavior is weird. The last line must be logout reached.
So Pam takes every time the condition to false. But for testing I have placed echo $PAM_TYPE; in the true-condition and this echo is displayed in the terminal by logout. So the if Statement leads to true with exit 0 but pam_exec takes it as false.

Has someone an idea what is going wrong?

Thanks in advance,

Helge

已采纳解答

原帖链接 · h___m · CC BY-SA 4.0

I have this answer from another site:

You cannot depend on jumps in PAM stack in the close_session calls. The pam module stack is "frozen" in the open_session and identical modules in the same order are invoked in the close_session call.

The behavior of my scripts is now clear: My approach is not possible!

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-06-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。