Running Gentoo 3.4.0

Having recently heard about the /etc/motd file, i tried to have it display random cowsay fortunes. I wrote some random bash script to act as a daemon, feeding the /etc/motd as a named pipe, as seen on some forums.

I don't think there's any problem with the script because cat'ing the pipe works just fine, but the MOTD won't display on login (using a regular file works) !

fira@nyan ~ % cat /etc/motd
/ We didn't put in ^^ because then we'd \
| have to keep telling people what it   |
| means, and then we'd have to keep     |
| telling them why it doesn't short     |
| circuit. :-/                          |
|                                       |
| -- Larry Wall in                      |
\ <199707300650.XAA05515@wall.org>      /
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\

Am i missing something obvious ?

Not using anything like a .hushlogin or whatnot, tried using several shells, pipe is readable a+r.


You're not missing anything obvious. I dug into the source of the pam_motd module to figure this one out.

The trick is that pam_motd does the following with /etc/motd:

  1. Check the size of the file.
  2. Allocate a buffer of that size.
  3. Read the entire file into the buffer.
  4. Output the buffer through whatever output method is in use. (PAM is modular, after all; can't assume it's a terminal.)

Since a pipe doesn't have a file size, this fails at step 1.

EDIT: Why is PAM concerned about the size in the first place? I imagine it's to prevent denials of service, either intentional or unintentional. When PAM checks the file size, it also refuses to output the motd if the file is larger than 64 kbytes. I imagine whoever tried to log into the system would be very sad if someone managed to pipe a DVD movie file into /etc/motd, for example -- not to mention how much memory that might take.

  • Well, in the end I just rebuilt PAM with a custom patch so it would read the pipe correctly if it's one => pastebin.com/bMpbLskH – Fira Jun 2 '12 at 20:25
  • Open source is wonderful that way. ^_^ I added my thoughts on why PAM checks the filesize, which I think you might have suspected from the "needs more checks" note in your patch. I guess the easiest thing to do would be to stop reading the pipe after 64k. – Jander Jun 2 '12 at 23:13

This link will walk you through all essential steps

  • 1
    Nice. You ought to add the steps directly in the answer too, so if the link breaks in the future your answer will still be useful. – Jander Jun 2 '12 at 7:23
  • So, disable the MotD, and show something manually instead ? Why not, but can i do this in a global way, independant of bash ? I'm using ZSH so the contents of /etc/profiles are not executed – Fira Jun 2 '12 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.