Bug 6196 - PAR::import conflict with main::changeEffectiveUserAndGroup
: PAR::import conflict with main::changeEffectiveUserAndGroup
Status: CLOSED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Plugins
: 7.0
: PC Linux (other)
: P2 minor (vote)
: 7.x
Assigned To: Andy Grundman
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-11-20 02:31 UTC by Markus Schiegl
Modified: 2011-03-16 04:39 UTC (History)
0 users

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Schiegl 2007-11-20 02:31:54 UTC
If I start SqueezeCenter (trunk 11/19) as root (i.e through an init script) on my Gentoo Box with "--user USER" the following happens (example)

- PAR::import creates a subdirectory
  drwxr-xr-x 2 root other 4096 Nov 20 09:12 /tmp/par-root/cache-6e4c55446ad771d0e176a9b5f1aaed204e0fad50

- After setuid to USER the plugins cannot be extracted using PAR::unpar, see: slimserver.log
  
  [09:11:02.8477] Slim::bootstrap::tryModuleLoad (266) Warning: Module [Plugins::TrackStat::Plugin] failed to load:
  Permission denied at /opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 872.
  BEGIN failed--compilation aborted at (eval 570) line 2.
  [09:11:02.8487] Slim::Utils::PluginManager::enablePlugins (411) Warning: Couldn't load Plugins::TrackStat::Plugin

Workaround:

As the directory name stays the same, I did a "chown -R USER /tmp/par-root" and restarted slimserver.

The root-cause is probably described in https://bugs-archive.lyrion.org/show_bug.cgi?id=5035 but as PAR is new in SS7 it took me while to figure this one out.
Is it possible to fix this? Any other solutions? Otherwise one could use sudo, start-stop-daemon, ... and declare --user and --group deprecated. 

kind regards,
Markus
Comment 1 Andy Grundman 2007-11-26 10:53:28 UTC
Should be fixed in change 14971, please test and reopen if you still have this problem.
Comment 2 Markus Schiegl 2007-11-26 11:18:12 UTC
problem persists.

I added a bit more logging:

