1 # copyright-file -- lintian check script -*- perl -*-
3 # Copyright (C) 1998 Christian Schwarz
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21 package Lintian::copyright_file;
28 use Encode qw(decode);
35 my $ppkg = quotemeta($pkg);
40 use lib "$ENV{'LINTIAN_ROOT'}/checks/";
43 # Read package contents...
44 open(IN, '<', "index") or fail("cannot open index file index: $!");
47 if (m,usr/(share/)?doc/$ppkg/copyright(\.\S+)?(\s+\-\>\s+.*)?$,) {
48 my ($ext,$link) = ($2,$3);
50 $ext = '' if (! defined $ext);
51 #an extension other than .gz doesn't count as copyright file
52 next unless ($ext eq '') or ($ext eq '.gz');
55 #search for an extension
57 tag "copyright-file-compressed", "";
61 #make sure copyright is not a symlink
63 tag "copyright-file-is-symlink", "";
68 if (($ext eq '') and not $link) {
72 fail("unhandled case: $_");
74 } elsif (m,usr/share/doc/$ppkg \-\>\s+(\S+),) {
80 # check if this symlink references a directory elsewhere
81 if ($link =~ m,^(\.\.)?/,) {
82 tag "usr-share-doc-symlink-points-outside-of-usr-share-doc", "$link";
86 # link might point to a subdirectory of another /usr/share/doc
90 # this case is allowed, if this package depends on link
91 # and both packages come from the same source package
93 if (not open (VERSION, '<', "fields/version")) {
94 fail("Can't open fields/version: $!");
96 chomp(my $our_version = <VERSION>);
99 # depend on $link pkg?
100 if ((not depends_on($link, $our_version)) &&
101 not (exists($known_essential{$link}) &&
102 defined($known_essential{$link}))) {
105 tag "usr-share-doc-symlink-without-dependency", "$link";
110 # We can only check if both packages come from the same source
111 # if our source package is currently unpacked in the lab, too!
112 if (-d "source") { # yes, it's unpacked
114 # $link from the same source pkg?
115 if (-l "source/binary/$link") {
116 # yes, everything is ok.
119 tag "usr-share-doc-symlink-to-foreign-package", "$link";
121 } else { # no, source is not available
122 tag "cannot-check-whether-usr-share-doc-symlink-points-to-foreign-package", "";
127 } elsif (m,usr/doc/copyright/$ppkg$,) {
128 tag "old-style-copyright-file", "";
136 tag "no-copyright-file", "";
139 # check that copyright is UTF-8 encoded
140 my $line = file_is_encoded_in_non_utf8("copyright", $type, $pkg);
142 tag "debian-copyright-file-uses-obsolete-national-encoding", "at line $line"
145 # check contents of copyright file
146 open(IN, '<', "copyright") or fail("cannot open copyright file copyright: $!");
152 # We have to decode into UTF-8 to get the right length for the length
153 # check. For some reason, use open ':utf8' isn't sufficient. If the
154 # file uses a non-UTF-8 encoding, this will mangle it, but it doesn't
155 # matter for the length check.
156 my @lines = split ("\n", decode ('utf-8', $_));
157 for my $i (0 .. $#lines) {
158 if (length ($lines[$i]) > 80) {
159 tag "debian-copyright-line-too-long", "line " . ($i+1);
163 my $wrong_directory_detected = 0;
165 if (m,\<fill in (http/)?ftp site\>, or m/\<Must follow here\>/) {
166 tag "helper-templates-in-copyright", "";
169 if (m,usr/share/common-licenses/(GPL|LGPL|BSD|Artistic)\.gz,) {
170 tag "copyright-refers-to-compressed-license", "$&";
173 if (m,usr/share/common-licences,) {
174 tag "copyright-refers-to-incorrect-directory", "$&";
175 $wrong_directory_detected = 1;
178 if (m,usr/share/doc/copyright,) {
179 tag "copyright-refers-to-old-directory", "";
180 $wrong_directory_detected = 1;
183 if (m,usr/doc/copyright,) {
184 tag "copyright-refers-to-old-directory", "";
185 $wrong_directory_detected = 1;
188 # Lame check for old FSF zip code. Try to avoid false positives from other
189 # Cambridge, MA addresses.
190 if (m/(Free\s*Software\s*Foundation.*02139|02111-1307)/s) {
191 tag "old-fsf-address-in-copyright-file", "";
194 # Whether the package is covered by the GPL, used later for the libssl check.
197 if (length($_) > 12000
198 and ((m/\bGNU GENERAL PUBLIC LICENSE\s*TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\b/m
199 and m/\bVersion 2\s/)
200 or (m/\bGNU GENERAL PUBLIC LICENSE\s*Version 3/ and m/\bTERMS AND CONDITIONS\s/))) {
201 tag "copyright-file-contains-full-gpl-license";
205 if (length($_) > 12000
206 and m/\bGNU Free Documentation License\s*Version 1\.2/ and m/\b1\. APPLICABILITY AND DEFINITIONS/) {
207 tag "copyright-file-contains-full-gfdl-license";
210 if (length($_) > 10000
211 and m/\bApache License\s+Version 2\.0,/
212 and m/TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION/) {
213 tag "copyright-file-contains-full-apache-2-license";
216 if (m/^This copyright info was automatically extracted from the perl module\./) {
217 tag "helper-templates-in-copyright", "";
220 if (m,(under )?(the )?(same )?(terms )?as Perl itself,i &&
221 !m,usr/share/common-licenses/,) {
222 tag "copyright-file-lacks-pointer-to-perl-license", "";
226 if ((m,common-licenses(/\S+),) && (! m,/usr/share/common-licenses/,)) {
227 tag "copyright-does-not-refer-to-common-license-file", "$1";
230 # This check is a bit prone to false positives, since some other licenses
231 # mention the GPL. Also exclude any mention of the GPL following what looks
232 # like mail headers, since sometimes e-mail discussions of licensing are
233 # included in the copyright file but aren't referring to the license of the
235 if (m,/usr/share/common-licenses,
236 || m/Zope Public License/
237 || m/LICENSE AGREEMENT FOR PYTHON 1.6.1/
238 || m/LaTeX Project Public License/
239 || m/(^From:.*^To:|^To:.*^From:).*(GNU General Public License|GPL)/ms
240 || m/AFFERO GENERAL PUBLIC LICENSE/
241 || m/GNU Free Documentation License\s*Version 1\.1/
242 || m/CeCILL FREE SOFTWARE LICENSE AGREEMENT/
243 || m/CNRI OPEN SOURCE GPL-COMPATIBLE LICENSE AGREEMENT/
244 || $wrong_directory_detected) {
245 # False positive or correct reference. Ignore.
246 } elsif (m/GNU Free Documentation License/i or m/\bGFDL\b/) {
247 tag "copyright-should-refer-to-common-license-file-for-gfdl";
248 } elsif (m/GNU (Lesser|Library) General Public License/i or m/\bLGPL\b/) {
249 tag "copyright-should-refer-to-common-license-file-for-lgpl";
250 } elsif (m/GNU General Public License/i or m/\bGPL\b/) {
251 tag "copyright-should-refer-to-common-license-file-for-gpl";
255 if (m,Upstream Author\(s\),) {
256 tag "copyright-lists-upstream-authors-with-dh_make-boilerplate";
259 if (m,url://example\.com,) {
260 tag "copyright-has-url-from-dh_make-boilerplate";
263 if (m{\# Please also look if there are files or directories which have a\n\# different copyright/license attached and list them here\.}) {
264 tag "copyright-contains-dh_make-todo-boilerplate", "";
266 if (m{This copyright info was automatically extracted from the perl module\.\nIt may not be accurate, so you better check the module sources\nif you don\'t want to get into legal troubles\.}) {
267 tag "copyright-contains-dh-make-perl-boilerplate", "";
270 if ($found && !$linked && !/(Copyright|Copr\.|\302\251)(.*|[\(C\):\s]+)\b\d{4}\b|\bpublic\s+domain\b/i) {
271 tag 'copyright-without-copyright-notice';
274 spelling_check('spelling-error-in-copyright', $_);
276 # Now, check for linking against libssl if the package is covered by the GPL.
277 # (This check was requested by ftp-master.) First, see if the package is
278 # under the GPL alone and try to exclude packages with a mix of GPL and LGPL
279 # or Artistic licensing or with an exception or exemption.
280 if ($gpl || m,/usr/share/common-licenses/GPL,) {
281 unless (m,exception|exemption|/usr/share/common-licenses/(?!GPL)\S,) {
283 if (open(DEP, '<', 'fields/depends')) {
284 @depends = split (/\s*,\s*/, scalar <DEP>);
286 if (open(DEP, '<', 'fields/pre-depends')) {
287 push @depends, split (/\s*,\s*/, scalar <DEP>);
290 if (grep { /^libssl[0-9.]+(\s|\z)/ && !/\|/ } @depends) {
291 tag 'possible-gpl-code-linked-with-openssl';
298 # -----------------------------------
300 # returns true, if $foo depends on $bar
302 my ($package, $version) = @_;
304 my ($deps, $predeps) = ("", "");
306 my $f = "fields/depends";
308 open(I, '<', $f) or die "cannot open depends file $f: $!";
313 $f = "fields/pre-depends";
315 open(I, '<', $f) or die "cannot open pre-depends file $f: $!";
316 chop($predeps = <I>);
320 return 1 if Dep::implies(Dep::parse($deps), Dep::parse($package));
321 return 1 if Dep::implies(Dep::parse($predeps), Dep::parse($package));
329 # indent-tabs-mode: t
330 # cperl-indent-level: 4
332 # vim: syntax=perl ts=8 sw=4