1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 09:29:52 +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: case PROTO_OPTION_BOOL:
rpc_option->Bool = option->Bool; rpc_option->Bool = option->Bool;
break; break;
case PROTO_OPTION_UINT32:
rpc_option->UInt32 = option->UInt32;
break;
case PROTO_OPTION_STRING: case PROTO_OPTION_STRING:
rpc_option->String = CopyStr(option->String); rpc_option->String = CopyStr(option->String);
break; break;
@ -10305,6 +10308,9 @@ UINT StSetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
case PROTO_OPTION_BOOL: case PROTO_OPTION_BOOL:
option->Bool = rpc_option->Bool; option->Bool = rpc_option->Bool;
break; break;
case PROTO_OPTION_UINT32:
option->UInt32 = rpc_option->UInt32;
break;
case PROTO_OPTION_STRING: case PROTO_OPTION_STRING:
Free(option->String); Free(option->String);
option->String = CopyStr(rpc_option->String); option->String = CopyStr(rpc_option->String);
@ -12700,6 +12706,9 @@ void InRpcProtoOptions(RPC_PROTO_OPTIONS *t, PACK *p)
case PROTO_OPTION_BOOL: case PROTO_OPTION_BOOL:
PackGetDataEx2(p, "Value", &option->Bool, sizeof(option->Bool), i); PackGetDataEx2(p, "Value", &option->Bool, sizeof(option->Bool), i);
break; break;
case PROTO_OPTION_UINT32:
PackGetDataEx2(p, "Value", &option->UInt32, sizeof(option->UInt32), i);
break;
default: default:
Debug("InRpcProtoOptions(): unhandled type %u!\n", option->Type); Debug("InRpcProtoOptions(): unhandled type %u!\n", option->Type);
} }
@ -12731,6 +12740,9 @@ void OutRpcProtoOptions(PACK *p, RPC_PROTO_OPTIONS *t)
case PROTO_OPTION_BOOL: case PROTO_OPTION_BOOL:
PackAddDataEx(p, "Value", &option->Bool, sizeof(option->Bool), i, t->Num); PackAddDataEx(p, "Value", &option->Bool, sizeof(option->Bool), i, t->Num);
break; break;
case PROTO_OPTION_UINT32:
PackAddDataEx(p, "Value", &option->UInt32, sizeof(option->UInt32), i, t->Num);
break;
default: default:
Debug("OutRpcProtoOptions(): unhandled type %u!\n", option->Type); 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: case PROTO_OPTION_BOOL:
option->Bool = GetParamYes(o, "VALUE"); option->Bool = GetParamYes(o, "VALUE");
break; break;
case PROTO_OPTION_UINT32:
option->UInt32 = GetParamInt(o, "VALUE");
break;
default: default:
ret = ERR_INTERNAL_ERROR; ret = ERR_INTERNAL_ERROR;
} }
@ -22979,13 +22982,19 @@ UINT PsProtoOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
switch (option->Type) switch (option->Type)
{ {
case PROTO_OPTION_STRING:
type = L"String";
value = CopyStrToUni(option->String);
break;
case PROTO_OPTION_BOOL: case PROTO_OPTION_BOOL:
type = L"Boolean"; type = L"Boolean";
value = option->Bool ? L"True" : L"False"; value = option->Bool ? L"True" : L"False";
break; break;
case PROTO_OPTION_STRING: case PROTO_OPTION_UINT32:
type = L"String"; type = L"32 bit unsigned integer";
value = CopyStrToUni(option->String); char tmp[MAX_SIZE];
Format(tmp, sizeof(tmp), "%u", option->UInt32);
value = CopyStrToUni(tmp);
break; break;
default: default:
Debug("StGetProtoOptions(): unhandled option type %u!\n", option->Type); 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)); CtInsert(ct, name, type, value, _UU(description_str_key));
if (option->Type == PROTO_OPTION_STRING) if (option->Type != PROTO_OPTION_BOOL)
{ {
Free(value); Free(value);
} }

View File

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

View File

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

View File

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