Merging master with the same SHA from upstream-master

Also upgrading libcups METADATA from ARCHIVE to GIT

Test: Treehugger
Change-Id: Ie43e44dbbb5a19f9f04dc3ace3caf85799f545d0
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..1bdccae
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,144 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE
+//     CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
+//     DEPENDING ON IT IN YOUR PROJECT. ***
+package {
+    default_applicable_licenses: ["external_libcups_license"],
+}
+
+// Added automatically by a large-scale-change that took the approach of
+// 'apply every license found to every target'. While this makes sure we respect
+// every license restriction, it may not be entirely correct.
+//
+// e.g. GPL in an MIT project might only apply to the contrib/ directory.
+//
+// Please consider splitting the single license below into multiple licenses,
+// taking care not to lose any license_kind information, and overriding the
+// default license using the 'licenses: [...]' property on targets as needed.
+//
+// For unused files, consider creating a 'fileGroup' with "//visibility:private"
+// to attach the license to, and including a comment whether the files may be
+// used in the current project.
+//
+// large-scale-change included anything that looked like it might be a license
+// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
+//
+// Please consider removing redundant or irrelevant files from 'license_text:'.
+// See: http://go/android-license-faq
+license {
+    name: "external_libcups_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+        "SPDX-license-identifier-BSD",
+        "SPDX-license-identifier-GPL",
+        "SPDX-license-identifier-GPL-2.0",
+        "SPDX-license-identifier-ISC",
+        "SPDX-license-identifier-LGPL",
+        "SPDX-license-identifier-MIT",
+        "SPDX-license-identifier-Zlib",
+        "legacy_by_exception_only", // by exception only
+    ],
+    license_text: [
+        "LICENSE",
+        "NOTICE",
+    ],
+}
+
+cc_library_shared {
+    name: "libcups",
+
+    sdk_version: "current",
+
+    srcs: [
+        "cups/array.c",
+        "cups/auth.c",
+        "cups/backchannel.c",
+        "cups/debug.c",
+        "cups/dest.c",
+        "cups/dest-job.c",
+        "cups/dest-localization.c",
+        "cups/dest-options.c",
+        "cups/dir.c",
+        "cups/encode.c",
+        "cups/file.c",
+        "cups/getdevices.c",
+        "cups/getputfile.c",
+        "cups/globals.c",
+        "cups/hash.c",
+        "cups/http.c",
+        "cups/http-addr.c",
+        "cups/http-addrlist.c",
+        "cups/http-support.c",
+        "cups/ipp.c",
+        "cups/ipp-support.c",
+        "cups/langprintf.c",
+        "cups/language.c",
+        "cups/md5.c",
+        "cups/md5passwd.c",
+        "cups/notify.c",
+        "cups/options.c",
+        "cups/pwg-media.c",
+        "cups/raster-error.c",
+        "cups/raster-stream.c",
+        "cups/raster-stubs.c",
+        "cups/request.c",
+        "cups/sidechannel.c",
+        "cups/snmp.c",
+        "cups/string.c",
+        "cups/tempfile.c",
+        "cups/thread.c",
+        "cups/tls-boringssl.c",
+        "cups/transcode.c",
+        "cups/usersys.c",
+        "cups/util.c",
+    ],
+
+    cflags: [
+        "-D_PPD_DEPRECATED=",
+
+        "-Wextra",
+        "-Wall",
+        "-Wno-unused-parameter",
+        "-Wno-unused-function",
+        "-Wno-unused-variable",
+        "-Wno-unused-value",
+        "-Wno-sign-compare",
+        "-Wno-missing-field-initializers",
+        "-Wno-implicit-function-declaration",
+        "-Wno-deprecated-declarations",
+        "-Werror",
+    ],
+
+    export_include_dirs: [
+        "cups",
+        "filter",
+        "."
+    ],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+        },
+    },
+
+    shared_libs: [
+        "libz",
+        "liblog",
+        "libcrypto",
+        "libssl",
+    ],
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..cc1d0e0
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,26 @@
+# *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE
+#     CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
+#     DEPENDING ON IT IN YOUR PROJECT. ***
+name: "libcups"
+description: "CUPS is the standards-based, open source printing system."
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://www.cups.org/"
+  }
+  url {
+    type: GIT
+    value: "https://github.com/apple/cups/"
+  }
+  version: "v2.3.3"
+  license_type: BY_EXCEPTION_ONLY
+  license_note: "would be RESTRICTED save for Apple license in backend/usb-darwin.c"
+  security {
+    tag: "NVD-CPE2.3:cpe:/a:cups:cups:2.3.3"
+  }
+  last_upgrade_date {
+    year: 2022
+    month: 10
+    day: 4
+  }
+}
diff --git a/MODULE_LICENSE_LGPL b/MODULE_LICENSE_LGPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_LGPL
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..fdecf91
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,3 @@
+# Default code reviewers picked from top 3 or more developers.
+# Please update this list if you find better candidates.
+# used by packages/services/BuiltInPrintService
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..03e12da
--- /dev/null
+++ b/config.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CUPS_CONFIG_H_
+#define _CUPS_CONFIG_H_
+
+#define CUPS_SVERSION "CUPS v2.2.9"
+#define CUPS_MINIMAL "CUPS/2.2.9"
+#define CUPS_DEFAULT_PRINTOPERATOR_AUTH "@SYSTEM"
+#define CUPS_DEFAULT_LOG_LEVEL "warn"
+#define CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "dnssd"
+#define CUPS_DEFAULT_IPP_PORT 631
+#define CUPS_DEFAULT_DOMAINSOCKET "/private/var/run/cupsd"
+#define CUPS_DATADIR "/usr/share/cups"
+#define CUPS_LOCALEDIR "/usr/share/locale"
+#define CUPS_SERVERBIN "/usr/lib/cups"
+#define CUPS_SERVERROOT "/etc/cups"
+#define CUPS_STATEDIR "/var/run/cups"
+#define HAVE_LIBZ 1
+#define HAVE_STDINT_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_LONG_LONG 1
+#ifdef HAVE_LONG_LONG
+#  define CUPS_LLFMT "%lld"
+#  define CUPS_LLCAST (long long)
+#else
+#  define CUPS_LLFMT "%ld"
+#  define CUPS_LLCAST (long)
+#endif /* HAVE_LONG_LONG */
+#define HAVE_STRDUP 1
+#define HAVE_GETEUID 1
+#define HAVE_SNPRINTF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY 1
+#define HAVE_CSSMERRORSTRING 1
+#define HAVE_GETADDRINFO 1
+#define HAVE_GETNAMEINFO 1
+#define HAVE_HSTRERROR 1
+#undef HAVE_RES_INIT
+#define HAVE_RESOLV_H 1
+#undef HAVE_PTHREAD_H
+#define CUPS_DEFAULT_GSSSERVICENAME "host"
+#define HAVE_POLL 1
+#define CUPS_RAND() random()
+#define CUPS_SRAND(v) srandom(v)
+#define HAVE_SSL 1
+
+#endif /* !_CUPS_CONFIG_H_ */
diff --git a/cups/tls-boringssl.c b/cups/tls-boringssl.c
new file mode 100644
index 0000000..c441862
--- /dev/null
+++ b/cups/tls-boringssl.c
@@ -0,0 +1,511 @@
+/*
+ * TLS support code for CUPS using Google BoringSSL.
+ *
+ * Copyright 2007-2016 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ *
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
+ *
+ * This file is subject to the Apple OS-Developed Software exception.
+ */
+
+/**** This file is included from tls.c ****/
+
+/*
+ * Local globals...
+ */
+
+#include "cups-private.h"
+#include "debug-internal.h"
+#include "http.h"
+#include "thread-private.h"
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+
+#include <sys/stat.h>
+
+static char		*tls_keypath = NULL;
+					/* Server cert keychain path */
+static int		tls_options = -1,/* Options for TLS connections */
+  tls_min_version = _HTTP_TLS_1_0,
+  tls_max_version = _HTTP_TLS_MAX;
+
+
+/*
+ * Local functions...
+ */
+
+static BIO_METHOD *     _httpBIOMethods(void);
+static int              http_bio_write(BIO *h, const char *buf, int num);
+static int              http_bio_read(BIO *h, char *buf, int size);
+static int              http_bio_puts(BIO *h, const char *str);
+static long             http_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2);
+static int              http_bio_new(BIO *h);
+static int              http_bio_free(BIO *data);
+
+static BIO_METHOD	http_bio_methods =
+			{
+			  BIO_TYPE_SSL,
+			  "http",
+			  http_bio_write,
+			  http_bio_read,
+			  http_bio_puts,
+			  NULL, /* http_bio_gets, */
+			  http_bio_ctrl,
+			  http_bio_new,
+			  http_bio_free,
+			  NULL,
+			};
+
+/*
+ * 'cupsMakeServerCredentials()' - Make a self-signed certificate and private key pair.
+ *
+ * @since CUPS 2.0/OS 10.10@
+ */
+
+int					/* O - 1 on success, 0 on failure */
+cupsMakeServerCredentials(
+    const char *path,			/* I - Path to keychain/directory */
+    const char *common_name,		/* I - Common name */
+    int        num_alt_names,		/* I - Number of subject alternate names */
+    const char **alt_names,		/* I - Subject Alternate Names */
+    time_t     expiration_date)		/* I - Expiration date */
+{
+  int		pid,			/* Process ID of command */
+		status;			/* Status of command */
+  char		command[1024],		/* Command */
+		*argv[12],		/* Command-line arguments */
+		*envp[1000],	        /* Environment variables */
+		infofile[1024],		/* Type-in information for cert */
+		seedfile[1024];		/* Random number seed file */
+  int		envc,			/* Number of environment variables */
+		bytes;			/* Bytes written */
+  cups_file_t	*fp;			/* Seed/info file */
+  int		infofd;			/* Info file descriptor */
+  char          temp[1024],	        /* Temporary directory name */
+                crtfile[1024],	        /* Certificate filename */
+                keyfile[1024];	        /* Private key filename */
+
+  DEBUG_printf(("cupsMakeServerCredentials(path=\"%s\", common_name=\"%s\", num_alt_names=%d, alt_names=%p, expiration_date=%d)", path, common_name, num_alt_names, alt_names, (int)expiration_date));
+
+  return 0;
+}
+
+
+/*
+ * '_httpCreateCredentials()' - Create credentials in the internal format.
+ */
+
+http_tls_credentials_t			/* O - Internal credentials */
+_httpCreateCredentials(
+    cups_array_t *credentials)		/* I - Array of credentials */
+{
+  (void)credentials;
+
+  return (NULL);
+}
+
+
+/*
+ * '_httpFreeCredentials()' - Free internal credentials.
+ */
+
+void
+_httpFreeCredentials(
+    http_tls_credentials_t credentials)	/* I - Internal credentials */
+{
+  (void)credentials;
+}
+
+
+/*
+ * '_httpBIOMethods()' - Get the OpenSSL BIO methods for HTTP connections.
+ */
+
+static BIO_METHOD *                            /* O - BIO methods for OpenSSL */
+_httpBIOMethods(void)
+{
+  return (&http_bio_methods);
+}
+
+
+/*
+ * 'http_bio_ctrl()' - Control the HTTP connection.
+ */
+
+static long				/* O - Result/data */
+http_bio_ctrl(BIO  *h,			/* I - BIO data */
+              int  cmd,			/* I - Control command */
+	      long arg1,		/* I - First argument */
+	      void *arg2)		/* I - Second argument */
+{
+  switch (cmd)
+  {
+    default :
+        return (0);
+
+    case BIO_CTRL_RESET :
+        h->ptr = NULL;
+	return (0);
+
+    case BIO_C_SET_FILE_PTR :
+        h->ptr  = arg2;
+	h->init = 1;
+	return (1);
+
+    case BIO_C_GET_FILE_PTR :
+        if (arg2)
+	{
+	  *((void **)arg2) = h->ptr;
+	  return (1);
+	}
+	else
+	  return (0);
+
+    case BIO_CTRL_DUP :
+    case BIO_CTRL_FLUSH :
+        return (1);
+  }
+}
+
+
+/*
+ * 'http_bio_free()' - Free OpenSSL data.
+ */
+
+static int				/* O - 1 on success, 0 on failure */
+http_bio_free(BIO *h)			/* I - BIO data */
+{
+  if (!h)
+    return (0);
+
+  if (h->shutdown)
+  {
+    h->init  = 0;
+    h->flags = 0;
+  }
+
+  return (1);
+}
+
+
+/*
+ * 'http_bio_new()' - Initialize an OpenSSL BIO structure.
+ */
+
+static int				/* O - 1 on success, 0 on failure */
+http_bio_new(BIO *h)			/* I - BIO data */
+{
+  if (!h)
+    return (0);
+
+  h->init  = 0;
+  h->num   = 0;
+  h->ptr   = NULL;
+  h->flags = 0;
+
+  return (1);
+}
+
+
+/*
+ * 'http_bio_puts()' - Send a string for OpenSSL.
+ */
+
+static int				/* O - Bytes written */
+http_bio_puts(BIO        *h,		/* I - BIO data */
+              const char *str)		/* I - String to write */
+{
+  return (send(((http_t *)h->ptr)->fd, str, strlen(str), 0));
+}
+
+
+/*
+ * 'http_bio_read()' - Read data for OpenSSL.
+ */
+
+static int				/* O - Bytes read */
+http_bio_read(BIO  *h,			/* I - BIO data */
+              char *buf,		/* I - Buffer */
+	      int  size)		/* I - Number of bytes to read */
+{
+  http_t	*http;			/* HTTP connection */
+
+
+  http = (http_t *)h->ptr;
+
+  if (!http->blocking)
+  {
+   /*
+    * Make sure we have data before we read...
+    */
+
+    while (!_httpWait(http, http->wait_value, 0))
+    {
+      if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data))
+	continue;
+
+      http->error = ETIMEDOUT;
+
+      return (-1);
+    }
+  }
+
+  return (recv(http->fd, buf, size, 0));
+}
+
+
+/*
+ * 'http_bio_write()' - Write data for OpenSSL.
+ */
+
+static int				/* O - Bytes written */
+http_bio_write(BIO        *h,		/* I - BIO data */
+               const char *buf,		/* I - Buffer to write */
+	       int        num)		/* I - Number of bytes to write */
+{
+  return (send(((http_t *)h->ptr)->fd, buf, num, 0));
+}
+
+
+/*
+ * '_httpTLSInitialize()' - Initialize the TLS stack.
+ */
+
+void
+_httpTLSInitialize(void)
+{
+  SSL_library_init();
+}
+
+
+/*
+ * '_httpTLSPending()' - Return the number of pending TLS-encrypted bytes.
+ */
+
+size_t					/* O - Bytes available */
+_httpTLSPending(http_t *http)		/* I - HTTP connection */
+{
+  return (SSL_pending(http->tls));
+}
+
+
+/*
+ * '_httpTLSRead()' - Read from a SSL/TLS connection.
+ */
+
+int					/* O - Bytes read */
+_httpTLSRead(http_t *http,		/* I - Connection to server */
+	     char   *buf,		/* I - Buffer to store data */
+	     int    len)		/* I - Length of buffer */
+{
+  return (SSL_read((SSL *)(http->tls), buf, len));
+}
+
+
+/*
+ * '_httpTLSSetOptions()' - Set TLS protocol and cipher suite options.
+ */
+
+void
+_httpTLSSetOptions(int options, int min_version, int max_version)		/* I - Options */
+{
+  tls_options = options;
+  tls_min_version = min_version;
+  tls_max_version = max_version;
+}
+
+
+/*
+ * '_httpTLSStart()' - Set up SSL/TLS support on a connection.
+ */
+
+int					/* O - 0 on success, -1 on failure */
+_httpTLSStart(http_t *http)		/* I - Connection to server */
+{
+  char			hostname[256],	/* Hostname */
+			*hostptr;	/* Pointer into hostname */
+
+  SSL_CTX		*context;	/* Context for encryption */
+  BIO			*bio;		/* BIO data */
+  const char		*message = NULL;/* Error message */
+
+  DEBUG_printf(("3_httpTLSStart(http=%p)", (void *)http));
+
+  if (tls_options < 0)
+  {
+    DEBUG_puts("4_httpTLSStart: Setting defaults.");
+    _cupsSetDefaults();
+    DEBUG_printf(("4_httpTLSStart: tls_options=%x", tls_options));
+  }
+
+  if (http->mode == _HTTP_MODE_SERVER && !tls_keypath)
+  {
+    DEBUG_puts("4_httpTLSStart: cupsSetServerCredentials not called.");
+    http->error  = errno = EINVAL;
+    http->status = HTTP_STATUS_ERROR;
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Server credentials not set."), 1);
+
+    return (-1);
+  }
+
+  context = SSL_CTX_new(TLS_method());
+  SSL_CTX_set_min_proto_version(context, tls_min_version);
+  SSL_CTX_set_max_proto_version(context, tls_max_version);
+
+  bio = BIO_new(_httpBIOMethods());
+  BIO_ctrl(bio, BIO_C_SET_FILE_PTR, 0, (char *)http);
+
+  http->tls = SSL_new(context);
+  SSL_set_bio(http->tls, bio, bio);
+
+  /* http->tls retains an internal reference to the SSL_CTX. */
+  SSL_CTX_free(context);
+
+  if (http->mode == _HTTP_MODE_CLIENT)
+  {
+    SSL_set_connect_state(http->tls);
+
+   /*
+    * Client: get the hostname to use for TLS...
+    */
+
+    if (httpAddrLocalhost(http->hostaddr))
+    {
+      strlcpy(hostname, "localhost", sizeof(hostname));
+    }
+    else
+    {
+     /*
+      * Otherwise make sure the hostname we have does not end in a trailing dot.
+      */
+
+      strlcpy(hostname, http->hostname, sizeof(hostname));
+      if ((hostptr = hostname + strlen(hostname) - 1) >= hostname &&
+	  *hostptr == '.')
+	*hostptr = '\0';
+    }
+    SSL_set_tlsext_host_name(http->tls, hostname);
+  }
+  else
+  {
+/* @@@ TODO @@@ */
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, "Server not supported", 0);
+  }
+
+
+  if (SSL_do_handshake(http->tls) != 1)
+  {
+    unsigned long	error;	/* Error code */
+    char		buf[256];
+
+    while ((error = ERR_get_error()) != 0)
+    {
+      ERR_error_string_n(error, buf, sizeof(buf));
+      DEBUG_printf(("8http_setup_ssl: %s", buf));
+    }
+
+    SSL_free(http->tls);
+    http->tls = NULL;
+
+    http->error  = errno;
+    http->status = HTTP_STATUS_ERROR;
+
+    if (!message)
+      message = _("Unable to establish a secure connection to host.");
+
+    _cupsSetError(IPP_STATUS_ERROR_CUPS_PKI, message, 1);
+
+    return (-1);
+  }
+
+  _cups_globals_t *cg = _cupsGlobals();
+  if (cg->server_cert_cb)
+  {
+    int error = 0;
+    X509 *peer_certificate = SSL_get_peer_certificate(http->tls);
+    if (peer_certificate)
+    {
+      ASN1_BIT_STRING *key = X509_get0_pubkey_bitstr(peer_certificate);
+      cups_array_t *credentials = cupsArrayNew(NULL, NULL);
+
+      if (credentials != NULL)
+      {
+        httpAddCredential(credentials, key->data, key->length);
+        error = cg->server_cert_cb(http, http->tls, credentials, cg->server_cert_data);
+        httpFreeCredentials(credentials);
+      }
+      X509_free(peer_certificate);
+    }
+
+    if (error != 0)
+    {
+      SSL_free(http->tls);
+      http->tls = NULL;
+      http->error  = errno = EINVAL;
+      http->status = HTTP_STATUS_ERROR;
+      _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Client rejected the server certificate."), 1);
+    }
+
+    return (error);
+  }
+
+  return (0);
+}
+
+
+/*
+ * '_httpTLSStop()' - Shut down SSL/TLS on a connection.
+ */
+
+void
+_httpTLSStop(http_t *http)		/* I - Connection to server */
+{
+  unsigned long	error;			/* Error code */
+
+  switch (SSL_shutdown(http->tls))
+  {
+    case 1 :
+	break;
+
+    case -1 :
+        _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+			"Fatal error during SSL shutdown!", 0);
+    default :
+	while ((error = ERR_get_error()) != 0)
+        {
+	  char	buf[256];
+	  ERR_error_string_n(error, buf, sizeof(buf));
+	  _cupsSetError(IPP_STATUS_ERROR_INTERNAL, buf, 0);
+        }
+	break;
+  }
+
+  SSL_free(http->tls);
+  http->tls = NULL;
+}
+
+/*
+ * '_httpTLSWrite()' - Write to a SSL/TLS connection.
+ */
+
+int					/* O - Bytes written */
+_httpTLSWrite(http_t     *http,		/* I - Connection to server */
+	      const char *buf,		/* I - Buffer holding data */
+	      int        len)		/* I - Length of buffer */
+{
+  int	result;			/* Return value */
+
+
+  DEBUG_printf(("2http_write_ssl(http=%p, buf=%p, len=%d)", http, buf, len));
+
+  result = SSL_write((SSL *)(http->tls), buf, len);
+
+  DEBUG_printf(("3http_write_ssl: Returning %d.", result));
+
+  return result;
+}
diff --git a/packaging/cups.spec b/packaging/cups.spec
new file mode 100644
index 0000000..82d803e
--- /dev/null
+++ b/packaging/cups.spec
@@ -0,0 +1,438 @@
+#
+# RPM "spec" file for CUPS.
+#
+# Original version by Jason McMullan <jmcc@ontv.com>.
+#
+# Copyright © 2007-2019 by Apple Inc.
+# Copyright © 1999-2007 by Easy Software Products, all rights reserved.
+#
+# Licensed under Apache License v2.0.  See the file "LICENSE" for more
+# information.
+#
+
+# Conditional build options (--with name/--without name):
+#
+#   dbus     - Enable/disable DBUS support (default = enable)
+#   dnssd    - Enable/disable DNS-SD support (default = enable)
+#   libusb1  - Enable/disable LIBUSB 1.0 support (default = enable)
+#   static   - Enable/disable static libraries (default = enable)
+#   systemd  - Enable/disable systemd support (default = enable)
+
+%{!?_with_dbus: %{!?_without_dbus: %define _with_dbus --with-dbus}}
+%{?_with_dbus: %define _dbus --enable-dbus}
+%{!?_with_dbus: %define _dbus --disable-dbus}
+
+%{!?_with_dnssd: %{!?_without_dnssd: %define _with_dnssd --with-dnssd}}
+%{?_with_dnssd: %define _dnssd --enable-avahi}
+%{!?_with_dnssd: %define _dnssd --disable-avahi}
+
+%{!?_with_libusb1: %{!?_without_libusb1: %define _with_libusb1 --with-libusb1}}
+%{?_with_libusb1: %define _libusb1 --enable-libusb}
+%{!?_with_libusb1: %define _libusb1 --disable-libusb}
+
+%{!?_with_static: %{!?_without_static: %define _without_static --without-static}}
+%{?_with_static: %define _static --enable-static}
+%{!?_with_static: %define _static --disable-static}
+
+%{!?_with_systemd: %{!?_without_systemd: %define _with_systemd --with-systemd}}
+%{?_with_systemd: %define _systemd --enable-systemd}
+%{!?_with_systemd: %define _systemd --disable-systemd}
+
+Summary: CUPS
+Name: cups
+Version: 2.3.3
+Release: 0
+Epoch: 1
+License: GPL
+Group: System Environment/Daemons
+Source: https://github.com/apple/cups/releases/download/v2.3.3/cups-2.3.3-source.tar.gz
+Url: http://www.cups.org
+Packager: Anonymous <anonymous@example.com>
+Vendor: Example Corp
+
+# Package names are as defined for Red Hat (and clone) distributions
+BuildRequires: gnutls-devel, pam-devel
+
+%if %{?_with_dbus:1}%{!?_with_dbus:0}
+BuildRequires: dbus-devel
+%endif
+
+%if %{?_with_dnssd:1}%{!?_with_dnssd:0}
+BuildRequires: avahi-devel
+%endif
+
+%if %{?_with_libusb1:1}%{!?_with_libusb1:0}
+BuildRequires: libusb-devel >= 1.0
+%endif
+
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+BuildRequires: systemd-devel
+%endif
+
+# Use buildroot so as not to disturb the version already installed
+BuildRoot: /tmp/%{name}-root
+
+# Dependencies...
+Requires: %{name}-libs = %{epoch}:%{version}
+Obsoletes: lpd, lpr, LPRng
+Provides: lpd, lpr, LPRng
+Obsoletes: cups-da, cups-de, cups-es, cups-et, cups-fi, cups-fr, cups-he
+Obsoletes: cups-id, cups-it, cups-ja, cups-ko, cups-nl, cups-no, cups-pl
+Obsoletes: cups-pt, cups-ru, cups-sv, cups-zh
+
+%package devel
+Summary: CUPS - development environment
+Group: Development/Libraries
+Requires: %{name}-libs = %{epoch}:%{version}
+
+%package libs
+Summary: CUPS - shared libraries
+Group: System Environment/Libraries
+Provides: libcups1
+
+%package lpd
+Summary: CUPS - LPD support
+Group: System Environment/Daemons
+Requires: %{name} = %{epoch}:%{version} xinetd
+
+%description
+CUPS is the standards-based, open source printing system developed by
+Apple Inc. for macOS® and other UNIX®-like operating systems.
+
+%description devel
+This package provides the CUPS headers and development environment.
+
+%description libs
+This package provides the CUPS shared libraries.
+
+%description lpd
+This package provides LPD client support.
+
+%prep
+%setup
+
+%build
+CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_OPT_FLAGS" \
+    ./configure %{_dbus} %{_dnssd} %{_libusb1} %{_static} %{_systemd}
+# If we got this far, all prerequisite libraries must be here.
+make
+
+%install
+# Make sure the RPM_BUILD_ROOT directory exists.
+rm -rf $RPM_BUILD_ROOT
+
+make BUILDROOT=$RPM_BUILD_ROOT install
+rm -rf $RPM_BUILD_ROOT/usr/share/cups/banners $RPM_BUILD_ROOT/usr/share/cups/data
+
+%post
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+/bin/systemctl enable org.cups.cupsd.service
+
+if test $1 -ge 1; then
+	/bin/systemctl stop org.cups.cupsd.service
+	/bin/systemctl start org.cups.cupsd.service
+fi
+
+%else
+/sbin/chkconfig --add cups
+/sbin/chkconfig cups on
+
+# Restart cupsd if we are upgrading...
+if test $1 -gt 1; then
+	/sbin/service cups stop
+	/sbin/service cups start
+fi
+%endif
+
+%post libs
+/sbin/ldconfig
+
+%preun
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+if test $1 -ge 1; then
+	/bin/systemctl stop org.cups.cupsd.service
+	/bin/systemctl disable org.cups.cupsd.service
+fi
+
+%else
+if test $1 = 0; then
+	/sbin/service cups stop
+	/sbin/chkconfig --del cups
+fi
+%endif
+
+%postun
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+if test $1 -ge 1; then
+	/bin/systemctl stop org.cups.cupsd.service
+	/bin/systemctl start org.cups.cupsd.service
+fi
+
+%else
+if test $1 -ge 1; then
+	/sbin/service cups stop
+	/sbin/service cups start
+fi
+%endif
+
+%postun libs
+/sbin/ldconfig
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%docdir /usr/share/doc/cups
+%defattr(-,root,root)
+%dir /etc/cups
+%config(noreplace) /etc/cups/*.conf
+/etc/cups/cups-files.conf.default
+/etc/cups/cupsd.conf.default
+/etc/cups/snmp.conf.default
+%dir /etc/cups/ppd
+%attr(0700,root,root) %dir /etc/cups/ssl
+
+%if %{?_with_dbus:1}%{!?_with_dbus:0}
+# DBUS
+/etc/dbus-1/system.d/*
+%endif
+
+# PAM
+%dir /etc/pam.d
+/etc/pam.d/*
+
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+# SystemD
+/usr/lib/systemd/system/org.cups.cupsd.*
+
+%else
+# Legacy init support on Linux
+/etc/init.d/*
+/etc/rc0.d/*
+/etc/rc2.d/*
+/etc/rc3.d/*
+/etc/rc5.d/*
+%endif
+
+/usr/bin/cancel
+/usr/bin/cupstestppd
+/usr/bin/ippeveprinter
+/usr/bin/ipptool
+/usr/bin/lp*
+%dir /usr/lib/cups
+%dir /usr/lib/cups/backend
+%if %{?_with_dnssd:1}%{!?_with_dnssd:0}
+# DNS-SD
+/usr/bin/ippfind
+/usr/lib/cups/backend/dnssd
+%endif
+/usr/lib/cups/backend/http
+/usr/lib/cups/backend/https
+%attr(0700,root,root) /usr/lib/cups/backend/ipp
+/usr/lib/cups/backend/ipps
+%attr(0700,root,root) /usr/lib/cups/backend/lpd
+/usr/lib/cups/backend/snmp
+/usr/lib/cups/backend/socket
+/usr/lib/cups/backend/usb
+%dir /usr/lib/cups/cgi-bin
+/usr/lib/cups/cgi-bin/*
+%dir /usr/lib/cups/command
+/usr/lib/cups/command/*
+%dir /usr/lib/cups/daemon
+/usr/lib/cups/daemon/cups-deviced
+/usr/lib/cups/daemon/cups-driverd
+/usr/lib/cups/daemon/cups-exec
+%dir /usr/lib/cups/driver
+%dir /usr/lib/cups/filter
+/usr/lib/cups/filter/*
+%dir /usr/lib/cups/monitor
+/usr/lib/cups/monitor/*
+%dir /usr/lib/cups/notifier
+/usr/lib/cups/notifier/*
+
+/usr/sbin/*
+%dir /usr/share/cups
+%dir /usr/share/cups/drv
+/usr/share/cups/drv/*
+%dir /usr/share/cups/ipptool
+/usr/share/cups/ipptool/*
+%dir /usr/share/cups/mime
+/usr/share/cups/mime/*
+%dir /usr/share/cups/model
+%dir /usr/share/cups/ppdc
+/usr/share/cups/ppdc/*
+%dir /usr/share/cups/templates
+/usr/share/cups/templates/*
+%if %{?_with_libusb1:1}%{!?_with_libusb1:0}
+# LIBUSB quirks files
+%dir /usr/share/cups/usb
+/usr/share/cups/usb/*
+%endif
+
+%dir /usr/share/doc/cups
+/usr/share/doc/cups/*.*
+%dir /usr/share/doc/cups/help
+/usr/share/doc/cups/help/accounting.html
+/usr/share/doc/cups/help/admin.html
+/usr/share/doc/cups/help/cgi.html
+/usr/share/doc/cups/help/encryption.html
+/usr/share/doc/cups/help/firewalls.html
+/usr/share/doc/cups/help/glossary.html
+/usr/share/doc/cups/help/kerberos.html
+/usr/share/doc/cups/help/license.html
+/usr/share/doc/cups/help/man-*.html
+/usr/share/doc/cups/help/network.html
+/usr/share/doc/cups/help/options.html
+/usr/share/doc/cups/help/overview.html
+/usr/share/doc/cups/help/policies.html
+/usr/share/doc/cups/help/ref-*.html
+/usr/share/doc/cups/help/security.html
+/usr/share/doc/cups/help/sharing.html
+/usr/share/doc/cups/help/translation.html
+%dir /usr/share/doc/cups/images
+/usr/share/doc/cups/images/*
+
+#%dir /usr/share/doc/cups/ca
+#/usr/share/doc/cups/ca/*
+#%dir /usr/share/doc/cups/cs
+#/usr/share/doc/cups/cs/*
+%dir /usr/share/doc/cups/de
+/usr/share/doc/cups/de/*
+%dir /usr/share/doc/cups/es
+/usr/share/doc/cups/es/*
+#%dir /usr/share/doc/cups/fr
+#/usr/share/doc/cups/fr/*
+%dir /usr/share/doc/cups/ja
+/usr/share/doc/cups/ja/*
+%dir /usr/share/doc/cups/pt_BR
+/usr/share/doc/cups/pt_BR/*
+%dir /usr/share/doc/cups/ru
+/usr/share/doc/cups/ru/*
+
+%dir /usr/share/locale/ca
+/usr/share/locale/ca/cups_ca.po
+%dir /usr/share/locale/cs
+/usr/share/locale/cs/cups_cs.po
+%dir /usr/share/locale/de
+/usr/share/locale/de/cups_de.po
+%dir /usr/share/locale/en
+/usr/share/locale/en/cups_en.po
+%dir /usr/share/locale/es
+/usr/share/locale/es/cups_es.po
+%dir /usr/share/locale/fr
+/usr/share/locale/fr/cups_fr.po
+%dir /usr/share/locale/it
+/usr/share/locale/it/cups_it.po
+%dir /usr/share/locale/ja
+/usr/share/locale/ja/cups_ja.po
+%dir /usr/share/locale/pt_BR
+/usr/share/locale/pt_BR/cups_pt_BR.po
+%dir /usr/share/locale/ru
+/usr/share/locale/ru/cups_ru.po
+%dir /usr/share/locale/zh_CN
+/usr/share/locale/zh_CN/cups_zh_CN.po
+
+%dir /usr/share/man/man1
+/usr/share/man/man1/cancel.1.gz
+/usr/share/man/man1/cups.1.gz
+/usr/share/man/man1/cupstestppd.1.gz
+/usr/share/man/man1/ippeveprinter.1.gz
+%if %{?_with_dnssd:1}%{!?_with_dnssd:0}
+# DNS-SD
+/usr/share/man/man1/ippfind.1.gz
+%endif
+/usr/share/man/man1/ipptool.1.gz
+/usr/share/man/man1/lp.1.gz
+/usr/share/man/man1/lpoptions.1.gz
+/usr/share/man/man1/lpq.1.gz
+/usr/share/man/man1/lpr.1.gz
+/usr/share/man/man1/lprm.1.gz
+/usr/share/man/man1/lpstat.1.gz
+%dir /usr/share/man/man5
+/usr/share/man/man5/*.conf.5.gz
+/usr/share/man/man5/cupsd-logs.5.gz
+/usr/share/man/man5/ipptoolfile.5.gz
+/usr/share/man/man5/mime.*.5.gz
+%dir /usr/share/man/man7
+/usr/share/man/man7/ippevepcl.7.gz
+/usr/share/man/man7/ippeveps.7.gz
+%dir /usr/share/man/man8
+/usr/share/man/man8/cups-deviced.8.gz
+/usr/share/man/man8/cups-driverd.8.gz
+/usr/share/man/man8/cups-exec.8.gz
+/usr/share/man/man8/cups-snmp.8.gz
+/usr/share/man/man8/cupsaccept.8.gz
+/usr/share/man/man8/cupsctl.8.gz
+/usr/share/man/man8/cupsfilter.8.gz
+/usr/share/man/man8/cupsd.8.gz
+/usr/share/man/man8/cupsd-helper.8.gz
+/usr/share/man/man8/cupsdisable.8.gz
+/usr/share/man/man8/cupsenable.8.gz
+/usr/share/man/man8/cupsreject.8.gz
+/usr/share/man/man8/lpadmin.8.gz
+/usr/share/man/man8/lpc.8.gz
+/usr/share/man/man8/lpinfo.8.gz
+/usr/share/man/man8/lpmove.8.gz
+
+%dir /var/cache/cups
+%attr(0775,root,sys) %dir /var/cache/cups/rss
+%dir /var/log/cups
+%dir /var/run/cups
+%attr(0711,lp,sys) %dir /var/run/cups/certs
+%attr(0710,lp,sys) %dir /var/spool/cups
+%attr(1770,lp,sys) %dir /var/spool/cups/tmp
+
+# Desktop files
+/usr/share/applications/*
+/usr/share/icons/*
+
+%files devel
+%defattr(-,root,root)
+%dir /usr/share/cups/examples
+/usr/share/cups/examples/*
+%dir /usr/share/man/man1
+/usr/share/man/man1/cups-config.1.gz
+/usr/share/man/man1/ppd*.1.gz
+%dir /usr/share/man/man5
+/usr/share/man/man5/ppdcfile.5.gz
+/usr/share/man/man7/backend.7.gz
+/usr/share/man/man7/filter.7.gz
+/usr/share/man/man7/notifier.7.gz
+
+/usr/bin/cups-config
+/usr/bin/ppd*
+%dir /usr/include/cups
+/usr/include/cups/*
+/usr/lib*/*.so
+
+%if %{?_with_static:1}%{!?_with_static:0}
+/usr/lib*/*.a
+%endif
+
+%dir /usr/share/doc/cups/help
+/usr/share/doc/cups/help/api*.html
+/usr/share/doc/cups/help/cupspm.*
+/usr/share/doc/cups/help/postscript-driver.html
+/usr/share/doc/cups/help/ppd-compiler.html
+/usr/share/doc/cups/help/raster-driver.html
+/usr/share/doc/cups/help/spec*.html
+
+%files libs
+%defattr(-,root,root)
+/usr/lib*/*.so.*
+
+%files lpd
+%defattr(-,root,root)
+%if %{?_with_systemd:1}%{!?_with_systemd:0}
+# SystemD
+/usr/lib/systemd/system/org.cups.cups-lpd*
+%else
+# Legacy xinetd
+/etc/xinetd.d/cups-lpd
+%endif
+
+%dir /usr/lib/cups
+%dir /usr/lib/cups/daemon
+/usr/lib/cups/daemon/cups-lpd
+%dir /usr/share/man/man8
+/usr/share/man/man8/cups-lpd.8.gz
diff --git a/post_update.sh b/post_update.sh
new file mode 100755
index 0000000..63e90be
--- /dev/null
+++ b/post_update.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# $1 Path to the new version.
+# $2 Path to the old version.
+
+cp -a -n $2/config.h $1/
+cp -a -n $2/cups/tls-boringssl.c $1/cups/