From a3e12a41da8c84724d9190074011bae71e5945b2 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sat, 9 Mar 2024 18:46:36 -0500 Subject: [PATCH] Add check for plugdev group. Note #287 --- minichlink/minichlink.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/minichlink/minichlink.c b/minichlink/minichlink.c index 8992116d..a7e544c4 100644 --- a/minichlink/minichlink.c +++ b/minichlink/minichlink.c @@ -17,7 +17,9 @@ void Sleep(uint32_t dwMilliseconds); #endif #else +#include #include +#include #endif static int64_t StringToMemoryAddress( const char * number ) __attribute__((used)); @@ -122,6 +124,30 @@ int main( int argc, char ** argv ) } } +#if !defined(WINDOWS) && !defined(WIN32) && !defined(_WIN32) + { + uid_t uid = getuid(); + struct passwd* pw = getpwuid(uid); + if( pw ) + { + gid_t groups[512]; + int ngroups = sizeof( groups ) / sizeof( groups[0] ); + int gl = getgrouplist( pw->pw_name, pw->pw_gid, groups, &ngroups ); + int i; + for( i = 0; i < gl; i++ ) + { + struct group * gr = getgrgid( groups[i] ); + if( strcmp( gr->gr_name, "plugdev" ) == 0 ) + break; + } + if( i == gl ) + { + printf( "WARNING: You are not in the plugdev group, the canned udev rules will not work on your system.\n" ); + } + } + } +#endif + void * dev = MiniCHLinkInitAsDLL( 0, &hints ); if( !dev ) {