aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/metadata.pm
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2017-06-13 17:03:38 +0800
committerYousong Zhou <yszhou4tech@gmail.com>2017-06-18 10:39:35 +0800
commit80d9ec5d3dbc1e393f377ede51e16d5c267475bd (patch)
treebc5f4a9581c170254c59d61eaeafad7ef31808ef /scripts/metadata.pm
parentf334a0cdb8498dfd2bbb780245e4e0ed0d103ece (diff)
downloadupstream-80d9ec5d3dbc1e393f377ede51e16d5c267475bd.tar.gz
upstream-80d9ec5d3dbc1e393f377ede51e16d5c267475bd.tar.bz2
upstream-80d9ec5d3dbc1e393f377ede51e16d5c267475bd.zip
scripts/package-metadata.pl: parse and validate field Require-User
The script will now detect uid/gid collision and can generate a table of current allocation ./scripts/package-metadata.pl usergroup tmp/.packageinfo \ | sort -k 1,1r -k 3,3n \ | column -t This should ensure that no collision will happen for each single build Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Diffstat (limited to 'scripts/metadata.pm')
-rw-r--r--scripts/metadata.pm72
1 files changed, 71 insertions, 1 deletions
diff --git a/scripts/metadata.pm b/scripts/metadata.pm
index 8334f26d31..d446892e2b 100644
--- a/scripts/metadata.pm
+++ b/scripts/metadata.pm
@@ -2,7 +2,7 @@ package metadata;
use base 'Exporter';
use strict;
use warnings;
-our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore);
+our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
our %package;
our %preconfig;
@@ -13,6 +13,11 @@ our %features;
our %overrides;
our @ignore;
+our %usernames;
+our %groupnames;
+our %userids;
+our %groupids;
+
sub get_multiline {
my $fh = shift;
my $prefix = shift;
@@ -31,6 +36,58 @@ sub confstr($) {
return $conf;
}
+sub parse_package_metadata_usergroup($$$$$) {
+ my $makefile = shift;
+ my $typename = shift;
+ my $names = shift;
+ my $ids = shift;
+ my $spec = shift;
+ my $name;
+ my $id;
+
+ # the regex for name is taken from is_valid_name() of package shadow
+ if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
+ $name = $spec;
+ $id = -1;
+ } elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
+ $name = $1;
+ $id = $2;
+ } else {
+ warn "$makefile: invalid $typename spec $spec\n";
+ return 0;
+ }
+
+ if ($id =~ /^[1-9]\d*$/) {
+ if ($id >= 65536) {
+ warn "$makefile: $typename $name id $id >= 65536";
+ return 0;
+ }
+ if (not exists $ids->{$id}) {
+ $ids->{$id} = {
+ name => $name,
+ makefile => $makefile,
+ };
+ } elsif ($ids->{$id}{name} ne $name) {
+ warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
+ return 0;
+ }
+ } elsif ($id != -1) {
+ warn "$makefile: $typename $name has invalid id $id\n";
+ return 0;
+ }
+
+ if (not exists $names->{$name}) {
+ $names->{$name} = {
+ id => $id,
+ makefile => $makefile,
+ };
+ } elsif ($names->{$name}{id} != $id) {
+ warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
+ return 0;
+ }
+ return 1;
+}
+
sub parse_target_metadata($) {
my $file = shift;
my ($target, @target, $profile);
@@ -128,6 +185,8 @@ sub clear_packages() {
%category = ();
%features = ();
%overrides = ();
+ %usernames = ();
+ %groupnames = ();
}
sub parse_package_metadata($) {
@@ -262,6 +321,17 @@ sub parse_package_metadata($) {
/^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
/^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
/^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
+ /^Require-User:\s*(.*?)\s*$/ and do {
+ my @ugspecs = split /\s+/, $1;
+
+ for my $ugspec (@ugspecs) {
+ my @ugspec = split /:/, $ugspec, 2;
+ parse_package_metadata_usergroup($makefile, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
+ if (@ugspec > 1) {
+ parse_package_metadata_usergroup($makefile, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;
+ }
+ }
+ };
}
close FILE;
return 1;