From 7cff777d05b1636f230dbfe148b18b527558aa2d Mon Sep 17 00:00:00 2001 From: jcorporation Date: Thu, 21 Jun 2018 23:15:54 +0100 Subject: [PATCH] Dont run under uid 0 Optimize mkdebug.sh and mkrelease.sh --- README.md | 12 ++++-------- mkdebug.sh | 2 +- mkrelease.sh | 29 ++++++++++++++++++++++------- src/mympd.c | 7 ++++++- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c7b9e3f..1d32812 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,9 @@ Unix Build Instructions ----------------------- 1. install dependencies. cmake and libmpdclient (dev) are available from all major distributions. -2. create build directory ```cd /path/to/src; mkdir build; cd build``` -3. create makefile ```cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=RELEASE``` -4. build ```make``` -5. install ```sudo make install``` -6. change owner of /var/lib/mympd to user you will run mympd, default nobody (chown nobody /var/lib/mympd) -7. Link your mpd music directory to ```/usr/share/mympd/htdocs/library``` and put ```folder.jpg``` files in your album directories -8. Configure your mpd with http stream output to use the local player +2. build and install it ```cd /path/to/src; ./mkrelease.sh``` +3. Link your mpd music directory to ```/usr/share/mympd/htdocs/library``` and put ```folder.jpg``` files in your album directories +4. Configure your mpd with http stream output to use the local player Run flags --------- @@ -46,7 +42,7 @@ Usage: ./mympd [OPTION]... -h, --host connect to mpd at host [localhost] -p, --port connect to mpd at port [6600] - -w, --webport [ip:] listen interface/port for webserver [8080] + -w, --webport listen port for webserver [80] -s, --streamport connect to mpd http stream at port [8000] -u, --user drop priviliges to user after socket bind -m, --mpdpass specifies the password to use when connecting to mpd diff --git a/mkdebug.sh b/mkdebug.sh index 994bb13..7802f6e 100755 --- a/mkdebug.sh +++ b/mkdebug.sh @@ -1,4 +1,4 @@ -#/bin/bash +#/bin/sh [ -d debug ] || mkdir debug cd debug diff --git a/mkrelease.sh b/mkrelease.sh index d95600d..2e7324f 100755 --- a/mkrelease.sh +++ b/mkrelease.sh @@ -1,4 +1,4 @@ -#/bin/bash +#/bin/sh if [ -f buildtools/closure-compiler.jar ] then @@ -7,8 +7,10 @@ then [ htdocs/js/mpd.js -nt htdocs/js/mpd.min.js ] && \ java -jar buildtools/closure-compiler.jar htdocs/js/mpd.js > htdocs/js/mpd.min.js else - cp htdocs/js/player.js htdocs/js/player.min.js - cp htdocs/js/mpd.js htdocs/js/mpd.min.js + [ htdocs/js/player.js -nt htdocs/js/player.min.js ] && \ + cp htdocs/js/player.js htdocs/js/player.min.js + [ htdocs/js/mpd.js -nt htdocs/js/mpd.min.js ] && \ + cp htdocs/js/mpd.js htdocs/js/mpd.min.js fi if [ -f buildtools/closure-stylesheets.jar ] @@ -16,13 +18,26 @@ then [ htdocs/css/mpd.css -nt htdocs/css/mpd.min.css ] && \ java -jar buildtools/closure-stylesheets.jar htdocs/css/mpd.css > htdocs/css/mpd.min.css else - cp htdocs/css/mpd.css htdocs/css/mpd.min.css + [ htdocs/css/mpd.css -nt htdocs/css/mpd.min.css ] && \ + cp htdocs/css/mpd.css htdocs/css/mpd.min.css fi [ -d release ] || mkdir release cd release cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=RELEASE .. make -make install -sed -i -e 's/mpd\.css/mpd\.min\.css/' -e 's/mpd\.js/mpd\.min\.js/' /usr/share/mympd/htdocs/index.html -sed -i -e 's/mpd\.css/mpd\.min\.css/' -e 's/player\.js/player\.min\.js/' /usr/share/mympd/htdocs/player.html +sudo make install +cd .. + +sudo sed -i -e 's/mpd\.css/mpd\.min\.css/' -e 's/mpd\.js/mpd\.min\.js/' /usr/share/mympd/htdocs/index.html +sudo sed -i -e 's/mpd\.css/mpd\.min\.css/' -e 's/player\.js/player\.min\.js/' /usr/share/mympd/htdocs/player.html + +sudo chown nobody /var/lib/mympd + +[ -d /etc/systemd/system ] && \ + sudo cp -v contrib/mympd.service /etc/systemd/system/ + +[ -d /etc/default ] && \ + sudo cp -v contrib/mympd.default /etc/default/mympd + +echo "myMPD installed" diff --git a/src/mympd.c b/src/mympd.c index 15b4412..42e2bd1 100644 --- a/src/mympd.c +++ b/src/mympd.c @@ -103,7 +103,7 @@ int main(int argc, char **argv) struct mg_connection *nc; unsigned int current_timer = 0, last_timer = 0; char *run_as_user = NULL; - char *webport = "8080"; + char *webport = "80"; mpd.port = 6600; strcpy(mpd.host, "127.0.0.1"); streamport = 8000; @@ -204,6 +204,11 @@ int main(int argc, char **argv) return EXIT_FAILURE; } } + + if (getuid() == 0) { + printf("myMPD should not be run with root privileges\n"); + return EXIT_FAILURE; + } mg_set_protocol_http_websocket(nc); s_http_server_opts.document_root = SRC_PATH;