# # {{{EMULAB-LICENSE# # This file is part of the Emulab network testbed software.# # This file is free software: you can redistribute it and/or modify it# under the terms of the GNU Affero General Public License as published by# the Free Software Foundation, either version 3 of the License, or (at# your option) any later version.# # This file is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public# License for more details.# # You should have received a copy of the GNU Affero General Public License# along with this file. If not, see <http://www.gnu.org/licenses/>.# # }}}

## Turn off line buffering on output#$|=1;## Untaint the path# $ENV{'PATH'}="/bin:/sbin:/usr/bin:";## Parse command arguments. Once we return from getopts, all that should be# left are the required arguments.#my%options=();if(!getopts($optlist,\%options)){usage();}if(defined($options{h})){usage();}if(defined($options{l})){$listonly=1;}if(defined($options{n})){$impotent=1;}

my$imageid=$ARGV[0];## Verify user.#my$this_user=User->ThisUser();if(!defined($this_user)){fatal("You ($UID) do not exist!");}if(defined($gid)){$target=Group->Lookup($gid);if(!defined($target)){fatal("No such project or group $gid\n");}}elsif(defined($uid)){$target=User->Lookup($uid);if(!defined($target)){fatal("No such user $uid\n");}}

if(!defined($image)){fatal("No such image exists");}$imageid=$image->imageid();# User must have permission.if(!$image->AccessCheck($this_user,TB_IMAGEID_EXPORT())){fatal("You do not have permission to change the external permissions");}if($listonly){my$query_result=DBQueryFatal("select * from image_permissions "."where imageid='$imageid'");while(my$row=$query_result->fetchrow_hashref()){my$perm_type=$row->{'permission_type'};my$perm_id=$row->{'permission_id'};my$perm_idx=$row->{'permission_idx'};my$write=$row->{'allow_write'};print"$perm_type: $perm_id ($perm_idx) ";print"writable"if($write);print"\n";}exit(0);}

if($PGENISUPPORT&&GetSiteVar("protogeni/use_imagetracker")){my$imageid=$image->imageid();print"Posting image $imageid to the image server ...\n";system("$POSTIMAGEDATA$imageid");if($?){printSTDERR"Could not post alias to the image server\n";}}