GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 John Darrington <jmd@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services kerberos)
  #:use-module (gnu services)
  #:use-module (gnu services configuration)
  #:use-module (gnu system pam)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:export (pam-krb5-configuration
            pam-krb5-configuration?
            pam-krb5-service-type

            krb5-realm
            krb5-realm?

            krb5-configuration
            krb5-configuration?
            krb5-service-type))



;; TODO Use %unset-value and the define-maybe infrastructure.
(define unset-field (list 'unset-field))

(define (predicate/unset pred)
  (lambda (x) (or (eq? x unset-field) (pred x))))

(define string/unset? (predicate/unset string?))
(define boolean/unset? (predicate/unset boolean?))
(define integer/unset? (predicate/unset integer?))

(define (uglify-field-name field-name)
  "Return FIELD-NAME with all instances of '-' replaced by '_' and any
trailing '?' removed."
  (let ((str (symbol->string field-name)))
    (string-join (string-split (if (string-suffix? "?" str)
                                   (substring str 0 (1- (string-length str)))
                                   str)
                               #\-)
                 "_")))

(define (serialize-field* field-name val)
  (format #t "~a = ~a\n" (uglify-field-name field-name) val))

(define (serialize-string/unset field-name val)
  (unless (eq? val unset-field)
      (serialize-field* field-name val)))

(define (serialize-integer/unset field-name val)
  (unless (eq? val unset-field)
      (serialize-field* field-name val)))

(define (serialize-boolean/unset field-name val)
  (unless (eq? val unset-field)
      (serialize-field* field-name
                        (if val "true" "false"))))


;; An end-point is an address such as "192.168.0.1"
;; or an address port pair ("foobar.example.com" . 109)
(define (end-point? val)
  (match val
    ((? string?) #t)
    (((? string?) . (? integer?)) #t)
    (_ #f)))

(define (serialize-end-point field-name val)
  (serialize-field* field-name
                    (match val
                      ((host . port)
                       ;; The [] are needed in the case of IPv6 addresses
                       (format #f "[~a]:~a" host port))
                      (host
                       (format #f "~a" host)))))

(define (serialize-space-separated-string-list/unset field-name val)
  (unless (eq? val unset-field)
      (serialize-field* field-name (string-join val " "))))

(define (space-separated-string-list? val)
  (and (list? val)
       (and-map (lambda (x)
                  (and (string? x) (not (string-index x #\space))))
                val)))

(define space-separated-string-list/unset?
  (predicate/unset space-separated-string-list?))

(define comma-separated-integer-list/unset?
  (predicate/unset (lambda (val)
                     (and (list? val)
                          (and-map (lambda (x) (integer? x))
                                   val)))))

(define (serialize-comma-separated-integer-list/unset field-name val)
  (unless (eq? val unset-field)
      (serialize-field* field-name
                       (string-drop ; Drop the leading comma
                        (fold
                         (lambda (i prev)
                           (string-append prev "," (number->string i)))
                         "" val) 1))))

(define file-name? (predicate/unset
                    (lambda (val)
                      (string-prefix? "/" val))))

(define (serialize-field field-name val)
  (format #t "~a ~a\n" (uglify-field-name field-name) val))

(define (serialize-string field-name val)
  (serialize-field field-name val))

(define (serialize-file-name field-name val)
  (unless (eq? val unset-field)
    (serialize-string field-name val)))

(define (serialize-space-separated-string-list field-name val)
  (serialize-field field-name (string-join val " ")))

(define (non-negative-integer? val)
  (and (exact-integer? val) (not (negative? val))))

(define (serialize-non-negative-integer/unset field-name val)
  (unless (eq? val unset-field)
    (serialize-field* field-name val)))

(define (free-form-fields? val)
  (match val
    (() #t)
    ((((? symbol?) . (? string)) . val) (free-form-fields? val))
    (_ #f)))

(define (serialize-free-form-fields field-name val)
  (for-each (match-lambda ((k . v) (serialize-field* k v))) val))

(define non-negative-integer/unset? (predicate/unset non-negative-integer?))

(define (realm-list? val)
  (and (list? val)
       (and-map (lambda (x) (krb5-realm? x)) val)))

(define (serialize-realm-list field-name val)
  (format #t "\n[~a]\n" field-name)
  (for-each (lambda (realm)
              (format #t "\n~a = {\n" (krb5-realm-name realm))
              (for-each (lambda (field)
                          (unless (eq? 'name (configuration-field-name field))
                            ((configuration-field-serializer field)
                             (configuration-field-name field)
                             ((configuration-field-getter field)
                              realm)))) krb5-realm-fields)

              (format #t "}\n")) val))



;; For a more detailed explanation of these fields see man 5 krb5.conf
(define-configuration krb5-realm
  (name
   (string/unset unset-field)
   "The name of the realm.")

  (kdc
   (end-point unset-field)
   "The host and port on which the realm's Key Distribution Server listens.")

  (admin-server
   (string/unset unset-field)
   "The Host running the administration server for the realm.")

  (master-kdc
   (string/unset unset-field)
   "If an attempt to get credentials fails because of an invalid password, 
the client software will attempt to contact the master KDC.")

  (kpasswd-server
   (string/unset unset-field)
   "The server where password changes are performed.")

  (auth-to-local
   (free-form-fields '())
   "Rules to map between principals and local users.")

  (auth-to-local-names
   (free-form-fields '())
   "Explicit mappings between principal names and local user names.")

  (http-anchors
   (free-form-fields '())
   "Useful only when http proxy is used to access KDC or KPASSWD.")

  ;; The following are useful only for working with V4 services
  (default-domain
    (string/unset unset-field)
    "The domain used to expand host names when translating Kerberos 4 service
principals to Kerberos 5 principals")

  (v4-instance-convert
   (free-form-fields '())
   "Exceptions to the default-domain mapping rule.")

  (v4-realm
   (string/unset unset-field)
   "Used  when the V4 realm name and the V5 realm name are not the same, but
still share the same principal names and passwords"))



;; For a more detailed explanation of these fields see man 5 krb5.conf
(define-configuration krb5-configuration
  (allow-weak-crypto?
   (boolean/unset unset-field)
   "If true, permits access to services which only offer weak encryption.")

  (ap-req-checksum-type
   (non-negative-integer/unset unset-field)
   "The type of the AP-REQ checksum.")

  (canonicalize?
   (boolean/unset unset-field)
   "Should principals in initial ticket requests be canonicalized?")

  (ccache-type
   (non-negative-integer/unset unset-field)
   "The format of the credential cache type.")

  (clockskew
   (non-negative-integer/unset unset-field)
   "Maximum allowable clock skew in seconds (default 300).")

  (default-ccache-name
    (file-name unset-field)
    "The name of the default credential cache.")

  (default-client-keytab-name
    (file-name unset-field)
    "The name of the default keytab for client credentials.")

  (default-keytab-name
    (file-name unset-field)
    "The name of the default keytab file.")

  (default-realm
    (string/unset unset-field)
    "The realm to be accessed if not explicitly specified by clients.")

  (default-tgs-enctypes
    (free-form-fields '())
    "Session key encryption types when making TGS-REQ requests.")

  (default-tkt-enctypes
    (free-form-fields '())
    "Session key encryption types when making AS-REQ requests.")

  (dns-canonicalize-hostname?
   (boolean/unset  unset-field)
   "Whether name lookups will be used to canonicalize host names for use in 
service principal names.")

  (dns-lookup-kdc?
   (boolean/unset unset-field)
 "Should DNS SRV records should be used to locate the KDCs and other servers 
not appearing in the realm specification")

  (err-fmt
   (string/unset unset-field)
   "Custom error message formatting. If not #f error messages will be formatted 
by substituting a normal error message for %M and an error code for %C in the 
value.")

  (forwardable?
   (boolean/unset unset-field)
   "Should initial tickets be forwardable by default?")

  (ignore-acceptor-hostname?
   (boolean/unset unset-field)
   "When accepting GSSAPI or krb5 security contexts for host-based service 
principals, ignore any hostname passed by the calling application, and allow 
clients to authenticate to any service principal in the keytab matching the 
service name and realm name.")

  (k5login-authoritative?
   (boolean/unset unset-field)
   "If this flag is true, principals must be listed in a local user's k5login
file to be granted login access, if a ~/.k5login file exists.")

  (k5login-directory
   (string/unset unset-field)
   "If not #f, the library will look for a local user's @file{k5login} file 
within the named directory (instead of the user's home directory), with a 
file name corresponding to the local user name.")

  (kcm-mach-service
   (string/unset unset-field)
   "The name of the bootstrap service used to contact the KCM daemon for the 
KCM credential cache type.")

  (kcm-socket
   (file-name unset-field)
 "Path to the Unix domain socket used to access the KCM daemon for the KCM 
credential cache type.")

  (kdc-default-options
   (non-negative-integer/unset unset-field)
   "Default KDC options (logored for multiple values) when requesting initial 
tickets.")

  (kdc-timesync
   (non-negative-integer/unset unset-field)
   "Attempt to compensate for clock skew between the KDC and client.")

  (kdc-req-checksum-type
   (non-negative-integer/unset unset-field)
   "The type of checksum to use for the KDC requests. Relevant only for DES 
keys")

  (noaddresses?
   (boolean/unset unset-field)
   "If true, initial ticket requests will not be made with address restrictions.
This enables their use across NATs.")

  (permitted-enctypes
   (space-separated-string-list/unset unset-field)
   "All encryption types that are permitted for use in session key encryption.")

  (plugin-base-dir
   (file-name unset-field)
   "The directory where krb5 plugins are located.")

  (preferred-preauth-types
   (comma-separated-integer-list/unset unset-field)
   "The preferred pre-authentication types which the client will attempt before 
others.")

  (proxiable?
   (boolean/unset unset-field)
   "Should initial tickets be proxiable by default?")

  (rdns?
   (boolean/unset unset-field)
   "Should reverse DNS lookup be used in addition to forward name lookup to 
canonicalize host names for use in service principal names.")

  (realm-try-domains
   (integer/unset unset-field)
   "Should a host's domain components should be used to determine the Kerberos 
realm of the host.")

  (renew-lifetime
   (non-negative-integer/unset unset-field)
   "The default renewable lifetime for initial ticket requests.")

  (safe-checksum-type
   (non-negative-integer/unset unset-field)
   "The type of checksum to use for the KRB-SAFE requests.")

  (ticket-lifetime
   (non-negative-integer/unset unset-field)
   "The default lifetime for initial ticket requests.")

  (udp-preference-limit
   (non-negative-integer/unset unset-field)
   "When sending messages to the KDC, the library will try using TCP
before UDP if the size of the message greater than this limit.")

  (verify-ap-rereq-nofail?
   (boolean/unset unset-field)
 "If true, then attempts to verify initial credentials will fail if the client
machine does not have a keytab.")

  (realms
   (realm-list '())
   "The list of realms which clients may access."))


(define (krb5-configuration-file config)
  "Create a Kerberos 5 configuration file based on CONFIG"
  (mixed-text-file "krb5.conf"
                   "[libdefaults]\n\n"
                   (with-output-to-string
                     (lambda ()
                       (serialize-configuration config
                                                krb5-configuration-fields)))))

(define (krb5-etc-service config)
  (list `("krb5.conf" ,(krb5-configuration-file config))))


(define krb5-service-type
  (service-type (name 'krb5)
                (extensions
                 (list (service-extension etc-service-type
                                          krb5-etc-service)))
                (description "Programs using a Kerberos client library
normally expect a configuration file in @file{/etc/krb5.conf}.  This service
generates such a file.  It does not cause any daemon to be started.")))



(define-record-type* <pam-krb5-configuration>
  pam-krb5-configuration  make-pam-krb5-configuration
  pam-krb5-configuration?
  (pam-krb5               pam-krb5-configuration-pam-krb5
                          (default pam-krb5))
  (minimum-uid            pam-krb5-configuration-minimum-uid
                          (default 1000)))

(define (pam-krb5-pam-service config)
  "Return a PAM service for Kerberos authentication."
  (pam-extension
   (transformer
    (lambda (pam)
      (define pam-krb5-module
        (file-append (pam-krb5-configuration-pam-krb5 config)
                     "/lib/security/pam_krb5.so"))

      (let ((pam-krb5-sufficient
             (pam-entry
              (control "sufficient")
              (module pam-krb5-module)
              (arguments
               (list
                (format #f "minimum_uid=~a"
                        (pam-krb5-configuration-minimum-uid config)))))))
        (pam-service
         (inherit pam)
         (auth (cons* pam-krb5-sufficient
                      (pam-service-auth pam)))
         (session (cons* pam-krb5-sufficient
                         (pam-service-session pam)))
         (account (cons* pam-krb5-sufficient
                         (pam-service-account pam)))))))))

(define (pam-krb5-pam-services config)
  (list (pam-krb5-pam-service config)))

(define pam-krb5-service-type
  (service-type (name 'pam-krb5)
                (extensions
                 (list
                  (service-extension pam-root-service-type
                                     pam-krb5-pam-services)))
                (description "The @code{pam-krb5} service allows for login
authentication and password management via Kerberos.  You will need this
service if you want PAM-enabled applications to authenticate users using
Kerberos.")))
ers of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .