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

MinGW: Fix ext_ad_group_acl build errors #2005

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/acl/external/AD_group/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ext_ad_group_acl_SOURCES = ext_ad_group_acl.cc
# TODO: test for these libraries in required.m4
#
ext_ad_group_acl_LDADD = \
$(top_builddir)/lib/libmiscencoding.la \
$(COMPAT_LIB) \
-lnetapi32 \
-ladvapi32 \
Expand Down
121 changes: 61 additions & 60 deletions src/acl/external/AD_group/ext_ad_group_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "squid.h"
#include "helper/protocol_defines.h"
#include "include/util.h"
#include "rfc1738.h"

#if _SQUID_CYGWIN_
#include <cwchar>
Expand Down Expand Up @@ -147,7 +148,7 @@ GetLPBYTEtoOctetString(VARIANT * pVar, LPBYTE * ppByte)

if ((!pVar) || (!ppByte))
return E_INVALIDARG;
if ((pVar->n1.n2.vt) != (VT_UI1 | VT_ARRAY))
if ((pVar->vt) != (VT_UI1 | VT_ARRAY))
return E_INVALIDARG;

hr = SafeArrayGetLBound(V_ARRAY(pVar), 1, &lLBound);
Expand Down Expand Up @@ -181,9 +182,9 @@ Get_primaryGroup(IADs * pUser)
VariantInit(&var);

/* Get the primaryGroupID property */
hr = pUser->lpVtbl->Get(pUser, L"primaryGroupID", &var);
hr = pUser->Get(BSTR(L"primaryGroupID"), &var);
if (SUCCEEDED(hr)) {
User_primaryGroupID = var.n1.n2.n3.uintVal;
User_primaryGroupID = var.uintVal;
} else {
debug("Get_primaryGroup: cannot get primaryGroupID, ERROR: %s\n", Get_WIN32_ErrorMessage(hr));
VariantClear(&var);
Expand All @@ -192,7 +193,7 @@ Get_primaryGroup(IADs * pUser)
VariantClear(&var);

/*Get the objectSid property */
hr = pUser->lpVtbl->Get(pUser, L"objectSid", &var);
hr = pUser->Get(BSTR(L"objectSid"), &var);
if (SUCCEEDED(hr)) {
PSID pObjectSID;
LPBYTE pByte = nullptr;
Expand Down Expand Up @@ -257,41 +258,41 @@ My_NameTranslate(wchar_t * name, int in_format, int out_format)
}
WIN32_COM_initialized = 1;
}
hr = CoCreateInstance(&CLSID_NameTranslate,
hr = CoCreateInstance(CLSID_NameTranslate,
nullptr,
CLSCTX_INPROC_SERVER,
&IID_IADsNameTranslate,
IID_IADsNameTranslate,
(void **) &pNto);
if (FAILED(hr)) {
debug("My_NameTranslate: cannot create COM instance, ERROR: %s\n", Get_WIN32_ErrorMessage(hr));
/* This is a fatal error */
exit(EXIT_FAILURE);
}
hr = pNto->lpVtbl->Init(pNto, ADS_NAME_INITTYPE_GC, L"");
hr = pNto->Init(ADS_NAME_INITTYPE_GC, BSTR(L""));
if (FAILED(hr)) {
debug("My_NameTranslate: cannot initialise NameTranslate API, ERROR: %s\n", Get_WIN32_ErrorMessage(hr));
pNto->lpVtbl->Release(pNto);
pNto->Release();
/* This is a fatal error */
exit(EXIT_FAILURE);
}
hr = pNto->lpVtbl->Set(pNto, in_format, name);
hr = pNto->Set(in_format, name);
if (FAILED(hr)) {
debug("My_NameTranslate: cannot set translate of %S, ERROR: %s\n", name, Get_WIN32_ErrorMessage(hr));
pNto->lpVtbl->Release(pNto);
pNto->Release();
return nullptr;
}
hr = pNto->lpVtbl->Get(pNto, out_format, &bstr);
hr = pNto->Get(out_format, &bstr);
if (FAILED(hr)) {
debug("My_NameTranslate: cannot get translate of %S, ERROR: %s\n", name, Get_WIN32_ErrorMessage(hr));
pNto->lpVtbl->Release(pNto);
pNto->Release();
return nullptr;
}
debug("My_NameTranslate: %S translated to %S\n", name, bstr);

wc = (wchar_t *) xmalloc((wcslen(bstr) + 1) * sizeof(wchar_t));
wcscpy(wc, bstr);
SysFreeString(bstr);
pNto->lpVtbl->Release(pNto);
pNto->Release();
return wc;
}

