Files
3proxy/src/plugins/WindowsAuthentication/WindowsAuthentication.c
T
Vladimir DubrovinandClaude Opus 5.5 fa3807c6f1 Builds: no Open Watcom, no build without IPv6, no select()
The Win32 "lite" build with Open Watcom (Makefile.watcom, its release
workflow, the CMake branch for it) was the only one built without IPv6
(NOIPV6), without fibers and event loops, with a select() of its own
for poll() (mypoll()), and with the calling conventions of Watcom's
pragmas in the plugins. They are gone with it: every build has IPv6,
and polls with poll() on Unix and WSAPoll() on Windows, which were
what every other build asked for (WITH_POLL, WITH_WSAPOLL, the
3PROXY_USE_POLL and 3PROXY_USE_WSAPOLL options of CMake, FD_SETSIZE
for select()). getip(), the IPv4-only resolver of NOIPV6, goes too.

Plugin binary compatibility: plugins built with Open Watcom, and their
calling convention, are no longer supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:54:51 +03:00

90 lines
2.0 KiB
C

/*
(c) 2007-2026 by Vladimir Dubrovin <vlad@3proxy.org>
please read License Agreement
*/
#include "../../structures.h"
#include <string.h>
#include <ctype.h>
#include <locale.h>
#ifdef __cplusplus
extern "C" {
#endif
static struct auth alwaysauth;
static char sidbuf[4096];
static PSID psid = (PSID)sidbuf;
#ifdef __cplusplus
extern "C" {
#endif
static int windowsfunc(struct clientparam *param){
char *dom;
HANDLE h;
DWORD dw, sidlen, i;
char tokenbuf[4096];
PTOKEN_GROUPS ptg = (PTOKEN_GROUPS)tokenbuf;
if(!*param->username || !*param->password || param->pwtype != 0) return 4;
dom = strchr((char *)param->username, '\\');
if(dom)*dom++=0;
if(!LogonUser( dom?dom:(char *)param->username,
dom?(char *)param->username:NULL,
(char *)param->password,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&h))return 5;
if(dom)*(dom-1)='\\';
if(!GetTokenInformation(h, TokenGroups, ptg, sizeof(tokenbuf), &dw)) return 6;
CloseHandle(h);
sidlen = GetLengthSid(psid);
for(i=0; i < ptg->GroupCount; i++){
if(GetLengthSid(ptg->Groups[i].Sid)==sidlen){
if(!memcmp((void *)ptg->Groups[i].Sid, (void *)psid, sidlen)) {
setlocale(LC_CTYPE, ".ACP");
_strlwr((char *)param->username);
return 0;
}
}
}
return 7;
}
PLUGINAPI int PLUGINCALL WindowsAuthentication(struct pluginlink * pluginlink, int argc, char** argv){
char tmpbuf[4096];
DWORD dlen, sidlen;
SID_NAME_USE snu;
static int loaded = 0;
if(argc != 2) return 11;
dlen = sizeof(tmpbuf)/sizeof(TCHAR);
sidlen = sizeof(sidbuf);
if(!LookupAccountName(NULL, argv[1], psid, &sidlen,
(LPTSTR) tmpbuf, &dlen, &snu)) return 100000 + (int)GetLastError();
if(snu != SidTypeGroup && snu != SidTypeAlias && snu != SidTypeWellKnownGroup) return 12;
if(!loaded){
alwaysauth.authenticate = windowsfunc;
alwaysauth.authorize = pluginlink->checkACL;
alwaysauth.desc = "windows";
alwaysauth.blocks = 1;
alwaysauth.next = pluginlink->authfuncs->next;
pluginlink->authfuncs->next = &alwaysauth;
loaded = 1;
}
return 0;
}
#ifdef __cplusplus
}
#endif