Bug 237034

Summary: yum-fastestmirror should operate without write access to timedhosts.txt
Product: [Fedora] Fedora Reporter: Christopher Aillon <caillon>
Component: yum-utilsAssignee: Luke Macken <lmacken>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: lmacken, pfrields, tla
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: 1.1.7-1.fc7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-09-18 03:21:19 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Description Flags
Fix fastestmirror plugin to work with nonroot user
Patch none

Description Christopher Aillon 2007-04-18 23:30:43 UTC
Some yum operations, such as yum search traditionally do not require root
access.  But after the mirror cache is set up with root privs, yum commands will
fail if the plugin cannot write to the cache file which is owned by root.  It
should use the values it obtains but simply not write out in this case.

% rpm -qf /usr/lib/yum-plugins/fastestmirror.py
% whoami 
% yum --noplugins search firefox-devel
firefox-devel.i386                       development     
Matched from:
Development files for Firefox.  This package exists temporarily.
When xulrunner has reached version 1.0, firefox-devel will be
removed in favor of xulrunner-devel.
% yum search firefox-devel 
Loading "fastestmirror" plugin
Loading "installonlyn" plugin
Determining fastest mirrors
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in <module>
  File "/usr/share/yum-cli/yummain.py", line 82, in main
  File "/usr/share/yum-cli/cli.py", line 156, in getOptionsConfig
    (opts, self.cmds) = self.optparser.setupYumConfig()
  File "/usr/share/yum-cli/cli.py", line 1149, in setupYumConfig
  File "/usr/share/yum-cli/output.py", line 322, in setupProgessCallbacks
  File "/usr/lib/python2.5/site-packages/yum/__init__.py", line 493, in <lambda>
    repos = property(fget=lambda self: self._getRepos(),
  File "/usr/lib/python2.5/site-packages/yum/__init__.py", line 342, in _getRepos
  File "/usr/lib/python2.5/site-packages/yum/plugins.py", line 162, in run
    func(conduitcls(self, self.base, conf, **kwargs))
  File "/usr/lib/yum-plugins/fastestmirror.py", line 88, in postreposetup_hook
  File "/usr/lib/yum-plugins/fastestmirror.py", line 103, in write_timedhosts
    hostfile = file(hostfilepath, 'w')
IOError: [Errno 13] Permission denied: '/var/cache/yum/timedhosts.txt'
zsh: exit 1     yum search firefox-devel
% ls -hl /var/cache/yum/timedhosts.txt 
-rw-r--r-- 1 root root 578 2007-04-18 16:22 /var/cache/yum/timedhosts.txt

Comment 1 Tim Lauridsen 2007-04-19 12:45:05 UTC
Created attachment 152994 [details]
Fix fastestmirror plugin to work with nonroot user

Comment 2 Tim Lauridsen 2007-04-19 12:46:56 UTC
please check the attached patch, before i submit it.

Comment 3 Christopher Aillon 2007-04-19 16:51:22 UTC
Comment on attachment 152994 [details]
Fix fastestmirror plugin to work with nonroot user

> def postreposetup_hook(conduit):
>     global loadcache
>-    if loadcache:
>+    conf = conduit.getConf()
>+    if loadcache or conf.uid > 0:
>         conduit.info(2, "Loading mirror speeds from cached hostfile")
>         read_timedhosts()
>     else:

Will this handle the case where someone first runs the fastestmirror plugin as
a non-root superuser and then run it from a different non-root user (this might
actually be a different bug here).  I think it might be better to see if the
user has write access to the file.

Comment 4 Luke Macken 2007-04-20 02:50:42 UTC
Tim, it looks like that patch only checks the uid when reading the hostfile,
where as caillon's traceback occurred when fastestmirror writes the hostfile.

Comment 5 Christopher Aillon 2007-08-01 18:02:37 UTC
Created attachment 160442 [details]

Luke, what do you think about this patch?

Comment 6 Luke Macken 2007-08-08 21:55:15 UTC
Applied, thanks!

Comment 7 Fedora Update System 2007-09-10 16:51:49 UTC
yum-utils-1.1.7-1.fc7 has been pushed to the Fedora 7 testing repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Fedora Update System 2007-09-18 03:21:12 UTC
yum-utils-1.1.7-1.fc7 has been pushed to the Fedora 7 stable repository.  If problems still persist, please make note of it in this bug report.