From 4b05de1a9342e59c78d9d4698397990f4476413f Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 21 Apr 2021 08:12:45 +0200 Subject: [PATCH] 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. --- src/Cedar/Admin.c | 12 ++++++++++++ src/Cedar/Command.c | 17 +++++++++++++---- src/Cedar/Proto.c | 3 +++ src/Cedar/Proto.h | 4 +++- src/Cedar/Server.c | 15 +++++++++++++-- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/Cedar/Admin.c b/src/Cedar/Admin.c index 298a9881..667e9344 100644 --- a/src/Cedar/Admin.c +++ b/src/Cedar/Admin.c @@ -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); } diff --git a/src/Cedar/Command.c b/src/Cedar/Command.c index a4e1c429..bab09bf6 100644 --- a/src/Cedar/Command.c +++ b/src/Cedar/Command.c @@ -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); } diff --git a/src/Cedar/Proto.c b/src/Cedar/Proto.c index 182cc183..3af4f386 100644 --- a/src/Cedar/Proto.c +++ b/src/Cedar/Proto.c @@ -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; diff --git a/src/Cedar/Proto.h b/src/Cedar/Proto.h index 909e3d5a..fbbad098 100644 --- a/src/Cedar/Proto.h +++ b/src/Cedar/Proto.h @@ -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; }; }; diff --git a/src/Cedar/Server.c b/src/Cedar/Server.c index 3d54a533..38f900e3 100644 --- a/src/Cedar/Server.c +++ b/src/Cedar/Server.c @@ -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);