824 Commits

Author SHA1 Message Date
Justin Maggard
256d271201 clients: Add webOS TV 3.5 FLAC support
webOS TV 3.5 needs a sepcial FLAC mime type.
2020-11-18 14:45:11 -08:00
Justin Maggard
42646c99e0 upnpsoap: Add "path" SortCriteria support
Useful for manual sort overrides, to sort by filename.
2020-11-18 14:45:11 -08:00
Andreas Boeckler
13efe02e2d activated systemd-foreground-option on OS X for launchd 2020-11-18 14:45:11 -08:00
Justin Maggard
a668daa9da upnphttp: Downgrade "HTTP Connection closed unexpectedly"
Lots of clients trigger this during normal operation.
2020-11-18 14:45:11 -08:00
Vlad Starodubtsev
204a0ded8d monitor: fix setting max_user_watches.
reset file position after read.
2020-11-18 14:45:11 -08:00
Justin Maggard
347aafa6d7 Fix some build warnings when building with musl 2020-11-18 14:45:11 -08:00
Justin Maggard
379b66ca95 Use $USER instead of $LOGNAME for default friendly_name
Using $USER in the friendly name will display which user minidlna is
running as on the clients, which can be helpful for detecting problems.
Using $LOGNAME on the other hand will display "root" as the username if
minidlna was started using the init script, regardless of which user
minidlna is currently running as.

Originally added by Benoît Knecht <benoit.knecht@fsfe.org>
2020-11-18 14:45:11 -08:00
Fabrice Fontaine
b5e75ff7d1 fix build with gcc 10
Define setjmp_buffer as static to avoid the following build failure with
gcc 10 (which defaults to -fno-common):

