Skip to content

Commit

Permalink
Implement PortsUDPGet and PortsUDPSet commands
Browse files Browse the repository at this point in the history
PortsUDPSet: This command can be used to specify a single or multiple UDP ports the server should listen on. "0" can be specified to disable the UDP listener.
Administrator privileges are required to execute the command.

PortsUDPGet: This command can be used to retrieve the UDP ports the server is listening on.

The two commands replace the functionality that was previously provided by OpenVpnEnable and OpenVpnGet, respectively.
  • Loading branch information
davidebeatrici committed May 19, 2020
1 parent 3c5738c commit 6408614
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/Cedar/Admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,8 @@ PACK *AdminDispatch(RPC *rpc, char *name, PACK *p)
DECLARE_RPC_EX("EnumListener", RPC_LISTENER_LIST, StEnumListener, InRpcListenerList, OutRpcListenerList, FreeRpcListenerList)
DECLARE_RPC("DeleteListener", RPC_LISTENER, StDeleteListener, InRpcListener, OutRpcListener)
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("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)
Expand Down Expand Up @@ -1674,6 +1676,8 @@ DECLARE_SC("CreateListener", RPC_LISTENER, ScCreateListener, InRpcListener, OutR
DECLARE_SC_EX("EnumListener", RPC_LISTENER_LIST, ScEnumListener, InRpcListenerList, OutRpcListenerList, FreeRpcListenerList)
DECLARE_SC("DeleteListener", RPC_LISTENER, ScDeleteListener, InRpcListener, OutRpcListener)
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("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)
Expand Down Expand Up @@ -9873,6 +9877,79 @@ UINT StCreateListener(ADMIN *a, RPC_LISTENER *t)
return ret;
}

// Set UDP ports the server should listen on
UINT StSetPortsUDP(ADMIN *a, RPC_PORTS *t)
{
UINT i;
LIST *ports, *server_ports;

SERVER_ADMIN_ONLY;

ports = NewIntList(true);

for (i = 0; i < t->Num; ++i)
{
const UINT port = t->Ports[i];
if (port < 1 || port > 65535)
{
ReleaseIntList(ports);
return ERR_INVALID_PARAMETER;
}

AddIntDistinct(ports, port);
}

server_ports = a->Server->PortsUDP;

LockList(server_ports);
{
for (i = 0; i < LIST_NUM(server_ports); ++i)
{
Free(LIST_DATA(server_ports, i));
}
DeleteAll(server_ports);

for (i = 0; i < t->Num; ++i)
{
const UINT port = *(UINT *)LIST_DATA(ports, i);
AddInt(server_ports, port);
}
}
UnlockList(server_ports);

ReleaseIntList(ports);

ProtoSetUdpPorts(a->Server->Proto, server_ports);

return ERR_NO_ERROR;
}

// List UDP ports the server is listening on
UINT StGetPortsUDP(ADMIN *a, RPC_PORTS *t)
{
LIST *ports = a->Server->PortsUDP;

FreeRpcPorts(t);

LockList(ports);
{
t->Num = LIST_NUM(ports);
t->Ports = t->Num > 0 ? Malloc(sizeof(UINT) * t->Num) : NULL;
if (t->Ports != NULL)
{
UINT i;
for (i = 0; i < t->Num; ++i)
{
const UINT port = *(UINT *)LIST_DATA(ports, i);
t->Ports[i] = port;
}
}
}
UnlockList(ports);

return ERR_NO_ERROR;
}

// Get server status
UINT StGetServerStatus(ADMIN *a, RPC_SERVER_STATUS *t)
{
Expand Down Expand Up @@ -12094,6 +12171,49 @@ void FreeRpcListenerList(RPC_LISTENER_LIST *t)
Free(t->Errors);
}

// RPC_PORTS
void InRpcPorts(RPC_PORTS *t, PACK *p)
{
UINT i;
// Validate arguments
if (t == NULL || p == NULL)
{
return;
}

t->Num = PackGetIndexCount(p, "Ports");
t->Ports = ZeroMalloc(sizeof(UINT) * t->Num);

for (i = 0; i < t->Num; ++i)
{
t->Ports[i] = PackGetIntEx(p, "Ports", i);
}
}
void OutRpcPorts(PACK *p, RPC_PORTS *t)
{
UINT i;
// Validate arguments
if (t == NULL || p == NULL)
{
return;
}

for (i = 0; i < t->Num; ++i)
{
PackAddIntEx(p, "Ports", t->Ports[i], i, t->Num);
}
}
void FreeRpcPorts(RPC_PORTS *t)
{
// Validate arguments
if (t == NULL)
{
return;
}

Free(t->Ports);
}

// RPC_STR
void InRpcStr(RPC_STR *t, PACK *p)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Cedar/Admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ struct RPC_LISTENER_LIST
bool *Errors; // An error occurred
};

// List of ports
struct RPC_PORTS
{
UINT Num; // Number of ports
UINT *Ports; // Ports
};

// String *
struct RPC_STR
{
Expand Down Expand Up @@ -957,6 +964,8 @@ UINT StCreateListener(ADMIN *a, RPC_LISTENER *t);
UINT StEnumListener(ADMIN *a, RPC_LISTENER_LIST *t);
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 StSetServerPassword(ADMIN *a, RPC_SET_PASSWORD *t);
UINT StSetFarmSetting(ADMIN *a, RPC_FARM *t);
UINT StGetFarmSetting(ADMIN *a, RPC_FARM *t);
Expand Down Expand Up @@ -1101,6 +1110,8 @@ UINT ScCreateListener(RPC *r, RPC_LISTENER *t);
UINT ScEnumListener(RPC *r, RPC_LISTENER_LIST *t);
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 ScSetServerPassword(RPC *r, RPC_SET_PASSWORD *t);
UINT ScSetFarmSetting(RPC *r, RPC_FARM *t);
UINT ScGetFarmSetting(RPC *r, RPC_FARM *t);
Expand Down Expand Up @@ -1251,6 +1262,9 @@ void OutRpcListener(PACK *p, RPC_LISTENER *t);
void InRpcListenerList(RPC_LISTENER_LIST *t, PACK *p);
void OutRpcListenerList(PACK *p, RPC_LISTENER_LIST *t);
void FreeRpcListenerList(RPC_LISTENER_LIST *t);
void InRpcPorts(RPC_PORTS *t, PACK *p);
void OutRpcPorts(PACK *p, RPC_PORTS *t);
void FreeRpcPorts(RPC_PORTS *t);
void InRpcStr(RPC_STR *t, PACK *p);
void OutRpcStr(PACK *p, RPC_STR *t);
void FreeRpcStr(RPC_STR *t);
Expand Down
1 change: 1 addition & 0 deletions src/Cedar/CedarType.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ typedef struct RPC_SERVER_INFO RPC_SERVER_INFO;
typedef struct RPC_SERVER_STATUS RPC_SERVER_STATUS;
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_SET_PASSWORD RPC_SET_PASSWORD;
typedef struct RPC_FARM RPC_FARM;
Expand Down
107 changes: 107 additions & 0 deletions src/Cedar/Command.c
Original file line number Diff line number Diff line change
Expand Up @@ -7505,6 +7505,8 @@ void PsMain(PS *ps)
{"ListenerList", PsListenerList},
{"ListenerEnable", PsListenerEnable},
{"ListenerDisable", PsListenerDisable},
{"PortsUDPGet", PsPortsUDPGet},
{"PortsUDPSet", PsPortsUDPSet},
{"ServerPasswordSet", PsServerPasswordSet},
{"ClusterSettingGet", PsClusterSettingGet},
{"ClusterSettingStandalone", PsClusterSettingStandalone},
Expand Down Expand Up @@ -22888,6 +22890,111 @@ UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
return 0;
}

// Set UDP ports the server should listen on
UINT PsPortsUDPSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
LIST *o, *ports;
PS *ps = (PS *)param;
UINT ret;
RPC_PORTS t;
PARAM args[] =
{
{"[ports]", CmdPrompt, _UU("CMD_PortsUDPSet_[ports]"), CmdEvalPortList, (void *)false}
};

o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
if (o == NULL)
{
return ERR_INVALID_PARAMETER;
}

ports = StrToPortList(GetParamStr(o, "[ports]"), false);

FreeParamValueList(o);

t.Num = LIST_NUM(ports);
if (t.Num > 0)
{
UINT i;
t.Ports = Malloc(sizeof(UINT) * t.Num);

for (i = 0; i < t.Num; ++i)
{
t.Ports[i] = (UINT)LIST_DATA(ports, i);
}
}
else
{
t.Ports = NULL;
}

ReleaseList(ports);

ret = ScSetPortsUDP(ps->Rpc, &t);
if (ret != ERR_NO_ERROR)
{
CmdPrintError(c, ret);
}

Free(t.Ports);

return ret;
}

