summaryrefslogtreecommitdiff
path: root/cpp/src/Glacier2/CryptPermissionsVerifierI.cpp
blob: 66a77599e0d5efb6750494e3462483ab065da817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <Glacier2/CryptPermissionsVerifierI.h>
#include <openssl/des.h>

using namespace std;
using namespace Ice;
using namespace Glacier2;

Glacier2::CryptPermissionsVerifierI::CryptPermissionsVerifierI(const map<string, string>& passwords) :
    _passwords(passwords)
{
}

bool
Glacier2::CryptPermissionsVerifierI::checkPermissions(
    const string& userId, const string& password, string&, const Current&) const
{
    IceUtil::Mutex::Lock sync(*this);

    map<string, string>::const_iterator p = _passwords.find(userId);

    if(p == _passwords.end())
    {
        return false;
    }

    if(p->second.size() != 13) // Crypt passwords are 13 characters long.
    {
        return false;
    }

    char buff[14];
    string salt = p->second.substr(0, 2);
#if OPENSSL_VERSION_NUMBER >= 0x0090700fL
    DES_fcrypt(password.c_str(), salt.c_str(), buff);
#else
    des_fcrypt(password.c_str(), salt.c_str(), buff);
#endif
    return p->second == buff;
}