pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files pkg_install-20090425:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/445f9e2b20dc
branches:  trunk
changeset: 392101:445f9e2b20dc
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sat Apr 25 21:31:13 2009 +0000

description:
pkg_install-20090425:
Add logic to evaluate license conditions. As frontend for pkgsrc,
pkg_admin gets two new commands (check-license and
check-single-license), which can be used to evaluate a given condition.
pkg_add will be changed to honour licenses at a later point.

diffstat:

 pkgtools/pkg_install/files/admin/main.c              |   37 ++-
 pkgtools/pkg_install/files/admin/pkg_admin.1         |   18 +-
 pkgtools/pkg_install/files/lib/Makefile.in           |    4 +-
 pkgtools/pkg_install/files/lib/lib.h                 |   12 +-
 pkgtools/pkg_install/files/lib/license.c             |  275 +++++++++++++++++++
 pkgtools/pkg_install/files/lib/parse-config.c        |    8 +-
 pkgtools/pkg_install/files/lib/pkg_install.conf.5.in |    8 +-
 pkgtools/pkg_install/files/lib/version.h             |    4 +-
 8 files changed, 351 insertions(+), 15 deletions(-)

diffs (truncated from 533 to 300 lines):

diff -r 0a274b5bacca -r 445f9e2b20dc pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c   Sat Apr 25 18:20:47 2009 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c   Sat Apr 25 21:31:13 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.51 2009/04/24 14:00:25 joerg Exp $  */
+/*     $NetBSD: main.c,v 1.52 2009/04/25 21:31:13 joerg Exp $  */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -7,7 +7,7 @@
 #if HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #endif
-__RCSID("$NetBSD: main.c,v 1.51 2009/04/24 14:00:25 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.52 2009/04/25 21:31:13 joerg Exp $");
 
 /*-
  * Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@@ -110,6 +110,8 @@
            " audit-pkg [-es] [-t type] ...   - check listed packages for vulnerabilities\n"
            " audit-batch [-es] [-t type] ... - check packages in listed files for vulnerabilities\n"
            " audit-history [-t type] ...     - print all advisories for package names\n"
+           " check-license <condition>       - check if condition is acceptable\n"
+           " check-single-license <license>  - check if license is acceptable\n"
            " config-var name                 - print current value of the configuration variable\n"
            " check-signature ...             - verify the signature of packages\n"
            " x509-sign-package pkg spkg key cert  - create X509 signature\n"
@@ -524,6 +526,37 @@
                if (argv == NULL || argv[1] != NULL)
                        errx(EXIT_FAILURE, "config-var takes exactly one argument");
                pkg_install_show_variable(argv[0]);
+       } else if (strcasecmp(argv[0], "check-license") == 0) {
+               if (argv[1] == NULL)
+                       errx(EXIT_FAILURE, "check-license takes exactly one argument");
+
+               load_license_lists();
+
+               switch (acceptable_pkg_license(argv[1])) {
+               case 0:
+                       puts("no");
+                       return 0;
+               case 1:
+                       puts("yes");
+                       return 0;
+               case -1:
+                       errx(EXIT_FAILURE, "invalid license condition");
+               }
+       } else if (strcasecmp(argv[0], "check-single-license") == 0) {
+               if (argv[1] == NULL)
+                       errx(EXIT_FAILURE, "check-license takes exactly one argument");
+               load_license_lists();
+
+               switch (acceptable_license(argv[1])) {
+               case 0:
+                       puts("no");
+                       return 0;
+               case 1:
+                       puts("yes");
+                       return 0;
+               case -1:
+                       errx(EXIT_FAILURE, "invalid license");
+               }
        }
 #ifndef BOOTSTRAP
        else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) {
diff -r 0a274b5bacca -r 445f9e2b20dc pkgtools/pkg_install/files/admin/pkg_admin.1
--- a/pkgtools/pkg_install/files/admin/pkg_admin.1      Sat Apr 25 18:20:47 2009 +0000
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.1      Sat Apr 25 21:31:13 2009 +0000
@@ -1,6 +1,6 @@
-.\"    $NetBSD: pkg_admin.1,v 1.22 2009/04/22 19:13:54 joerg Exp $
+.\"    $NetBSD: pkg_admin.1,v 1.23 2009/04/25 21:31:13 joerg Exp $
 .\"
-.\" Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -34,7 +34,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 30, 2008
+.Dd April 25, 2009
 .Dt PKG_ADMIN 1
 .Os
 .Sh NAME
@@ -160,6 +160,12 @@
 checksum of the file on disk.
 Symbolic links are also checked, ensuring that the targets on disk are
 the same as the contents recorded at package installation time.
+.It Cm check-license Ar condition
+Check if
+.Ar condition
+can be fulfilled with the currently set of accepted licenses.
+Prints either yes or no to stdout if the condition can be parsed,
+otherwise it exits with error.
 .It Cm check-pkg-vulnerabilities Oo Fl s Oc Ar file
 Check format and hashes in the pkg-vulnerabilities file
 .Ar file .
@@ -170,6 +176,12 @@
 Reports if
 .Ar file
 is a correctly signed package.
+.It Cm check-single-license Ar liccense
+Check if
+.Ar license
+is a valid license name and if it is in the set of acceptable licenses.
+Prints either yes or no to stdout if the condition can be parsed,
+otherwise it exits with error.
 .It Cm config-var Ar variable
 Print the current value of
 .Ar variable
diff -r 0a274b5bacca -r 445f9e2b20dc pkgtools/pkg_install/files/lib/Makefile.in
--- a/pkgtools/pkg_install/files/lib/Makefile.in        Sat Apr 25 18:20:47 2009 +0000
+++ b/pkgtools/pkg_install/files/lib/Makefile.in        Sat Apr 25 21:31:13 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.26 2009/02/28 16:03:56 joerg Exp $
+# $NetBSD: Makefile.in,v 1.27 2009/04/25 21:31:13 joerg Exp $
 
 srcdir=                @srcdir@
 
@@ -27,7 +27,7 @@
 LIB=   libinstall.a
 
 OBJS=  automatic.o conflicts.o decompress.o dewey.o fexec.o file.o \
-       gpgsig.o global.o iterate.o lpkg.o opattern.o \
+       gpgsig.o global.o iterate.o license.o lpkg.o opattern.o \
        parse-config.o pkgdb.o plist.o remove.o \
        str.o var.o version.o vulnerabilities-file.o xwrapper.o
 
diff -r 0a274b5bacca -r 445f9e2b20dc pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h      Sat Apr 25 18:20:47 2009 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h      Sat Apr 25 21:31:13 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.54 2009/04/24 14:00:26 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.55 2009/04/25 21:31:13 joerg Exp $ */
 
 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
 