// List UDP ports the server is listening on
UINT PsPortsUDPGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
LIST *o;
PS *ps = (PS *)param;
UINT ret;
RPC_PORTS t;

o = ParseCommandList(c, cmd_name, str, NULL, 0);
if (o == NULL)
{
return ERR_INVALID_PARAMETER;
}

FreeParamValueList(o);

Zero(&t, sizeof(t));

ret = ScGetPortsUDP(ps->Rpc, &t);
if (ret == ERR_NO_ERROR)
{
wchar_t str[MAX_SIZE];
CT *ct = CtNewStandard();

Zero(str, sizeof(str));

if (t.Num > 0)
{
UINT i;
wchar_t buf[MAX_SIZE];

UniFormat(buf, sizeof(buf), L"%u", t.Ports[0]);
UniStrCat(str, sizeof(str), buf);

for (i = 1; i < t.Num; ++i)
{
UniFormat(buf, sizeof(buf), L", %u", t.Ports[i]);
UniStrCat(str, sizeof(str), buf);
}
}

CtInsert(ct, _UU("CMD_PortsUDPGet_Ports"), str);
CtFree(ct, c);
}
else
{
CmdPrintError(c, ret);
}

FreeRpcPorts(&t);

return ret;
}

// Draw a row of console table
void CtPrintRow(CONSOLE *c, UINT num, UINT *widths, wchar_t **strings, bool *rights, char separate_char)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Cedar/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ UINT PsListenerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsListenerList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsListenerDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsPortsUDPSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsPortsUDPGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsServerPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsClusterSettingGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsClusterSettingStandalone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
Expand Down
14 changes: 14 additions & 0 deletions src/bin/hamcore/strtable_cn.stb
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,20 @@ CMD_ListenerDisable_[port] 使用一个整数,指定要停止的 TCP/IP 监
CMD_ListenerDisable_PortPrompt 启动 TCP/IP 监听器端口号:


