1#! /usr/bin/perl -w 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 25# 26 27# 28# Create THIRDPARTYLICENSE files using the index file in $CODEMGR_WS. 29# 30 31use Cwd; 32use Env; 33use strict; 34use vars qw($opt_c); 35use Getopt::Std; 36 37# -c: only generate crypto license file 38my $usage = "mktpl [-c] license-list-file"; 39 40my $top = $ENV{"CODEMGR_WS"}; 41if (! $top) { 42 die "CODEMGR_WS must be set.\n"; 43} 44 45if (! getopts('c')) { 46 die "usage: $usage\n"; 47} 48if (@ARGV != 1) { 49 die "usage: $usage\n"; 50} 51 52my $indexfile = $ARGV[0]; 53 54my $exitstatus = 0; 55 56# 57# Create a THIRDPARTYLICENSE file from the given license list and suffix. 58# 59sub maketpl { 60 my ($suffix, @tpllist) = @_; 61 my $licnum = 1; 62 my $tplname = "$top/THIRDPARTYLICENSE.$suffix"; 63 64 if (! @tpllist) { 65 unlink $tplname; 66 return; 67 } 68 69 open(TPL, ">$tplname") or die "Can't create $tplname: $!\n"; 70 71 print TPL "DO NOT TRANSLATE OR LOCALIZE.\n\n"; 72 73 foreach my $licfile (@tpllist) { 74 my $descrip = `cat "$licfile.descrip"`; 75 if (! $descrip) { 76 warn "Missing description for $licfile\n"; 77 $exitstatus = 1; 78 $descrip = "(MISSING DESCRIPTION for $licfile)\n"; 79 } 80 print TPL "$licnum) The following software may be included ", 81 "in this product:\n\n"; 82 print TPL "\t$descrip\n"; 83 print TPL " Use of this software is governed by the ", 84 "terms of the following license:\n"; 85 print TPL "\n"; 86 if (open(LIC, "<$licfile")) { 87 while (<LIC>) { 88 print TPL " " . $_; 89 } 90 close LIC; 91 } else { 92 warn "Can't open $licfile: $!\n"; 93 $exitstatus = 1; 94 print TPL " (MISSING LICENSE: $licfile)\n"; 95 } 96 print TPL "\n"; 97 $licnum++; 98 } 99 100 close TPL or die "I/O error on $tplname: $!\n"; 101} 102 103# 104# Return non-zero if we expect the crypto for the given 105# third-party license file to be signed. Else, return zero. 106# 107my $hashes = qr"/(rng|md4|md5|sha1/sha2)/"; 108sub signedcrypto { 109 my ($licpath) = @_; 110 111 return 0 if $licpath =~ m#$hashes#; 112 return 1; 113} 114 115# 116# Make file list for each TPL file. 117# 118 119chdir($top) or die "Can't chdir to $top: $!\n"; 120$top = getcwd(); 121 122my $isclosed = qr"^usr/closed"; 123my $iscrypto = qr"(^usr/src/common/crypto)|(^usr/src/lib/pkcs11)"; 124 125my @closedlist; 126my @cryptolist; 127 128open(IX, "<$indexfile") or die "Can't open $indexfile: $!\n"; 129while (<IX>) { 130 chomp; 131 my $lic = $_; 132 if (! $opt_c && $lic =~ /$isclosed/) { 133 push @closedlist, $lic; 134 } 135 if ($lic =~ /$iscrypto/ && signedcrypto($lic)) { 136 push @cryptolist, $lic; 137 } 138} 139close IX; 140 141# 142# Generate each TPL file. 143# 144 145maketpl("ON-BINARIES", @closedlist); 146maketpl("ON-CRYPTO", @cryptolist); 147 148exit $exitstatus; 149