2018-07-06 14:11:38 +00:00
|
|
|
#ifndef ENGINE_SERVER_AUTHMANAGER_H
|
|
|
|
#define ENGINE_SERVER_AUTHMANAGER_H
|
2017-03-02 15:16:29 +00:00
|
|
|
|
2019-04-06 00:46:56 +00:00
|
|
|
#include <base/hash.h>
|
2017-03-02 15:16:29 +00:00
|
|
|
#include <base/tl/array.h>
|
|
|
|
|
|
|
|
#define SALT_BYTES 8
|
|
|
|
|
|
|
|
class CAuthManager
|
|
|
|
{
|
|
|
|
private:
|
2017-03-09 12:37:54 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-03-02 15:16:29 +00:00
|
|
|
AUTHED_NO = 0,
|
|
|
|
AUTHED_HELPER,
|
|
|
|
AUTHED_MOD,
|
|
|
|
AUTHED_ADMIN
|
|
|
|
};
|
|
|
|
struct CKey
|
|
|
|
{
|
|
|
|
char m_aIdent[64];
|
2019-04-06 00:46:56 +00:00
|
|
|
MD5_DIGEST m_Pw;
|
2017-03-02 15:16:29 +00:00
|
|
|
unsigned char m_aSalt[SALT_BYTES];
|
|
|
|
int m_Level;
|
|
|
|
};
|
|
|
|
array<CKey> m_aKeys;
|
|
|
|
|
|
|
|
int m_aDefault[3];
|
2017-03-04 20:06:22 +00:00
|
|
|
bool m_Generated;
|
2017-03-02 15:16:29 +00:00
|
|
|
public:
|
|
|
|
typedef void (*FListCallback)(const char *pIdent, int Level, void *pUser);
|
|
|
|
|
|
|
|
CAuthManager();
|
|
|
|
|
|
|
|
void Init();
|
2019-04-06 00:46:56 +00:00
|
|
|
int AddKeyHash(const char *pIdent, MD5_DIGEST Hash, const unsigned char *pSalt, int AuthLevel);
|
2017-03-02 15:16:29 +00:00
|
|
|
int AddKey(const char *pIdent, const char *pPw, int AuthLevel);
|
2017-03-06 17:02:19 +00:00
|
|
|
int RemoveKey(int Slot); // Returns the old key slot that is now in the named one.
|
2017-03-02 15:16:29 +00:00
|
|
|
int FindKey(const char *pIdent);
|
|
|
|
bool CheckKey(int Slot, const char *pPw);
|
|
|
|
int DefaultKey(int AuthLevel);
|
|
|
|
int KeyLevel(int Slot);
|
|
|
|
const char *KeyIdent(int Slot);
|
2019-04-06 00:46:56 +00:00
|
|
|
void UpdateKeyHash(int Slot, MD5_DIGEST Hash, const unsigned char *pSalt, int AuthLevel);
|
2017-03-02 15:16:29 +00:00
|
|
|
void UpdateKey(int Slot, const char *pPw, int AuthLevel);
|
|
|
|
void ListKeys(FListCallback pfnListCallbac, void *pUser);
|
2017-03-06 17:02:19 +00:00
|
|
|
void AddDefaultKey(int Level, const char *pPw);
|
2017-03-04 20:06:22 +00:00
|
|
|
bool IsGenerated();
|
2017-07-24 19:43:55 +00:00
|
|
|
int NumNonDefaultKeys();
|
2017-03-02 15:16:29 +00:00
|
|
|
};
|
|
|
|
|
2018-07-06 14:11:38 +00:00
|
|
|
#endif //ENGINE_SERVER_AUTHMANAGER_H
|