# PortsUDPSet command
CMD_PortsUDPSet Sets the UDP ports that the server should listen on
CMD_PortsUDPSet_Help This command can be used to specify a single or multiple UDP ports the server should listen on. \nYou can specify a port that is used by another process, however the server will not be able to use it until the port becomes free. \nSpecify a port number that is within the range of 1 to 65535. \nYou can list the ports that are currently set with the PortsUDPGet command. \nTo execute this command, you must have VPN Server administrator privileges.
CMD_PortsUDPSet_Args PortsUDPSet [ports]
CMD_PortsUDPSet_[ports] Multiple UDP ports can be specified by splitting them with a space or a comma, for example: "443, 992, 1194, 5555". \nSpecify "0" to disable the UDP listener. \n\nPorts:


# PortsUDPGet command
CMD_PortsUDPGet Lists the UDP ports that the server is listening on
CMD_PortsUDPGet_Help This command can be used to retrieve the UDP ports the server is listening on. \nYou can set the ports with the PortsUDPSet command.
CMD_PortsUDPGet_Args PortsUDPGet
CMD_PortsUDPGet_Ports UDP ports


# ServerPasswordSet 命令
CMD_ServerPasswordSet 设置 VPN Server 管理员密码
CMD_ServerPasswordSet_Help 这将设置 VPN Server 管理员密码。您可以指定密码为一个参数。如果密码没有指定,将显示提示输入密码和密码确认。如果指定密码为一个参数,这个密码将在屏幕上显示瞬间,这构成了风险。我们建议尽可能避免指定这个参数,使用密码提示输入密码。\n为了执行这个命令,您必须有 VPN Server 管理员权限。
Expand Down
14 changes: 14 additions & 0 deletions src/bin/hamcore/strtable_en.stb
Original file line number Diff line number Diff line change
Expand Up @@ -4548,6 +4548,20 @@ CMD_ListenerDisable_[port] Using an integer, specify the port number of the TCP/
CMD_ListenerDisable_PortPrompt Port number of TCP/IP Listener to start:


