Files
WoW-Hybrid-gateway/tests/source_local_account_fixture.c
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

61 lines
6.4 KiB
C

/* Standalone local-profile exercise; no game process. Real mode is separately
* gated and reads one bounded credential frame from an inherited stdin pipe. */
#include <windows.h>
#include <stdint.h>
#include <string.h>
#include "wine_wire_host.h"
#include "wine_engine_realm.h"
typedef LONG (WINAPI *Initialize)(const WCHAR*);
typedef LONG (WINAPI *Shutdown)(void);
typedef LONG (WINAPI *Kind)(void);
typedef LONG (WINAPI *PreStart)(uint32_t);
typedef LONG (WINAPI *PreStatus)(uint32_t);
typedef LONG (WINAPI *PreTake)(uint32_t,char[16]);
typedef LONG (WINAPI *AccountStart)(void);
typedef LONG (WINAPI *Snapshot)(struct gw_wire_account_ui_state*,struct gw_native_realm*,uint32_t);
typedef LONG (WINAPI *Select)(uint32_t,uint32_t);
typedef void (WINAPI *Activate)(void);
static void emit(const char*s){DWORD n,w=0;for(n=0;s[n];++n){}WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),s,n,&w,0);}
static void stop(unsigned code){ExitProcess(code);}
static int read_exact(unsigned char*p,DWORD n){HANDLE h=GetStdHandle(STD_INPUT_HANDLE);DWORD r;while(n){if(!ReadFile(h,p,n,&r,0)||!r)return 0;p+=r;n-=r;}return 1;}
static int printable(const unsigned char*p,unsigned n){unsigned i;for(i=0;i<n;++i)if(p[i]<32||p[i]>126)return 0;return 1;}
static int index_value(const char*s,uint32_t*out){unsigned i,n=0;if(!s[0])return 0;for(i=0;s[i];++i){if(i>1||s[i]<'0'||s[i]>'9')return 0;n=n*10+(unsigned)(s[i]-'0');}if(n>=64)return 0;*out=n;return 1;}
static void cancel_and_stop(struct gw_wire_auth_control*auth,Shutdown shutdown,unsigned code){
DWORD end=GetTickCount()+5000;LONG result;
InterlockedExchange((LONG*)&auth->cancel,1);
do {result=shutdown();if(!result)stop(code);if(result!=(LONG)0x80000011)stop(code);Sleep(2);}while((LONG)(end-GetTickCount())>0);
stop(code);
}
static int loopback_realm(const char*s){return strcmp(s,"127.0.0.1:8090")==0;}
void fixture_start(void){
HMODULE m=LoadLibraryA(GW_WIRE_DLL);Initialize init;Shutdown shutdown;Kind kind;PreStart ps;PreStatus status;PreTake take;AccountStart start;Snapshot snapshot;Select select;Activate activate;
struct gw_wire_auth_control *auth;struct gw_wire_auth_credentials *cred;struct gw_wire_endpoint_profile *endpoint;struct gw_wire_account_ui_state view;struct gw_native_realm rows[64];
char addr[16]={0},mode[16]={0},index[8]={0};uint32_t chosen=0;DWORD end,n;LONG state;unsigned char lens[2]={0};
if(!m)stop(1);
init=(Initialize)GetProcAddress(m,"gw_wire_initialize");shutdown=(Shutdown)GetProcAddress(m,"gw_wire_shutdown");kind=(Kind)GetProcAddress(m,"gw_source_profile_kind");ps=(PreStart)GetProcAddress(m,"gw_source_preflight_start");status=(PreStatus)GetProcAddress(m,"gw_source_preflight_status");take=(PreTake)GetProcAddress(m,"gw_source_preflight_take");start=(AccountStart)GetProcAddress(m,"gw_wire_account_start");snapshot=(Snapshot)GetProcAddress(m,"gw_wire_account_ui_snapshot");select=(Select)GetProcAddress(m,"gw_wire_account_ui_select");activate=(Activate)GetProcAddress(m,"gw_wire_account_ui_activate");auth=(void*)GetProcAddress(m,"gw_wire_auth_data");cred=(void*)GetProcAddress(m,"gw_wire_auth_credentials_data");endpoint=(void*)GetProcAddress(m,"gw_wire_endpoint_profile_data");
if(!init||!shutdown||!kind||!ps||!status||!take||!start||!snapshot||!select||!activate||!auth||!cred||!endpoint)stop(2);
if(kind()!=4||init(GW_WIRE_UNIX)!=0||auth->abi!=1||auth->size!=sizeof(*auth)||cred->abi!=1||cred->size!=sizeof(*cred)||endpoint->abi!=1||endpoint->size!=sizeof(*endpoint))stop(3);
activate();if(ps(1)!=0)stop(4);end=GetTickCount()+10000;
while((state=status(1))==1){if((LONG)(end-GetTickCount())<=0)stop(5);Sleep(2);}if(state!=2)stop(6);
while(take(1,addr)!=0){if((LONG)(end-GetTickCount())<=0)stop(7);Sleep(2);}if(strcmp(addr,"127.0.0.1")||take(1,addr)!=-1)stop(8);
if(select(0,1)!=-2)stop(9);emit("GW_LOCAL_PROFILE offline-preflight-pass\n");
n=GetEnvironmentVariableA("GW_LOCAL_FIXTURE_MODE",mode,sizeof(mode));
if(!n){if(shutdown()!=0)stop(10);FreeLibrary(m);stop(0);}
if(n>=sizeof(mode)||strcmp(mode,"real-once"))stop(11);
n=GetEnvironmentVariableA("GW_LOCAL_REALM_INDEX",index,sizeof(index));if(!n||n>=sizeof(index)||!index_value(index,&chosen))stop(12);
n=GetEnvironmentVariableA("GW_LOCAL_VERSION_PATH",auth->version_hash_path,sizeof(auth->version_hash_path));if(!n||n>=sizeof(auth->version_hash_path))stop(13);
n=GetEnvironmentVariableA("GW_LOCAL_ADDON_PATH",auth->addon_path,sizeof(auth->addon_path));if(!n||n>=sizeof(auth->addon_path))stop(14);
/* Do not read secrets until all nonsecret configuration has passed. */
if(!read_exact(lens,2)||!lens[0]||lens[0]>32||!lens[1]||lens[1]>64||!read_exact((unsigned char*)cred->username,lens[0])||!read_exact(cred->password,lens[1])||!printable((unsigned char*)cred->username,lens[0])||!printable(cred->password,lens[1])){SecureZeroMemory(cred->username,sizeof(cred->username));SecureZeroMemory(cred->password,sizeof(cred->password));stop(15);}
cred->generation=1;cred->username_bytes=lens[0];cred->password_bytes=lens[1];auth->auth_port=3724;auth->retention_ms=30000;auth->selected_index=-1;endpoint->kind=1;memcpy(endpoint->auth_ipv4,"127.0.0.1",10);InterlockedExchange((LONG*)&cred->state,1);
if(start()!=0){SecureZeroMemory(cred->username,sizeof(cred->username));SecureZeroMemory(cred->password,sizeof(cred->password));stop(16);}emit("GW_LOCAL_PROFILE submitted-once\n");
end=GetTickCount()+25000;for(;;){state=InterlockedCompareExchange((LONG*)&auth->state,0,0);if(state==5)break;if(state==3||state==4)cancel_and_stop(auth,shutdown,17);if((LONG)(end-GetTickCount())<=0){cancel_and_stop(auth,shutdown,18);}Sleep(5);}
memset(&view,0,sizeof(view));view.abi=1;view.size=sizeof(view);memset(rows,0,sizeof(rows));
if(snapshot(&view,rows,64)!=0||view.generation!=1||!view.genuine_discovery||view.selected_index!=-1||view.transport_prepared||view.realm_count<1||chosen>=(uint32_t)view.realm_count||!loopback_realm(rows[chosen].address)||(rows[chosen].flags&2))cancel_and_stop(auth,shutdown,19);
if(select(chosen,1)!=0)cancel_and_stop(auth,shutdown,20);emit("GW_LOCAL_PROFILE one-proposal-sent\n");
end=GetTickCount()+20000;for(;;){state=InterlockedCompareExchange((LONG*)&auth->state,0,0);if(state==2)break;if(state==3||state==4)cancel_and_stop(auth,shutdown,21);if((LONG)(end-GetTickCount())<=0){cancel_and_stop(auth,shutdown,22);}Sleep(5);}
if(auth->selected_index!=(LONG)chosen||auth->server_proof_verified!=1||auth->transport_prepared!=1)cancel_and_stop(auth,shutdown,23);emit("GW_LOCAL_PROFILE genuine-realm-prepared\n");
cancel_and_stop(auth,shutdown,0);
}