Now checks to see if user is in group as well as owner
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3036 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
parent
103bba682d
commit
72416fc24b
|
@ -31,6 +31,52 @@
|
|||
#include "zm.h"
|
||||
#include "zm_db.h"
|
||||
|
||||
// Determine if we are a member of the group
|
||||
int inGroup( gid_t gid )
|
||||
{
|
||||
// Get how many groups we are in
|
||||
int n_gids = getgroups( 0, NULL );
|
||||
if ( n_gids < 0 )
|
||||
{
|
||||
Error( "getgroups:%s", strerror(errno) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
// Not in any groups
|
||||
if ( !n_gids )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
// Allocate space to hold groups
|
||||
gid_t *gids = new gid_t[n_gids * sizeof(gid_t)];
|
||||
if ( !gids )
|
||||
{
|
||||
Error( "Unable to allocate groups: %s", strerror(errno) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
// Get list of groups
|
||||
if ( getgroups( n_gids, gids ) != n_gids )
|
||||
{
|
||||
Error( "getgroups:%s", strerror(errno) );
|
||||
delete[] gids;
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
// See if gid in list of groups we belong to
|
||||
int in_gid = 0;
|
||||
for ( int i = 0; i < n_gids; i++ )
|
||||
{
|
||||
if ( gids[i] == gid )
|
||||
{
|
||||
in_gid = 1;
|
||||
}
|
||||
}
|
||||
delete[] gids;
|
||||
return( in_gid );
|
||||
}
|
||||
|
||||
bool fixDevice( const char *device_path )
|
||||
{
|
||||
struct stat stat_buf;
|
||||
|
@ -44,13 +90,19 @@ bool fixDevice( const char *device_path )
|
|||
uid_t uid = getuid();
|
||||
gid_t gid = getgid();
|
||||
|
||||
int in_gid;
|
||||
if ( (in_gid = inGroup( stat_buf.st_gid )) < 0 )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
mode_t mask = 0;
|
||||
if ( uid == stat_buf.st_uid )
|
||||
{
|
||||
// If we are the owner
|
||||
mask = 00600;
|
||||
}
|
||||
else if ( gid == stat_buf.st_gid )
|
||||
else if ( gid == stat_buf.st_gid || in_gid )
|
||||
{
|
||||
// If we are in the owner group
|
||||
mask = 00060;
|
||||
|
|
Loading…
Reference in New Issue