30#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH
31#define PATHCCH_ENSURE_TRAILING_SLASH 0x20
40 L
"management-forget-disconnect",
42 L
"management-query-passwords",
43 L
"management-query-proxy",
45 L
"management-up-down",
56static BOOL
IsUserInGroup(PSID sid,
const PTOKEN_GROUPS groups,
const WCHAR *group_name);
68 const WCHAR *config_file = NULL;
69 WCHAR config_dir[MAX_PATH];
72 if (wcscmp(fname, L
"stdin") == 0)
77 if (PathIsRelativeW(fname))
79 swprintf(tmp, _countof(tmp), L
"%ls\\%ls", workdir, fname);
88 HRESULT res = PathCchCanonicalizeEx(config_dir, _countof(config_dir), s->
config_dir,
92 && wcsncmp(config_dir, config_file, wcslen(config_dir)) == 0
93 && wcsstr(config_file + wcslen(config_dir), L
"..") == NULL)
130 PSID admin_sid = NULL;
131 DWORD sid_size = SECURITY_MAX_SID_SIZE;
135 DWORD dlen = _countof(domain);
137 admin_sid = malloc(sid_size);
143 b = CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid, &sid_size);
146 b = LookupAccountSidW(NULL, admin_sid, name, &nlen, domain, &dlen, &snu);
156 const WCHAR *ovpn_service_user)
158 const WCHAR *admin_group[2];
164 SID_NAME_USE sid_type;
167 if (!LookupAccountSidW(NULL, sid, username, &len, domain, &len, &sid_type))
176 if ((wcscmp(username, ovpn_service_user) == 0) && (wcscmp(domain, L
"NT SERVICE") == 0))
183 admin_group[0] = sysadmin_group;
188 L
"Failed to get the name of Administrators group. Using the default.");
192 admin_group[1] = ovpn_admin_group;
195 for (
int i = 0; i < 2; ++i)
201 L
"Authorizing user '%ls@%ls' by virtue of membership in group '%ls'",
202 username, domain, admin_group[i]);
220 PTOKEN_GROUPS groups = NULL;
223 if (!GetTokenInformation(token, TokenGroups, groups, buf_size, &buf_size)
224 && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
226 groups = malloc(buf_size);
232 else if (!GetTokenInformation(token, TokenGroups, groups, buf_size, &buf_size))
252 DWORD dlen = _countof(domain);
254 if (!LookupAccountName(NULL, name, sid, &sid_size, domain, &dlen, &su))
274IsUserInGroup(PSID sid,
const PTOKEN_GROUPS token_groups,
const WCHAR *group_name)
277 DWORD_PTR resume = 0;
279 BYTE grp_sid[SECURITY_MAX_SID_SIZE];
283 if (token_groups &&
LookupSID(group_name, (PSID)grp_sid, _countof(grp_sid)))
285 for (DWORD i = 0; i < token_groups->GroupCount; ++i)
287 if (EqualSid((PSID)grp_sid, token_groups->Groups[i].Sid))
302 LOCALGROUP_MEMBERS_INFO_0 *members = NULL;
303 err = NetLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *)&members, MAX_PREFERRED_LENGTH,
304 &nread, &nmax, &resume);
305 if ((err != NERR_Success && err != ERROR_MORE_DATA))
310 for (DWORD i = 0; i < nread && !ret; ++i)
312 ret = EqualSid(members[i].lgrmi0_sid, sid);
314 NetApiBufferFree(members);
316 }
while (err == ERROR_MORE_DATA && nloop++ < 100);
318 if (err != NERR_Success && err != NERR_GroupNotFound)
DWORD MsgToEventLog(DWORD flags, LPCWSTR format,...)
WCHAR config_dir[MAX_PATH]
static BOOL CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)
static const WCHAR * white_list[]
#define PATHCCH_ENSURE_TRAILING_SLASH
static int OptionLookup(const WCHAR *name, const WCHAR *white_list[])
BOOL IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_group, const WCHAR *ovpn_service_user)
static BOOL IsUserInGroup(PSID sid, const PTOKEN_GROUPS groups, const WCHAR *group_name)
User is in group if the token groups contain the SID of the group of if the user is a direct member o...
static BOOL LookupSID(const WCHAR *name, PSID sid, DWORD sid_size)
BOOL CheckOption(const WCHAR *workdir, int argc, WCHAR *argv[], const settings_t *s)
static BOOL GetBuiltinAdminGroupName(WCHAR *name, DWORD nlen)
static PTOKEN_GROUPS GetTokenGroups(const HANDLE token)
Get a list of groups in token.
#define SYSTEM_ADMIN_GROUP