1#ifndef ENGINE_SERVER_AUTHMANAGER_H
2#define ENGINE_SERVER_AUTHMANAGER_H
3
4#include <vector>
5
6#include <base/hash.h>
7
8#define SALT_BYTES 8
9
10class CAuthManager
11{
12private:
13 struct CKey
14 {
15 char m_aIdent[64];
16 MD5_DIGEST m_Pw;
17 unsigned char m_aSalt[SALT_BYTES];
18 int m_Level;
19 };
20 std::vector<CKey> m_vKeys;
21
22 int m_aDefault[3];
23 bool m_Generated;
24
25public:
26 typedef void (*FListCallback)(const char *pIdent, int Level, void *pUser);
27
28 CAuthManager();
29
30 void Init();
31 int AddKeyHash(const char *pIdent, MD5_DIGEST Hash, const unsigned char *pSalt, int AuthLevel);
32 int AddKey(const char *pIdent, const char *pPw, int AuthLevel);
33 void RemoveKey(int Slot);
34 int FindKey(const char *pIdent) const;
35 bool CheckKey(int Slot, const char *pPw) const;
36 int DefaultKey(int AuthLevel) const;
37 int KeyLevel(int Slot) const;
38 const char *KeyIdent(int Slot) const;
39 void UpdateKeyHash(int Slot, MD5_DIGEST Hash, const unsigned char *pSalt, int AuthLevel);
40 void UpdateKey(int Slot, const char *pPw, int AuthLevel);
41 void ListKeys(FListCallback pfnListCallbac, void *pUser);
42 void AddDefaultKey(int Level, const char *pPw);
43 bool IsGenerated() const;
44 int NumNonDefaultKeys() const;
45};
46
47#endif //ENGINE_SERVER_AUTHMANAGER_H
48