Add safety check for local --remove-source-files.
[rsync.git] / usage.c
1 /*
2  * Some usage & version related functions.
3  *
4  * Copyright (C) 2002-2022 Wayne Davison
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, visit the http://fsf.org website.
18  */
19
20 #include "rsync.h"
21 #include "version.h"
22 #include "latest-year.h"
23 #include "git-version.h"
24 #include "default-cvsignore.h"
25
26 extern struct name_num_obj valid_checksums;
27 extern struct name_num_obj valid_compressions;
28
29 static char *istring(const char *fmt, int val)
30 {
31         char *str;
32         if (asprintf(&str, fmt, val) < 0)
33                 out_of_memory("istring");
34         return str;
35 }
36
37 static void print_info_flags(enum logcode f)
38 {
39         STRUCT_STAT *dumstat;
40         char line_buf[75];
41         int line_len, j;
42         char *info_flags[] = {
43
44         "*Capabilities",
45
46                 istring("%d-bit files", (int)(sizeof (OFF_T) * 8)),
47                 istring("%d-bit inums", (int)(sizeof dumstat->st_ino * 8)), /* Don't check ino_t! */
48                 istring("%d-bit timestamps", (int)(sizeof (time_t) * 8)),
49                 istring("%d-bit long ints", (int)(sizeof (int64) * 8)),
50
51 #ifndef HAVE_SOCKETPAIR
52                 "no "
53 #endif
54                         "socketpairs",
55
56 #ifndef SUPPORT_LINKS
57                 "no "
58 #endif
59                         "symlinks",
60
61 #ifndef CAN_SET_SYMLINK_TIMES
62                 "no "
63 #endif
64                         "symtimes",
65
66 #ifndef SUPPORT_HARD_LINKS
67                 "no "
68 #endif
69                         "hardlinks",
70
71 #ifndef CAN_HARDLINK_SPECIAL
72                 "no "
73 #endif
74                         "hardlink-specials",
75
76 #ifndef CAN_HARDLINK_SYMLINK
77                 "no "
78 #endif
79                         "hardlink-symlinks",
80
81 #ifndef INET6
82                 "no "
83 #endif
84                         "IPv6",
85
86 #ifndef SUPPORT_ATIMES
87                 "no "
88 #endif
89                         "atimes",
90
91                 "batchfiles",
92
93 #ifndef HAVE_FTRUNCATE
94                 "no "
95 #endif
96                         "inplace",
97
98 #ifndef HAVE_FTRUNCATE
99                 "no "
100 #endif
101                         "append",
102
103 #ifndef SUPPORT_ACLS
104                 "no "
105 #endif
106                         "ACLs",
107
108 #ifndef SUPPORT_XATTRS
109                 "no "
110 #endif
111                         "xattrs",
112
113 #ifdef RSYNC_USE_PROTECTED_ARGS
114                 "default "
115 #else
116                 "optional "
117 #endif
118                         "protect-args",
119
120 #ifndef ICONV_OPTION
121                 "no "
122 #endif
123                         "iconv",
124
125 #ifndef SUPPORT_PREALLOCATION
126                 "no "
127 #endif
128                         "prealloc",
129
130 #ifndef HAVE_MKTIME
131                 "no "
132 #endif
133                         "stop-at",
134
135 #ifndef SUPPORT_CRTIMES
136                 "no "
137 #endif
138                         "crtimes",
139
140         "*Optimizations",
141
142 #ifndef USE_ROLL_SIMD
143                 "no "
144 #endif
145                         "SIMD-roll",
146
147 #ifndef USE_ROLL_ASM
148                 "no "
149 #endif
150                         "asm-roll",
151
152 #ifndef USE_OPENSSL
153                 "no "
154 #endif
155                         "openssl-crypto",
156
157 #ifndef USE_MD5_ASM
158                 "no "
159 #endif
160                         "asm-MD5",
161
162                 NULL
163         };
164
165         for (line_len = 0, j = 0; ; j++) {
166                 char *str = info_flags[j], *next_nfo = str ? info_flags[j+1] : NULL;
167                 int str_len = str && *str != '*' ? strlen(str) : 1000;
168                 int need_comma = next_nfo && *next_nfo != '*' ? 1 : 0;
169                 if (line_len && line_len + 1 + str_len + need_comma >= (int)sizeof line_buf) {
170                         rprintf(f, "   %s\n", line_buf);
171                         line_len = 0;
172                 }
173                 if (!str)
174                         break;
175                 if (*str == '*') {
176                         rprintf(f, "%s:\n", str+1);
177                         continue;
178                 }
179                 line_len += snprintf(line_buf+line_len, sizeof line_buf - line_len, " %s%s", str, need_comma ? "," : "");
180         }
181 }
182
183 void print_rsync_version(enum logcode f)
184 {
185         char tmpbuf[256], *subprotocol = "";
186
187 #if SUBPROTOCOL_VERSION != 0
188         subprotocol = istring(".PR%d", SUBPROTOCOL_VERSION);
189 #endif
190         rprintf(f, "%s  version %s  protocol version %d%s\n",
191                 RSYNC_NAME, rsync_version(), PROTOCOL_VERSION, subprotocol);
192
193         rprintf(f, "Copyright (C) 1996-" LATEST_YEAR " by Andrew Tridgell, Wayne Davison, and others.\n");
194         rprintf(f, "Web site: https://rsync.samba.org/\n");
195
196         print_info_flags(f);
197
198         init_checksum_choices();
199
200         rprintf(f, "Checksum list:\n");
201         get_default_nno_list(&valid_checksums, tmpbuf, sizeof tmpbuf, '(');
202         rprintf(f, "    %s\n", tmpbuf);
203
204         rprintf(f, "Compress list:\n");
205         get_default_nno_list(&valid_compressions, tmpbuf, sizeof tmpbuf, '(');
206         rprintf(f, "    %s\n", tmpbuf);
207
208 #ifdef MAINTAINER_MODE
209         rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
210 #endif
211
212 #if SIZEOF_INT64 < 8
213         rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
214 #endif
215         if (sizeof (int64) != SIZEOF_INT64) {
216                 rprintf(f,
217                         "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
218                         (int) SIZEOF_INT64, (int) sizeof (int64));
219         }
220
221         rprintf(f,"\n");
222         rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you\n");
223         rprintf(f,"are welcome to redistribute it under certain conditions.  See the GNU\n");
224         rprintf(f,"General Public Licence for details.\n");
225 }
226
227 void usage(enum logcode F)
228 {
229   print_rsync_version(F);
230
231   rprintf(F,"\n");
232   rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
233   rprintf(F,"via a fast differencing algorithm.\n");
234
235   rprintf(F,"\n");
236   rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
237   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
238   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
239   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
240   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
241   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
242   rprintf(F,"  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
243   rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
244   rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n");
245   rprintf(F,"\n");
246   rprintf(F,"Options\n");
247 #include "help-rsync.h"
248   rprintf(F,"\n");
249   rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
250   rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) manpages for full documentation.\n");
251   rprintf(F,"See https://rsync.samba.org/ for updates, bug reports, and answers\n");
252 }
253
254 void daemon_usage(enum logcode F)
255 {
256   print_rsync_version(F);
257
258   rprintf(F,"\n");
259   rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
260 #include "help-rsyncd.h"
261   rprintf(F,"\n");
262   rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n");
263   rprintf(F,"daemon-specific rsync options.  See also the rsyncd.conf(5) manpage.\n");
264 }
265
266 const char *rsync_version(void)
267 {
268 #ifdef RSYNC_GITVER
269         return RSYNC_GITVER;
270 #else
271         return RSYNC_VERSION;
272 #endif
273 }
274
275 const char *default_cvsignore(void)
276 {
277         return DEFAULT_CVSIGNORE;
278 }