1

I have a simple procmailrc recipe that hands mail off to a script:

LOGFILE=/home/foouser/procmail-log
VERBOSE=yes
MAILDIR=/var/spool/mail/foouser
DEFAULT=/var/spool/mail/foouser
SHELL=/bin/sh
DELIVERED=yes
COMSAT=no

:0
| `/home/foouser/scripts/footool/footool.sh`

The script itself is pretty resilient and reasonably safe. My concern is that the procmail recipe itself might not sanitize correctly and in the process of piping it over, an email that contains, say, ; rm -rf / could wreak havoc. Should I use double-quotes?

MORE INFORMATION

Based on some feedback here, it sounds like I might want to temporarily disable shell metas and use double-quotes.

So that would perhaps change the recommended code implementation to:

LOGFILE=/home/foouser/procmail-log
VERBOSE=yes
MAILDIR=/var/spool/mail/foouser
DEFAULT=/var/spool/mail/foouser
SHELL=/bin/sh
DELIVERED=yes
COMSAT=no
savedMetas  = $SHELLMETAS
SHELLMETAS    # Kill variable

:0
| "/home/foouser/scripts/footool/footool.sh"
SHELLMETAS  = $savedMetas    

Does that look better?

  • 2
    pm-doc.sourceforge.net/doc/… – grebneke Feb 7 '14 at 8:51
  • regular use is without any quotes or backticks after pipe. – user55518 Feb 7 '14 at 13:55
  • @grebneke Forgive my ignorance but I'm not sure I fully understand the article. I added a new example. Can you please review? – Mike B Feb 7 '14 at 16:17
  • @MikeB - Forgive me, I might have misread your post. Will post answer below in a second. – grebneke Feb 7 '14 at 16:56
  • It is extremely unclear what you are trying to accomplish. What is the output of footool.sh? If it outputs shell commands that Procmail should interpret (which your first syntax means) then it should escape them properly before printing them. On the other hand, your attempt at a "fixed" solution does nothing of the sort. Please describe your problem in more detail. Until then, nominating for closing as unclear what you are asking. – tripleee Feb 10 '14 at 17:38
2

This invocation is incorrect, unless you're somehow trying to run a command whose name is the output of footools.sh:

:0
| `/home/foouser/scripts/footool/footool.sh`

This is normal syntax:

:0
| /home/foouser/scripts/footool/footools.sh

procmail will execute footools.sh and pass the email to the script on stdin.

No need for $SHELLMETAS or special escaping. $SHELLMETAS is for unusual cases where you need to send special characters as arguments to your script, but don't want those arguments interpreted by a shell. You can safely ignore it for a simple use case like above.

  • Thanks for the prompt response. I'm getting confused though... in one of the prior links you referenced above, it mentioned adding savedMetas = $SHELLMETAS followed by SHELLMETAS # Kill variable and then SHELLMETAS = $savedMetas at the bottom. That's not needed? It's "safe" with a straight-up pipe? – Mike B Feb 8 '14 at 2:55
  • @MikeB - Yes it's safe. I misunderstood your initial question. No need to touch $SHELLMETAS except for the (unusual) case where your script needs special arguments containing any of the SHELLMETA-characters. It will not influence the data you send on stdin, it concerns special script arguments only. – grebneke Feb 8 '14 at 11:02
  • @grebneke Does this need locking similar to sending the email content to a file? Or is each email's shell invocation in its own session so no locking is required? Thanks. – Vishnu Jan 3 at 17:27
  • 1
    @Vishnu No locking needed at this level. The executed script itself might need locks to manage handling of a shared resource like a file, but that is outside the scope of this question. Basically the script should be designed to handle multiple parallel independent executions of itself. – grebneke Jan 8 at 13:38

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.