From 6cef303fc1cdf4d3fa99c4ebe46c70dfdf15b547 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 27 Feb 2014 15:47:02 -0800 Subject: [PATCH] try to ensure proper ownership of db_dir If user has been set, try to ensure that db_dir is owned by that user. If that fails, log an error. --- minidlna.c | 8 ++++++++ minissdp.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/minidlna.c b/minidlna.c index 46b7cb9..a24f9f4 100644 --- a/minidlna.c +++ b/minidlna.c @@ -938,6 +938,14 @@ init(int argc, char **argv) if (writepidfile(pidfilename, pid, uid) != 0) pidfilename = NULL; + if (uid >= 0) + { + struct stat st; + if (stat(db_path, &st) == 0 && st.st_uid != uid && chown(db_path, uid, -1) != 0) + DPRINTF(E_ERROR, L_GENERAL, "Unable to set db_path [%s] ownership to %d: %s\n", + db_path, uid, strerror(errno)); + } + if (uid != -1 && setuid(uid) == -1) DPRINTF(E_FATAL, L_GENERAL, "Failed to switch to uid '%d'. [%s] EXITING.\n", uid, strerror(errno)); diff --git a/minissdp.c b/minissdp.c index 4f99444..d7c0ad6 100644 --- a/minissdp.c +++ b/minissdp.c @@ -733,7 +733,7 @@ SendSSDPGoodbyes(int s) (i > 0 ? "::" : ""), (i > 0 ? known_service_types[i] : ""), (i > 1 ? "1" : "")); - DPRINTF(E_MAXDEBUG, L_SSDP, "Sending ssdp:byebye [%s]\n", s); + DPRINTF(E_MAXDEBUG, L_SSDP, "Sending ssdp:byebye [%d]\n", s); n = sendto(s, bufr, l, 0, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in) ); if (n < 0)