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

Cedar: Add support for 32 bit unsigned integer Proto options

This commit also fixes a bug which caused the server to initialize all boolean options to false.

It was caused by SiLoadProtoCfg() not checking whether the item exists in the configuration file.

CfgGetBool() always returns false if the item doesn't exist.
This commit is contained in:
Davide Beatrici 2021-04-21 08:12:45 +02:00
parent 6a25ccfa28
commit 4b05de1a93
5 changed files with 44 additions and 7 deletions

View File

@ -10239,6 +10239,9 @@ UINT StGetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
case PROTO_OPTION_BOOL:
rpc_option->Bool = option->Bool;
break;
case PROTO_OPTION_UINT32:
rpc_option->UInt32 = option->UInt32;
break;
case PROTO_OPTION_STRING:
rpc_option->String = CopyStr(option->String);
break;
@ -10305,6 +10308,9 @@ UINT StSetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
case PROTO_OPTION_BOOL:
option->Bool = rpc_option->Bool;
break;
case PROTO_OPTION_UINT32:
option->UInt32 = rpc_option->UInt32;
break;
case PROTO_OPTION_STRING:
Free(option->String);
option->String = CopyStr(rpc_option->String);
@ -12700,6 +12706,9 @@ void InRpcProtoOptions(RPC_PROTO_OPTIONS *t, PACK *p)
case PROTO_OPTION_BOOL:
PackGetDataEx2(p, "Value", &option->Bool, sizeof(option->Bool), i);
break;
case PROTO_OPTION_UINT32:
PackGetDataEx2(p, "Value", &option->UInt32, sizeof(option->UInt32), i);
break;
default:
Debug("InRpcProtoOptions(): unhandled type %u!\n", option->Type);
}
@ -12731,6 +12740,9 @@ void OutRpcProtoOptions(PACK *p, RPC_PROTO_OPTIONS *t)
case PROTO_OPTION_BOOL:
PackAddDataEx(p, "Value", &option->Bool, sizeof(option->Bool), i, t->Num);
break;
case PROTO_OPTION_UINT32:
PackAddDataEx(p, "Value", &option->UInt32, sizeof(option->UInt32), i, t->Num);
break;
default:
Debug("OutRpcProtoOptions(): unhandled type %u!\n", option->Type);
}

View File

@ -22909,6 +22909,9 @@ UINT PsProtoOptionsSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
case PROTO_OPTION_BOOL:
option->Bool = GetParamYes(o, "VALUE");
break;
case PROTO_OPTION_UINT32:
option->UInt32 = GetParamInt(o, "VALUE");
break;
default:
ret = ERR_INTERNAL_ERROR;
}
@ -22979,13 +22982,19 @@ UINT PsProtoOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
switch (option->Type)
{
case PROTO_OPTION_STRING:
type = L"String";
value = CopyStrToUni(option->String);
break;
case PROTO_OPTION_BOOL:
type = L"Boolean";
value = option->Bool ? L"True" : L"False";
break;
case PROTO_OPTION_STRING:
type = L"String";
value = CopyStrToUni(option->String);
case PROTO_OPTION_UINT32:
type = L"32 bit unsigned integer";
char tmp[MAX_SIZE];
Format(tmp, sizeof(tmp), "%u", option->UInt32);
value = CopyStrToUni(tmp);
break;
default:
Debug("StGetProtoOptions(): unhandled option type %u!\n", option->Type);
@ -22997,7 +23006,7 @@ UINT PsProtoOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
CtInsert(ct, name, type, value, _UU(description_str_key));
if (option->Type == PROTO_OPTION_STRING)
if (option->Type != PROTO_OPTION_BOOL)
{
Free(value);
}

View File

@ -278,6 +278,9 @@ PROTO_CONTAINER *ProtoContainerNew(const PROTO_IMPL *impl)
case PROTO_OPTION_BOOL:
option->Bool = impl_option->Bool;
break;
case PROTO_OPTION_UINT32:
option->UInt32 = impl_option->UInt32;
break;
case PROTO_OPTION_STRING:
option->String = impl_option->String != NULL ? CopyStr(impl_option->String) : impl->OptionStringValue(option->Name);
break;

View File

@ -25,7 +25,8 @@ typedef enum PROTO_OPTION_VALUE
{
PROTO_OPTION_UNKNOWN,
PROTO_OPTION_STRING,
PROTO_OPTION_BOOL
PROTO_OPTION_BOOL,
PROTO_OPTION_UINT32
} PROTO_OPTION_VALUE;
typedef struct PROTO
@ -44,6 +45,7 @@ struct PROTO_OPTION
{
bool Bool;
char *String;
UINT UInt32;
};
};

View File

@ -6362,11 +6362,19 @@ void SiLoadProtoCfg(PROTO *p, FOLDER *f)
for (j = 0; j < LIST_NUM(options); ++j)
{
PROTO_OPTION *option = LIST_DATA(options, j);
if (CfgIsItem(ff, option->Name) == false)
{
continue;
}
switch (option->Type)
{
case PROTO_OPTION_BOOL:
option->Bool = CfgGetBool(ff, option->Name);
break;
case PROTO_OPTION_UINT32:
option->UInt32 = CfgGetInt(ff, option->Name);
break;
case PROTO_OPTION_STRING:
{
UINT size;
@ -6414,11 +6422,14 @@ void SiWriteProtoCfg(FOLDER *f, PROTO *p)
const PROTO_OPTION *option = LIST_DATA(options, j);
switch (option->Type)
{
case PROTO_OPTION_STRING:
CfgAddStr(ff, option->Name, option->String);
break;
case PROTO_OPTION_BOOL:
CfgAddBool(ff, option->Name, option->Bool);
break;
case PROTO_OPTION_STRING:
CfgAddStr(ff, option->Name, option->String);
case PROTO_OPTION_UINT32:
CfgAddInt(ff, option->Name, option->UInt32);
break;
default:
Debug("SiWriteProtoCfg(): unhandled option type %u!\n", option->Type);