1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-12-26 18:19:53 +03:00

Cedar/Admin: implement RPC methods to get/set Proto options

This commit is contained in:
Davide Beatrici 2020-07-21 03:23:54 +02:00
parent aa65327e73
commit 3a275d7257
10 changed files with 285 additions and 0 deletions

View File

@ -1496,6 +1496,8 @@ PACK *AdminDispatch(RPC *rpc, char *name, PACK *p)
DECLARE_RPC("EnableListener", RPC_LISTENER, StEnableListener, InRpcListener, OutRpcListener)
DECLARE_RPC_EX("SetPortsUDP", RPC_PORTS, StSetPortsUDP, InRpcPorts, OutRpcPorts, FreeRpcPorts)
DECLARE_RPC_EX("GetPortsUDP", RPC_PORTS, StGetPortsUDP, InRpcPorts, OutRpcPorts, FreeRpcPorts)
DECLARE_RPC_EX("SetProtoOptions", RPC_PROTO_OPTIONS, StSetProtoOptions, InRpcProtoOptions, OutRpcProtoOptions, FreeRpcProtoOptions)
DECLARE_RPC_EX("GetProtoOptions", RPC_PROTO_OPTIONS, StGetProtoOptions, InRpcProtoOptions, OutRpcProtoOptions, FreeRpcProtoOptions)
DECLARE_RPC("SetServerPassword", RPC_SET_PASSWORD, StSetServerPassword, InRpcSetPassword, OutRpcSetPassword)
DECLARE_RPC_EX("SetFarmSetting", RPC_FARM, StSetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)
DECLARE_RPC_EX("GetFarmSetting", RPC_FARM, StGetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)
@ -1678,6 +1680,8 @@ DECLARE_SC("DeleteListener", RPC_LISTENER, ScDeleteListener, InRpcListener, OutR
DECLARE_SC("EnableListener", RPC_LISTENER, ScEnableListener, InRpcListener, OutRpcListener)
DECLARE_SC_EX("SetPortsUDP", RPC_PORTS, ScSetPortsUDP, InRpcPorts, OutRpcPorts, FreeRpcPorts)
DECLARE_SC_EX("GetPortsUDP", RPC_PORTS, ScGetPortsUDP, InRpcPorts, OutRpcPorts, FreeRpcPorts)
DECLARE_SC_EX("SetProtoOptions", RPC_PROTO_OPTIONS, ScSetProtoOptions, InRpcProtoOptions, OutRpcProtoOptions, FreeRpcProtoOptions)
DECLARE_SC_EX("GetProtoOptions", RPC_PROTO_OPTIONS, ScGetProtoOptions, InRpcProtoOptions, OutRpcProtoOptions, FreeRpcProtoOptions)
DECLARE_SC("SetServerPassword", RPC_SET_PASSWORD, ScSetServerPassword, InRpcSetPassword, OutRpcSetPassword)
DECLARE_SC_EX("SetFarmSetting", RPC_FARM, ScSetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)
DECLARE_SC_EX("GetFarmSetting", RPC_FARM, ScGetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)
@ -9959,6 +9963,140 @@ UINT StGetPortsUDP(ADMIN *a, RPC_PORTS *t)
return ERR_NO_ERROR;
}
UINT StGetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
{
PROTO *proto = a->Server->Proto;
PROTO_CONTAINER *container, tmp;
UINT ret = ERR_NO_ERROR;
LIST *options;
if (proto == NULL)
{
return ERR_NOT_SUPPORTED;
}
tmp.Name = t->Protocol;
container = Search(proto->Containers, &tmp);
if (container == NULL)
{
return ERR_INVALID_PARAMETER;
}
options = container->Options;
LockList(options);
{
UINT i;
t->Num = LIST_NUM(options);
t->Options = Malloc(sizeof(PROTO_OPTION) * t->Num);
for (i = 0; i < t->Num; ++i)
{
const PROTO_OPTION *option = LIST_DATA(options, i);
PROTO_OPTION *rpc_option = &t->Options[i];
switch (option->Type)
{
case PROTO_OPTION_BOOL:
rpc_option->Bool = option->Bool;
break;
case PROTO_OPTION_STRING:
rpc_option->String = CopyStr(option->String);
break;
default:
Debug("StGetProtoOptions(): unhandled option type %u!\n", option->Type);
ret = ERR_INTERNAL_ERROR;
}
if (ret == ERR_NO_ERROR)
{
rpc_option->Name = CopyStr(option->Name);
rpc_option->Type = option->Type;
}
else
{
break;
}
}
}
UnlockList(options);
return ret;
}
UINT StSetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
{
PROTO *proto = a->Server->Proto;
PROTO_CONTAINER *container, tmp;
UINT ret = ERR_NO_ERROR;
bool changed = false;
LIST *options;
SERVER_ADMIN_ONLY;
if (proto == NULL)
{
return ERR_NOT_SUPPORTED;
}
tmp.Name = t->Protocol;
container = Search(proto->Containers, &tmp);
if (container == NULL)
{
return ERR_INVALID_PARAMETER;
}
options = container->Options;
LockList(options);
{
UINT i;
for (i = 0; i < t->Num; ++i)
{
PROTO_OPTION *rpc_option = &t->Options[i];
PROTO_OPTION *option = Search(options, rpc_option);
if (option == NULL || rpc_option->Type != option->Type)
{
ret = ERR_INVALID_PARAMETER;
break;
}
switch (option->Type)
{
case PROTO_OPTION_BOOL:
option->Bool = rpc_option->Bool;
break;
case PROTO_OPTION_STRING:
Free(option->String);
option->String = CopyStr(rpc_option->String);
break;
default:
Debug("StSetProtoOptions(): unhandled option type %u!\n", option->Type);
ret = ERR_INTERNAL_ERROR;
}
if (ret == ERR_NO_ERROR)
{
changed = true;
}
else
{
break;
}
}
}
UnlockList(options);
if (changed)
{
ALog(a, NULL, "LA_SET_PROTO_OPTIONS", t->Protocol);
IncrementServerConfigRevision(a->Server);
}
return ret;
}
// Get server status
UINT StGetServerStatus(ADMIN *a, RPC_SERVER_STATUS *t)
{
@ -12266,6 +12404,130 @@ void FreeRpcStr(RPC_STR *t)
Free(t->String);
}
// RPC_PROTO_OPTIONS
void InRpcProtoOptions(RPC_PROTO_OPTIONS *t, PACK *p)
{
UINT i, size;
// Validate arguments
if (t == NULL || p == NULL)
{
return;
}
Zero(t, sizeof(RPC_PROTO_OPTIONS));
size = PackGetStrSize(p, "Protocol");
if (size > 0)
{
t->Protocol = Malloc(size);
if (PackGetStr(p, "Protocol", t->Protocol, size) == false)
{
Zero(t->Protocol, size);
}
}
t->Num = PackGetIndexCount(p, "Name");
if (t->Num == 0)
{
return;
}
t->Options = ZeroMalloc(sizeof(PROTO_OPTION) * t->Num);
for (i = 0; i < t->Num; ++i)
{
PROTO_OPTION *option = &t->Options[i];
size = PackGetStrSizeEx(p, "Name", i);
if (size > 0)
{
option->Name = Malloc(size);
if (PackGetStrEx(p, "Name", option->Name, size, i) == false)
{
Zero(option->Name, size);
}
}
option->Type = PackGetIntEx(p, "Type", i);
switch (option->Type)
{
case PROTO_OPTION_STRING:
size = PackGetDataSizeEx(p, "Value", i);
if (size > 0)
{
option->String = Malloc(size);
if (PackGetDataEx2(p, "Value", option->String, size, i) == false)
{
Zero(option->String, size);
}
}
break;
case PROTO_OPTION_BOOL:
PackGetDataEx2(p, "Value", &option->Bool, sizeof(option->Bool), i);
break;
default:
Debug("InRpcProtoOptions(): unhandled type %u!\n", option->Type);
}
}
}
void OutRpcProtoOptions(PACK *p, RPC_PROTO_OPTIONS *t)
{
UINT i;
// Validate arguments
if (t == NULL || p == NULL)
{
return;
}
PackAddStr(p, "Protocol", t->Protocol);
for (i = 0; i < t->Num; ++i)
{
PROTO_OPTION *option = &t->Options[i];
PackAddStrEx(p, "Name", option->Name, i, t->Num);
PackAddIntEx(p, "Type", option->Type, i, t->Num);
switch (option->Type)
{
case PROTO_OPTION_STRING:
PackAddDataEx(p, "Value", option->String, StrLen(option->String) + 1, i, t->Num);
break;
case PROTO_OPTION_BOOL:
PackAddDataEx(p, "Value", &option->Bool, sizeof(option->Bool), i, t->Num);
break;
default:
Debug("OutRpcProtoOptions(): unhandled type %u!\n", option->Type);
}
}
}
void FreeRpcProtoOptions(RPC_PROTO_OPTIONS *t)
{
UINT i;
// Validate arguments
if (t == NULL)
{
return;
}
Free(t->Protocol);
for (i = 0; i < t->Num; ++i)
{
PROTO_OPTION *option = &t->Options[i];
Free(option->Name);
if (option->Type == PROTO_OPTION_STRING)
{
Free(option->String);
}
}
Free(t->Options);
}
// RPC_SET_PASSWORD
void InRpcSetPassword(RPC_SET_PASSWORD *t, PACK *p)
{

View File

@ -124,6 +124,14 @@ struct RPC_INT
UINT IntValue; // Integer
};
// Proto options
struct RPC_PROTO_OPTIONS
{
char *Protocol; // Protocol name
UINT Num; // Number of options
PROTO_OPTION *Options; // Options
};
// Set Password
struct RPC_SET_PASSWORD
{
@ -966,6 +974,8 @@ UINT StDeleteListener(ADMIN *a, RPC_LISTENER *t);
UINT StEnableListener(ADMIN *a, RPC_LISTENER *t);
UINT StSetPortsUDP(ADMIN *a, RPC_PORTS *t);
UINT StGetPortsUDP(ADMIN *a, RPC_PORTS *t);
UINT StGetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t);
UINT StSetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t);
UINT StSetServerPassword(ADMIN *a, RPC_SET_PASSWORD *t);
UINT StSetFarmSetting(ADMIN *a, RPC_FARM *t);
UINT StGetFarmSetting(ADMIN *a, RPC_FARM *t);
@ -1112,6 +1122,8 @@ UINT ScDeleteListener(RPC *r, RPC_LISTENER *t);
UINT ScEnableListener(RPC *r, RPC_LISTENER *t);
UINT ScSetPortsUDP(RPC *r, RPC_PORTS *t);
UINT ScGetPortsUDP(RPC *r, RPC_PORTS *t);
UINT ScSetProtoOptions(RPC *r, RPC_PROTO_OPTIONS *t);
UINT ScGetProtoOptions(RPC *r, RPC_PROTO_OPTIONS *t);
UINT ScSetServerPassword(RPC *r, RPC_SET_PASSWORD *t);
UINT ScSetFarmSetting(RPC *r, RPC_FARM *t);
UINT ScGetFarmSetting(RPC *r, RPC_FARM *t);
@ -1268,6 +1280,9 @@ void FreeRpcPorts(RPC_PORTS *t);
void InRpcStr(RPC_STR *t, PACK *p);
void OutRpcStr(PACK *p, RPC_STR *t);
void FreeRpcStr(RPC_STR *t);
void InRpcProtoOptions(RPC_PROTO_OPTIONS *t, PACK *p);
void OutRpcProtoOptions(PACK *p, RPC_PROTO_OPTIONS *t);
void FreeRpcProtoOptions(RPC_PROTO_OPTIONS *t);
void InRpcSetPassword(RPC_SET_PASSWORD *t, PACK *p);
void OutRpcSetPassword(PACK *p, RPC_SET_PASSWORD *t);
void InRpcFarm(RPC_FARM *t, PACK *p);

