Files
2026-11-23 03:28:32 +02:00

98 lines
4.2 KiB
C

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include <stdint.h>
#include "priority_route_slot.h"
#include "wine_source_profile.h"
#include "wine_wire_host.h"
#include "wine_session_retirement.h"
extern struct gw_wire_auth_control gw_wire_auth_data;
extern struct gw_wire_auth_credentials gw_wire_auth_credentials_data;
extern LONG WINAPI gw_wire_account_active(void);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
#define GW_PRIORITY_GATE_PROFILE 5
static volatile LONG local_ready_generation;
#else
#define GW_PRIORITY_GATE_PROFILE 2
#endif
/* Both the Bridge trigger and the explicit Glue fallback require the same
* pre-credential epoch. Neither may change a route after login starts. */
static int priority_generation_admitted(uint32_t generation) {
const struct gw_session_retirement_control *r = &gw_wire_session_retirement_data;
const struct gw_wire_auth_credentials *c = &gw_wire_auth_credentials_data;
const struct gw_wire_auth_control *a = &gw_wire_auth_data;
if (gw_source_profile_kind() != GW_PRIORITY_GATE_PROFILE || !generation ||
generation > GW_SESSION_EPOCH_LIMIT ||
r->abi != 1 || r->size != sizeof(*r) ||
r->next_credentials_generation != generation ||
a->abi != 1 || a->size != sizeof(*a) || a->state || a->cancel ||
a->username[0] || a->password_path[0] || gw_wire_account_active() ||
c->abi != 1 || c->size != sizeof(*c) || c->state || c->generation ||
c->username_bytes || c->password_bytes)
return 0;
if (generation == 1) {
if (r->state || r->expected_credentials_generation ||
r->completed_credentials_generation) return 0;
} else if (r->state != 2 ||
r->expected_credentials_generation != generation - 1 ||
r->completed_credentials_generation != generation - 1)
return 0;
return 1;
}
/* Called only by the admitted Bridge after login installation. */
__declspec(dllexport) LONG WINAPI gw_wire_priority_begin(uint32_t generation) {
if (!priority_generation_admitted(generation)) return -1;
#if GW_PRIORITY_GATE_PROFILE == 5
/* The local server address is compiled in. Only publish readiness for
* this epoch; an old concurrent begin must never replace a newer one. */
LONG prior = InterlockedCompareExchange(&local_ready_generation, 0, 0);
while (prior < (LONG)generation) {
LONG observed = InterlockedCompareExchange(&local_ready_generation, (LONG)generation, prior);
if (observed == prior) return 0;
prior = observed;
}
return prior == (LONG)generation ? 0 : -1;
#else
if (gw_priority_slot_start(generation) == 0) return 0;
/* Resource failure never redirects to a third party. The only fallback
* is the compiled play.octowow.st profile for this generation. */
return gw_priority_slot_public(generation);
#endif
}
/* Numeric status for Glue; never reveals a private address or bearer. */
__declspec(dllexport) LONG WINAPI gw_wire_priority_status(uint32_t generation) {
if (!generation) generation =
gw_wire_session_retirement_data.next_credentials_generation;
#if GW_PRIORITY_GATE_PROFILE == 5
/* Glue uses status 3 for a ready fixed route. The local account worker
* still performs ordinary SRP against its pinned server. */
if (generation && generation == gw_wire_session_retirement_data.next_credentials_generation &&
gw_source_profile_kind() == 5 &&
generation == (uint32_t)InterlockedCompareExchange(&local_ready_generation, 0, 0))
return GW_PRIORITY_SLOT_PUBLIC;
return GW_PRIORITY_SLOT_NONE;
#else
return gw_source_profile_kind() == 2 ?
gw_priority_slot_status(generation) : GW_PRIORITY_SLOT_NONE;
#endif
}
/* User's explicit Use public choice; only the fixed Octo host is selected. */
__declspec(dllexport) LONG WINAPI gw_wire_priority_use_public(uint32_t generation) {
#if GW_PRIORITY_GATE_PROFILE == 5
(void)generation;
return -1;
#else
if (!generation) generation =
gw_wire_session_retirement_data.next_credentials_generation;
if (!priority_generation_admitted(generation)) return -1;
return gw_priority_slot_public(generation);
#endif
}