4

I have a CentOS 7 machine where I'd like to display a message when authentication fails during sudo. I tried to do this by adding a pam_echo line in /etc/pam.d/sudo.

For testing, I created a file, /etc/security/foo, that contains the string 'bar'.

This is my sudo pam stack, /etc/pam.d/sudo: auth include system-auth auth optional pam_echo.so file=/etc/security/foo account include system-auth password include system-auth session optional pam_keyinit.so revoke session required pam_limits.so

For some reason, I don't see this output of pam_echo when I fail to authenticate. $ sudo ls [sudo] password for steve: Sorry, try again. [sudo] password for steve: Sorry, try again. [sudo] password for steve: sudo: 3 incorrect password attempts

I tested the sudo pam stack with pamtester and got the expected result after entering the wrong password. $ pamtester sudo steve authenticate Password: bar

Likewise, I got no output when entering the correct password. $ pamtester sudo steve authenticate Password: pamtester: successfully authenticated

It seems that sudo is somehow overriding or interfering with the pam output. Why would sudo need to do this? Can I change the behavior of sudo so the output gets through?

Steve F
  • 351
  • 1
  • 2
  • 9

1 Answers1

3

I ran sudo and used GDB to do a back-trace. I followed the bread crumbs and found that preventing PAM output is hard coded into sudo.

The backtrace:

#13 0x00007f9879eba7e0 in pam_authenticate (pamh=0x56373c553960, flags=flags@entry=32768) at pam_auth.c:34
#14 0x00007f987a3510de in sudo_pam_verify (pw=, prompt=0x56373c553d00 "[sudo] password for steve: ", auth=, callback=0x7ffea8406880)
    at auth/pam.c:182
#15 0x00007f987a35052c in verify_user (pw=0x56373c54ce98, prompt=prompt@entry=0x56373c553d00 "[sudo] password for steve: ", validated=validated@entry=2, callback=callback@entry=0x7ffea8406880) at auth/sudo_auth.c:294
#16 0x00007f987a3520e5 in check_user (auth_pw=0x56373c54ce98, mode=, validated=2) at ./check.c:149
#17 0x00007f987a3520e5 in check_user (validated=validated@entry=2, mode=) at ./check.c:212
#18 0x00007f987a36506d in sudoers_policy_main (argc=argc@entry=1, argv=argv@entry=0x7ffea8406cf0, pwflag=pwflag@entry=0, env_add=env_add@entry=0x56373c5414f0, closure=closure@entry=0x7ffea84069f0) at ./sudoers.c:423
#19 0x00007f987a35eca4 in sudoers_policy_check (argc=1, argv=0x7ffea8406cf0, env_add=0x56373c5414f0, command_infop=0x7ffea8406a80, argv_out=0x7ffea8406a88, user_env_out=0x7ffea8406a90) at ./policy.c:758
#20 0x000056373aee448f in main (plugin=0x56373b102480 , user_env_out=0x7ffea8406a90, argv_out=0x7ffea8406a88, command_info=0x7ffea8406a80, env_add=0x56373c5414f0, argv=0x7ffea8406cf0, argc=1) at ./sudo.c:1342
#21 0x000056373aee448f in main (argc=, argv=, envp=) at ./sudo.c:261

On lines 181-182 of auth/pam.c, I found that pam_authenticate is called with the PAM_SILENT flag to prevent any output.

    /* PAM_SILENT prevents the authentication service from generating output. */
    *pam_status = pam_authenticate(pamh, PAM_SILENT);
Steve F
  • 351
  • 1
  • 2
  • 9