2003-02-13 23:44:00 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Access Method
|
2003-02-19 07:14:39 +01:00
|
|
|
* MODULE: jrd_pwd.h
|
2003-02-13 23:44:00 +01:00
|
|
|
* DESCRIPTION: User information database name
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*
|
|
|
|
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
|
|
|
|
* 2003.02.02 Dmitry Yemanov: Implemented cached security database connection
|
|
|
|
*/
|
|
|
|
|
2003-10-03 03:53:34 +02:00
|
|
|
#ifndef JRD_PWD_H
|
|
|
|
#define JRD_PWD_H
|
2003-02-13 23:44:00 +01:00
|
|
|
|
|
|
|
#include "../jrd/ibase.h"
|
2009-09-11 12:49:46 +02:00
|
|
|
#include "../common/utils_proto.h"
|
2004-11-14 19:09:14 +01:00
|
|
|
#include "../jrd/sha.h"
|
2008-09-04 15:16:59 +02:00
|
|
|
#include "gen/iberror.h"
|
2010-01-22 15:55:11 +01:00
|
|
|
#include "../common/classes/ClumpletWriter.h"
|
|
|
|
|
|
|
|
#include "../auth/AuthInterface.h"
|
|
|
|
|
2004-11-16 12:41:35 +01:00
|
|
|
#ifdef HAVE_STDLIB_H
|
2004-11-14 19:09:14 +01:00
|
|
|
#include <stdlib.h>
|
2004-11-16 12:41:35 +01:00
|
|
|
#endif
|
2004-11-07 15:50:53 +01:00
|
|
|
#include <time.h>
|
2003-02-13 23:44:00 +01:00
|
|
|
|
2010-01-22 15:55:11 +01:00
|
|
|
namespace Auth {
|
|
|
|
|
2009-04-03 12:49:07 +02:00
|
|
|
const size_t MAX_PASSWORD_ENC_LENGTH = 12; // passed by remote protocol
|
|
|
|
const size_t MAX_PASSWORD_LENGTH = 64; // used to store passwords internally
|
2009-04-04 18:28:33 +02:00
|
|
|
static const char* const PASSWORD_SALT = "9z"; // for old ENC_crypt()
|
2009-04-03 12:49:07 +02:00
|
|
|
const size_t SALT_LENGTH = 12; // measured after base64 coding
|
2003-02-13 23:44:00 +01:00
|
|
|
|
|
|
|
class SecurityDatabase
|
|
|
|
{
|
|
|
|
public:
|
2010-01-22 15:55:11 +01:00
|
|
|
static void getPath(char* path_buffer)
|
2004-11-07 15:50:53 +01:00
|
|
|
{
|
2008-01-16 10:29:37 +01:00
|
|
|
static const char* USER_INFO_NAME = "security2.fdb";
|
2009-09-11 12:49:46 +02:00
|
|
|
Firebird::PathName name = fb_utils::getPrefix(fb_utils::FB_DIR_SECDB, USER_INFO_NAME);
|
|
|
|
name.copyTo(path_buffer, MAXPATHLEN);
|
2004-11-07 15:50:53 +01:00
|
|
|
}
|
|
|
|
|
2010-01-24 16:18:43 +01:00
|
|
|
static Result verify(WriterInterface* authBlock,
|
2010-01-22 15:55:11 +01:00
|
|
|
Firebird::ClumpletReader& originalDpb);
|
|
|
|
|
2010-01-24 18:15:57 +01:00
|
|
|
static void shutdown(void*);
|
2003-02-13 23:44:00 +01:00
|
|
|
|
2008-12-22 10:00:05 +01:00
|
|
|
static void hash(Firebird::string& h, const Firebird::string& userName, const TEXT* passwd)
|
2004-11-07 15:50:53 +01:00
|
|
|
{
|
|
|
|
Firebird::string salt;
|
2004-11-14 19:09:14 +01:00
|
|
|
Jrd::CryptSupport::random(salt, SALT_LENGTH);
|
2004-11-07 15:50:53 +01:00
|
|
|
hash(h, userName, passwd, salt);
|
|
|
|
}
|
|
|
|
|
2008-12-05 01:56:15 +01:00
|
|
|
static void hash(Firebird::string& h,
|
|
|
|
const Firebird::string& userName,
|
2010-01-22 15:55:11 +01:00
|
|
|
const Firebird::string& passwd,
|
2004-11-07 15:50:53 +01:00
|
|
|
const Firebird::string& oldHash)
|
|
|
|
{
|
|
|
|
Firebird::string salt(oldHash);
|
|
|
|
salt.resize(SALT_LENGTH, '=');
|
|
|
|
Firebird::string allData(salt);
|
|
|
|
allData += userName;
|
|
|
|
allData += passwd;
|
2004-11-14 19:09:14 +01:00
|
|
|
Jrd::CryptSupport::hash(h, allData);
|
2004-11-07 15:50:53 +01:00
|
|
|
h = salt + h;
|
|
|
|
}
|
|
|
|
|
2003-02-13 23:44:00 +01:00
|
|
|
private:
|
2008-02-05 09:21:18 +01:00
|
|
|
Firebird::Mutex mutex;
|
2003-05-02 20:41:12 +02:00
|
|
|
|
2003-04-16 12:18:51 +02:00
|
|
|
ISC_STATUS_ARRAY status;
|
2003-02-13 23:44:00 +01:00
|
|
|
|
|
|
|
isc_db_handle lookup_db;
|
|
|
|
isc_req_handle lookup_req;
|
|
|
|
|
2010-01-22 15:55:11 +01:00
|
|
|
int timer;
|
|
|
|
char user_info_name[MAXPATHLEN];
|
2003-02-13 23:44:00 +01:00
|
|
|
|
|
|
|
void init();
|
2010-01-22 15:55:11 +01:00
|
|
|
void fini();
|
|
|
|
bool lookup_user(const char*, char*);
|
2008-09-04 15:16:59 +02:00
|
|
|
void prepare();
|
|
|
|
void checkStatus(const char* callName, ISC_STATUS userError = isc_psw_db_error);
|
2003-02-13 23:44:00 +01:00
|
|
|
|
2003-10-03 14:28:54 +02:00
|
|
|
static SecurityDatabase instance;
|
2003-02-13 23:44:00 +01:00
|
|
|
|
2008-05-02 13:10:00 +02:00
|
|
|
SecurityDatabase()
|
2010-01-22 15:55:11 +01:00
|
|
|
: lookup_db(0), lookup_req(0), timer(0)
|
2008-02-13 14:10:23 +01:00
|
|
|
{
|
2010-01-22 15:55:11 +01:00
|
|
|
}
|
2003-02-13 23:44:00 +01:00
|
|
|
};
|
|
|
|
|
2010-01-22 15:55:11 +01:00
|
|
|
class SecurityDatabaseServer : public ServerPlugin
|
2008-01-16 10:29:37 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-01-22 15:55:11 +01:00
|
|
|
ServerInstance* instance();
|
2010-01-27 17:51:26 +01:00
|
|
|
void getName(const char** data, unsigned short* dataSize);
|
2010-01-22 15:55:11 +01:00
|
|
|
void release();
|
2008-01-16 10:29:37 +01:00
|
|
|
};
|
|
|
|
|
2010-01-22 15:55:11 +01:00
|
|
|
class SecurityDatabaseServerInstance : public ServerInstance
|
|
|
|
{
|
|
|
|
public:
|
2010-01-24 16:18:43 +01:00
|
|
|
|
|
|
|
Result startAuthentication(bool isService, const char* dbName,
|
2010-01-22 15:55:11 +01:00
|
|
|
const unsigned char* dpb, unsigned int dpbSize,
|
|
|
|
WriterInterface* writerInterface);
|
2010-01-24 16:18:43 +01:00
|
|
|
Result contAuthentication(WriterInterface* writerInterface,
|
2010-01-22 15:55:11 +01:00
|
|
|
const unsigned char* data, unsigned int size);
|
2010-01-27 17:51:26 +01:00
|
|
|
void getData(const unsigned char** data, unsigned short* dataSize);
|
2010-01-22 15:55:11 +01:00
|
|
|
void release();
|
|
|
|
};
|
2008-01-16 10:29:37 +01:00
|
|
|
|
2010-01-22 15:55:11 +01:00
|
|
|
} // namespace Auth
|
2008-01-16 10:29:37 +01:00
|
|
|
|
2008-05-02 13:10:00 +02:00
|
|
|
#endif // JRD_PWD_H
|