# PortsUDPSet command
CMD_PortsUDPSet Sets the UDP ports that the server should listen on
CMD_PortsUDPSet_Help This command can be used to specify a single or multiple UDP ports the server should listen on. \nYou can specify a port that is used by another process, however the server will not be able to use it until the port becomes free. \nSpecify a port number that is within the range of 1 to 65535. \nYou can list the ports that are currently set with the PortsUDPGet command. \nTo execute this command, you must have VPN Server administrator privileges.
CMD_PortsUDPSet_Args PortsUDPSet [ports]
CMD_PortsUDPSet_[ports] Multiple UDP ports can be specified by splitting them with a space or a comma, for example: "443, 992, 1194, 5555". \nSpecify "0" to disable the UDP listener. \n\nPorts:


# PortsUDPGet command
CMD_PortsUDPGet Lists the UDP ports that the server is listening on
CMD_PortsUDPGet_Help This command can be used to retrieve the UDP ports the server is listening on. \nYou can set the ports with the PortsUDPSet command.
CMD_PortsUDPGet_Args PortsUDPGet
CMD_PortsUDPGet_Ports UDP ports


# ServerPasswordSet command
CMD_ServerPasswordSet Set VPN Server Administrator Password
CMD_ServerPasswordSet_Help This sets the VPN Server administrator password. You can specify the password as a parameter. If the password is not specified, a prompt will be displayed to input the password and password confirmation. If you include the password as a parameter, this password will be displayed momentarily on the screen, which poses a risk. We recommend that whenever possible, avoid specifying this parameter and input the password using the password prompt. \nTo execute this command, you must have VPN Server administrator privileges.
Expand Down
14 changes: 14 additions & 0 deletions src/bin/hamcore/strtable_ja.stb
Original file line number Diff line number Diff line change
Expand Up @@ -4551,6 +4551,20 @@ CMD_ListenerDisable_[port] 停止する TCP/IP リスナーのポート番号を
CMD_ListenerDisable_PortPrompt 開始する TCP/IP リスナーのポート番号:


# PortsUDPSet command
CMD_PortsUDPSet サーバーが着信を受付ける UDP ポート番号の一覧を設定します。
CMD_PortsUDPSet_Help このコマンドを使用すると、このサーバーが着信を受付ける単一または複数の UDP ポートの一覧を設定することができます。\n他のプロセスによって使用されている UDP ポートを設定することも可能ですが、そのポートが解放されるまでは機能しません。\nポート番号は、1 から 65535 の間で指定します。\n現在設定されているポートの一覧は、PortsUDPGet コマンドを使用して確認することができます。\nこのコマンドを実行するには、VPN Server の管理者権限が必要です。
CMD_PortsUDPSet_Args PortsUDPSet [ports]
CMD_PortsUDPSet_[ports] 複数のポート番号を指定する場合は、スペース文字またはカンマ文字で区切ってください。例: "443, 992, 1194, 5555". \n"0" を指定すると、UDP リスナーを無効化することができます。\n\nポート一覧:


# PortsUDPGet command
CMD_PortsUDPGet サーバーにおける着信 UDP ポートの一覧を表示します。
CMD_PortsUDPGet_Help このコマンドを使用すると、サーバーで待受け状態になっている UDP ポートの一覧を表示することができます。\nポートの設定を変更するには、PortsUDPSet コマンドを使用してください。
CMD_PortsUDPGet_Args PortsUDPGet
CMD_PortsUDPGet_Ports UDP ポート一覧


# ServerPasswordSet コマンド
CMD_ServerPasswordSet VPN Server の管理者パスワードの設定
CMD_ServerPasswordSet_Help VPN Server の管理者パスワードを設定します。パラメータとしてパスワードを指定することができます。パラメータを指定しない場合は、パスワードと、その確認入力を行なうためのプロンプトが表示されます。パスワードをパラメータに与えた場合、そのパスワードが一時的に画面に表示されるため危険です。できる限り、パラメータを指定せずに、パスワードプロンプトを用いてパスワードを入力することを推奨します。\nこのコマンドを実行するには、VPN Server の管理者権限が必要です。
Expand Down
Loading

0 comments on commit 6408614

Please sign in to comment.