|
a/src/ohcredentials.cxx |
|
b/src/ohcredentials.cxx |
|
... |
|
... |
27 |
#include <iostream>
|
27 |
#include <iostream>
|
28 |
#include <map>
|
28 |
#include <map>
|
29 |
#include <utility>
|
29 |
#include <utility>
|
30 |
#include <vector>
|
30 |
#include <vector>
|
31 |
#include <regex>
|
31 |
#include <regex>
|
|
|
32 |
#include <sstream>
|
32 |
|
33 |
|
33 |
#include "conftree.h"
|
34 |
#include "conftree.h"
|
34 |
#include "main.hxx"
|
35 |
#include "main.hxx"
|
|
|
36 |
#include "smallut.h"
|
35 |
#include "pathut.h"
|
37 |
#include "pathut.h"
|
36 |
#include "execmd.h"
|
38 |
#include "execmd.h"
|
|
|
39 |
#include "sysvshm.h"
|
37 |
#include "mediaserver/cdplugins/cmdtalk.h"
|
40 |
#include "mediaserver/cdplugins/cmdtalk.h"
|
38 |
|
41 |
|
39 |
#include "libupnpp/log.hxx"
|
42 |
#include "libupnpp/log.hxx"
|
40 |
#include "libupnpp/base64.hxx"
|
43 |
#include "libupnpp/base64.hxx"
|
41 |
#include "libupnpp/soaphelp.hxx"
|
44 |
#include "libupnpp/soaphelp.hxx"
|
|
... |
|
... |
43 |
#include "mediaserver/cdplugins/cdplugin.hxx"
|
46 |
#include "mediaserver/cdplugins/cdplugin.hxx"
|
44 |
#include "mediaserver/cdplugins/plgwithslave.hxx"
|
47 |
#include "mediaserver/cdplugins/plgwithslave.hxx"
|
45 |
|
48 |
|
46 |
using namespace std;
|
49 |
using namespace std;
|
47 |
using namespace std::placeholders;
|
50 |
using namespace std::placeholders;
|
|
|
51 |
|
|
|
52 |
const size_t ohcreds_segsize{3000};
|
|
|
53 |
const int ohcreds_segid{923102018};
|
|
|
54 |
const char *ohcreds_segpath = "/etc/upmpdcli.conf";
|
48 |
|
55 |
|
49 |
static const string sTpCredentials("urn:av-openhome-org:service:Credentials:1");
|
56 |
static const string sTpCredentials("urn:av-openhome-org:service:Credentials:1");
|
50 |
static const string sIdCredentials("urn:av-openhome-org:serviceId:Credentials");
|
57 |
static const string sIdCredentials("urn:av-openhome-org:serviceId:Credentials");
|
51 |
|
58 |
|
52 |
static const string idstring{"tidalhifi.com qobuz.com"};
|
59 |
static const string idstring{"tidalhifi.com qobuz.com"};
|
|
... |
|
... |
286 |
it->second.enabled = enabled;
|
293 |
it->second.enabled = enabled;
|
287 |
return true;
|
294 |
return true;
|
288 |
}
|
295 |
}
|
289 |
|
296 |
|
290 |
bool save() {
|
297 |
bool save() {
|
|
|
298 |
bool saveohcredentials = true;
|
|
|
299 |
string val;
|
|
|
300 |
if (g_config && g_config->get("saveohcredentials", val)) {
|
|
|
301 |
saveohcredentials = stringToBool(val);
|
|
|
302 |
}
|
|
|
303 |
// We share the creds with the media server process because it
|
|
|
304 |
// needs them for url translation If saveohcredentials is
|
|
|
305 |
// true, we use a file, which can also be used by the regular
|
|
|
306 |
// media server plugin, for possible later access without
|
|
|
307 |
// ohcredentials. If it's false, we use a shared mem segment,
|
|
|
308 |
// and the user/pass would have to be set in
|
|
|
309 |
// /etc/upmpdcli.conf for the regular plugin to work.
|
|
|
310 |
if (saveohcredentials) {
|
291 |
string credsfile = path_cat(cachedir, "screds");
|
311 |
string credsfile = path_cat(cachedir, "screds");
|
292 |
ConfSimple credsconf(credsfile.c_str());
|
312 |
ConfSimple credsconf(credsfile.c_str());
|
293 |
if (!credsconf.ok()) {
|
313 |
if (!credsconf.ok()) {
|
294 |
LOGERR("OHCredentials: error opening " << credsfile <<
|
314 |
LOGERR("OHCredentials: error opening " << credsfile <<
|
295 |
" errno " << errno << endl);
|
315 |
" errno " << errno << endl);
|
296 |
return false;
|
316 |
return false;
|
297 |
}
|
317 |
}
|
298 |
for (const auto& cred : creds) {
|
318 |
for (const auto& cred : creds) {
|
299 |
credsconf.set(cred.second.servicename + "user", cred.second.user);
|
319 |
credsconf.set(cred.second.servicename + "user", cred.second.user);
|
300 |
credsconf.set(cred.second.servicename + "pass", cred.second.password);
|
320 |
credsconf.set(cred.second.servicename + "pass", cred.second.password);
|
301 |
}
|
321 |
}
|
302 |
chmod(credsfile.c_str(), 0600);
|
322 |
chmod(credsfile.c_str(), 0600);
|
|
|
323 |
} else {
|
|
|
324 |
string data;
|
|
|
325 |
ConfSimple credsconf(data);
|
|
|
326 |
for (const auto& cred : creds) {
|
|
|
327 |
credsconf.set(cred.second.servicename + "user", cred.second.user);
|
|
|
328 |
credsconf.set(cred.second.servicename + "pass", cred.second.password);
|
|
|
329 |
}
|
|
|
330 |
LockableShmSeg seg(ohcreds_segpath, ohcreds_segid, ohcreds_segsize, true);
|
|
|
331 |
if (!seg.ok()) {
|
|
|
332 |
LOGERR("OHCredentials: shared memory segment allocate/attach failed\n");
|
|
|
333 |
return false;
|
|
|
334 |
}
|
|
|
335 |
LockableShmSeg::Accessor access(seg);
|
|
|
336 |
char *cp = (char *)(access.getseg());
|
|
|
337 |
ostringstream strm;
|
|
|
338 |
credsconf.write(strm);
|
|
|
339 |
strcpy(cp, strm.str().c_str());
|
|
|
340 |
LOGDEB1("OHCredentials: shm seg content: [" << cp << "]\n");
|
|
|
341 |
}
|
303 |
return true;
|
342 |
return true;
|
304 |
}
|
343 |
}
|
305 |
|
344 |
|
306 |
ExecCmd cmd;
|
345 |
ExecCmd cmd;
|
307 |
string cachedir;
|
346 |
string cachedir;
|