Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to clang-format #718

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
BasedOnStyle: Mozilla
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 1
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakStringLiterals: false
ColumnLimit: '100'
ContinuationIndentWidth: '4'
DerivePointerAlignment: false
IndentCaseLabels: true
IndentGotoLabels: false
IndentWidth: '4'
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: '2'
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: '2'
SpacesInParens: Never
TabWidth: '4'
UseTab: Never
27 changes: 7 additions & 20 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,16 @@ name: Build
on: [push, pull_request]

jobs:
checkuncrustify:
name: "Check code style with Uncrustify"
# Ubuntu 22.04 has uncrustify 0.72_f
runs-on: ubuntu-22.04
checkformat:
name: "Check code style with clang-format"
runs-on: ubuntu-24.04
steps:
- name: Install dependencies
run: sudo apt update && sudo apt install -y uncrustify
- name: Install pre-commit
run: pip3 install pre-commit
- name: Checkout OpenVPN-GUI
uses: actions/checkout@v3
- name: Show uncrustify version
run: uncrustify --version
- name: Run uncrustify
run: ./dev-tools/reformat-all.sh
- name: Check for changes
run: git diff --output=uncrustify-changes.patch
- name: Show changes on standard output
run: git diff
- uses: actions/upload-artifact@v3
with:
name: uncrustify-changes.patch
path: uncrustify-changes.patch
- name: Set job status
run: test ! -s uncrustify-changes.patch
- name: Run pre-commit
run: pre-commit run -a

msvc:
strategy:
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v19.1.4'
hooks:
- id: clang-format
files: \.[ch]$
49 changes: 25 additions & 24 deletions access.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ GetBuiltinAdminGroupName(WCHAR *name, DWORD nlen)
return FALSE;
}

b = CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid,
&sid_size);
b = CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid, &sid_size);
if (b)
{
b = LookupAccountSidW(NULL, admin_sid, name, &nlen, domain, &dlen, &su);
Expand Down Expand Up @@ -127,22 +126,22 @@ AddUserToGroup(const WCHAR *group)
size = _countof(syspath);
if (GetSystemDirectory(syspath, size))
{
syspath[size-1] = L'\0';
syspath[size - 1] = L'\0';
size = _countof(cmd);
_snwprintf(cmd, size, L"%ls\\%ls", syspath, L"cmd.exe");
cmd[size-1] = L'\0';
cmd[size - 1] = L'\0';
size = _countof(netcmd);
_snwprintf(netcmd, size, L"%ls\\%ls", syspath, L"net.exe");
netcmd[size-1] = L'\0';
netcmd[size - 1] = L'\0';
}
size = (wcslen(fmt) + wcslen(username) + 2*wcslen(group) + 2*wcslen(netcmd)+ 1);
if ((params = malloc(size*sizeof(WCHAR))) == NULL)
size = (wcslen(fmt) + wcslen(username) + 2 * wcslen(group) + 2 * wcslen(netcmd) + 1);
if ((params = malloc(size * sizeof(WCHAR))) == NULL)
{
return retval;
}

_snwprintf(params, size, fmt, netcmd, group, netcmd, group, username);
params[size-1] = L'\0';
params[size - 1] = L'\0';

status = RunAsAdmin(cmd, params);
if (status == 0)
Expand All @@ -151,15 +150,16 @@ AddUserToGroup(const WCHAR *group)
}

#ifdef DEBUG
if (status == (DWORD) -1)
if (status == (DWORD)-1)
{
PrintDebug(L"RunAsAdmin: failed to execute the command [%ls %ls] : error = 0x%x",
cmd, params, GetLastError());
cmd,
params,
GetLastError());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a case where it splits args each into a new line.

}
else if (status)
{
PrintDebug(L"RunAsAdmin: command [%ls %ls] returned exit_code = %lu",
cmd, params, status);
PrintDebug(L"RunAsAdmin: command [%ls %ls] returned exit_code = %lu", cmd, params, status);
}
#endif