...
sub init {
        my $class = shift;
        $log->error("my current id: $<");

        # Bug 6196, Delay PAR loading to init phase so any temp directories
        # are created as the proper user
        require PAR;
        PAR->import;
...

on startup the logfiles shows the process still runs with uid 0 at this moment:

[20:09:14.4092] main::init (293) SqueezeCenter OS Specific init...
[20:09:14.4096] main::init (313) SqueezeCenter daemonizing...
[20:09:14.4171] Slim::bootstrap::theEND (400) Got to the END
[20:09:14.4172] main::init (322) SqueezeCenter settings effective user and group if requested...
[20:09:14.4191] main::changeEffectiveUserAndGroup (844) Running as uid: 1002 / gid: 100 100 100
[20:09:14.4194] main::init (332) SqueezeCenter strings init...
[20:09:14.4252] Slim::Utils::Strings::loadStrings (108) Retrieving string data from string cache: /home/control/stringcache
[20:09:14.4354] main::init (335) SqueezeCenter MySQL init...
[20:09:15.5377] main::init (338) Async DNS init...
[20:09:36.2080] main::init (341) Firmware init...
[20:09:36.2092] main::init (344) SqueezeCenter Info init...
[20:09:36.4716] main::init (347) SqueezeCenter IR init...
[20:09:36.4857] main::init (350) SqueezeCenter Request init...
[20:09:36.4909] main::init (353) SqueezeCenter Buttons init...
[20:09:36.4937] main::init (356) SqueezeCenter Graphic Fonts init...
[20:09:36.6147] main::init (364) UDP init...
[20:09:36.6158] main::init (367) Slimproto Init...
[20:09:36.6166] main::init (370) mDNS init...
[20:09:36.6170] main::init (373) Cache init...
[20:09:36.6195] main::init (377) SqueezeNetwork Sync Init...
[20:09:36.6200] main::init (386) SqueezeCenter HTTP init...
[20:09:36.6264] main::init (389) Source conversion init..
[20:09:36.6292] main::init (394) SqueezeCenter Web Settings init...
[20:09:36.6737] main::init (398) SqueezeCenter Jive init...
[20:09:36.6744] main::init (401) SqueezeCenter Plugins init...
[20:09:36.6747] Slim::Utils::PluginManager::init (73) my current id: 0
[20:09:36.8624] Slim::bootstrap::tryModuleLoad (266) Warning: Module [Plugins::CustomBrowse::Plugin] failed to load:
Permission denied at /opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 872.
BEGIN failed--compilation aborted at (eval 535) line 2.
...

This made sense (as i've found out later) because the temp-directory is always /tmp/par-$USER, therefore it should be /tmp/par-control (in my case, user control has uid 1002)

have a nice day,
Markus
Comment 3 Andy Grundman 2007-11-26 12:25:50 UTC
That doesn't make much sense, if $> is correct much earlier in changeEffectiveUserAndGroup, how can it still be root during plugin init?  I think the directory name will still be '/tmp/par-root' since it uses $ENV{USER} but the permissions should be OK since it's created by the user with uid 1002.  Did you make sure /tmp/par-root was removed before starting SC?  I haven't tried to reproduce this yet, as I don't have a Linux system handy at the moment.  
Comment 4 Markus Schiegl 2007-11-26 12:52:55 UTC
1. verified /tmp/par-root is deleted.

2. start slimserver

3. directory is created:

ls --full-time /tmp/par-root 
drwxr-xr-x 2 root root 4096 2007-11-26 21:37:04.000000000 +0100 cache-2991388d557d47876869c8f911c56074bf249084

4. tail -f /var/log/slimserver.log

[21:37:06.5895] main::init (293) SqueezeCenter OS Specific init...
[21:37:06.5900] main::init (313) SqueezeCenter daemonizing...
[21:37:06.5976] main::init (322) SqueezeCenter settings effective user and group if requested...
[21:37:06.5982] Slim::bootstrap::theEND (400) Got to the END
[21:37:06.6168] main::changeEffectiveUserAndGroup (844) Running as uid: 1002 / gid: 100 100 100
[21:37:06.6179] main::init (332) SqueezeCenter strings init...
...

It's really strange that the directory is created even before the first line is logged. i'll try to narrow it down...
Comment 5 Andy Grundman 2007-11-26 13:10:14 UTC
OK, maybe PAR is being loaded somewhere else.  Try putting a logging statement in CPAN/PAR.pm's import sub.  Try also adding a call to Slim::Utils::Misc::bt() there, if Misc is loaded it will print a backtrace to where it's loaded.
Comment 6 Markus Schiegl 2007-11-26 13:32:57 UTC
okay, as neither the logging system nor Slim::Utils::Misc::bt was available, i inserted the bt-code on the import sub.
output:

Backtrace:

   frame 0: Slim::bootstrap::BEGIN (/opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 2)
   frame 1: (eval) (/opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 2)
   frame 2: (eval) (/opt/SlimServer_svn_trunk/server/Slim/bootstrap.pm line 339)
   frame 3: Slim::bootstrap::check_valid_versions (/opt/SlimServer_svn_trunk/server/Slim/bootstrap.pm line 184)
   frame 4: Slim::bootstrap::loadModules (/opt/slimserver/slimserver.pl line 108)
   frame 5: main::BEGIN (/opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 2)
   frame 6: (eval) (/opt/SlimServer_svn_trunk/server/CPAN/PAR.pm line 2)

and here it is: check_valid_versions tries to load/use each CPAN module.
thanks for pointing into this direction. was fun :-)

Unfortunately Slim::bootstrap->loadModules() cannot be moved below the user switch...

kind regards,
Markus
Comment 7 Andy Grundman 2007-11-26 13:42:26 UTC
Aha, oops.   OK I think I can work around this, should have a fix in a little bit.
Comment 8 Andy Grundman 2007-11-27 08:48:32 UTC
OK, think this is fixed now.
Comment 9 Markus Schiegl 2007-11-27 15:33:05 UTC
yes, it is. thanks

directory is not created much later and with the correct permissions and name (par-control in my case)
Comment 10 James Richardson 2008-05-06 11:45:56 UTC
(In reply to comment #9)
> yes, it is. thanks
> 
> directory is not created much later and with the correct permissions and name
> (par-control in my case)
> 

Marking bug as Closed, please reopen the bug if you see this issue happen again.
Comment 11 Chris Owens 2009-07-31 10:15:21 UTC
Reduce number of active targets for SC