mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: client: idenitification: add /etc/machine-id
This commit is contained in:
@@ -165,6 +165,8 @@ static void ID_VerifyHEX_f( void )
|
||||
}
|
||||
|
||||
#if XASH_LINUX
|
||||
// TODO: do modern Linux even expose CPU serial number?
|
||||
// if not, remove this
|
||||
static qboolean ID_ProcessCPUInfo( bloomfilter_t *value )
|
||||
{
|
||||
int cpuinfofd = open( "/proc/cpuinfo", O_RDONLY );
|
||||
@@ -174,8 +176,11 @@ static qboolean ID_ProcessCPUInfo( bloomfilter_t *value )
|
||||
if( cpuinfofd < 0 )
|
||||
return false;
|
||||
|
||||
if( (ret = read( cpuinfofd, buffer, 1023 ) ) < 0 )
|
||||
if(( ret = read( cpuinfofd, buffer, sizeof( buffer ) - 1 )) < 0 )
|
||||
{
|
||||
close( cpuinfofd );
|
||||
return false;
|
||||
}
|
||||
|
||||
close( cpuinfofd );
|
||||
|
||||
@@ -184,15 +189,13 @@ static qboolean ID_ProcessCPUInfo( bloomfilter_t *value )
|
||||
if( !ret )
|
||||
return false;
|
||||
|
||||
pbuf = Q_strstr( buffer, "Serial" );
|
||||
pbuf = Q_stristr( buffer, "Serial" );
|
||||
if( !pbuf )
|
||||
return false;
|
||||
pbuf += 6;
|
||||
|
||||
if( ( pbuf2 = Q_strchr( pbuf, '\n' ) ) )
|
||||
*pbuf2 = 0;
|
||||
else
|
||||
pbuf2 = pbuf + Q_strlen( pbuf );
|
||||
pbuf2 = Q_strchrnul( pbuf, '\n' );
|
||||
*pbuf2 = 0;
|
||||
|
||||
if( !ID_VerifyHEX( pbuf ) )
|
||||
return false;
|
||||
@@ -302,8 +305,11 @@ static qboolean ID_ProcessFile( bloomfilter_t *value, const char *path )
|
||||
if( fd < 0 )
|
||||
return false;
|
||||
|
||||
if( (ret = read( fd, buffer, 255 ) ) < 0 )
|
||||
if(( ret = read( fd, buffer, sizeof( buffer ) - 1 )) < 0 )
|
||||
{
|
||||
close( fd );
|
||||
return false;
|
||||
}
|
||||
|
||||
close( fd );
|
||||
|
||||
@@ -522,7 +528,7 @@ static bloomfilter_t ID_GenerateRawId( void )
|
||||
int count = 0;
|
||||
|
||||
#if XASH_LINUX
|
||||
#if XASH_ANDROID && !XASH_DEDICATED
|
||||
#if XASH_ANDROID
|
||||
{
|
||||
const char *androidid = Android_GetAndroidID();
|
||||
if( androidid && ID_VerifyHEX( androidid ) )
|
||||
@@ -531,7 +537,11 @@ static bloomfilter_t ID_GenerateRawId( void )
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // !XASH_ANDROID
|
||||
// most systemd/Linux distros expose this file
|
||||
count += ID_ProcessFile( &value, "/etc/machine-id" );
|
||||
#endif // !XASH_ANDROID
|
||||
|
||||
count += ID_ProcessCPUInfo( &value );
|
||||
count += ID_ProcessFiles( &value, "/sys/block", "device/cid" );
|
||||
count += ID_ProcessNetDevices( &value );
|
||||
@@ -563,7 +573,7 @@ static uint ID_CheckRawId( bloomfilter_t filter )
|
||||
int count = 0;
|
||||
|
||||
#if XASH_LINUX
|
||||
#if XASH_ANDROID && !XASH_DEDICATED
|
||||
#if XASH_ANDROID
|
||||
{
|
||||
const char *androidid = Android_GetAndroidID();
|
||||
if( androidid && ID_VerifyHEX( androidid ) )
|
||||
@@ -573,7 +583,15 @@ static uint ID_CheckRawId( bloomfilter_t filter )
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // !XASH_ANDROID
|
||||
// most systemd/Linux distros expose this file
|
||||
if( ID_ProcessFile( &value, "/etc/machine-id" ))
|
||||
{
|
||||
count += (filter & value) == value;
|
||||
value = 0;
|
||||
}
|
||||
|
||||
#endif // !XASH_ANDROID
|
||||
count += ID_CheckNetDevices( filter );
|
||||
count += ID_CheckFiles( filter, "/sys/block", "device/cid" );
|
||||
if( ID_ProcessCPUInfo( &value ) )
|
||||
@@ -622,7 +640,7 @@ static void ID_Check( void )
|
||||
{
|
||||
id = 0;
|
||||
#if 0
|
||||
Msg( "%s: fail %d\n", __func__, weight );
|
||||
Con_Printf( "%s: "S_RED"fail"S_DEFAULT" %d\n", __func__, weight );
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@@ -630,7 +648,7 @@ static void ID_Check( void )
|
||||
if( ID_CheckRawId( id ) < mincount )
|
||||
id = 0;
|
||||
#if 0
|
||||
Msg( "%s: success %d\n", __func__, weight );
|
||||
Con_Printf( "%s: "S_GREEN"success"S_DEFAULT" %d\n", __func__, weight );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user