Skip to content

Commit

Permalink
Add check for plugdev group. Note #287
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Mar 9, 2024
1 parent 021a19a commit a3e12a4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions minichlink/minichlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
void Sleep(uint32_t dwMilliseconds);
#endif
#else
#include <pwd.h>
#include <unistd.h>
#include <grp.h>
#endif

static int64_t StringToMemoryAddress( const char * number ) __attribute__((used));
Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit a3e12a4

Please sign in to comment.