Expand Down Expand Up @@ -386,17 +387,18 @@ add_User_Group(wchar_t * Group)
return 1;
}

/* returns 0 on match, -1 if no match */
static int
wccmparray(const wchar_t * str, const wchar_t ** array)
/* returns true on match, false if no match */
/* TODO: convert to std::containers */
static bool
wccmparray(const wchar_t * str, wchar_t ** array)
{
while (*array) {
debug("Windows group: %S, Squid group: %S\n", str, *array);
if (wcscmp(str, *array) == 0)
return 0;
return true;
++array;
}
return -1;
return false;
}

/* returns 0 on match, -1 if no match */
Expand Down Expand Up @@ -424,24 +426,24 @@ Recursive_Memberof(IADs * pObj)
HRESULT hr;

VariantInit(&var);
hr = pObj->lpVtbl->Get(pObj, L"memberOf", &var);
hr = pObj->Get(BSTR(L"memberOf"), &var);
if (SUCCEEDED(hr)) {
if (VT_BSTR == var.n1.n2.vt) {
if (add_User_Group(var.n1.n2.n3.bstrVal)) {
if (VT_BSTR == var.vt) {
if (add_User_Group(var.bstrVal)) {
wchar_t *Group_Path;
IADs *pGrp;

Group_Path = GetLDAPPath(var.n1.n2.n3.bstrVal, GC_MODE);
hr = ADsGetObject(Group_Path, &IID_IADs, (void **) &pGrp);
Group_Path = GetLDAPPath(var.bstrVal, GC_MODE);
hr = ADsGetObject(Group_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
safe_free(Group_Path);
Group_Path = GetLDAPPath(var.n1.n2.n3.bstrVal, LDAP_MODE);
hr = ADsGetObject(Group_Path, &IID_IADs, (void **) &pGrp);
Group_Path = GetLDAPPath(var.bstrVal, LDAP_MODE);
hr = ADsGetObject(Group_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
} else
debug("Recursive_Memberof: ERROR ADsGetObject for %S failed: %s\n", Group_Path, Get_WIN32_ErrorMessage(hr));
} else
Expand All @@ -455,21 +457,21 @@ Recursive_Memberof(IADs * pObj)
while (lBound <= uBound) {
hr = SafeArrayGetElement(V_ARRAY(&var), &lBound, &elem);
if (SUCCEEDED(hr)) {
if (add_User_Group(elem.n1.n2.n3.bstrVal)) {
if (add_User_Group(elem.bstrVal)) {
wchar_t *Group_Path;
IADs *pGrp;

Group_Path = GetLDAPPath(elem.n1.n2.n3.bstrVal, GC_MODE);
hr = ADsGetObject(Group_Path, &IID_IADs, (void **) &pGrp);
Group_Path = GetLDAPPath(elem.bstrVal, GC_MODE);
hr = ADsGetObject(Group_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
safe_free(Group_Path);
Group_Path = GetLDAPPath(elem.n1.n2.n3.bstrVal, LDAP_MODE);
hr = ADsGetObject(Group_Path, &IID_IADs, (void **) &pGrp);
Group_Path = GetLDAPPath(elem.bstrVal, LDAP_MODE);
hr = ADsGetObject(Group_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
safe_free(Group_Path);
} else
debug("Recursive_Memberof: ERROR ADsGetObject for %S failed: %s\n", Group_Path, Get_WIN32_ErrorMessage(hr));
Expand All @@ -489,8 +491,9 @@ Recursive_Memberof(IADs * pObj)
}
VariantClear(&var);
} else {
if (hr != E_ADS_PROPERTY_NOT_FOUND)
if (hr != E_ADS_PROPERTY_NOT_FOUND) {
debug("Recursive_Memberof: ERROR getting memberof attribute: %s\n", Get_WIN32_ErrorMessage(hr));
}
}
return hr;
}
Expand Down Expand Up @@ -628,7 +631,6 @@ Valid_Global_Groups(char *UserName, const char **Groups)
size_t j;

wchar_t *User_DN, *User_LDAP_path, *User_PrimaryGroup;
wchar_t **wszGroups, **tmp;
IADs *pUser;
HRESULT hr;

Expand Down Expand Up @@ -662,11 +664,11 @@ Valid_Global_Groups(char *UserName, const char **Groups)
debug("Valid_Global_Groups: cannot get DN for '%s'.\n", User);
return result;
}
wszGroups = build_groups_DN_array(Groups, NTDomain);
auto wszGroups = build_groups_DN_array(Groups, NTDomain);

User_LDAP_path = GetLDAPPath(User_DN, GC_MODE);

hr = ADsGetObject(User_LDAP_path, &IID_IADs, (void **) &pUser);
hr = ADsGetObject(User_LDAP_path, IID_IADs, (void **) &pUser);
if (SUCCEEDED(hr)) {
wchar_t *User_PrimaryGroup_Path;
IADs *pGrp;
Expand All @@ -677,48 +679,49 @@ Valid_Global_Groups(char *UserName, const char **Groups)
else {
add_User_Group(User_PrimaryGroup);
User_PrimaryGroup_Path = GetLDAPPath(User_PrimaryGroup, GC_MODE);
hr = ADsGetObject(User_PrimaryGroup_Path, &IID_IADs, (void **) &pGrp);
hr = ADsGetObject(User_PrimaryGroup_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
safe_free(User_PrimaryGroup_Path);
User_PrimaryGroup_Path = GetLDAPPath(User_PrimaryGroup, LDAP_MODE);
hr = ADsGetObject(User_PrimaryGroup_Path, &IID_IADs, (void **) &pGrp);
hr = ADsGetObject(User_PrimaryGroup_Path, IID_IADs, (void **) &pGrp);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pGrp);
pGrp->lpVtbl->Release(pGrp);
pGrp->Release();
} else
debug("Valid_Global_Groups: ADsGetObject for %S failed, ERROR: %s\n", User_PrimaryGroup_Path, Get_WIN32_ErrorMessage(hr));
} else
debug("Valid_Global_Groups: ADsGetObject for %S failed, ERROR: %s\n", User_PrimaryGroup_Path, Get_WIN32_ErrorMessage(hr));
safe_free(User_PrimaryGroup_Path);
}
hr = Recursive_Memberof(pUser);
pUser->lpVtbl->Release(pUser);
pUser->Release();
safe_free(User_LDAP_path);
User_LDAP_path = GetLDAPPath(User_DN, LDAP_MODE);
hr = ADsGetObject(User_LDAP_path, &IID_IADs, (void **) &pUser);
hr = ADsGetObject(User_LDAP_path, IID_IADs, (void **) &pUser);
if (SUCCEEDED(hr)) {
hr = Recursive_Memberof(pUser);
pUser->lpVtbl->Release(pUser);
pUser->Release();
} else
debug("Valid_Global_Groups: ADsGetObject for %S failed, ERROR: %s\n", User_LDAP_path, Get_WIN32_ErrorMessage(hr));

tmp = User_Groups;
auto tmp = User_Groups;
while (*tmp) {
if (wccmparray(*tmp, wszGroups) == 0) {
if (wccmparray(*tmp, wszGroups)) {
result = 1;
break;
}
++tmp;
}
} else
} else {
debug("Valid_Global_Groups: ADsGetObject for %S failed, ERROR: %s\n", User_LDAP_path, Get_WIN32_ErrorMessage(hr));
}

safe_free(User_DN);
safe_free(User_LDAP_path);
safe_free(User_PrimaryGroup);
tmp = wszGroups;
auto tmp = wszGroups;
while (*tmp) {
safe_free(*tmp);
++tmp;
Expand Down Expand Up @@ -794,13 +797,10 @@ main(int argc, char *argv[])
const char *groups[512];
int n;

if (argc > 0) { /* should always be true */
program_name = strrchr(argv[0], '/');
if (program_name == NULL)
program_name = argv[0];
} else {
program_name = "(unknown)";
}
assert(argc > 0);
program_name = strrchr(argv[0], '/');
if (program_name == NULL)
program_name = argv[0];
mypid = getpid();

setbuf(stdout, nullptr);
Expand All @@ -819,10 +819,12 @@ main(int argc, char *argv[])
DefaultDomain = xstrdup(machinedomain);
}
debug("%s " VERSION " " SQUID_BUILD_INFO " starting up...\n", argv[0]);
if (use_global)
if (use_global) {
debug("Domain Global group mode enabled using '%s' as default domain.\n", DefaultDomain);
if (use_case_insensitive_compare)
}
if (use_case_insensitive_compare) {
debug("Warning: running in case insensitive mode !!!\n");
}

atexit(CloseCOM);

Expand All @@ -844,7 +846,7 @@ main(int argc, char *argv[])
if ((p = strchr(buf, '\r')) != NULL)
*p = '\0'; /* strip \r */

debug("Got '%s' from Squid (length: %d).\n", buf, strlen(buf));
debug("Got '%s' from Squid (length: %d).\n", buf, static_cast<int>(strlen(buf)));

if (buf[0] == '\0') {
SEND_BH(HLP_MSG("Invalid Request. No Input."));
Expand All @@ -869,7 +871,6 @@ main(int argc, char *argv[])
} else {
SEND_ERR("");
}
err = 0;
}
return EXIT_SUCCESS;
}
Expand Down