View File

@ -290,6 +290,7 @@ typedef struct RPC_LISTENER RPC_LISTENER;
typedef struct RPC_LISTENER_LIST RPC_LISTENER_LIST;
typedef struct RPC_PORTS RPC_PORTS;
typedef struct RPC_STR RPC_STR;
typedef struct RPC_PROTO_OPTIONS RPC_PROTO_OPTIONS;
typedef struct RPC_SET_PASSWORD RPC_SET_PASSWORD;
typedef struct RPC_FARM RPC_FARM;
typedef struct RPC_FARM_HUB RPC_FARM_HUB;

View File

@ -2007,6 +2007,7 @@ LA_DELETE_LISTENER 已删除 TCP 监听器 (端口号 %u)。
LA_ENABLE_LISTENER 已启用 TCP 监听器 (端口号 %u)。
LA_DISABLE_LISTENER 已禁用 TCP 监听器 (端口号 %u)。
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD 服务端管理员密码设置完成。
LA_SET_FARM_SETTING 群集设置变更完成。
LA_SET_SERVER_CERT 服务端证书设定完成。

View File

@ -1989,6 +1989,7 @@ LA_DELETE_LISTENER TCP listener (port number %u) has been deleted.
LA_ENABLE_LISTENER TCP listener (port number %u) has been enabled.
LA_DISABLE_LISTENER TCP listener (port number %u) has been disabled.
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD The server administrator password has been set.
LA_SET_FARM_SETTING The clustering setting has been changed.
LA_SET_SERVER_CERT The server certificates have been set.

