Commit 6978c4a5 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add LookupAccess() to see if a target (user,group) has access to an image,

returning a writeable flag.
parent 36b179cc
#!/usr/bin/perl -wT
#
# Copyright (c) 2007-2014 University of Utah and the Flux Group.
# Copyright (c) 2007-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -1693,6 +1693,41 @@ sub GrantAccess($$$)
return 0;
}
sub LookupAccess($$$$)
{
my ($self, $target, $paccess, $pwriteable) = @_;
my $imageid = $self->imageid();
my $imagename = $self->imagename();
my ($perm_idx, $perm_id, $perm_type);
if (ref($target) eq "User") {
$perm_idx = $target->uid_idx();
$perm_id = $target->uid();
$perm_type = "user";
}
elsif (ref($target) eq "Group") {
$perm_idx = $target->gid_idx();
$perm_id = $target->pid() . "/" . $target->gid();
$perm_type = "group";
}
my $query_result =
DBQueryWarn("select allow_write from image_permissions ".
"where imageid='$imageid' and ".
" permission_type='$perm_type' and ".
" permission_idx='$perm_idx'");
return -1
if (!$query_result);
if (!$query_result->numrows) {
$$paccess = 0;
$$pwriteable = 0 if (defined($pwriteable));
}
my ($writeable) = $query_result->fetchrow_array();
$$paccess = 1;
$$pwriteable = $writeable if (defined($pwriteable));
return 0;
}
sub RevokeAccess($$)
{
my ($self, $target) = @_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment