Re: [SLUG] Masquerading as another user on boot

From: Paul M Foster (paulf@quillandmouse.com)
Date: Mon Aug 17 2009 - 22:01:39 EDT


On Mon, Aug 10, 2009 at 11:28:03PM -0400, Eben King wrote:

> On Mon, 10 Aug 2009, Paul M Foster wrote:
>
>> On Mon, Aug 10, 2009 at 10:45:48PM -0400, Chris Mathey wrote:
>>
>>> Paul M Foster wrote:
>>>> I just set up a centralized mailserver for our network. As configured, a
>>>> fetchmail process runs as a daemon for each user. (Fetchmail run as a
>>>> single, central daemon dumps email into /var/mail/fetchmail, instead of
>>>> the individual spool files.) If I have to restart that system for some
>>>> reason, I'd like a way to restart the individual fetchmail daemons (all
>>>> two of them). But they run under the UID of the individual users who
>>>> issue the fetchmail command. Rather than having to ssh into that server
>>>> as each user and issue a fetchmail command, I'd like a way (preferably a
>>>> script) which will lauch the two fetchmail instances as the individual
>>>> users without my intervention. I know, tall order.
>>>>
>>>> Any ideas?
>>>>
>>>>
>>> If you are running fetchamil in daemon mode then all you need is
>>> /etc/fetchmailrc. Add "poll" for each user.
>>> If a users wants to set up an individual one then they can create their
>>> own file in ~/
>>
>> Here's the problem: unless you use "multidrop mode", which is hairy and
>> which I don't fully understand, if you just run a central fetchmail
>> daemon, the mail dumps into /var/mail/fetchmail. What I need instead is
>> for mail for me to end up in /var/mail/paulf and mail for Nancy to end
>> up in /var/mail/nancyf. Hence the need for two separate user-launched
>> fetchmail daemons.
>
> First guess:
>
> /bin/foo:
> ,--
> | #! /bin/sh
> | for user in $(</var/bar) ; do
> | if [ -e ~"$user"/.fetchmail ] ; then
> | # whatever
> | else
> | sudo "$user" -c $FETCHMAIL_DAEMON_COMMAND_FOR_$user # & if required
> | fi
> | done
> '--
>
> /var/bar:
> ,--
> | user1
> | user2
> ...
> '--

Good start. Actual code:

#!/bin/bash
for user in joe tom ; do
    if [ -e /home/"$user"/.fetchmailrc ] ; then
        sudo -u $user fetchmail
    else
        echo "User $user has no fetchmailrc"
    fi
done

Paul

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 13:23:16 EDT