View File

@ -1993,6 +1993,7 @@ LA_DELETE_LISTENER TCP リスナー (ポート番号 %u) を削除しました
LA_ENABLE_LISTENER TCP リスナー (ポート番号 %u) を有効化しました。
LA_DISABLE_LISTENER TCP リスナー (ポート番号 %u) を無効化しました。
LA_SET_PORTS_UDP UDP ポートの一覧が設定されました: %s.
LA_SET_PROTO_OPTIONS オプション %s が設定されました。
LA_SET_SERVER_PASSWORD サーバー管理者パスワードを設定しました。
LA_SET_FARM_SETTING クラスタリング設定を変更しました。
LA_SET_SERVER_CERT サーバー証明書を設定しました。

View File

@ -1971,6 +1971,7 @@ LA_DELETE_LISTENER TCP 리스너 (포트 번호 %u)을 삭제했습니다.
LA_ENABLE_LISTENER TCP 리스너 (포트 번호 %u)를 활성화했습니다.
LA_DISABLE_LISTENER TCP 리스너 (포트 번호 %u)를 비활성화했습니다.
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD 서버 관리자 암호를 설정했습니다.
LA_SET_FARM_SETTING 클러스터링 설정을 변경했습니다.
LA_SET_SERVER_CERT 서버 인증서를 설정했습니다.

