-
Notifications
You must be signed in to change notification settings - Fork 408
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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]$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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) | ||
|
@@ -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()); | ||
} | ||
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 | ||
|
||
|
@@ -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))) | ||
|
@@ -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); | ||
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an example of line break after opening "(" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, one can play around with the different penalty values like |
||
if (err != NERR_Success && err != ERROR_MORE_DATA) | ||
{ | ||
break; | ||
|
There was a problem hiding this comment.
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.