Switch to unified view

a/src/ohcredentials.cxx b/src/ohcredentials.cxx
...
...
365
        }
365
        }
366
        return saveohcredentials;
366
        return saveohcredentials;
367
    }        
367
    }        
368
368
369
    void saveToConfTree(ConfSimple& credsconf) {
369
    void saveToConfTree(ConfSimple& credsconf) {
370
        credsconf.clear();
370
        for (const auto& cred : creds) {
371
        for (const auto& cred : creds) {
371
            const string& shortid = cred.second.servicename;
372
            const string& shortid = cred.second.servicename;
372
            credsconf.set(shortid + "user", cred.second.user);
373
            credsconf.set(shortid + "user", cred.second.user);
373
            credsconf.set(shortid + "pass", cred.second.password);
374
            credsconf.set(shortid + "pass", cred.second.password);
374
            // Saving the encrypted version is redundant, but it
375
            // Saving the encrypted version is redundant, but it
...
...
491
           in_UserName << " Password " << in_Password << endl);
492
           in_UserName << " Password " << in_Password << endl);
492
493
493
    const auto it1 = idmap.find(in_Id);
494
    const auto it1 = idmap.find(in_Id);
494
    if (it1 == idmap.end()) {
495
    if (it1 == idmap.end()) {
495
        LOGERR("OHCredentials::actSet: bad service id [" << in_Id <<"]\n");
496
        LOGERR("OHCredentials::actSet: bad service id [" << in_Id <<"]\n");
496
        return UPNP_E_INVALID_PARAM;
497
        return 800;
497
    }
498
    }
498
    string servicename = it1->second;
499
    string servicename = it1->second;
499
    string cpass = base64_decode(in_Password);
500
    string cpass = base64_decode(in_Password);
500
    string plainpass;
501
    string plainpass;
501
    if (!m->decrypt(cpass, plainpass)) {
502
    if (!m->decrypt(cpass, plainpass)) {
...
...
512
    m->seq++;
513
    m->seq++;
513
    m->save();
514
    m->save();
514
    if (m->setEnabled(in_Id, true)) {
515
    if (m->setEnabled(in_Id, true)) {
515
        return UPNP_E_SUCCESS;
516
        return UPNP_E_SUCCESS;
516
    } else {
517
    } else {
517
        return UPNP_E_INVALID_PARAM;
518
        return 800;
518
    }
519
    }
519
}
520
}
520
521
521
int OHCredentials::actLogin(const SoapIncoming& sc, SoapOutgoing& data)
522
int OHCredentials::actLogin(const SoapIncoming& sc, SoapOutgoing& data)
522
{
523
{
...
...
530
531
531
    LOGDEB("OHCredentials::actLogin: " << " Id " << in_Id << endl);
532
    LOGDEB("OHCredentials::actLogin: " << " Id " << in_Id << endl);
532
    auto it = m->creds.find(in_Id);
533
    auto it = m->creds.find(in_Id);
533
    if (it == m->creds.end()) {
534
    if (it == m->creds.end()) {
534
        LOGERR("OHCredentials::Login: Id " << in_Id << " not found\n");
535
        LOGERR("OHCredentials::Login: Id " << in_Id << " not found\n");
535
        return UPNP_E_INVALID_PARAM;
536
        return 800;
536
    }
537
    }
537
    string token = it->second.login();
538
    string token = it->second.login();
538
    LOGDEB("OHCredentials::Login: got token " << token << endl);
539
    LOGDEB("OHCredentials::Login: got token " << token << endl);
539
    data.addarg("Token", token);
540
    data.addarg("Token", token);
541
542
    // If login failed, erase the probably incorrect data from memory
543
    // and disk.
544
    if (token.empty()) {
545
        m->creds.erase(in_Id);
546
        m->save();
547
    }
548
540
    m->seq++;
549
    m->seq++;
541
    return UPNP_E_SUCCESS;
550
    return token.empty() ? 801 : UPNP_E_SUCCESS;
542
}
551
}
543
552
544
int OHCredentials::actReLogin(const SoapIncoming& sc, SoapOutgoing& data)
553
int OHCredentials::actReLogin(const SoapIncoming& sc, SoapOutgoing& data)
545
{
554
{
546
    bool ok = false;
555
    bool ok = false;
...
...
561
           << in_CurrentToken << endl);
570
           << in_CurrentToken << endl);
562
571
563
    auto it = m->creds.find(in_Id);
572
    auto it = m->creds.find(in_Id);
564
    if (it == m->creds.end()) {
573
    if (it == m->creds.end()) {
565
        LOGERR("OHCredentials::Login: Id " << in_Id << " not found\n");
574
        LOGERR("OHCredentials::Login: Id " << in_Id << " not found\n");
566
        return UPNP_E_INVALID_PARAM;
575
        return 800;
567
    }
576
    }
568
    it->second.logout();
577
    it->second.logout();
569
    string token = it->second.login();
578
    string token = it->second.login();
579
    if (token.empty()) {
580
        return 801;
581
    }
570
    data.addarg("NewToken", token);
582
    data.addarg("NewToken", token);
571
    m->seq++;
583
    m->seq++;
572
    return UPNP_E_SUCCESS;
584
    return UPNP_E_SUCCESS;
573
}
585
}
574
586
...
...
583
    }
595
    }
584
596
585
    LOGDEB("OHCredentials::actClear: " << " Id " << in_Id << endl);
597
    LOGDEB("OHCredentials::actClear: " << " Id " << in_Id << endl);
586
    if (idmap.find(in_Id) == idmap.end()) {
598
    if (idmap.find(in_Id) == idmap.end()) {
587
        LOGERR("OHCredentials::actClear: bad service id [" << in_Id <<"]\n");
599
        LOGERR("OHCredentials::actClear: bad service id [" << in_Id <<"]\n");
588
        return UPNP_E_INVALID_PARAM;
600
        return 800;
589
    }
601
    }
590
    auto it = m->creds.find(in_Id);
591
    if (it != m->creds.end()) {
592
        m->creds.erase(it);
602
    m->creds.erase(in_Id);
593
        m->seq++;
603
    m->save();
594
    }
595
    return UPNP_E_SUCCESS;
604
    return UPNP_E_SUCCESS;
596
}
605
}
597
606
598
int OHCredentials::actSetEnabled(const SoapIncoming& sc, SoapOutgoing& data)
607
int OHCredentials::actSetEnabled(const SoapIncoming& sc, SoapOutgoing& data)
599
{
608
{
...
...
615
           in_Enabled << endl);
624
           in_Enabled << endl);
616
    if (m->setEnabled(in_Id, in_Enabled)) {
625
    if (m->setEnabled(in_Id, in_Enabled)) {
617
        m->seq++;
626
        m->seq++;
618
        return UPNP_E_SUCCESS;
627
        return UPNP_E_SUCCESS;
619
    } else {
628
    } else {
620
        return UPNP_E_INVALID_PARAM;
629
        return 800;
621
    }
630
    }
622
}
631
}
623
632
624
int OHCredentials::actGet(const SoapIncoming& sc, SoapOutgoing& data)
633
int OHCredentials::actGet(const SoapIncoming& sc, SoapOutgoing& data)
625
{
634
{