Expand Down Expand Up @@ -206,7 +206,7 @@ AuthorizeConfig(const connection_t *c)
WCHAR sysadmin_group[MAX_NAME];
BYTE sid_buf[SECURITY_MAX_SID_SIZE];
DWORD sid_size = SECURITY_MAX_SID_SIZE;
PSID sid = (PSID) sid_buf;
PSID sid = (PSID)sid_buf;
PTOKEN_GROUPS groups = NULL;

if (GetBuiltinAdminGroupName(sysadmin_group, _countof(sysadmin_group)))
Expand All @@ -229,22 +229,20 @@ AuthorizeConfig(const connection_t *c)
{
if (!o.silent_connection)
{
MessageBoxW(NULL, L"Failed to determine process owner SID", L""PACKAGE_NAME, MB_OK);
MessageBoxW(NULL, L"Failed to determine process owner SID", L"" PACKAGE_NAME, MB_OK);
}
return FALSE;
}
groups = GetProcessTokenGroups();
if (IsUserInGroup(sid, groups, admin_group)
|| IsUserInGroup(sid, groups, o.ovpn_admin_group))
if (IsUserInGroup(sid, groups, admin_group) || IsUserInGroup(sid, groups, o.ovpn_admin_group))
{
flichtenheld marked this conversation as resolved.
Show resolved Hide resolved
free(groups);
return TRUE;
}
free(groups);

/* do not attempt to add user to sysadmin_group or a no-name group */
if (wcscmp(admin_group, o.ovpn_admin_group) == 0
|| wcslen(o.ovpn_admin_group) == 0
if (wcscmp(admin_group, o.ovpn_admin_group) == 0 || wcslen(o.ovpn_admin_group) == 0
|| !o.netcmd_semaphore)
{
ShowLocalizedMsg(IDS_ERR_CONFIG_NOT_AUTHORIZED, c->config_name, o.ovpn_admin_group);
Expand All @@ -258,8 +256,11 @@ AuthorizeConfig(const connection_t *c)
return FALSE;
}
/* semaphore locked -- relase before return */
res = ShowLocalizedMsgEx(MB_YESNO|MB_ICONWARNING, NULL, TEXT(PACKAGE_NAME),
IDS_ERR_CONFIG_TRY_AUTHORIZE, c->config_name,
res = ShowLocalizedMsgEx(MB_YESNO | MB_ICONWARNING,
NULL,
TEXT(PACKAGE_NAME),
IDS_ERR_CONFIG_TRY_AUTHORIZE,
c->config_name,
o.ovpn_admin_group);
if (res == IDYES)
{
Expand Down Expand Up @@ -364,11 +365,11 @@ IsUserInGroup(PSID sid, const PTOKEN_GROUPS token_groups, const WCHAR *group_nam
int nloop = 0; /* a counter used to not get stuck in the do .. while() */

/* first check in the token groups */
if (token_groups && LookupSID(group_name, (PSID) grp_sid, _countof(grp_sid)))
if (token_groups && LookupSID(group_name, (PSID)grp_sid, _countof(grp_sid)))
{
for (DWORD i = 0; i < token_groups->GroupCount; ++i)
{
if (EqualSid((PSID) grp_sid, token_groups->Groups[i].Sid))
if (EqualSid((PSID)grp_sid, token_groups->Groups[i].Sid))
{
PrintDebug(L"Found group in token at position %lu", i);
return TRUE;
Expand All @@ -385,8 +386,8 @@ IsUserInGroup(PSID sid, const PTOKEN_GROUPS token_groups, const WCHAR *group_nam
{
DWORD nread, nmax;
LOCALGROUP_MEMBERS_INFO_0 *members = NULL;
err = NetLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *) &members,
MAX_PREFERRED_LENGTH, &nread, &nmax, &resume);
err = NetLocalGroupGetMembers(
NULL, group_name, 0, (LPBYTE *)&members, MAX_PREFERRED_LENGTH, &nread, &nmax, &resume);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example of line break after opening "("

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, one can play around with the different penalty values like PenaltyBreakBeforeFirstCallParameter to influence this. And obviously the ColumnLimit plays a huge role here.

if (err != NERR_Success && err != ERROR_MORE_DATA)
{
break;
Expand Down
Loading