Fix a security race with "cp -p A B" when B already exists.
[coreutils/bo.git] / src / install.c
blobdb08751e48eb00828df61b2ccf5d4606d388a60b
1 /* install - copy files and set attributes
2 Copyright (C) 89, 90, 91, 1995-2007 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by David MacKenzie <djm@gnu.ai.mit.edu> */
19 #include <config.h>
20 #include <stdio.h>
21 #include <getopt.h>
22 #include <sys/types.h>
23 #include <signal.h>
24 #include <pwd.h>
25 #include <grp.h>
26 #include <selinux/selinux.h>
28 #include "system.h"
29 #include "backupfile.h"
30 #include "error.h"
31 #include "cp-hash.h"
32 #include "copy.h"
33 #include "filenamecat.h"
34 #include "mkancesdirs.h"
35 #include "mkdir-p.h"
36 #include "modechange.h"
37 #include "quote.h"
38 #include "quotearg.h"
39 #include "savewd.h"
40 #include "stat-time.h"
41 #include "utimens.h"
42 #include "xstrtol.h"
44 /* The official name of this program (e.g., no `g' prefix). */
45 #define PROGRAM_NAME "install"
47 #define AUTHORS "David MacKenzie"
49 #if HAVE_SYS_WAIT_H
50 # include <sys/wait.h>
51 #endif
53 static int selinux_enabled = 0;
54 static bool use_default_selinux_context = true;
56 #if ! HAVE_ENDGRENT
57 # define endgrent() ((void) 0)
58 #endif
60 #if ! HAVE_ENDPWENT
61 # define endpwent() ((void) 0)
62 #endif
64 #if ! HAVE_LCHOWN
65 # define lchown(name, uid, gid) chown (name, uid, gid)
66 #endif
68 /* Initial number of entries in each hash table entry's table of inodes. */
69 #define INITIAL_HASH_MODULE 100
71 /* Initial number of entries in the inode hash table. */
72 #define INITIAL_ENTRY_TAB_SIZE 70
74 /* Number of bytes of a file to copy at a time. */
75 #define READ_SIZE (32 * 1024)
77 static bool change_timestamps (struct stat const *from_sb, char const *to);
78 static bool change_attributes (char const *name);
79 static bool copy_file (const char *from, const char *to,
80 const struct cp_options *x);
81 static bool install_file_in_file_parents (char const *from, char *to,
82 struct cp_options *x);
83 static bool install_file_in_dir (const char *from, const char *to_dir,
84 const struct cp_options *x);
85 static bool install_file_in_file (const char *from, const char *to,
86 const struct cp_options *x);
87 static void get_ids (void);
88 static void strip (char const *name);
89 static void announce_mkdir (char const *dir, void *options);
90 static int make_ancestor (char const *dir, char const *component,
91 void *options);
92 void usage (int status);
94 /* The name this program was run with, for error messages. */
95 char *program_name;
97 /* The user name that will own the files, or NULL to make the owner
98 the current user ID. */
99 static char *owner_name;
101 /* The user ID corresponding to `owner_name'. */
102 static uid_t owner_id;
104 /* The group name that will own the files, or NULL to make the group
105 the current group ID. */
106 static char *group_name;
108 /* The group ID corresponding to `group_name'. */
109 static gid_t group_id;
111 #define DEFAULT_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
113 /* The file mode bits to which non-directory files will be set. The umask has
114 no effect. */
115 static mode_t mode = DEFAULT_MODE;
117 /* Similar, but for directories. */
118 static mode_t dir_mode = DEFAULT_MODE;
120 /* The file mode bits that the user cares about. This should be a
121 superset of DIR_MODE and a subset of CHMOD_MODE_BITS. This matters
122 for directories, since otherwise directories may keep their S_ISUID
123 or S_ISGID bits. */
124 static mode_t dir_mode_bits = CHMOD_MODE_BITS;
126 /* If true, strip executable files after copying them. */
127 static bool strip_files;
129 /* If true, install a directory instead of a regular file. */
130 static bool dir_arg;
132 /* For long options that have no equivalent short option, use a
133 non-character as a pseudo short option, starting with CHAR_MAX + 1. */
134 enum
136 PRESERVE_CONTEXT_OPTION = CHAR_MAX + 1
139 static struct option const long_options[] =
141 {"backup", optional_argument, NULL, 'b'},
142 {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
143 {"directory", no_argument, NULL, 'd'},
144 {"group", required_argument, NULL, 'g'},
145 {"mode", required_argument, NULL, 'm'},
146 {"no-target-directory", no_argument, NULL, 'T'},
147 {"owner", required_argument, NULL, 'o'},
148 {"preserve-timestamps", no_argument, NULL, 'p'},
149 {"preserve-context", no_argument, NULL, PRESERVE_CONTEXT_OPTION},
150 /* Continue silent support for --preserve_context until Jan 2008. FIXME-obs
151 After that, FIXME-obs: warn in, say, late 2008, and disable altogether
152 a year or two later. */
153 {"preserve_context", no_argument, NULL, PRESERVE_CONTEXT_OPTION},
154 {"strip", no_argument, NULL, 's'},
155 {"suffix", required_argument, NULL, 'S'},
156 {"target-directory", required_argument, NULL, 't'},
157 {"verbose", no_argument, NULL, 'v'},
158 {GETOPT_HELP_OPTION_DECL},
159 {GETOPT_VERSION_OPTION_DECL},
160 {NULL, 0, NULL, 0}
163 static void
164 cp_option_init (struct cp_options *x)
166 cp_options_default (x);
167 x->copy_as_regular = true;
168 x->dereference = DEREF_ALWAYS;
169 x->unlink_dest_before_opening = true;
170 x->unlink_dest_after_failed_open = false;
171 x->hard_link = false;
172 x->interactive = I_UNSPECIFIED;
173 x->move_mode = false;
174 x->one_file_system = false;
175 x->preserve_ownership = false;
176 x->preserve_links = false;
177 x->preserve_mode = false;
178 x->preserve_timestamps = false;
179 x->require_preserve = false;
180 x->require_preserve_context = false;
181 x->recursive = false;
182 x->sparse_mode = SPARSE_AUTO;
183 x->symbolic_link = false;
184 x->backup_type = no_backups;
186 /* Create destination files initially writable so we can run strip on them.
187 Although GNU strip works fine on read-only files, some others
188 would fail. */
189 x->set_mode = true;
190 x->mode = S_IRUSR | S_IWUSR;
191 x->stdin_tty = false;
193 x->open_dangling_dest_symlink = false;
194 x->update = false;
195 x->preserve_security_context = false;
196 x->verbose = false;
197 x->dest_info = NULL;
198 x->src_info = NULL;
201 #ifdef ENABLE_WHEN_MATCHPATHCON_IS_MORE_EFFICIENT
202 /* Modify file context to match the specified policy.
203 If an error occurs the file will remain with the default directory
204 context. */
205 static void
206 setdefaultfilecon (char const *file)
208 struct stat st;
209 security_context_t scontext = NULL;
210 if (selinux_enabled != 1)
212 /* Indicate no context found. */
213 return;
215 if (lstat (file, &st) != 0)
216 return;
218 if (IS_ABSOLUTE_FILE_NAME (file))
220 /* Calling matchpathcon_init_prefix (NULL, "/first_component/")
221 is an optimization to minimize the expense of the following
222 matchpathcon call. */
223 char const *p0;
224 char const *p = file + 1;
225 while (ISSLASH (*p))
226 ++p;
228 /* Record final leading slash, for when FILE starts with two or more. */
229 p0 = p - 1;
231 if (*p)
233 char *prefix;
236 ++p;
238 while (*p && !ISSLASH (*p));
240 prefix = malloc (p - p0 + 2);
241 if (prefix)
243 stpcpy (stpncpy (prefix, p0, p - p0), "/");
244 matchpathcon_init_prefix (NULL, prefix);
245 free (prefix);
250 /* If there's an error determining the context, or it has none,
251 return to allow default context */
252 if ((matchpathcon (file, st.st_mode, &scontext) != 0) ||
253 STREQ (scontext, "<<none>>"))
255 if (scontext != NULL)
256 freecon (scontext);
257 return;
260 if (lsetfilecon (file, scontext) < 0 && errno != ENOTSUP)
261 error (0, errno,
262 _("warning: %s: failed to change context to %s"),
263 quotearg_colon (file), scontext);
265 freecon (scontext);
266 return;
268 #else
269 static void
270 setdefaultfilecon (char const *file)
272 (void) file;
274 #endif
276 /* FILE is the last operand of this command. Return true if FILE is a
277 directory. But report an error there is a problem accessing FILE,
278 or if FILE does not exist but would have to refer to an existing
279 directory if it referred to anything at all. */
281 static bool
282 target_directory_operand (char const *file)
284 char const *b = last_component (file);
285 size_t blen = strlen (b);
286 bool looks_like_a_dir = (blen == 0 || ISSLASH (b[blen - 1]));
287 struct stat st;
288 int err = (stat (file, &st) == 0 ? 0 : errno);
289 bool is_a_dir = !err && S_ISDIR (st.st_mode);
290 if (err && err != ENOENT)
291 error (EXIT_FAILURE, err, _("accessing %s"), quote (file));
292 if (is_a_dir < looks_like_a_dir)
293 error (EXIT_FAILURE, err, _("target %s is not a directory"), quote (file));
294 return is_a_dir;
297 /* Process a command-line file name, for the -d option. */
298 static int
299 process_dir (char *dir, struct savewd *wd, void *options)
301 return (make_dir_parents (dir, wd,
302 make_ancestor, options,
303 dir_mode, announce_mkdir,
304 dir_mode_bits, owner_id, group_id, false)
305 ? EXIT_SUCCESS
306 : EXIT_FAILURE);
310 main (int argc, char **argv)
312 int optc;
313 int exit_status = EXIT_SUCCESS;
314 const char *specified_mode = NULL;
315 bool make_backups = false;
316 char *backup_suffix_string;
317 char *version_control_string = NULL;
318 bool mkdir_and_install = false;
319 struct cp_options x;
320 char const *target_directory = NULL;
321 bool no_target_directory = false;
322 int n_files;
323 char **file;
324 security_context_t scontext = NULL;
325 /* set iff kernel has extra selinux system calls */
326 selinux_enabled = (0 < is_selinux_enabled ());
328 initialize_main (&argc, &argv);
329 program_name = argv[0];
330 setlocale (LC_ALL, "");
331 bindtextdomain (PACKAGE, LOCALEDIR);
332 textdomain (PACKAGE);
334 atexit (close_stdin);
336 cp_option_init (&x);
338 owner_name = NULL;
339 group_name = NULL;
340 strip_files = false;
341 dir_arg = false;
342 umask (0);
344 /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
345 we'll actually use backup_suffix_string. */
346 backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
348 while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pt:TvS:Z:", long_options,
349 NULL)) != -1)
351 switch (optc)
353 case 'b':
354 make_backups = true;
355 if (optarg)
356 version_control_string = optarg;
357 break;
358 case 'c':
359 break;
360 case 's':
361 strip_files = true;
362 #ifdef SIGCHLD
363 /* System V fork+wait does not work if SIGCHLD is ignored. */
364 signal (SIGCHLD, SIG_DFL);
365 #endif
366 break;
367 case 'd':
368 dir_arg = true;
369 break;
370 case 'D':
371 mkdir_and_install = true;
372 break;
373 case 'v':
374 x.verbose = true;
375 break;
376 case 'g':
377 group_name = optarg;
378 break;
379 case 'm':
380 specified_mode = optarg;
381 break;
382 case 'o':
383 owner_name = optarg;
384 break;
385 case 'p':
386 x.preserve_timestamps = true;
387 break;
388 case 'S':
389 make_backups = true;
390 backup_suffix_string = optarg;
391 break;
392 case 't':
393 if (target_directory)
394 error (EXIT_FAILURE, 0,
395 _("multiple target directories specified"));
396 else
398 struct stat st;
399 if (stat (optarg, &st) != 0)
400 error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
401 if (! S_ISDIR (st.st_mode))
402 error (EXIT_FAILURE, 0, _("target %s is not a directory"),
403 quote (optarg));
405 target_directory = optarg;
406 break;
407 case 'T':
408 no_target_directory = true;
409 break;
411 case PRESERVE_CONTEXT_OPTION:
412 if ( ! selinux_enabled)
414 error (0, 0, _("Warning: ignoring --preserve-context; "
415 "this kernel is not SELinux-enabled."));
416 break;
418 x.preserve_security_context = true;
419 use_default_selinux_context = false;
420 break;
421 case 'Z':
422 if ( ! selinux_enabled)
424 error (0, 0, _("Warning: ignoring --context (-Z); "
425 "this kernel is not SELinux-enabled."));
426 break;
428 scontext = optarg;
429 use_default_selinux_context = false;
430 break;
431 case_GETOPT_HELP_CHAR;
432 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
433 default:
434 usage (EXIT_FAILURE);
438 /* Check for invalid combinations of arguments. */
439 if (dir_arg & strip_files)
440 error (EXIT_FAILURE, 0,
441 _("the strip option may not be used when installing a directory"));
442 if (dir_arg && target_directory)
443 error (EXIT_FAILURE, 0,
444 _("target directory not allowed when installing a directory"));
446 if (x.preserve_security_context && scontext != NULL)
447 error (EXIT_FAILURE, 0,
448 _("cannot force target context to %s and preserve it"),
449 quote (scontext));
451 if (backup_suffix_string)
452 simple_backup_suffix = xstrdup (backup_suffix_string);
454 x.backup_type = (make_backups
455 ? xget_version (_("backup type"),
456 version_control_string)
457 : no_backups);
459 if (scontext && setfscreatecon (scontext) < 0)
460 error (EXIT_FAILURE, errno,
461 _("failed to set default file creation context to %s"),
462 quote (scontext));
464 n_files = argc - optind;
465 file = argv + optind;
467 if (n_files <= ! (dir_arg || target_directory))
469 if (n_files <= 0)
470 error (0, 0, _("missing file operand"));
471 else
472 error (0, 0, _("missing destination file operand after %s"),
473 quote (file[0]));
474 usage (EXIT_FAILURE);
477 if (no_target_directory)
479 if (target_directory)
480 error (EXIT_FAILURE, 0,
481 _("Cannot combine --target-directory (-t) "
482 "and --no-target-directory (-T)"));
483 if (2 < n_files)
485 error (0, 0, _("extra operand %s"), quote (file[2]));
486 usage (EXIT_FAILURE);
489 else if (! (dir_arg || target_directory))
491 if (2 <= n_files && target_directory_operand (file[n_files - 1]))
492 target_directory = file[--n_files];
493 else if (2 < n_files)
494 error (EXIT_FAILURE, 0, _("target %s is not a directory"),
495 quote (file[n_files - 1]));
498 if (specified_mode)
500 struct mode_change *change = mode_compile (specified_mode);
501 if (!change)
502 error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
503 mode = mode_adjust (0, false, 0, change, NULL);
504 dir_mode = mode_adjust (0, true, 0, change, &dir_mode_bits);
505 free (change);
508 get_ids ();
510 if (dir_arg)
511 exit_status = savewd_process_files (n_files, file, process_dir, &x);
512 else
514 /* FIXME: it's a little gross that this initialization is
515 required by copy.c::copy. */
516 hash_init ();
518 if (!target_directory)
520 if (! (mkdir_and_install
521 ? install_file_in_file_parents (file[0], file[1], &x)
522 : install_file_in_file (file[0], file[1], &x)))
523 exit_status = EXIT_FAILURE;
525 else
527 int i;
528 dest_info_init (&x);
529 for (i = 0; i < n_files; i++)
530 if (! install_file_in_dir (file[i], target_directory, &x))
531 exit_status = EXIT_FAILURE;
535 exit (exit_status);
538 /* Copy file FROM onto file TO, creating any missing parent directories of TO.
539 Return true if successful. */
541 static bool
542 install_file_in_file_parents (char const *from, char *to,
543 struct cp_options *x)
545 bool save_working_directory =
546 ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to));
547 int status = EXIT_SUCCESS;
549 struct savewd wd;
550 savewd_init (&wd);
551 if (! save_working_directory)
552 savewd_finish (&wd);
554 if (mkancesdirs (to, &wd, make_ancestor, x) == -1)
556 error (0, errno, _("cannot create directory %s"), to);
557 status = EXIT_FAILURE;
560 if (save_working_directory)
562 int restore_result = savewd_restore (&wd, status);
563 int restore_errno = errno;
564 savewd_finish (&wd);
565 if (EXIT_SUCCESS < restore_result)
566 return false;
567 if (restore_result < 0 && status == EXIT_SUCCESS)
569 error (0, restore_errno, _("cannot create directory %s"), to);
570 return false;
574 return (status == EXIT_SUCCESS && install_file_in_file (from, to, x));
577 /* Copy file FROM onto file TO and give TO the appropriate
578 attributes.
579 Return true if successful. */
581 static bool
582 install_file_in_file (const char *from, const char *to,
583 const struct cp_options *x)
585 struct stat from_sb;
586 if (x->preserve_timestamps && stat (from, &from_sb) != 0)
588 error (0, errno, _("cannot stat %s"), quote (from));
589 return false;
591 if (! copy_file (from, to, x))
592 return false;
593 if (strip_files)
594 strip (to);
595 if (x->preserve_timestamps && (strip_files || ! S_ISREG (from_sb.st_mode))
596 && ! change_timestamps (&from_sb, to))
597 return false;
598 return change_attributes (to);
601 /* Copy file FROM into directory TO_DIR, keeping its same name,
602 and give the copy the appropriate attributes.
603 Return true if successful. */
605 static bool
606 install_file_in_dir (const char *from, const char *to_dir,
607 const struct cp_options *x)
609 const char *from_base = last_component (from);
610 char *to = file_name_concat (to_dir, from_base, NULL);
611 bool ret = install_file_in_file (from, to, x);
612 free (to);
613 return ret;
616 /* Copy file FROM onto file TO, creating TO if necessary.
617 Return true if successful. */
619 static bool
620 copy_file (const char *from, const char *to, const struct cp_options *x)
622 bool copy_into_self;
624 /* Allow installing from non-regular files like /dev/null.
625 Charles Karney reported that some Sun version of install allows that
626 and that sendmail's installation process relies on the behavior.
627 However, since !x->recursive, the call to "copy" will fail if FROM
628 is a directory. */
630 return copy (from, to, false, x, &copy_into_self, NULL);
633 /* Set the attributes of file or directory NAME.
634 Return true if successful. */
636 static bool
637 change_attributes (char const *name)
639 bool ok = false;
640 /* chown must precede chmod because on some systems,
641 chown clears the set[ug]id bits for non-superusers,
642 resulting in incorrect permissions.
643 On System V, users can give away files with chown and then not
644 be able to chmod them. So don't give files away.
646 We don't normally ignore errors from chown because the idea of
647 the install command is that the file is supposed to end up with
648 precisely the attributes that the user specified (or defaulted).
649 If the file doesn't end up with the group they asked for, they'll
650 want to know. */
652 if (! (owner_id == (uid_t) -1 && group_id == (gid_t) -1)
653 && lchown (name, owner_id, group_id) != 0)
654 error (0, errno, _("cannot change ownership of %s"), quote (name));
655 else if (chmod (name, mode) != 0)
656 error (0, errno, _("cannot change permissions of %s"), quote (name));
657 else
658 ok = true;
660 if (use_default_selinux_context)
661 setdefaultfilecon (name);
663 return ok;
666 /* Set the timestamps of file TO to match those of file FROM.
667 Return true if successful. */
669 static bool
670 change_timestamps (struct stat const *from_sb, char const *to)
672 struct timespec timespec[2];
673 timespec[0] = get_stat_atime (from_sb);
674 timespec[1] = get_stat_mtime (from_sb);
676 if (utimens (to, timespec))
678 error (0, errno, _("cannot set time stamps for %s"), quote (to));
679 return false;
681 return true;
684 /* Strip the symbol table from the file NAME.
685 We could dig the magic number out of the file first to
686 determine whether to strip it, but the header files and
687 magic numbers vary so much from system to system that making
688 it portable would be very difficult. Not worth the effort. */
690 static void
691 strip (char const *name)
693 int status;
694 pid_t pid = fork ();
696 switch (pid)
698 case -1:
699 error (EXIT_FAILURE, errno, _("fork system call failed"));
700 break;
701 case 0: /* Child. */
702 execlp ("strip", "strip", name, NULL);
703 error (EXIT_FAILURE, errno, _("cannot run strip"));
704 break;
705 default: /* Parent. */
706 if (waitpid (pid, &status, 0) < 0)
707 error (EXIT_FAILURE, errno, _("waiting for strip"));
708 else if (! WIFEXITED (status) || WEXITSTATUS (status))
709 error (EXIT_FAILURE, 0, _("strip process terminated abnormally"));
710 break;
714 /* Initialize the user and group ownership of the files to install. */
716 static void
717 get_ids (void)
719 struct passwd *pw;
720 struct group *gr;
722 if (owner_name)
724 pw = getpwnam (owner_name);
725 if (pw == NULL)
727 unsigned long int tmp;
728 if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK
729 || UID_T_MAX < tmp)
730 error (EXIT_FAILURE, 0, _("invalid user %s"), quote (owner_name));
731 owner_id = tmp;
733 else
734 owner_id = pw->pw_uid;
735 endpwent ();
737 else
738 owner_id = (uid_t) -1;
740 if (group_name)
742 gr = getgrnam (group_name);
743 if (gr == NULL)
745 unsigned long int tmp;
746 if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK
747 || GID_T_MAX < tmp)
748 error (EXIT_FAILURE, 0, _("invalid group %s"), quote (group_name));
749 group_id = tmp;
751 else
752 group_id = gr->gr_gid;
753 endgrent ();
755 else
756 group_id = (gid_t) -1;
759 /* Report that directory DIR was made, if OPTIONS requests this. */
760 static void
761 announce_mkdir (char const *dir, void *options)
763 struct cp_options const *x = options;
764 if (x->verbose)
765 error (0, 0, _("creating directory %s"), quote (dir));
768 /* Make ancestor directory DIR, whose last file name component is
769 COMPONENT, with options OPTIONS. Assume the working directory is
770 COMPONENT's parent. */
771 static int
772 make_ancestor (char const *dir, char const *component, void *options)
774 int r = mkdir (component, DEFAULT_MODE);
775 if (r == 0)
776 announce_mkdir (dir, options);
777 return r;
780 void
781 usage (int status)
783 if (status != EXIT_SUCCESS)
784 fprintf (stderr, _("Try `%s --help' for more information.\n"),
785 program_name);
786 else
788 printf (_("\
789 Usage: %s [OPTION]... [-T] SOURCE DEST\n\
790 or: %s [OPTION]... SOURCE... DIRECTORY\n\
791 or: %s [OPTION]... -t DIRECTORY SOURCE...\n\
792 or: %s [OPTION]... -d DIRECTORY...\n\
794 program_name, program_name, program_name, program_name);
795 fputs (_("\
796 In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to\n\
797 the existing DIRECTORY, while setting permission modes and owner/group.\n\
798 In the 4th form, create all components of the given DIRECTORY(ies).\n\
800 "), stdout);
801 fputs (_("\
802 Mandatory arguments to long options are mandatory for short options too.\n\
803 "), stdout);
804 fputs (_("\
805 --backup[=CONTROL] make a backup of each existing destination file\n\
806 -b like --backup but does not accept an argument\n\
807 -c (ignored)\n\
808 -d, --directory treat all arguments as directory names; create all\n\
809 components of the specified directories\n\
810 "), stdout);
811 fputs (_("\
812 -D create all leading components of DEST except the last,\n\
813 then copy SOURCE to DEST\n\
814 -g, --group=GROUP set group ownership, instead of process' current group\n\
815 -m, --mode=MODE set permission mode (as in chmod), instead of rwxr-xr-x\n\
816 -o, --owner=OWNER set ownership (super-user only)\n\
817 "), stdout);
818 fputs (_("\
819 -p, --preserve-timestamps apply access/modification times of SOURCE files\n\
820 to corresponding destination files\n\
821 -s, --strip strip symbol tables\n\
822 -S, --suffix=SUFFIX override the usual backup suffix\n\
823 -t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY\n\
824 -T, --no-target-directory treat DEST as a normal file\n\
825 -v, --verbose print the name of each directory as it is created\n\
826 "), stdout);
827 fputs (_("\
828 --preserve-context preserve SELinux security context\n\
829 -Z, --context=CONTEXT set SELinux security context of files and directories\n\
830 "), stdout);
832 fputs (HELP_OPTION_DESCRIPTION, stdout);
833 fputs (VERSION_OPTION_DESCRIPTION, stdout);
834 fputs (_("\
836 The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
837 The version control method may be selected via the --backup option or through\n\
838 the VERSION_CONTROL environment variable. Here are the values:\n\
840 "), stdout);
841 fputs (_("\
842 none, off never make backups (even if --backup is given)\n\
843 numbered, t make numbered backups\n\
844 existing, nil numbered if numbered backups exist, simple otherwise\n\
845 simple, never always make simple backups\n\
846 "), stdout);
847 emit_bug_reporting_address ();
849 exit (status);