View File

@ -1990,6 +1990,7 @@ LA_DELETE_LISTENER TCP listener (port number %u) has been deleted.
LA_ENABLE_LISTENER TCP listener (port number %u) has been enabled.
LA_DISABLE_LISTENER TCP listener (port number %u) has been disabled.
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD The server administrator password has been set.
LA_SET_FARM_SETTING The clustering setting has been changed.
LA_SET_SERVER_CERT The server certificates have been set.

View File

@ -1990,6 +1990,7 @@ LA_DELETE_LISTENER TCP listener (port number %u) has been deleted.
LA_ENABLE_LISTENER TCP listener (port number %u) has been enabled.
LA_DISABLE_LISTENER TCP listener (port number %u) has been disabled.
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD The server administrator password has been set.
LA_SET_FARM_SETTING The clustering setting has been changed.
LA_SET_SERVER_CERT The server certificates have been set.

View File

@ -2010,6 +2010,7 @@ LA_DELETE_LISTENER 已刪除 TCP 監聽器 (埠號 %u)。
LA_ENABLE_LISTENER 已啟用 TCP 監聽器 (埠號 %u)。
LA_DISABLE_LISTENER 已禁用 TCP 監聽器 (埠號 %u)。
LA_SET_PORTS_UDP UDP ports have been set: %s.
LA_SET_PROTO_OPTIONS %s options have been set.
LA_SET_SERVER_PASSWORD 服務端管理員密碼設置完成。
LA_SET_FARM_SETTING 群集設置變更完成。
LA_SET_SERVER_CERT 服務端證書設定完成。