initial import of group reader (unfinished)

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40426
This commit is contained in:
David Anderson 2007-01-30 05:42:57 +00:00
parent d52aaa81d9
commit 5085521b54
4 changed files with 157 additions and 4 deletions

View File

@ -4,9 +4,9 @@ Groups
* Allowed properties for a group:
*
* "flags" - Flag string.
* "inherit" - Inherits permissions from another group.
* "inherit" - Inherits permissions from another group. Use one group per instance of this key.
* "immunity" - Specifies a group to be immune to. Use "*" for all or "$" for users with no group.
* NOTE: No one, even a root user, is immune from other root users.
* This key may be used multiple times.
*/
"Full Admins"
{
@ -14,7 +14,7 @@ Groups
* You can override commands and command groups here.
* Specify a command name or group and either "allow" or "deny"
* Examples:
* ":CSDM" "allow"
* ":CSDM" "allow"
* "csdm_enable" "deny"
*/
Commands

View File

@ -0,0 +1,147 @@
#define GROUP_STATE_NONE 0
#define GROUP_STATE_GROUPS 1
#define GROUP_STATE_INGROUP 2
#define GROUP_STATE_OVERRIDES 3
#define GROUP_PASS_FIRST 1
#define GROUP_PASS_SECOND 2
static Handle:g_hGroupParser = INVALID_HANDLE;
static GroupId:g_CurGrp = INVALID_GROUP_ID;
static g_GroupState = GROUP_STATE_NONE;
static g_GroupPass = 0
static LevelGroupError(const String:buffer[], {Handle,String,Float,_}:...)
{
decl String:buffer[512];
if (!g_LoggedFileName)
{
LogError("Error(s) detected parsing admin_groups.cfg:");
g_LoggedFileName = true;
}
VFormat(buffer, sizeof(buffer), format, 2);
LogError(" (%d) %s", ++g_ErrorCount, buffer);
}
public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
{
if (g_GroupState == GROUP_STATE_NONE)
{
if (StrEqual(name, "Groups"))
{
g_GroupState = GROUP_STATE_GROUPS;
}
} else if (g_GroupState == GROUP_STATE_GROUPS) {
if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
{
g_CurGrp = FindAdmGroup(name);
}
g_GroupState = GROUP_STATE_INGROUP;
} else if (g_GroupState == GROUP_STATE_INGROUP) {
if (StrEqual(name, "Overrides"))
{
g_GroupState = GROUP_STATE_OVERRIDES;
}
}
return SMCParse_Continue;
}
public SMCResult:ReadGroups_KeyValue(Handle:smc,
const String:key[],
const String:value[],
bool:key_quotes,
bool:value_quotes)
{
if (g_CurGrp == INVALID_GROUP_ID)
{
return SMCParse_Continue;
}
new AdminFlag:flag;
if (StrEqual(key, "flags"))
{
new len = strlen(value);
for (new i=0; i<len; i++)
{
if (value[i] < 'a' || value[i] > 'z')
{
continue;
}
flag = g_FlagLetters[value[i] - 'a'];
if (flag == Admin_None)
{
continue;
}
SetAdmGroupAddFlag(g_CurGrp, flag, true);
}
} else if (StrEqual(key, "immunity")) {
if (StrEqual(value, "*"))
{
SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true);
} else if (StrEqual(value, "$")) {
SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true);
}
}
return SMCParse_Continue;
}
public SMCResult:ReadGroups_EndSection(Handle:smc)
{
if (g_GroupState == GROUP_STATE_OVERRIDES)
{
g_GroupState = GROUP_STATE_INGROUP;
} else if (g_GroupState == GROUP_STATE_INGROUP) {
g_GroupState = GROUP_STATE_GROUPS;
g_CurGrp = INVALID_GROUP_ID;
} else if (g_GroupState == GROUP_STATE_GROUPS) {
g_GroupState = GROUP_STATE_NONE;
}
return SMCParse_Continue;
}
static InitializeGroupParser()
{
if (g_hGroupParser == INVALID_HANDLE)
{
g_hGroupParser = SMC_CreateParser();
SMC_SetReaders(g_hGroupParser,
ReadGroup_NewSection,
ReadGroup_KeyValue,
ReadGroup_EndSection);
}
}
ReadGroups()
{
new String:path[PLATFORM_MAX_PATH];
InitializeGroupParser();
BuildPath(Path_SM, path, sizeof(path), "configs/admin_groups.cfg");
/* Set states */
g_GroupState = GROUP_STATE_NONE;
g_LoggedFileName = false;
g_ErrorCount = 0;
g_CurGrp = INVALID_GROUP_ID;
g_GroupPass = GROUP_PASS_FIRST;
new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
if (err != SMCError_Okay)
{
decl String:buffer[64];
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
{
LogGroupError("%s", buffer);
} else {
LogGroupError("Fatal parse error");
}
}
}

View File

@ -5,7 +5,7 @@
static Handle:g_hOverrideParser = INVALID_HANDLE;
static g_OverrideState = OVERRIDE_STATE_NONE;
LogOverrideError(const String:format[], {Handle,String,Float,_}:...)
static LogOverrideError(const String:format[], {Handle,String,Float,_}:...)
{
decl String:buffer[512];

View File

@ -62,6 +62,12 @@ enum GroupId
INVALID_GROUP_ID = -1,
};
/** Note: These are not Handles */
enum AdminId
{
INVALID_ADMIN_ID = -1,
};
#define ADMIN_CACHE_OVERRIDES (1<<0)
#define ADMIN_CACHE_ADMINS (1<<1)
#define ADMIN_CACHE_GROUPS ((1<<2)|ADMIN_CACHE_ADMINS)