Re: Automatic proxy configuration in dispatcher.d



I don't need superuser rights. Network Manager's dispatcher.d runs as
superuser, and I need to execute commands as a particular user to set
its proxy configuration in gconf. As root, it is not possible to
change user's gconf, because it cannot connect to the user's gconfd.

2011/9/21 José Queiroz <zekkerj gmail com>:
> I don't think so. Consider if super-user rights is really needed inside the
> script, if so, use SUID-root. It's lame, but works.
>
> 2011/9/21 José Moyano <josehmoyano gmail com>
>>
>> Hi José Queiroz (tocayo ;)
>>
>> Do you think that su $user -c will work instead of sudo?
>>
>> 2011/9/21 José Queiroz <zekkerj gmail com>:
>> > Hello Jose Moyano,
>> >
>> > "sudo" only works if run from a valid terminal. This may be the problem
>> > with
>> > your script.
>> >
>> > 2011/9/21 José Moyano <josehmoyano gmail com>
>> >>
>> >> Hi everybody,
>> >>
>> >> I write the following script to make network manager dispatcher to
>> >> change the proxy automagically based on site IP.
>> >>
>> >> #!/bin/sh
>> >>
>> >> IF=$1
>> >> STATUS=$2
>> >>
>> >> echo
>> >> "-----------------------------------------------------------------"
>> >> >> \
>> >>    /var/log/autoproxy.log
>> >>
>> >> date >> /var/log/autoproxy.log
>> >>
>> >> echo "Configuring proxy..." >> /var/log/autoproxy.log
>> >> NETMASK=<somemask>
>> >>
>> >> if [ -n "`/sbin/ip addr show to $NETMASK`" ]; then
>> >>    echo "Address with proxy detected..." >> /var/log/autoproxy.log
>> >>
>> >>    PROXY_HOST="proxy.something.ar"
>> >>    PROXY_PORT="8080"
>> >>
>> >>    for user in "jose"
>> >>    do
>> >>        echo "Setting proxy for user $user" >> /var/log/autoproxy.log
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf --type string \
>> >>            --set /system/http_proxy/host $PROXY_HOST >> \
>> >>            /var/log/autoproxy.log
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf --type int \
>> >>            --set /system/http_proxy/port $PROXY_PORT >> \
>> >>            /var/log/autoproxy.log
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf --type bool \
>> >>            --set /system/http_proxy/use_same_proxy true >> \
>> >>            /var/log/autoproxy.log
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf --type bool \
>> >>            --set /system/http_proxy/use_http_proxy true >> \
>> >>            /var/log/autoproxy.log
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf --type string \
>> >>            --set /system/proxy/mode manual >> /var/log/autoproxy.log
>> >>    done
>> >> else
>> >>    echo "The address has no proxy known" >> /var/log/autoproxy.log
>> >>
>> >>    # Clear proxy configuration for all users
>> >>    for user in "jose"
>> >>    do
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf \
>> >>            --unset /system/http_proxy/host
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf \
>> >>            --unset /system/http_proxy/port
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf \
>> >>            --unset /system/http_proxy/use_same_proxy
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf \
>> >>            --unset /system/http_proxy/use_http_proxy
>> >>
>> >>        /usr/bin/sudo -u $user /usr/bin/gconftool-2 \
>> >>            --config-source=xml::/home/$user/.gconf \
>> >>            --unset /system/proxy/mode
>> >>    done
>> >> fi
>> >>
>> >> echo "Proxy configuration done" >> /var/log/autoproxy.log
>> >>
>> >> Funny thing, the script works if executed manually as root. When the
>> >> script is executed by network manager dispatcher, the calls to
>> >> gconftool-2 do nothing. The script is executed because all the log
>> >> printing can be seen in the /var/log/autoproxy.log file. I tried
>> >> adding other commands to the script, printing whoami (replies "root")
>> >> and everything seems to be fine. However, gconftool-2 has no effect in
>> >> the gnome configuration.
>> >> Does anyone know what can be the problem?
>> >> Thanks in advance!
>> >>
>> >> José.
>> >> _______________________________________________
>> >> networkmanager-list mailing list
>> >> networkmanager-list gnome org
>> >> http://mail.gnome.org/mailman/listinfo/networkmanager-list
>> >
>> >
>> > _______________________________________________
>> > networkmanager-list mailing list
>> > networkmanager-list gnome org
>> > http://mail.gnome.org/mailman/listinfo/networkmanager-list
>> >
>> >
>> _______________________________________________
>> networkmanager-list mailing list
>> networkmanager-list gnome org
>> http://mail.gnome.org/mailman/listinfo/networkmanager-list
>
>
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list
>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]