@@ -399,6 +399,13 @@
 int detached_gpg_sign(const char *, size_t, char **, size_t *, const char *,
     const char *);
 
+/* License handling */
+int add_licenses(const char *);
+int acceptable_license(const char *);
+int acceptable_pkg_license(const char *);
+void load_license_lists(void);
+
+/* Helper functions for memory allocation */
 char *xstrdup(const char *);
 void *xrealloc(void *, size_t);
 void *xcalloc(size_t, size_t);
@@ -429,4 +436,7 @@
 extern const char *ignore_advisories;
 extern const char tnf_vulnerability_base[];
 
+extern const char *acceptable_licenses;
+extern const char *default_acceptable_licenses;
+
 #endif                         /* _INST_LIB_LIB_H_ */
diff -r 0a274b5bacca -r 445f9e2b20dc pkgtools/pkg_install/files/lib/license.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_install/files/lib/license.c  Sat Apr 25 21:31:13 2009 +0000
@@ -0,0 +1,275 @@
+/*     $NetBSD: license.c,v 1.1 2009/04/25 21:31:14 joerg Exp $        */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <nbcompat.h>
+
+#if HAVE_ERR_H
+#include <err.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+
+#include "lib.h"
+
+#define        HASH_SIZE       521
+
+const char *default_acceptable_licenses =
+    "public-domain "
+    "gnu-gpl-v2 "
+    "gnu-lgpl-v2 gnu-lgpl-v2.1 "
+    "gnu-gpl-v3 gnu-lgpl-v3 "
+    "original-bsd modified-bsd x11 "
+    "apache-2.0 "
+    "artistic artistic-2.0 "
+    "cddl-1.0 "
+    "open-font-license ";
+
+#ifdef DEBUG
+static size_t hash_collisions;
+#endif
+
+static char **license_hash[HASH_SIZE];
+static const char license_spaces[] = " \t\n";
+static const char license_chars[] = "abcdefghijklmnopqrstuvwxyz0123456789_-.";
+
+static size_t
+hash_license(const char *license, size_t len)
+{
+       size_t hash;
+
+       for (hash = 0; *license && len; ++license, --len)
+               hash = *license + hash * 32;
+       return hash % HASH_SIZE;
+}
+
+static void
+add_license_internal(const char *license, size_t len)
+{
+       char *new_license;
+       size_t slot, i;
+
+       slot = hash_license(license, len);
+
+       new_license = malloc(len + 1);
+       memcpy(new_license, license, len);
+       new_license[len] = '\0';
+
+       if (license_hash[slot] == NULL) {
+               license_hash[slot] = calloc(sizeof(char *), 2);
+               license_hash[slot][0] = new_license;
+       } else {
+               for (i = 0; license_hash[slot][i]; ++i) {
+                       if (!memcmp(license_hash[slot][i], license, len) &&
+                           license_hash[slot][i][len] == '\0') {
+                               free(new_license);
+                               return;
+                       }
+               }
+
+#ifdef DEBUG
+               ++hash_collisions;
+#endif
+
+               license_hash[slot] = realloc(license_hash[slot],
+                   sizeof(char *) * (i + 2));
+               license_hash[slot][i] = new_license;
+               license_hash[slot][i + 1] = NULL;
+       }
+}
+
+int
+add_licenses(const char *line)
+{
+       const char *next;
+
+       if (line == NULL)
+               return 0;
+
+       for (line += strspn(line, license_spaces); line; ) {
+               next = line + strspn(line, license_chars);
+               if (next == line)
+                       return *line ? -1 : 0;
+               add_license_internal(line, next - line);
+               line = next + strspn(next, license_spaces);
+               if (next == line)
+                       return *line ? -1 : 0;
+       }
+       return 0;
+}
+
+static int
+acceptable_license_internal(const char *license, size_t len)
+{
+       size_t slot, i;



Home | Main Index | Thread Index | Old Index