core/smn_admin.cpp
changeset 436 ffadb284461e
parent 433 d699e31199ad
child 438 e6e11c82d87e
     1.1 --- a/core/smn_admin.cpp	Mon Feb 05 20:32:34 2007 +0000
     1.2 +++ b/core/smn_admin.cpp	Tue Feb 06 01:14:32 2007 +0000
     1.3 @@ -183,6 +183,241 @@
     1.4  	return g_Admins.GetGroupAddFlags(id);
     1.5  }
     1.6  
     1.7 +static cell_t RegisterAuthIdentType(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	char *type;
    1.10 +	pContext->LocalToString(params[1], &type);
    1.11 +
    1.12 +	g_Admins.RegisterAuthIdentType(type);
    1.13 +
    1.14 +	return 1;
    1.15 +}
    1.16 +
    1.17 +static cell_t CreateAdmin(IPluginContext *pContext, const cell_t *params)
    1.18 +{
    1.19 +	char *admin;
    1.20 +	pContext->LocalToString(params[1], &admin);
    1.21 +
    1.22 +	if (admin[0] == '\0')
    1.23 +	{
    1.24 +		admin = NULL;
    1.25 +	}
    1.26 +
    1.27 +	return g_Admins.CreateAdmin(admin);
    1.28 +}
    1.29 +
    1.30 +static cell_t GetAdminUsername(IPluginContext *pContext, const cell_t *params)
    1.31 +{
    1.32 +	AdminId id = params[1];
    1.33 +	size_t written;
    1.34 +	const char *name = g_Admins.GetAdminName(id);
    1.35 +
    1.36 +	if (!name)
    1.37 +	{
    1.38 +		return 0;
    1.39 +	}
    1.40 +
    1.41 +	pContext->StringToLocalUTF8(params[2], params[3], name, &written);
    1.42 +
    1.43 +	return written;
    1.44 +}
    1.45 +
    1.46 +static cell_t BindAdminIdentity(IPluginContext *pContext, const cell_t *params)
    1.47 +{
    1.48 +	AdminId id = params[1];
    1.49 +	char *auth, *ident;
    1.50 +
    1.51 +	pContext->LocalToString(params[2], &auth);
    1.52 +	pContext->LocalToString(params[3], &ident);
    1.53 +
    1.54 +	return g_Admins.BindAdminIdentity(id, auth, ident);
    1.55 +}
    1.56 +
    1.57 +static cell_t SetAdminFlag(IPluginContext *pContext, const cell_t *params)
    1.58 +{
    1.59 +	AdminId id = params[1];
    1.60 +	AdminFlag flag = (AdminFlag)params[2];
    1.61 +	bool enabled = params[3] ? true : false;
    1.62 +
    1.63 +	g_Admins.SetAdminFlag(id, flag, enabled);
    1.64 +
    1.65 +	return 1;
    1.66 +}
    1.67 +
    1.68 +static cell_t GetAdminFlag(IPluginContext *pContext, const cell_t *params)
    1.69 +{
    1.70 +	AdminId id = params[1];
    1.71 +	AdminFlag flag = (AdminFlag)params[2];
    1.72 +	AccessMode mode = (AccessMode)params[3];
    1.73 +
    1.74 +	return g_Admins.GetAdminFlag(id, flag, mode);
    1.75 +}
    1.76 +
    1.77 +static cell_t GetAdminFlags(IPluginContext *pContext, const cell_t *params)
    1.78 +{
    1.79 +	AdminId id = params[1];
    1.80 +	AccessMode mode = (AccessMode)params[2];
    1.81 +
    1.82 +	return g_Admins.GetAdminFlags(id, mode);
    1.83 +}
    1.84 +
    1.85 +static cell_t AdminInheritGroup(IPluginContext *pContext, const cell_t *params)
    1.86 +{
    1.87 +	AdminId id = params[1];
    1.88 +	GroupId gid = params[2];
    1.89 +
    1.90 +	return g_Admins.AdminInheritGroup(id, gid);
    1.91 +}
    1.92 +
    1.93 +static cell_t GetAdminGroupCount(IPluginContext *pContext, const cell_t *params)
    1.94 +{
    1.95 +	AdminId id = params[1];
    1.96 +
    1.97 +	return g_Admins.GetAdminGroupCount(id);
    1.98 +}
    1.99 +
   1.100 +static cell_t GetAdminGroup(IPluginContext *pContext, const cell_t *params)
   1.101 +{
   1.102 +	AdminId id = params[1];
   1.103 +	unsigned int index = params[2];
   1.104 +	const char *name;
   1.105 +	GroupId gid;
   1.106 +
   1.107 +	if ((gid=g_Admins.GetAdminGroup(id, index, &name)) == INVALID_GROUP_ID)
   1.108 +	{
   1.109 +		return gid;
   1.110 +	}
   1.111 +
   1.112 +	if (name == NULL)
   1.113 +	{
   1.114 +		name = "";
   1.115 +	}
   1.116 +
   1.117 +	pContext->StringToLocalUTF8(params[3], params[4], name, NULL);
   1.118 +
   1.119 +	return gid;
   1.120 +}
   1.121 +
   1.122 +static cell_t SetAdminPassword(IPluginContext *pContext, const cell_t *params)
   1.123 +{
   1.124 +	AdminId id = params[1];
   1.125 +	char *password;
   1.126 +
   1.127 +	pContext->LocalToString(params[2], &password);
   1.128 +
   1.129 +	g_Admins.SetAdminPassword(id, password);
   1.130 +
   1.131 +	return 1;
   1.132 +}
   1.133 +
   1.134 +static cell_t GetAdminPassword(IPluginContext *pContext, const cell_t *params)
   1.135 +{
   1.136 +	AdminId id = params[1];
   1.137 +	const char *password = g_Admins.GetAdminPassword(id);
   1.138 +
   1.139 +	if (!password)
   1.140 +	{
   1.141 +		return 0;
   1.142 +	}
   1.143 +
   1.144 +	pContext->StringToLocalUTF8(params[2], params[3], password, NULL);
   1.145 +
   1.146 +	return 1;
   1.147 +}
   1.148 +
   1.149 +static cell_t FindAdminByIdentity(IPluginContext *pContext, const cell_t *params)
   1.150 +{
   1.151 +	char *auth, *ident;
   1.152 +
   1.153 +	pContext->LocalToString(params[1], &auth);
   1.154 +	pContext->LocalToString(params[2], &ident);
   1.155 +
   1.156 +	return g_Admins.FindAdminByIdentity(auth, ident);
   1.157 +}
   1.158 +
   1.159 +static cell_t RemoveAdmin(IPluginContext *pContext, const cell_t *params)
   1.160 +{
   1.161 +	AdminId id = params[1];
   1.162 +
   1.163 +	return g_Admins.InvalidateAdmin(id);
   1.164 +}
   1.165 +
   1.166 +static cell_t FlagBitsToBitArray(IPluginContext *pContext, const cell_t *params)
   1.167 +{
   1.168 +	FlagBits bits = (FlagBits)params[1];
   1.169 +	bool array[AdminFlags_TOTAL];
   1.170 +	cell_t *addr;
   1.171 +	unsigned int numWr = g_Admins.FlagBitsToBitArray(bits, array, AdminFlags_TOTAL);
   1.172 +
   1.173 +	pContext->LocalToPhysAddr(params[2], &addr);
   1.174 +
   1.175 +	unsigned int i;
   1.176 +	for (i=0; i<numWr && i<(unsigned int)params[3]; i++)
   1.177 +	{
   1.178 +		addr[i] = array[i] ? 1 : 0;
   1.179 +	}
   1.180 +
   1.181 +	return i;
   1.182 +}
   1.183 +
   1.184 +static cell_t FlagBitArrayToBits(IPluginContext *pContext, const cell_t *params)
   1.185 +{
   1.186 +	bool array[AdminFlags_TOTAL];
   1.187 +	unsigned int num = ((unsigned int)params[2] > AdminFlags_TOTAL ? params[2] : AdminFlags_TOTAL);
   1.188 +	cell_t *addr;
   1.189 +
   1.190 +	pContext->LocalToPhysAddr(params[1], &addr);
   1.191 +
   1.192 +	for (unsigned int i=0; i<num; i++)
   1.193 +	{
   1.194 +		array[i] = addr[i] ? true : false;
   1.195 +	}
   1.196 +
   1.197 +	return g_Admins.FlagBitArrayToBits(array, num);
   1.198 +}
   1.199 +
   1.200 +static cell_t FlagArrayToBits(IPluginContext *pContext, const cell_t *params)
   1.201 +{
   1.202 +	cell_t *addr;
   1.203 +	pContext->LocalToPhysAddr(params[1], &addr);
   1.204 +
   1.205 +	if (sizeof(AdminFlag) == sizeof(cell_t))
   1.206 +	{
   1.207 +		return g_Admins.FlagArrayToBits((const AdminFlag *)addr, params[2]);
   1.208 +	} else {
   1.209 +		AdminFlag flags[AdminFlags_TOTAL];
   1.210 +		unsigned int num = ((unsigned)params[2] > AdminFlags_TOTAL ? AdminFlags_TOTAL : params[2]);
   1.211 +
   1.212 +		for (unsigned int i=0; i<num; i++)
   1.213 +		{
   1.214 +			flags[i] = (AdminFlag)addr[i];
   1.215 +		}
   1.216 +		return g_Admins.FlagArrayToBits(flags, num);
   1.217 +	}
   1.218 +}
   1.219 +
   1.220 +static cell_t FlagBitsToArray(IPluginContext *pContext, const cell_t *params)
   1.221 +{
   1.222 +	cell_t *addr;
   1.223 +	pContext->LocalToPhysAddr(params[2], &addr);
   1.224 +
   1.225 +	if (sizeof(AdminFlag) == sizeof(cell_t))
   1.226 +	{
   1.227 +		return g_Admins.FlagBitsToArray(params[1], (AdminFlag *)addr, params[3]);
   1.228 +	} else {
   1.229 +		AdminFlag flags[AdminFlags_TOTAL];
   1.230 +		unsigned int num = ((unsigned)params[2] > AdminFlags_TOTAL ? AdminFlags_TOTAL : params[2]);
   1.231 +		num = g_Admins.FlagBitsToArray(params[1], flags, num);
   1.232 +
   1.233 +		for (unsigned int i=0; i<num; i++)
   1.234 +		{
   1.235 +			addr[i] = flags[i];
   1.236 +		}
   1.237 +
   1.238 +		return num;
   1.239 +	}
   1.240 +}
   1.241 +
   1.242  REGISTER_NATIVES(adminNatives)
   1.243  {
   1.244  	{"DumpAdminCache",			DumpAdminCache},
   1.245 @@ -201,5 +436,24 @@
   1.246  	{"AddAdmGroupCmdOverride",	AddAdmGroupCmdOverride},
   1.247  	{"GetAdmGroupCmdOverride",	GetAdmGroupCmdOverride},
   1.248  	{"GetAdmGroupAddFlags",		GetAdmGroupAddFlags},
   1.249 +	{"RegisterAuthIdentType",	RegisterAuthIdentType},
   1.250 +	{"CreateAdmin",				CreateAdmin},
   1.251 +	{"GetAdminUsername",		GetAdminUsername},
   1.252 +	{"BindAdminIdentity",		BindAdminIdentity},
   1.253 +	{"SetAdminFlag",			SetAdminFlag},
   1.254 +	{"GetAdminFlag",			GetAdminFlag},
   1.255 +	{"GetAdminFlags",			GetAdminFlags},
   1.256 +	{"AdminInheritGroup",		AdminInheritGroup},
   1.257 +	{"GetAdminGroupCount",		GetAdminGroupCount},
   1.258 +	{"GetAdminGroup",			GetAdminGroup},
   1.259 +	{"SetAdminPassword",		SetAdminPassword},
   1.260 +	{"GetAdminPassword",		GetAdminPassword},
   1.261 +	{"FindAdminByIdentity",		FindAdminByIdentity},
   1.262 +	{"RemoveAdmin",				RemoveAdmin},
   1.263 +	{"FlagBitsToBitArray",		FlagBitsToBitArray},
   1.264 +	{"FlagBitArrayToBits",		FlagBitArrayToBits},
   1.265 +	{"FlagArrayToBits",			FlagArrayToBits},
   1.266 +	{"FlagBitsToArray",			FlagBitsToArray},
   1.267 +	/* -------------------------------------------------- */
   1.268  	{NULL,						NULL},
   1.269  };