#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "%Z%%M% %I% %E% SMI"
#
require 5.005;
use strict;
use locale;
use Errno;
use Fcntl;
#
# Print a usage message and exit.
#
sub usage
{
my (@msg) = @_;
"Usage: %s [-n] [-f filename]\n"), $prog);
" %s [-n] [-A|-f filename] [-p projid [-o]] [-c comment]\n".
" %s [-a|-s|-r] [-U user[,user...]] [-G group[,group...]]\n".
" %s [-K name[=value[,value...]]] [-l new_projectname] ".
exit(2);
}
#
# Print a list of error messages and exit.
#
sub error
{
foreach my $err (@_) {
}
exit($exit);
}
#
# is the first argument, an array ref is the second argument. The third
# argument is the mode which can be one of:
# add add all entries in the first arg to the second
# remove remove all entries in the first arg from the second
# replace replace the second arg by the first
# The resulting array is returned as a reference.
#
sub merge_lists
{
my @err;
if ($mode eq 'add') {
my @leftover;
foreach my $e (@$new) {
if (! exists($look{$e})) {
push(@merged, $e);
} else {
push(@leftover, $e);
}
}
if (@leftover) {
push(@err,
join(',', @leftover)]);
return (1, \@err);
}
return(0, \@merged);
} elsif ($mode eq 'remove') {
my %seen;
if (@dups) {
join(',', @dups)]);
return (1, \@err);
}
my @merged;
foreach my $e (@$old) {
if (exists($look{$e})) {
$look{$e}++;
} else {
push(@merged, $e);
}
}
if (@leftover) {
push(@err, [6,
gettext('Project does not contain "%s"'),
join(',', @leftover)]);
return (1, \@err);
}
return (0, \@merged);
return (0, $new);
}
}
#
# merge_values(ref to listA, ref to listB, mode
#
# Merges the values in listB with the values in listA. Dups are not
# merged away, but instead are maintained.
#
# modes:
# add : add values in listB to listA
# remove: removes first instance of each value in listB from listA
#
sub merge_values
{
my $undefined;
my @merged;
my $lastmerged;
my $found;
my @err;
return (0, $undefined);
}
if ($mode eq 'add') {
if (defined($old)) {
}
if (defined($new)) {
}
return (0, \@merged);
} elsif ($mode eq 'remove') {
$lastmerged = $old;
$found = 0;
@merged = ();
foreach $oldval (@$lastmerged) {
if (!$found &&
$found = 1;
} else {
}
}
if (!$found) {
'Value "%s" not found'),
}
@$lastmerged = @merged;
}
if (@err) {
return (1, \@err);
} else {
return (0, \@merged);
}
}
}
#
# merge_attribs(listA ref, listB ref, mode)
#
# Each hash ref should have keys "name" and "values"
#
# modes:
# add For each attribute in listB, add its values to
# the matching attribute in listA. If listA does not
# contain this attribute, add it.
#
# remove For each attribute in listB, remove its values from
# the matching attribute in listA. If all of an
# attributes values are removed, the attribute is removed.
# If the attribute in listB has no values, then the attribute
# and all of it's values are removed from listA
#
# substitute For each attribute in listB, replace the values of
# the matching attribute in listA with its values. If
# listA does not contain this attribute, add it.
#
# replace Return listB
#
# The resulting array is returned as a reference.
#
sub merge_attribs
{
my @merged;
my @err;
my $ret;
my $tmp;
my $newattrib;
my $oldattrib;
my $values;
if ($mode eq 'add') {
my %oldhash;
if (defined($oldattrib)) {
$newattrib->{'values'},
$oldattrib->{'values'},
$mode);
if ($ret != 0) {
} else {
}
} else {
}
}
if (@err) {
return (1, \@err);
} else {
return (0, \@merged);
}
} elsif ($mode eq 'remove') {
my %seen;
if (@dups) {
'Duplicate Attributes "%s"'),
join(',', @dups)]);
return (1, \@err);
}
if (!defined($newattrib)) {
} else {
if (defined($newattrib->{'values'})) {
$newattrib->{'values'},
$oldattrib->{'values'},
$mode);
if ($ret != 0) {
} else {
}
}
}
}
}
push(@err, [6,
gettext('Project does not contain "%s"'),
$tmp]);
}
if (@err) {
return (1, \@err);
} else {
return (0, \@merged);
}
} elsif ($mode eq 'substitute') {
my %oldhash;
if (defined($oldattrib)) {
$oldattrib->{'values'} =
$newattrib->{'values'};
} else {
}
}
if (@err) {
return (1, \@err);
} else {
return (0, \@merged);
}
} elsif ($mode eq 'replace') {
return (0, $new);
}
}
#
# Main routine of script.
#
# Set the message locale.
#
# Process command options and do some initial command-line validity checking.
$flags = {};
my $modify = 0;
my $projfile;
my $opt_n;
my $opt_c;
my $opt_o;
my $opt_p;
my $opt_l;
my $opt_a;
my $opt_r;
my $opt_s;
my $opt_U;
my $opt_G;
my @opt_K;
my $opt_A;
"n" => \$opt_n,
"c=s" => \$opt_c,
"o" => \$opt_o,
"p=s" => \$opt_p,
"l=s" => \$opt_l,
"s" => \$opt_s,
"r" => \$opt_r,
"a" => \$opt_a,
"U=s" => \$opt_U,
"G=s" => \$opt_G,
"K=s" => \@opt_K,
$modify = 1;
if (! defined($ARGV[0])) {
}
}
}
}
if (! defined($projfile)) {
$projfile = &PROJF_PATH;
}
}
if (defined($opt_a)) {
} elsif (defined($opt_r)) {
} elsif (defined($opt_s)) {
} else {
}
# Fabricate an unique temporary filename.
my $pfh;
#
# Read the project file. sysopen() is used so we can control the file mode.
# Handle special case for standard input.
if ($projfile eq '-') {
gettext('Cannot open standard input')]);
}
if ($opt_n) {
} else {
}
if ($ret != 0) {
}
close($pfh);
my $err;
my $tmperr;
my $value;
# Find existing record.
$idx = 0;
if (defined($pname)) {
foreach my $r (@$pf) {
if ($r->{'name'} eq $pname) {
$proj = $r;
last;
}
$idx++;
}
if (! $proj);
}
#
# If there are no modification options, simply reading the file, which
# includes parsing and verifying, is sufficient.
#
if (!$modify) {
exit(0);
}
foreach my $r (@$pf) {
if ($r->{'name'} eq $pname) {
$proj = $r;
last;
}
$idx++;
}
# Update the record as appropriate.
$err = [];
# Set new project name.
if (defined($opt_l)) {
if ($ret != 0) {
} else {
if (!defined($opt_n)) {
if ($ret != 0) {
}
}
}
}
# Set new project id.
if (defined($opt_p)) {
if ($ret != 0) {
} else {
# Check for dupicate.
if ($ret != 0) {
}
}
}
}
# Set new comment.
if (defined($opt_c)) {
if ($ret != 0) {
} else {
}
}
# Set new users.
if (defined($opt_U)) {
my @sortlist;
my $list;
if ($ret != 0) {
} else {
if ($ret != 0) {
} else {
}
}
}
# Set new groups.
if (defined($opt_G)) {
my @sortlist;
my $list;
if ($ret != 0) {
} else {
if ($ret != 0) {
} else {
}
}
}
# Set new attributes.
my $attrib;
my @attriblist;
my $list;
if ($ret != 0) {
} else {
push(@attriblist, @$list);
}
}
if (@attriblist) {
my @sortlist;
my $list;
if ($ret != 0) {
} else {
@sortlist =
}
}
# Validate all projent fields.
if (!defined($opt_n)) {
if ($ret != 0) {
}
}
if (@$err) {
}
# Write out the project file.
if ($modify) {
#
# Mark projent to write based on new values instead of
# original line.
#
umask(0000);
close($pfh);
# Update file attributes.
unlink($tmpprojf);
$tmpprojf, $!]);
}
unlink($tmpprojf);
}
}
if (defined($opt_A)) {
my $error;
if ($error == SETPROJ_ERR_TASK) {
if ($!{EAGAIN}) {
"been reached\n")]);
} elsif ($!{ESRCH}) {
} elsif ($!{EACCES}) {
)]);
} else {
"\"\n"), $pname]);
}
} elsif ($error == SETPROJ_ERR_POOL) {
if ($!{EACCES}) {
"default bindings exists for project \"%s".
"\"\n"), $pname]);
} elsif ($!{ESRCH}) {
"does not exist for project \"%s\"\n"),
$pname]);
} else {
"resource pool for project \"%s\"\n"),
$pname]);
}
} else {
#
# $error represents the position - within the semi-colon
# delimited $attribute - that generated the error
#
if ($error <= 0) {
"project \"%s\"\n"), $pname]);
} else {
/(\S+?)=\S+?(?:;|\z)/g)[$error - 1];
if (!$attribute) {
"control assignment failed for ".
"project \"%s\" attribute %d\n"),
} else {
"resource control assignment ".
"failed for project \"%s\"\n"),
}
}
}
}
}
exit(0);