User:Mjb/Logitech Media Server

From Offset
Jump to navigationJump to search

In early 2017 I started playing with my new SqueezeBox Boom. It's a great mini boom box which gets all its music over a LAN or WiFi connection. It can play Internet radio (Pandora, SHOUTcast, etc.) as well as audio from your own music library via Logitech Media Server or a DLNA server.

Folder loop problems

I ran into an issue with Logitech Media Server on my system, though. Logitech Media Server will follow all "link"-type files (as seen by Perl), which includes any shortcuts to folders. It does not attempt any kind of loop detection. My library has hundreds of Windows shortcut files. Some of these point to folders elsewhere in the same tree. Logitech Media Server currently doesn't really detect these loops, so it endlessly scans the same set of folders.

In theory you could detect a loop by keeping track of the inode for each folder visited, but only Unix and HFS+ file systems have inodes. FAT32 & NTFS APIs (probably unavailable in Perl) might be able to provide a unique-enough ID for those systems. Not sure about network drives. Another option might be writing an ID-containing file to each folder and then deleting them all when the scan is done, but this would be slow and is inelegant as the scan would no longer be passive. So I think loop detection is just not going to be feasible.

Patching LMS

On the support forum, in late December 2016, I suggested detecting when a folder has already been visited, or just offering a configuration option to prevent the following of links to folders entirely. The main developer said he couldn't get to it until after New Year's. I suspect he has already forgotten about it and won't be getting around to it at all.

I decided to see if I can build the software myself, make the changes I want, test them, and maybe submit a pull request on GitHub.

Preparation

1. Get ActivePerl-5.14.1.1401-MSWin32-x86-294969.msi from somewhere. You have to use this version (5.14.1), nothing older or newer will work.

2. Get one or both:

3. Fork both of these repositories:

Forking is a GitHub (not Git) feature; it means you will make a writable copy of the repos in your GitHub account, to use as a starting point. You have to do this from the GitHub website; go to each of the URLs above and click on Fork. Don't worry; you'll still be able to track changes made to the upstream repos!

If you don't fork, and just clone directly from the repos, you will not be able to push your changes to the server (unless you have been given access by the repo owners) and you will not be able to even make pull requests. So don't do that.

4. Clone (make a local copy of) the forks on your local machine, where you will be making your own development. You can do the cloning in GitHub Desktop or Git GUI, or from the command line (e.g. in Git BASH).

Presumably then you make your changes in your code, and use the usual ways of getting it onto GitHub. I did not get this far because I did not have the patience to figure out where and how to make the necessary edits. There are about a half-dozen places where folder links get followed, and I couldn't find configuration options at all. So I gave up on that for now.

Deny LMS permission to access folder shortcuts

In early 2018 I tried another approach suggested in the forum: set permissions on folder links (or at least just the problematic ones) such that the LMS process cannot follow them, but your other accounts can. This requires running the process as a special user. On windows 7 and up, it is not necessary to create a user for this; you can just make LMS service run under a virtual account "NT SERVICE\foo" where foo is an arbitrary name, and then you can use that name when setting folder ACLs:

   net stop squeezesvc
   sc config squeezesvc obj= "NT SERVICE\squeezesvc"
   net start squeezesvc

(alternatively, you can set the LMS Control Panel > Status > Startup Options > Username to NT SERVICE\squeezesvc and then stop and start the server from there).

Now set the Deny permissions for the user NT SERVICE\squeezesvc on your folder shortcuts:

   icacls "foo.lnk" /deny "NT SERVICE\squeezesvc:F"

...or to deny access to folder shell links, in PowerShell maybe you would do this:

   Get-ChildItem 'E:\music' -Recurse -Filter target.lnk | foreach { icacls $_.Directory /deny ("NT SERVICE\squeezesvc" + ":F") /t } 

If you make a mistake, you can reset it to inherited permissions:

   icacls "foo.lnk" /reset

or

   Get-ChildItem 'E:\music' -Recurse -Filter target.lnk | foreach { icacls $_.Directory /reset /t }

Once permissions are set OK, go to the LMS control panel delete the cache and rescan your library. If all goes well, the folder shortcuts you have denied access to will not be followed. The log will show them as having a bad path.