On Tue, Mar 20, 2001 at 12:36:13PM -0500, Peter Green wrote:
[snip]
>   #!/bin/bash2
> 
>   # check vmailmgr first; save the environment
>   # /tmp/scr just executes /usr/bin/id
>   ENVIRON = $(/usr/bin/checkvpw /tmp/scr Maildir/)
>   rc=$?
>   if [ $rc -ne 0 ]; then
>           # failed; try vpopmail
>           ENVIRON = $(/usr/local/vpopmail/bin/vchkpw /tmp/scr Maildir/)
>           rc=$?
>           if [ $rc -ne 0 ]; then
>                   # failed all
>                   echo "-ERR Authorization failed"
>                   exit $rc
>           else
>                   export $ENVIRON
>                   exec qmail-pop3d "$@"
>           fi
>   else
>           export $ENVIRON
>           exec qmail-pop3d "$MAILDIR"
>   fi
> 
> It mostly works, since all child processes inherit FD 3 properly. However,
> if the first method fails, it cannot try the second method, since FD 3 has
> already hit EOF; how can I rewind this from bash? Also, if it succeeds, the
> exec line simply does not work; the error is always ``-ERR this user has no
> $HOME/Maildir''. I have double-checked the environment with
> ``env>>/tmp/debug'' after the export call, and home get set properly.
[snip]

You can rewind by saving FD3 to an ordinary file. Try this example:

        #! /bin/sh
        exec 0<&3
        cat>/tmp/pwd

        exec 3</tmp/pwd
        checkpassword qmail-pop3d Maildir

        exec 3</tmp/pwd
        checkpassword qmail-pop3d Maildir

I don't know if you mind the file /tmp/pwd or if it is possible to get
rid of it at all but pop is insecure anyway -- don't forget to create a
unique file instead (and to remove it after the session).

I had the same problem with $HOME/Maildir when I started qmail-pop3d by
itself...

This example isn't all good since qmail-pop3d terminates directly :)

Jörgen

Reply via email to