/home/buildroot/autobuild/instance-1/output-1/host/lib/gcc/arm-buildroot-linux-gnueabihf/10.2.0/../../../../arm-buildroot-linux-gnueabihf/bin/ld: image_utils.o:(.bss+0x0): multiple definition of `setjmp_buffer'; metadata.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status

Fixes:
 - http://autobuild.buildroot.org/results/8754bb4f7d749f999d5f8ddfec587470ceec4476

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-11-18 14:45:11 -08:00
Justin Maggard
9f1677825c Fix some warnings from newer compilers 2020-11-18 14:45:11 -08:00
Justin Maggard
9fba41008a upnphttp: Disallow negative HTTP chunk lengths
[CVE-2020-28926]

This fixes a couple vulnerabilities that could lead to an infinite loop
or heap corruption.
2020-11-18 14:44:42 -08:00
Justin Maggard
06ee114731 upnphttp: Validate SUBSCRIBE callback URL
The UPnP protocol specification mandates that subscribers can request a
callback to an arbitrary URL. This recently resulted in CVE-2020-12695
(CallStranger) outlining the risk of information disclosure and DoS
attacks.

This commit ensures that the callback URL sent in a SUBSCRIBE request
points to the same IP address that made the request.
2020-11-18 14:44:33 -08:00
Justin Maggard
0763719f27 tagutils: Fix spurious warnings with ogg coverart
Silences common "Vorbis coverart too long" / "Vorbis
METADATA_BLOCK_PICTURE too long" warning messages.
2019-12-09 21:34:44 -08:00
Justin Maggard
8f14d7223d upnpsoap: Return truncated results on full buffer
If our response buffer fills up to the max buffer size on a UPnP Browse
request, we should return short results rather than erroring out.

Fixes: #314 (Cannot browse MiniDLNA 1.2.1 with VLC 2.2.6 (UPnPError 709: Unsupported or invalid sort criteria))
2019-12-09 21:14:59 -08:00
Alex Stanev
ca6dbba183 clients: Fix bookmarks on Samsung Q series
Add flag for milliseconds conversion for bookmarks and model for Samsung Q
series, which needs this. This allows for bookmark synchronization when 2
or more TVs are using the same DLNA server.
2019-07-01 09:59:43 -07:00
Takeshich NAKAMURA
799e6cf505 Add DSD file support
* add mimetype audio/x-dsd  (.dsf/.dff)
* add id3tag and fileinfo support (only .dsf)
2018-05-04 16:11:25 -07:00
Josh Watzman
ade51e9c94 Fix potential stack smash in getsyshwaddr on OS X
getsyshwaddr assumed that the first ifaddr it came across was the MAC
address, and as such assumes that it has the right length. After
upgrading to OS X 10.13.4, this causes minidlnad to crash on startup due
to tripping stack smash protection -- I'm not sure if the order of
addresses returned previously happened to accidentally hit this
invariant, or if this was always an issue and the stack smash protection
got smarter.

In any event, we just need to look for the AF_LINK address and use that.
As an extra check, we make sure the length is the length we expect to
copy into the target buffer.
2018-04-11 10:01:21 -07:00
Justin Maggard
138d03db19 Reload log file on SIGHUP
There's a report about a nightly "crash" when users download, compile
from source, and replace their distro's mindlnad binary.  This is because
the Debian package includes a patch that uses SIGUSR2 to reopen the log
file and sends SIGUSR2 from logrotate instead of just using the
"copytruncate" logrotate option.  Then logrotate sends SIGUSR2 at 6:25AM,
which causes us to abort due to the unhandled signal.

I don't want to sacrifice SIGUSR2 just for log rotation, especially when
we already do some reload operations on SIGHUP.  So to avoid this
Debian/Ubuntu issue, we'll explicitly ignore SIGUSR2, and add log file
reopening to the SIGHUP handler.  Then hopefully a future Debian package
version will remove the SIGUSR2 patch and use SIGHUP instead (or
copytruncate).

Fixes: SF Bug #313 (log rotation kills minidlna service)
2018-01-23 22:01:10 -08:00
Justin Maggard
7a8ef80af0 Clean up event module on shutdown
Fixes a harmless memory leak reported by Valgrind.
2018-01-23 22:00:02 -08:00
Justin Maggard
fa20ca8526 upnpsoap: Work around some bad SearchCriteria
The Control4 app apparently sends us badly-formatted SearchCriteria,
where they don't quote the upnp:class value.  So we'll add it in for them
if we detect that situation.

Fixes: SF Patches #173 (DLNA search query not as minidlna expects)
2018-01-18 17:35:02 -08:00
Justin Maggard
f2294ebea8 upnpsoap: Move watch count set code to a new function 2018-01-16 17:43:15 -08:00
Justin Maggard
4c4485d225 upnpsoap: Only return sec:dcmInfo with a bookmark
There's no point in returning bookmark info without a bookmark.  It also
has been reported that certain Samsung models may have issues with
subtitles if we send dcmInfo data.  So we'll only return it if we have a
bookmark set.

[minidlna:support-requests] #52 External srt subtitles for Samsung UA48JU7800
2018-01-16 17:38:37 -08:00
Justin Maggard
9bb6cf5051 minissdp: Re-add SSDP filtering
Add back SSDP filtering.  Relying on the kernel to filter out multicast
traffic from non-member interfaces simply doesn't work the way many
people think it does, so we need to re-introduce manual filtering.  But
this time we will use in_pktinfo's ifindex for comparison rather than a
netmask comparison, so SSDP packets from other subnets should still work.
2018-01-16 17:12:20 -08:00
Gleb Smirnoff
8fe7293c7a Fix compilation warning for undeclared struct event. 2018-01-16 17:05:53 -08:00
Gleb Smirnoff
f7604117c0 Fix more compilation mistakes from 338ee4bd7bb44 in TiVo. 2018-01-16 17:05:51 -08:00
Gleb Smirnoff
3e8da9bb1a Return back checking file for sparseness. Use lseek(SEEK_HOLE) if supported by the system, otherwise fallback to block check. This allows to workaround bugs with SMB client and not introduce new bugs for filesystems with compression and deduplication.
This has theoretical bug if our collection spans different
filesystems and some filesystems support holes, and some not.
If this ever encountered we should use pathconf(2) and cache
its result for directories.
2018-01-16 17:05:44 -08:00
Gleb Smirnoff
debb502ff3 Fix compilation mistakes from 338ee4bd7bb44 in TiVo. 2018-01-16 17:05:42 -08:00
Gleb Smirnoff
da30df3350 Remove C99 code. 2018-01-16 17:05:40 -08:00
Gleb Smirnoff
7428b8dede This file is derived from code by Bernard Spil. Fix copyright. 2018-01-16 17:04:32 -08:00
Gleb Smirnoff
1cb676f51d Add license and my copyright to monitor_kqueue.c. The file contains portions of code that were made either by William or by Stefan. Since I am unsure about that, put them both. To be clarified later. 2018-01-16 17:03:20 -08:00
Gleb Smirnoff
a4dc9a1996 Add nginx's and my copyright to the files that borrow ideas from nginx. 2018-01-16 17:03:00 -08:00
Gleb Smirnoff
4db229534b Initialize libav before enabling kqueue monitor, missed in b2613161329. 2018-01-16 17:02:13 -08:00
Gleb Smirnoff
d02866a084 Filled up event list isn't something warning. 2018-01-16 17:02:10 -08:00
Gleb Smirnoff
d6374fa4e2 Fix SQL queries that intended to match directories. Code originates from FreeBSD ports extra patch. Probably it was working on previous versions of SQLite, or on previous minidlna schema. 2018-01-16 17:02:05 -08:00
Gleb Smirnoff
4ba6f1fa27 Fix stupid logic typo, that prevented monitoring from working. 2018-01-16 17:02:03 -08:00
Gleb Smirnoff
42f0630198 Remove (st.st_blocks<<9 >= st.st_size) check. It may fail if a file system supports deduplication, compression and other features.
My guess the goal was to skip files with holes in them. Original commit
590f0761f4aba64c4a3b4c8f11543a929178da38, doesn't explain that. If that
is still necessary, better to add lseek(SEEK_DATA) check later.
2018-01-16 17:02:01 -08:00
Gleb Smirnoff
958da67592 Initialize libav before enabling kqueue monitor. 2018-01-16 17:01:59 -08:00
Gleb Smirnoff
dfdd81a09f Wrap struct event into struct watch. For now this is just code bloat. We might start monitoring files later. We also might want to create a tree/list of all watches if we ever need to search within them, like the inotify module does. 2018-01-16 17:01:55 -08:00
Gleb Smirnoff
5e320f2798 Add monitoring support via kqueue(2). Based on patch from FreeBSD ports, authored by wg@FreeBSD.org and se@FreeBSD.org. However, this version doesn't create any thread, it uses main event dispatcher.
Some effort was made to unify monitoring via kqueue and via inotify
APIs. Now both provide their implementation of add_watch() function.

I guess there are some logical bugs in vnode_process(). With this commit
it would be better provide code as is, and resolve bugs separately.
2018-01-16 17:01:43 -08:00
Gleb Smirnoff
184607cb56 Remove obsoleted useless flag. 2018-01-16 16:55:26 -08:00
Gleb Smirnoff
7ba9e52fc8 Add kqueue event module. Code inspired by nginx. There are a lot of room for optimization here, this is just first working version. 2018-01-16 16:55:23 -08:00
Gleb Smirnoff
aefe4dd0bf With current forking model of minidlna, we no longer need the event module in the child, so shut it down. While here, make any error from fork() a fatal error. 2018-01-16 16:53:14 -08:00
Gleb Smirnoff
33fb664fba Failure of event_module init is fatal. 2018-01-16 16:53:12 -08:00
Gleb Smirnoff
8fcb1258b4 Shut up compilation warning. 2018-01-16 16:53:10 -08:00
Gleb Smirnoff
f9a78d598e Support for pluggable event modules, stage 1. Take out select() loop and associated code into a separate module select.c. Detailed list of changes down below.
The idea is taken from the nginx web server, but much simplified and
almost no copypaste left. This will allow minidlna to use different
event dispatcher APIs, which would be defined at compile time.

My personal goal is to convert minidlna to kqueue(2) on FreeBSD. This
would later allow for kqueue based directory change notification, which
won't conflict with select(2) like the current patch does.
Other platforms will also benefit from the pluggability of the event
system, Linux can switch to epoll(2) or at least to poll(2).

Detailed list of changes:

* event.h [New]
  Our internal API to unify different event dispatch systems.
* select.c [New]
  Much simplified version of nginx's ngx_select_module.c.
* minidlna.c
  - Split out listen socket event processing into separate function
    ProcessListen(), which matches event_process_t type.
  - Create and initialize struct event for the monitor socket, SSDP
    socket, HTTP socket and beacon socket.
  - Simplify and make more precise timeout calculation using
    helper timeval functions from utils.c. Treat gettimeofday() error
    as a fatal event.
  - Rip out all stuff related to select(2). Just call event_module.process().
* upnpevents.c
  - Embed struct event into upnp_event_notify.
  - Merge upnp_event_create_notify() with upnp_event_notify_connect().
    Start connecting immediately after socket creation. Garbage collect
    now useless ECreated state.
  - Make upnp_event_process_notify() of event_process_t type, and use it
    as process callback for upnp_event_notify event.
  - Looks like we always create upnp_event_notify with existing subscriber,
    and never clear it later. Remove checks for obj->sub and assert that it
    is never NULL. Simplifies things.
  - When switching obj state, add/del it to event dispatcher accrodingly.
  - Garbage collect upnpevents_selectfds().
  - Garbage collect select(2) related stuff from upnpevents_processfds().
    Rename function to upnpevents_gc(), since the remaining functionality
    is garbage collecting, not file descriptor processing.
    Actually, this can be simplified even more. We can safely close sockets
    and free objects immediately, eliminating need for upnpevents_gc(). But
    this change would be beyond scope of this commit.
* upnphttp.c, upnphttp.h
  Embed struct event into struct upnphttp. Adjust Process_upnphttp() to match
  event_process_t type. Add/del to event dispatcher once creating/closing a
  socket.
* minissdp.c, minissdp.h
  Make ProcessSSDPRequest() of event_process_t type.
* getifaddr.c, getifaddr.h
  Make ProcessMonitorEvent() of event_process_t type.
2018-01-16 16:53:08 -08:00
Gleb Smirnoff
04e243c85c Add handy functions for timeval manipulations. Obtained from FreeBSD. 2018-01-16 16:49:52 -08:00
Stefan Esser
63f725f8c9 Fix DEBUG build. 2018-01-16 16:49:49 -08:00
Gleb Smirnoff
8fb89dc6fa Remove reference to non-existent INSTALL file. 2018-01-16 16:49:43 -08:00
Justin Maggard
3990f61c57 monitor: Abort inotify directory scanning on quit
Add more interruption point in case we receive a quit signal while we're
scanning a large directory.
2018-01-12 13:57:58 -08:00
Justin Maggard
c2a9186c71 Increase MAX_LAN_ADDR to 8 2018-01-11 16:09:15 -08:00
Justin Maggard
3e9ca13fa3 upnpsoap: Add forced alphasort capability
Add the ability to force title modification for clients that do their own
alphanumeric sorting.  Adding a '!' to the beginning of the
force_sort_criteria value will enable this behavior.

It is implemented by prepending all titles with a zero-padded number, and
possibly season and episode (or disc and track) numbers if they aren't
already in the title.
2018-01-11 11:12:22 -08:00