move footnotes into chapters and appendices
[debian-policy.git] / policy / ch-customized-programs.rst
blobf83f0d879d7b5c06acfe88e32689719161be75fd
1 Customized programs
2 ===================
4 .. _s-arch-spec:
6 Architecture specification strings
7 ----------------------------------
9 If a program needs to specify an *architecture specification string* in
10 some place, it should select one of the strings provided by
11 ``dpkg-architecture -L``. The strings are in the format ``os-arch``, though the OS
12 part is sometimes elided, as when the OS is Linux.
14 Note that we don't want to use ``arch-debian-linux`` to apply to the
15 rule ``architecture-vendor-os`` since this would make our programs
16 incompatible with other Linux distributions. We also don't use something
17 like ``arch-unknown-linux``, since the ``unknown`` does not look very
18 good.
20 .. _s-arch-wildcard-spec:
22 Architecture wildcards
23 ~~~~~~~~~~~~~~~~~~~~~~
25 A package may specify an architecture wildcard. Architecture wildcards
26 are in the format ``any`` (which matches every architecture),
27 ``os``-any, or any-\ ``cpu``.  [#]_
29 .. _s11.2:
31 Daemons
32 -------
34 The configuration files ``/etc/services``, ``/etc/protocols``, and
35 ``/etc/rpc`` are managed by the ``netbase`` package and must not be
36 modified by other packages.
38 If a package requires a new entry in one of these files, the maintainer
39 should get in contact with the ``netbase`` maintainer, who will add the
40 entries and release a new version of the ``netbase`` package.
42 The configuration file ``/etc/inetd.conf`` must not be modified by the
43 package's scripts except via the ``update-inetd`` script or the
44 ``DebianNet.pm`` Perl module. See their documentation for details on how
45 to add entries.
47 If a package wants to install an example entry into ``/etc/inetd.conf``,
48 the entry must be preceded with exactly one hash character (``#``). Such
49 lines are treated as "commented out by user" by the ``update-inetd``
50 script and are not changed or activated during package updates.
52 .. _s11.3:
54 Using pseudo-ttys and modifying wtmp, utmp and lastlog
55 ------------------------------------------------------
57 Some programs need to create pseudo-ttys. This should be done using
58 Unix98 ptys if the C library supports it. The resulting program must not
59 be installed setuid root, unless that is required for other
60 functionality.
62 The files ``/var/run/utmp``, ``/var/log/wtmp`` and ``/var/log/lastlog``
63 must be installed writable by group ``utmp``. Programs which need to
64 modify those files must be installed setgid ``utmp``.
66 .. _s11.4:
68 Editors and pagers
69 ------------------
71 Some programs have the ability to launch an editor or pager program to
72 edit or display a text document. Since there are lots of different
73 editors and pagers available in the Debian distribution, the system
74 administrator and each user should have the possibility to choose their
75 preferred editor and pager.
77 In addition, every program should choose a good default editor/pager if
78 none is selected by the user or system administrator.
80 Thus, every program that launches an editor or pager must use the EDITOR
81 or PAGER environment variable to determine the editor or pager the user
82 wishes to use. If these variables are not set, the programs
83 ``/usr/bin/editor`` and ``/usr/bin/pager`` should be used, respectively.
85 These two files are managed through the ``dpkg`` "alternatives"
86 mechanism. Every package providing an editor or pager must call the
87 ``update-alternatives`` script to register as an alternative for
88 ``/usr/bin/editor`` or ``/usr/bin/pager`` as appropriate. The
89 alternative should have a slave alternative for
90 ``/usr/share/man/man1/editor.1.gz`` or
91 ``/usr/share/man/man1/pager.1.gz`` pointing to the corresponding manual
92 page.
94 If it is very hard to adapt a program to make use of the EDITOR or PAGER
95 variables, that program may be configured to use
96 ``/usr/bin/sensible-editor`` and ``/usr/bin/sensible-pager`` as the
97 editor or pager program respectively. These are two scripts provided in
98 the sensible-utils package that check the EDITOR and PAGER variables and
99 launch the appropriate program, and fall back to ``/usr/bin/editor`` and
100 ``/usr/bin/pager`` if the variable is not set.
102 A program may also use the VISUAL environment variable to determine the
103 user's choice of editor. If it exists, it should take precedence over
104 EDITOR. This is in fact what ``/usr/bin/sensible-editor`` does.
106 It is not required for a package to depend on ``editor`` and ``pager``,
107 nor is it required for a package to provide such virtual
108 packages. [#]_
110 .. _s-web-appl:
112 Web servers and applications
113 ----------------------------
115 This section describes the locations and URLs that should be used by all
116 web servers and web applications in the Debian system.
118 1. Cgi-bin executable files are installed in the directory
120    ::
122        /usr/lib/cgi-bin
124    or a subdirectory of that directory, and the script
126    ::
128        /usr/lib/cgi-bin/.../cgi-bin-name
130    should be referred to as
132    ::
134        http://localhost/cgi-bin/.../cgi-bin-name
136 2. (Deleted)
138 3. Access to images
140    It is recommended that images for a package be stored in
141    ``/usr/share/images/package`` and may be referred to through an alias
142    ``/images/`` as
144    ::
146        http://localhost/images/package/filename
148 4. Web Document Root
150    Web Applications should try to avoid storing files in the Web
151    Document Root. Instead they should use the /usr/share/doc/package
152    directory for documents and register the Web Application via the
153    doc-base package. If access to the web document root is unavoidable
154    then use
156    ::
158        /var/www/html
160    as the Document Root. This might be just a symbolic link to the
161    location where the system administrator has put the real document
162    root.
164 5. Providing httpd and/or httpd-cgi
166    All web servers should provide the virtual package ``httpd``. If a
167    web server has CGI support it should provide ``httpd-cgi``
168    additionally.
170    All web applications which do not contain CGI scripts should depend
171    on ``httpd``, all those web applications which ``do`` contain CGI
172    scripts, should depend on ``httpd-cgi``.
174 .. _s-mail-transport-agents:
176 Mail transport, delivery and user agents
177 ----------------------------------------
179 Debian packages which process electronic mail, whether mail user agents
180 (MUAs) or mail transport agents (MTAs), must ensure that they are
181 compatible with the configuration decisions below. Failure to do this
182 may result in lost mail, broken ``From:`` lines, and other serious brain
183 damage!
185 The mail spool is ``/var/mail`` and the interface to send a mail message
186 is ``/usr/sbin/sendmail`` (as per the FHS). On older systems, the mail
187 spool may be physically located in ``/var/spool/mail``, but all access
188 to the mail spool should be via the ``/var/mail`` symlink. The mail
189 spool is part of the base system and not part of the MTA package.
191 All Debian MUAs, MTAs, MDAs and other mailbox accessing programs (such
192 as IMAP daemons) must lock the mailbox in an NFS-safe way. This means
193 that ``fcntl()`` locking must be combined with dot locking. To avoid
194 deadlocks, a program should use ``fcntl()`` first and dot locking after
195 this, or alternatively implement the two locking methods in a non
196 blocking way.  [#]_ Using the functions ``maillock`` and
197 ``mailunlock`` provided by the ``liblockfile*`` packages is the
198 recommended way to accomplish this.
200 Mailboxes are generally either mode 600 and owned by user or mode 660
201 and owned by ``user:mail``.  [#]_ The local system administrator may
202 choose a different permission scheme; packages should not make
203 assumptions about the permission and ownership of mailboxes unless
204 required (such as when creating a new mailbox). A MUA may remove a
205 mailbox (unless it has nonstandard permissions) in which case the MTA or
206 another MUA must recreate it if needed.
208 The mail spool is 2775 ``root:mail``, and MUAs should be setgid mail to
209 do the locking mentioned above (and must obviously avoid accessing other
210 users' mailboxes using this privilege).
212 ``/etc/aliases`` is the source file for the system mail aliases (e.g.,
213 postmaster, usenet, etc.), it is the one which the sysadmin and
214 ``postinst`` scripts may edit. After ``/etc/aliases`` is edited the
215 program or human editing it must call ``newaliases``. All MTA packages
216 must come with a ``newaliases`` program, even if it does nothing, but
217 older MTA packages did not do this so programs should not fail if
218 ``newaliases`` cannot be found. Note that because of this, all MTA
219 packages must have ``Provides``, ``Conflicts`` and
220 ``Replaces:  mail-transport-agent`` control fields.
222 The convention of writing ``forward to address`` in the mailbox itself is not supported. Use a
223 ``.forward`` file instead.
225 The ``rmail`` program used by UUCP for incoming mail should be
226 ``/usr/sbin/rmail``. Likewise, ``rsmtp``, for receiving
227 batch-SMTP-over-UUCP, should be ``/usr/sbin/rsmtp`` if it is supported.
229 If your package needs to know what hostname to use on (for example)
230 outgoing news and mail messages which are generated locally, you should
231 use the file ``/etc/mailname``. It will contain the portion after the
232 username and ``@`` (at) sign for email addresses of users on the machine
233 (followed by a newline).
235 Such a package should check for the existence of this file when it is
236 being configured. If it exists, it should be used without comment,
237 although an MTA's configuration script may wish to prompt the user even
238 if it finds that this file exists. If the file does not exist, the
239 package should prompt the user for the value (preferably using
240 ``debconf``) and store it in ``/etc/mailname`` as well as using it in
241 the package's configuration. The prompt should make it clear that the
242 name will not just be used by that package. For example, in this
243 situation the ``inn`` package could say something like:
247     Please enter the "mail name" of your system.  This is the hostname portion
248     of the address to be shown on outgoing news and mail messages.  The
249     default is syshostname, your system's host name.
251     Mail name ["syshostname"]:
253 where syshostname is the output of ``hostname --fqdn``.
255 .. _s11.7:
257 News system configuration
258 -------------------------
260 All the configuration files related to the NNTP (news) servers and
261 clients should be located under ``/etc/news``.
263 There are some configuration issues that apply to a number of news
264 clients and server packages on the machine. These are:
266 ``/etc/news/organization``
267     A string which should appear as the organization header for all
268     messages posted by NNTP clients on the machine
270 ``/etc/news/server``
271     Contains the FQDN of the upstream NNTP server, or localhost if the
272     local machine is an NNTP server.
274 Other global files may be added as required for cross-package news
275 configuration.
277 .. _s11.8:
279 Programs for the X Window System
280 --------------------------------
282 .. _s11.8.1:
284 Providing X support and package priorities
285 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287 Programs that can be configured with support for the X Window System
288 must be configured to do so and must declare any package dependencies
289 necessary to satisfy their runtime requirements when using the X Window
290 System. If such a package is of higher priority than the X packages on
291 which it depends, it is required that either the X-specific components
292 be split into a separate package, or that an alternative version of the
293 package, which includes X support, be provided, or that the package's
294 priority be lowered.
296 .. _s11.8.2:
298 Packages providing an X server
299 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301 Packages that provide an X server that, directly or indirectly,
302 communicates with real input and display hardware should declare in
303 their ``Provides`` control field that they provide the virtual package
304 ``xserver``.  [#]_
306 .. _s11.8.3:
308 Packages providing a terminal emulator
309 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311 Packages that provide a terminal emulator for the X Window System which
312 meet the criteria listed below should declare in their ``Provides``
313 control field that they provide the virtual package
314 ``x-terminal-emulator``. They should also register themselves as an
315 alternative for ``/usr/bin/x-terminal-emulator``, with a priority of 20.
316 That alternative should have a slave alternative for
317 ``/usr/share/man/man1/x-terminal-emulator.1.gz`` pointing to the
318 corresponding manual page.
320 To be an ``x-terminal-emulator``, a program must:
322 -  Be able to emulate a DEC VT100 terminal, or a compatible terminal.
324 -  Support the command-line option ``-e command``, which creates a new terminal window  [105]_
325    and runs the specified command, interpreting the entirety of the rest
326    of the command line as a command to pass straight to exec, in the
327    manner that ``xterm`` does.
329 -  Support the command-line option ``-T title``, which creates a new terminal window with the
330    window title title.
332 .. _s11.8.4:
334 Packages providing a window manager
335 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
337 Packages that provide a window manager should declare in their
338 ``Provides`` control field that they provide the virtual package
339 ``x-window-manager``. They should also register themselves as an
340 alternative for ``/usr/bin/x-window-manager``, with a priority
341 calculated as follows:
343 -  Start with a priority of 20.
345 -  If the window manager supports the Debian menu system, add 20 points
346    if this support is available in the package's default configuration
347    (i.e., no configuration files belonging to the system or user have to
348    be edited to activate the feature); if configuration files must be
349    modified, add only 10 points.
351 -  If the window manager complies with `The Window Manager Specification
352    Project <https://www.freedesktop.org/wiki/Specifications/wm-spec>`_,
353    written by the `Free Desktop
354    Group <https://www.freedesktop.org/wiki/>`_, add 40 points.
356 -  If the window manager permits the X session to be restarted using a
357    *different* window manager (without killing the X server) in its
358    default configuration, add 10 points; otherwise add none.
360 That alternative should have a slave alternative for
361 ``/usr/share/man/man1/x-window-manager.1.gz`` pointing to the
362 corresponding manual page.
364 .. _s11.8.5:
366 Packages providing fonts
367 ~~~~~~~~~~~~~~~~~~~~~~~~
369 Packages that provide fonts for the X Window System  [#]_ must do a
370 number of things to ensure that they are both available without
371 modification of the X or font server configuration, and that they do not
372 corrupt files used by other font packages to register information about
373 themselves.
375 1.  Fonts of any type supported by the X Window System must be in a
376     separate binary package from any executables, libraries, or
377     documentation (except that specific to the fonts shipped, such as
378     their license information). If one or more of the fonts so packaged
379     are necessary for proper operation of the package with which they
380     are associated the font package may be Recommended; if the fonts
381     merely provide an enhancement, a Suggests relationship may be used.
382     Packages must not Depend on font packages.  [#]_
384 2.  BDF fonts must be converted to PCF fonts with the ``bdftopcf``
385     utility (available in the ``xfonts-utils`` package, ``gzip``\ ped,
386     and placed in a directory that corresponds to their resolution:
388     -  100 dpi fonts must be placed in ``/usr/share/fonts/X11/100dpi/``.
390     -  75 dpi fonts must be placed in ``/usr/share/fonts/X11/75dpi/``.
392     -  Character-cell fonts, cursor fonts, and other low-resolution
393        fonts must be placed in ``/usr/share/fonts/X11/misc/``.
395 3.  Type 1 fonts must be placed in ``/usr/share/fonts/X11/Type1/``. If
396     font metric files are available, they must be placed here as well.
398 4.  Subdirectories of ``/usr/share/fonts/X11/`` other than those listed
399     above must be neither created nor used. (The ``PEX``, ``CID``,
400     ``Speedo``, and ``cyrillic`` directories are excepted for historical
401     reasons, but installation of files into these directories remains
402     discouraged.)
404 5.  Font packages may, instead of placing files directly in the X font
405     directories listed above, provide symbolic links in that font
406     directory pointing to the files' actual location in the filesystem.
407     Such a location must comply with the FHS.
409 6.  Font packages should not contain both 75dpi and 100dpi versions of a
410     font. If both are available, they should be provided in separate
411     binary packages with ``-75dpi`` or ``-100dpi`` appended to the names
412     of the packages containing the corresponding fonts.
414 7.  Fonts destined for the ``misc`` subdirectory should not be included
415     in the same package as 75dpi or 100dpi fonts; instead, they should
416     be provided in a separate package with ``-misc`` appended to its
417     name.
419 8.  Font packages must not provide the files ``fonts.dir``,
420     ``fonts.alias``, or ``fonts.scale`` in a font directory:
422     -  ``fonts.dir`` files must not be provided at all.
424     -  ``fonts.alias`` and ``fonts.scale`` files, if needed, should be
425        provided in the directory
426        ``/etc/X11/fonts/fontdir/package.extension``, where fontdir is
427        the name of the subdirectory of ``/usr/share/fonts/X11/`` where
428        the package's corresponding fonts are stored (e.g., ``75dpi`` or
429        ``misc``), package is the name of the package that provides these
430        fonts, and extension is either ``scale`` or ``alias``, whichever
431        corresponds to the file contents.
433 9.  Font packages must declare a dependency on ``xfonts-utils`` in their
434     ``Depends`` or ``Pre-Depends`` control field.
436 10. Font packages that provide one or more ``fonts.scale`` files as
437     described above must invoke ``update-fonts-scale`` on each directory
438     into which they installed fonts *before* invoking
439     ``update-fonts-dir`` on that directory. This invocation must occur
440     in both the ``postinst`` (for all arguments) and ``postrm`` (for all
441     arguments except ``upgrade``) scripts.
443 11. Font packages that provide one or more ``fonts.alias`` files as
444     described above must invoke ``update-fonts-alias`` on each directory
445     into which they installed fonts. This invocation must occur in both
446     the ``postinst`` (for all arguments) and ``postrm`` (for all
447     arguments except ``upgrade``) scripts.
449 12. Font packages must invoke ``update-fonts-dir`` on each directory
450     into which they installed fonts. This invocation must occur in both
451     the ``postinst`` (for all arguments) and ``postrm`` (for all
452     arguments except ``upgrade``) scripts.
454 13. Font packages must not provide alias names for the fonts they
455     include which collide with alias names already in use by fonts
456     already packaged.
458 14. Font packages must not provide fonts with the same XLFD registry
459     name as another font already packaged.
461 .. _s-appdefaults:
463 Application defaults files
464 ~~~~~~~~~~~~~~~~~~~~~~~~~~
466 Application defaults files must be installed in the directory
467 ``/etc/X11/app-defaults/`` (use of a localized subdirectory of
468 ``/etc/X11/`` as described in the *X Toolkit Intrinsics - C Language
469 Interface* manual is also permitted). They must be registered as
470 ``conffile``\ s or handled as configuration files.
472 Customization of programs' X resources may also be supported with the
473 provision of a file with the same name as that of the package placed in
474 the ``/etc/X11/Xresources/`` directory, which must be registered as a
475 ``conffile`` or handled as a configuration file.  [#]_
477 .. _s11.8.7:
479 Installation directory issues
480 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
482 Historically, packages using the X Window System used a separate set of
483 installation directories from other packages. This practice has been
484 discontinued and packages using the X Window System should now generally
485 be installed in the same directories as any other package. Specifically,
486 packages must not install files under the ``/usr/X11R6/`` directory and
487 the ``/usr/X11R6/`` directory hierarchy should be regarded as obsolete.
489 Include files previously installed under ``/usr/X11R6/include/X11/``
490 should be installed into ``/usr/include/X11/``. For files previously
491 installed into subdirectories of ``/usr/X11R6/lib/X11/``, package
492 maintainers should determine if subdirectories of ``/usr/lib/`` and
493 ``/usr/share/`` can be used. If not, a subdirectory of ``/usr/lib/X11/``
494 should be used.
496 Configuration files for window, display, or session managers or other
497 applications that are tightly integrated with the X Window System may be
498 placed in a subdirectory of ``/etc/X11/`` corresponding to the package
499 name. Other X Window System applications should use the ``/etc/``
500 directory unless otherwise mandated by policy (such as for
501 :ref:`s-appdefaults`).
503 .. _s-perl:
505 Perl programs and modules
506 -------------------------
508 Perl programs and modules should follow the current Perl policy.
510 The Perl policy can be found in the ``perl-policy`` files in the
511 ``debian-policy`` package. It is also available from the Debian web
512 mirrors at https://www.debian.org/doc/packaging-manuals/perl-policy/.
514 .. _s-emacs:
516 Emacs lisp programs
517 -------------------
519 Please refer to the "Debian Emacs Policy" for details of how to package
520 emacs lisp programs.
522 The Emacs policy is available in ``debian-emacs-policy.gz`` of the
523 emacsen-common package. It is also available from the Debian web mirrors
524 at https://www.debian.org/doc/packaging-manuals/debian-emacs-policy.
526 .. _s11.11:
528 Games
529 -----
531 The permissions on ``/var/games`` are mode 755, owner ``root`` and group
532 ``root``.
534 Each game decides on its own security policy.
536 Games which require protected, privileged access to high-score files,
537 saved games, etc., may be made set-\ *group*-id (mode 2755) and owned by
538 ``root:games``, and use files and directories with appropriate
539 permissions (770 ``root:games``, for example). They must not be made
540 set-\ *user*-id, as this causes security problems. (If an attacker can
541 subvert any set-user-id game they can overwrite the executable of any
542 other, causing other players of these games to run a Trojan horse
543 program. With a set-group-id game the attacker only gets access to less
544 important game data, and if they can get at the other players' accounts
545 at all it will take considerably more effort.)
547 Some packages, for example some fortune cookie programs, are configured
548 by the upstream authors to install with their data files or other static
549 information made unreadable so that they can only be accessed through
550 set-id programs provided. You should not do this in a Debian package:
551 anyone can download the ``.deb`` file and read the data from it, so
552 there is no point making the files unreadable. Not making the files
553 unreadable also means that you don't have to make so many programs
554 set-id, which reduces the risk of a security hole.
556 As described in the FHS, binaries of games should be installed in the
557 directory ``/usr/games``. This also applies to games that use the X
558 Window System. Manual pages for games (X and non-X games) should be
559 installed in ``/usr/share/man/man6``.
561 .. [#]
562    Internally, the package system normalizes the GNU triplets and the
563    Debian arches into Debian arch triplets (which are kind of inverted
564    GNU triplets), with the first component of the triplet representing
565    the libc and ABI in use, and then does matching against those
566    triplets. However, such triplets are an internal implementation
567    detail that should not be used by packages directly. The libc and ABI
568    portion is handled internally by the package system based on the os
569    and cpu.
571 .. [#]
572    The Debian base system already provides an editor and a pager
573    program.
575 .. [#]
576    If it is not possible to establish both locks, the system shouldn't
577    wait for the second lock to be established, but remove the first
578    lock, wait a (random) time, and start over locking again.
580 .. [#]
581    There are two traditional permission schemes for mail spools: mode
582    600 with all mail delivery done by processes running as the
583    destination user, or mode 660 and owned by group mail with mail
584    delivery done by a process running as a system user in group mail.
585    Historically, Debian required mode 660 mail spools to enable the
586    latter model, but that model has become increasingly uncommon and the
587    principle of least privilege indicates that mail systems that use the
588    first model should use permissions of 600. If delivery to programs is
589    permitted, it's easier to keep the mail system secure if the delivery
590    agent runs as the destination user. Debian Policy therefore permits
591    either scheme.
593 .. [#]
594    This implements current practice, and provides an actual policy for
595    usage of the ``xserver`` virtual package which appears in the virtual
596    packages list. In a nutshell, X servers that interface directly with
597    the display and input hardware or via another subsystem (e.g., GGI)
598    should provide ``xserver``. Things like ``Xvfb``, ``Xnest``, and
599    ``Xprt`` should not.
601 .. [#]
602    "New terminal window" does not necessarily mean a new top-level X
603    window directly parented by the window manager; it could, if the
604    terminal emulator application were so coded, be a new "view" in a
605    multiple-document interface (MDI).
607 .. [#]
608    For the purposes of Debian Policy, a "font for the X Window System"
609    is one which is accessed via X protocol requests. Fonts for the Linux
610    console, for PostScript renderer, or any other purpose, do not fit
611    this definition. Any tool which makes such fonts available to the X
612    Window System, however, must abide by this font policy.
614 .. [#]
615    This is because the X server may retrieve fonts from the local file
616    system or over the network from an X font server; the Debian package
617    system is empowered to deal only with the local file system.
619 .. [#]
620    Note that this mechanism is not the same as using app-defaults;
621    app-defaults are tied to the client binary on the local file system,
622    whereas X resources are stored in the X server and affect all
623    connecting clients.