//
// sub_10057D1A8 from 0x10057d1a8 to 0x10057d73c (1428 bytes)
//
// 1 xrefs:
// > sub_1005502E0 @ 0x100550354
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __fastcall sub_10057D1A8(__int64 a1, int a2)
{
void **v4; // x26
const char **v5; // x9
_DWORD *v6; // x28
__int64 v7; // x23
const char *v8; // x8
const char *v9; // x21
char *v10; // x22
__int64 v11; // x21
const char *v12; // x8
char *v13; // x0
char *pw_name; // x22
char *v15; // x0
char *v16; // x0
uid_t v17; // w0
bool v18; // zf
char *v19; // x23
char *v20; // x0
char *v21; // x21
int v22; // w22
__int64 v23; // x24
int v24; // w22
__int64 v25; // x23
pid_t v26; // w0
pid_t v27; // w23
int v28; // w22
__int64 v29; // x23
const char *v30; // x8
int v32; // w20
__int64 v33; // x21
int v34; // w20
__int64 v35; // x21
int v36; // w20
__int64 v37; // x21
passwd *v38; // [xsp+50h] [xbp-4B0h] BYREF
passwd v39; // [xsp+58h] [xbp-4A8h] BYREF
char v40[1024]; // [xsp+A0h] [xbp-460h] BYREF
int v41; // [xsp+4A0h] [xbp-60h] BYREF
int v42; // [xsp+4A4h] [xbp-5Ch]
if ( a2 )
v4 = (void **)(a1 + 832);
else
v4 = (void **)(a1 + 856);
if ( a2 )
v5 = (const char **)(a1 + 400);
else
v5 = (const char **)(a1 + 368);
if ( a2 )
v6 = (_DWORD *)(a1 + 1008);
else
v6 = (_DWORD *)(a1 + 976);
if ( a2 )
v7 = *(_QWORD *)a1 + 35416LL;
else
v7 = *(_QWORD *)a1 + 35384LL;
v8 = *v5;
*(_BYTE *)(v7 + 24) = 0;
if ( v8 )
v9 = v8;
else
v9 = "";
if ( *v6 == 2 )
{
v10 = sub_1005628DC("TT %s\n", *(const char **)(a1 + 1048));
if ( !v10 )
return 27;
v11 = sub_10057D73C(a1, v10, (unsigned int)*v6);
off_10085DEB8(v10);
if ( !(_DWORD)v11 )
{
off_10085DEB8(*v4);
v12 = "Proxy-";
if ( !a2 )
v12 = "";
*v4 = sub_1005628DC("%sAuthorization: %s\r\n", v12, *(const char **)(a1 + 1056));
*v6 = 3;
*(_BYTE *)(v7 + 24) = 1;
sub_10057D080(a1);
return 0;
}
return v11;
}
if ( *v6 == 3 )
{
off_10085DEB8(*v4);
v11 = 0;
*v4 = nullptr;
*(_BYTE *)(v7 + 24) = 1;
return v11;
}
if ( *(_DWORD *)(a1 + 1040) != -1 || *(_DWORD *)(a1 + 1044) )
goto LABEL_58;
if ( *v9 )
goto LABEL_43;
v13 = getenv("NTLMUSER");
pw_name = v13;
if ( !v13 || !*v13 )
{
v15 = getenv("LOGNAME");
pw_name = v15;
if ( !v15 || !*v15 )
{
v16 = getenv("USER");
pw_name = v16;
if ( v16 )
{
if ( *v16 )
goto LABEL_44;
}
else
{
pw_name = nullptr;
}
v17 = geteuid();
if ( getpwuid_r(v17, &v39, v40, 0x400u, &v38) )
v18 = 1;
else
v18 = v38 == nullptr;
if ( !v18 )
pw_name = v39.pw_name;
if ( !pw_name || !*pw_name )
LABEL_43:
pw_name = (char *)v9;
}
}
LABEL_44:
v19 = strpbrk(pw_name, "\\/");
if ( !v19 )
{
v21 = nullptr;
goto LABEL_48;
}
v20 = off_10085DEC8(pw_name);
v21 = v20;
if ( v20 )
{
v20[v19 - pw_name] = 0;
pw_name = v19 + 1;
LABEL_48:
if ( access("/usr/bin/ntlm_auth", 1) )
{
v22 = *__error();
v23 = *(_QWORD *)a1;
sub_100570168(a1, v22);
sub_100552734(v23, "Could not access ntlm_auth: %s errno %d: %s");
LABEL_56:
off_10085DEB8(v21);
off_10085DEB8(nullptr);
v11 = 9;
goto LABEL_59;
}
if ( socketpair(1, 1, 0, &v41) )
{
v24 = *__error();
v25 = *(_QWORD *)a1;
sub_100570168(a1, v24);
sub_100552734(v25, "Could not open socket pair. errno %d: %s");
goto LABEL_56;
}
v26 = fork();
v27 = v26;
if ( !v26 )
{
close(v41);
if ( dup2(v42, 0) == -1 )
{
v32 = *__error();
v33 = *(_QWORD *)a1;
sub_100570168(a1, v32);
sub_100552734(v33, "Could not redirect child stdin. errno %d: %s");
}
else if ( dup2(v42, 1) == -1 )
{
v34 = *__error();
v35 = *(_QWORD *)a1;
sub_100570168(a1, v34);
sub_100552734(v35, "Could not redirect child stdout. errno %d: %s");
}
else
{
if ( v21 )
execl(
"/usr/bin/ntlm_auth",
"/usr/bin/ntlm_auth",
"--helper-protocol",
"ntlmssp-client-1",
"--use-cached-creds",
"--username",
pw_name,
"--domain",
v21,
0);
else
execl(
"/usr/bin/ntlm_auth",
"/usr/bin/ntlm_auth",
"--helper-protocol",
"ntlmssp-client-1",
"--use-cached-creds",
"--username",
pw_name,
0);
v36 = *__error();
close(v42);
v37 = *(_QWORD *)a1;
sub_100570168(a1, v36);
sub_100552734(v37, "Could not execl(). errno %d: %s");
}
exit(1);
}
if ( v26 == -1 )
{
v28 = *__error();
close(v41);
close(v42);
v29 = *(_QWORD *)a1;
sub_100570168(a1, v28);
sub_100552734(v29, "Could not fork. errno %d: %s");
goto LABEL_56;
}
close(v42);
*(_DWORD *)(a1 + 1040) = v41;
*(_DWORD *)(a1 + 1044) = v27;
off_10085DEB8(v21);
off_10085DEB8(nullptr);
LABEL_58:
v11 = 0;
goto LABEL_59;
}
v11 = 27;
LABEL_59:
if ( !(_DWORD)v11 )
{
v11 = sub_10057D73C(a1, "YR\n", (unsigned int)*v6);
if ( !(_DWORD)v11 )
{
off_10085DEB8(*v4);
v30 = "Proxy-";
if ( !a2 )
v30 = "";
*v4 = sub_1005628DC("%sAuthorization: %s\r\n", v30, *(const char **)(a1 + 1056));
off_10085DEB8(*(void **)(a1 + 1056));
v11 = 0;
*(_QWORD *)(a1 + 1056) = 0;
}
}
return v11;
}