|
a/src/upmpd.cxx |
|
b/src/upmpd.cxx |
|
... |
|
... |
23 |
#include <signal.h> // for sigaction, SIG_IGN, etc
|
23 |
#include <signal.h> // for sigaction, SIG_IGN, etc
|
24 |
#include <stdio.h> // for fprintf, perror, stderr
|
24 |
#include <stdio.h> // for fprintf, perror, stderr
|
25 |
#include <stdlib.h> // for atoi, getenv, exit
|
25 |
#include <stdlib.h> // for atoi, getenv, exit
|
26 |
#include <sys/param.h> // for MIN
|
26 |
#include <sys/param.h> // for MIN
|
27 |
#include <unistd.h> // for geteuid, chown, sleep, etc
|
27 |
#include <unistd.h> // for geteuid, chown, sleep, etc
|
|
|
28 |
#include <string.h> // for memset
|
|
|
29 |
#include <grp.h>
|
28 |
|
30 |
|
29 |
#include <iostream> // for basic_ostream, operator<<, etc
|
31 |
#include <iostream> // for basic_ostream, operator<<, etc
|
30 |
#include <string> // for string, operator<<, etc
|
32 |
#include <string> // for string, operator<<, etc
|
31 |
#include <unordered_map> // for unordered_map, etc
|
33 |
#include <unordered_map> // for unordered_map, etc
|
32 |
#include <vector> // for vector, vector<>::iterator
|
34 |
#include <vector> // for vector, vector<>::iterator
|
|
... |
|
... |
80 |
OHPlaylist *ohpl = new OHPlaylist(this, rdctl, opts.ohmetasleep);
|
82 |
OHPlaylist *ohpl = new OHPlaylist(this, rdctl, opts.ohmetasleep);
|
81 |
m_services.push_back(ohpl);
|
83 |
m_services.push_back(ohpl);
|
82 |
if (avt)
|
84 |
if (avt)
|
83 |
avt->setOHP(ohpl);
|
85 |
avt->setOHP(ohpl);
|
84 |
if (ohReceiver) {
|
86 |
if (ohReceiver) {
|
|
|
87 |
struct OHReceiverParams parms;
|
|
|
88 |
parms.pl = ohpl;
|
|
|
89 |
parms.pr = ohpr;
|
|
|
90 |
if (opts.schttpport)
|
|
|
91 |
parms.httpport = opts.schttpport;
|
|
|
92 |
if (!opts.scplaymethod.empty()) {
|
|
|
93 |
if (!opts.scplaymethod.compare("alsa")) {
|
|
|
94 |
parms.pm = OHReceiverParams::OHRP_ALSA;
|
|
|
95 |
} else if (!opts.scplaymethod.compare("mpd")) {
|
|
|
96 |
parms.pm = OHReceiverParams::OHRP_MPD;
|
|
|
97 |
}
|
|
|
98 |
}
|
85 |
m_services.push_back(new OHReceiver(this, ohpl, ohpr,
|
99 |
m_services.push_back(new OHReceiver(this, parms));
|
86 |
opts.schttpport));
|
|
|
87 |
}
|
100 |
}
|
88 |
}
|
101 |
}
|
89 |
}
|
102 |
}
|
90 |
|
103 |
|
91 |
UpMpd::~UpMpd()
|
104 |
UpMpd::~UpMpd()
|
|
... |
|
... |
302 |
if (!(op_flags & OPT_P) && config.get("upnpport", value)) {
|
315 |
if (!(op_flags & OPT_P) && config.get("upnpport", value)) {
|
303 |
upport = atoi(value.c_str());
|
316 |
upport = atoi(value.c_str());
|
304 |
}
|
317 |
}
|
305 |
if (config.get("schttpport", value))
|
318 |
if (config.get("schttpport", value))
|
306 |
opts.schttpport = atoi(value.c_str());
|
319 |
opts.schttpport = atoi(value.c_str());
|
|
|
320 |
config.get("scplaymethod", opts.scplaymethod);
|
307 |
config.get("sc2mpd", g_sc2mpd_path);
|
321 |
config.get("sc2mpd", g_sc2mpd_path);
|
308 |
if (config.get("ohmetasleep", value))
|
322 |
if (config.get("ohmetasleep", value))
|
309 |
opts.ohmetasleep = atoi(value.c_str());
|
323 |
opts.ohmetasleep = atoi(value.c_str());
|
310 |
}
|
324 |
}
|
311 |
if (Logger::getTheLog(logfilename) == 0) {
|
325 |
if (Logger::getTheLog(logfilename) == 0) {
|
|
... |
|
... |
322 |
|
336 |
|
323 |
Pidfile pidfile(pidfilename);
|
337 |
Pidfile pidfile(pidfilename);
|
324 |
|
338 |
|
325 |
// If started by root, do the pidfile + change uid thing
|
339 |
// If started by root, do the pidfile + change uid thing
|
326 |
uid_t runas(0);
|
340 |
uid_t runas(0);
|
|
|
341 |
gid_t runasg(0);
|
327 |
if (geteuid() == 0) {
|
342 |
if (geteuid() == 0) {
|
328 |
struct passwd *pass = getpwnam(upmpdcliuser.c_str());
|
343 |
struct passwd *pass = getpwnam(upmpdcliuser.c_str());
|
329 |
if (pass == 0) {
|
344 |
if (pass == 0) {
|
330 |
LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser <<
|
345 |
LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser <<
|
331 |
" does not exist " << endl);
|
346 |
" does not exist " << endl);
|
332 |
return 1;
|
347 |
return 1;
|
333 |
}
|
348 |
}
|
334 |
runas = pass->pw_uid;
|
349 |
runas = pass->pw_uid;
|
|
|
350 |
runasg = pass->pw_gid;
|
335 |
|
351 |
|
336 |
pid_t pid;
|
352 |
pid_t pid;
|
337 |
if ((pid = pidfile.open()) != 0) {
|
353 |
if ((pid = pidfile.open()) != 0) {
|
338 |
LOGFAT("Can't open pidfile: " << pidfile.getreason() <<
|
354 |
LOGFAT("Can't open pidfile: " << pidfile.getreason() <<
|
339 |
". Return (other pid?): " << pid << endl);
|
355 |
". Return (other pid?): " << pid << endl);
|
|
... |
|
... |
384 |
if (!logfilename.empty() && logfilename.compare("stderr")) {
|
400 |
if (!logfilename.empty() && logfilename.compare("stderr")) {
|
385 |
if (chown(logfilename.c_str(), runas, -1) < 0) {
|
401 |
if (chown(logfilename.c_str(), runas, -1) < 0) {
|
386 |
LOGERR("chown("<<logfilename<<") : errno : " << errno << endl);
|
402 |
LOGERR("chown("<<logfilename<<") : errno : " << errno << endl);
|
387 |
}
|
403 |
}
|
388 |
}
|
404 |
}
|
|
|
405 |
if (initgroups(upmpdcliuser.c_str(), runasg) < 0) {
|
|
|
406 |
LOGERR("initgroup failed. Errno: " << errno << endl);
|
|
|
407 |
}
|
389 |
if (setuid(runas) < 0) {
|
408 |
if (setuid(runas) < 0) {
|
390 |
LOGFAT("Can't set my uid to " << runas << " current: " << geteuid()
|
409 |
LOGFAT("Can't set my uid to " << runas << " current: " << geteuid()
|
391 |
<< endl);
|
410 |
<< endl);
|
392 |
return 1;
|
411 |
return 1;
|
393 |
}
|
412 |
}
|
|
|
413 |
#if 0
|
|
|
414 |
gid_t list[100];
|
|
|
415 |
int ng = getgroups(100, list);
|
|
|
416 |
cerr << "GROUPS: ";
|
|
|
417 |
for (int i = 0; i < ng; i++) {
|
|
|
418 |
cerr << int(list[i]) << " ";
|
|
|
419 |
}
|
|
|
420 |
cerr << endl;
|
|
|
421 |
#endif
|
394 |
}
|
422 |
}
|
395 |
|
423 |
|
396 |
//// Dropped root
|
424 |
//// Dropped root
|
397 |
|
425 |
|
398 |
if (!g_sc2mpd_path.empty()) {
|
426 |
if (!g_sc2mpd_path.empty()) {
|