core/AdminCache.h
changeset 404 673ccd0935ba
parent 370 d3a484f98f6d
child 405 3e5727a37caa
     1.1 --- a/core/AdminCache.h	Sun Jan 28 04:19:46 2007 +0000
     1.2 +++ b/core/AdminCache.h	Mon Jan 29 04:19:14 2007 +0000
     1.3 @@ -17,6 +17,7 @@
     1.4  #include "sm_memtable.h"
     1.5  #include <sm_trie.h>
     1.6  #include <sh_list.h>
     1.7 +#include <sh_string.h>
     1.8  #include <IAdminSystem.h>
     1.9  #include "sm_globals.h"
    1.10  #include <IForwardSys.h>
    1.11 @@ -25,6 +26,8 @@
    1.12  
    1.13  #define GRP_MAGIC_SET		0xDEADFADE
    1.14  #define GRP_MAGIC_UNSET		0xFACEFACE
    1.15 +#define USR_MAGIC_SET		0xDEADFACE
    1.16 +#define USR_MAGIC_UNSET		0xFADEDEAD
    1.17  
    1.18  struct AdminGroup
    1.19  {
    1.20 @@ -44,6 +47,35 @@
    1.21  	bool addflags[AdminFlags_TOTAL];	/* Additive flags */
    1.22  };
    1.23  
    1.24 +struct AuthMethod
    1.25 +{
    1.26 +	String name;
    1.27 +	Trie *table;
    1.28 +};
    1.29 +
    1.30 +struct UserAuth
    1.31 +{
    1.32 +	unsigned int index;				/* Index into auth table */
    1.33 +	int identidx;					/* Index into the string table */
    1.34 +};
    1.35 +
    1.36 +struct AdminUser
    1.37 +{
    1.38 +	int magic;						/* Magic flag, for memory validation */
    1.39 +	bool flags[AdminFlags_TOTAL];	/* Base flags */
    1.40 +	bool eflags[AdminFlags_TOTAL];	/* Effective flags */
    1.41 +	int nameidx;					/* Name index */
    1.42 +	int password;					/* Password index */
    1.43 +	unsigned int grp_count;			/* Number of groups */
    1.44 +	unsigned int grp_size;			/* Size of groups table */
    1.45 +	int grp_table;					/* Group table itself */
    1.46 +	int next_user;					/* Next user in ze list */
    1.47 +	int prev_user;					/* Prev user in the list */
    1.48 +	unsigned int auth_count;		/* Number of auth methods */
    1.49 +	unsigned int auth_size;			/* Size of auth table */
    1.50 +	int auth_table;					/* Auth table itself */
    1.51 +};
    1.52 +
    1.53  class AdminCache : 
    1.54  	public IAdminSystem,
    1.55  	public SMGlobalClass
    1.56 @@ -52,6 +84,7 @@
    1.57  	AdminCache();
    1.58  	~AdminCache();
    1.59  public: //SMGlobalClass
    1.60 +	void OnSourceModStartup(bool late);
    1.61  	void OnSourceModAllInitialized();
    1.62  	void OnSourceModShutdown();
    1.63  public: //IAdminSystem
    1.64 @@ -76,6 +109,21 @@
    1.65  	void DumpAdminCache(int cache_flags, bool rebuild);
    1.66  	void AddAdminListener(IAdminListener *pListener);
    1.67  	void RemoveAdminListener(IAdminListener *pListener);
    1.68 +	/** User stuff */
    1.69 +	void RegisterAuthIdentType(const char *name);
    1.70 +	AdminId CreateAdmin(const char *name);
    1.71 +	const char *GetAdminName(AdminId id);
    1.72 +	bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
    1.73 +	virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
    1.74 +	bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
    1.75 +	unsigned int GetAdminFlags(AdminId id, bool flags[], unsigned int total, AccessMode mode);
    1.76 +	bool AdminInheritGroup(AdminId id, GroupId gid);
    1.77 +	unsigned int GetAdminGroupCount(AdminId id);
    1.78 +	GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
    1.79 +	void SetAdminPassword(AdminId id, const char *password);
    1.80 +	const char *GetAdminPassword(AdminId id);
    1.81 +	AdminId FindAdminByIdentity(const char *auth, const char *identity);
    1.82 +	bool InvalidateAdmin(AdminId id);
    1.83  private:
    1.84  	void _AddCommandOverride(const char *cmd, AdminFlag flag);
    1.85  	void _AddCommandGroupOverride(const char *group, AdminFlag flag);
    1.86 @@ -84,7 +132,9 @@
    1.87  	void _UnsetCommandOverride(const char *cmd);
    1.88  	void _UnsetCommandGroupOverride(const char *group);
    1.89  	void InvalidateGroupCache();
    1.90 +	void InvalidateAdminCache(bool unlink_admins);
    1.91  	void DumpCommandOverrideCache(OverrideType type);
    1.92 +	Trie *GetMethodByIndex(unsigned int index);
    1.93  public:
    1.94  	BaseStringTable *m_pStrings;
    1.95  	BaseMemTable *m_pMemory;
    1.96 @@ -95,7 +145,12 @@
    1.97  	int m_FreeGroupList;
    1.98  	Trie *m_pGroups;
    1.99  	List<IAdminListener *> m_hooks;
   1.100 +	List<AuthMethod> m_AuthMethods;
   1.101 +	Trie *m_pAuthTables;
   1.102  	IForward *m_pCacheFwd;
   1.103 +	int m_FirstUser;
   1.104 +	int m_LastUser;
   1.105 +	int m_FreeUserList;
   1.106  };
   1.107  
   1.108  extern AdminCache g_Admins;