| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
#include "itypes.h" |
| 26 |
#include "lib/acl.h" |
| 27 |
|
| 28 |
extern struct name_num_obj valid_checksums, valid_compressions, valid_auth_checksums; |
| 29 |
|
| 30 |
static char *istring(const char *fmt, int val) |
| 31 |
{ |
| 32 |
char *str; |
| 33 |
if (asprintf(&str, fmt, val) < 0) |
| 34 |
out_of_memory("istring"); |
| 35 |
return str; |
| 36 |
} |
| 37 |
|
| 38 |
static void print_info_flags(enum logcode f) |
| 39 |
{ |
| 40 |
STRUCT_STAT *dumstat; |
| 41 |
BOOL as_json = f == FNONE ? 1 : 0; |
| 42 |
char line_buf[75], item_buf[32]; |
| 43 |
int line_len, j; |
| 44 |
char *info_flags[] = { |
| 45 |
|
| 46 |
"*Capabilities", |
| 47 |
|
| 48 |
istring("%d-bit files", (int)(sizeof (OFF_T) * 8)), |
| 49 |
istring("%d-bit inums", (int)(sizeof dumstat->st_ino * 8)), |
| 50 |
istring("%d-bit timestamps", (int)(sizeof (time_t) * 8)), |
| 51 |
istring("%d-bit long ints", (int)(sizeof (int64) * 8)), |
| 52 |
|
| 53 |
#ifndef HAVE_SOCKETPAIR |
| 54 |
"no " |
| 55 |
#endif |
| 56 |
"socketpairs", |
| 57 |
|
| 58 |
#ifndef SUPPORT_LINKS |
| 59 |
"no " |
| 60 |
#endif |
| 61 |
"symlinks", |
| 62 |
|
| 63 |
#ifndef CAN_SET_SYMLINK_TIMES |
| 64 |
"no " |
| 65 |
#endif |
| 66 |
"symtimes", |
| 67 |
|
| 68 |
#ifndef SUPPORT_HARD_LINKS |
| 69 |
"no " |
| 70 |
#endif |
| 71 |
"hardlinks", |
| 72 |
|
| 73 |
#ifndef CAN_HARDLINK_SPECIAL |
| 74 |
"no " |
| 75 |
#endif |
| 76 |
"hardlink-specials", |
| 77 |
|
| 78 |
#ifndef CAN_HARDLINK_SYMLINK |
| 79 |
"no " |
| 80 |
#endif |
| 81 |
"hardlink-symlinks", |
| 82 |
|
| 83 |
#ifndef INET6 |
| 84 |
"no " |
| 85 |
#endif |
| 86 |
"IPv6", |
| 87 |
|
| 88 |
#ifndef SUPPORT_ATIMES |
| 89 |
"no " |
| 90 |
#endif |
| 91 |
"atimes", |
| 92 |
|
| 93 |
"batchfiles", |
| 94 |
|
| 95 |
#ifndef HAVE_FTRUNCATE |
| 96 |
"no " |
| 97 |
#endif |
| 98 |
"inplace", |
| 99 |
|
| 100 |
#ifndef HAVE_FTRUNCATE |
| 101 |
"no " |
| 102 |
#endif |
| 103 |
"append", |
| 104 |
|
| 105 |
#ifndef SUPPORT_ACLS |
| 106 |
"no " |
| 107 |
#endif |
| 108 |
"ACLs", |
| 109 |
|
| 110 |
#ifdef SUPPORT_ACL_FD |
| 111 |
#ifdef HAVE_LIBACL_AT |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
"ACL-at", |
| 117 |
"ACL-libacl-at", |
| 118 |
#else |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
xacl_at_available() ? "ACL-at" : "no ACL-at", |
| 124 |
#endif |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifndef SUPPORT_XATTRS |
| 128 |
"no " |
| 129 |
#endif |
| 130 |
"xattrs", |
| 131 |
|
| 132 |
#ifdef RSYNC_USE_SECLUDED_ARGS |
| 133 |
"default " |
| 134 |
#else |
| 135 |
"optional " |
| 136 |
#endif |
| 137 |
"secluded-args", |
| 138 |
|
| 139 |
#ifndef ICONV_OPTION |
| 140 |
"no " |
| 141 |
#endif |
| 142 |
"iconv", |
| 143 |
|
| 144 |
#ifndef SUPPORT_PREALLOCATION |
| 145 |
"no " |
| 146 |
#endif |
| 147 |
"prealloc", |
| 148 |
|
| 149 |
#ifndef HAVE_MKTIME |
| 150 |
"no " |
| 151 |
#endif |
| 152 |
"stop-at", |
| 153 |
|
| 154 |
#ifndef SUPPORT_CRTIMES |
| 155 |
"no " |
| 156 |
#endif |
| 157 |
"crtimes", |
| 158 |
|
| 159 |
"*Optimizations", |
| 160 |
|
| 161 |
#ifndef USE_ROLL_SIMD |
| 162 |
"no " |
| 163 |
#endif |
| 164 |
"SIMD-roll", |
| 165 |
|
| 166 |
#ifndef USE_ROLL_ASM |
| 167 |
"no " |
| 168 |
#endif |
| 169 |
"asm-roll", |
| 170 |
|
| 171 |
#ifndef USE_OPENSSL |
| 172 |
"no " |
| 173 |
#endif |
| 174 |
"openssl-crypto", |
| 175 |
|
| 176 |
#ifndef USE_MD5_ASM |
| 177 |
"no " |
| 178 |
#endif |
| 179 |
"asm-MD5", |
| 180 |
|
| 181 |
NULL |
| 182 |
}; |
| 183 |
|
| 184 |
for (line_len = 0, j = 0; ; j++) { |
| 185 |
char *str = info_flags[j], *next_nfo = str ? info_flags[j+1] : NULL; |
| 186 |
int need_comma = next_nfo && *next_nfo != '*' ? 1 : 0; |
| 187 |
int item_len; |
| 188 |
if (!str || *str == '*') |
| 189 |
item_len = 1000; |
| 190 |
else if (as_json) { |
| 191 |
char *space = strchr(str, ' '); |
| 192 |
int is_no = space && strncmp(str, "no ", 3) == 0; |
| 193 |
int is_bits = space && isDigit(str); |
| 194 |
char *quot = space && !is_no && !is_bits ? "\"" : ""; |
| 195 |
char *item = space ? space + 1 : str; |
| 196 |
char *val = !space ? "true" : is_no ? "false" : str; |
| 197 |
int val_len = !space ? 4 : is_no ? 5 : space - str; |
| 198 |
if (is_bits && (space = strchr(val, '-')) != NULL) |
| 199 |
val_len = space - str; |
| 200 |
item_len = snprintf(item_buf, sizeof item_buf, |
| 201 |
" \"%s%s\": %s%.*s%s%s", item, is_bits ? "bits" : "", |
| 202 |
quot, val_len, val, quot, need_comma ? "," : ""); |
| 203 |
if (is_bits) |
| 204 |
item_buf[strlen(item)+2-1] = '_'; |
| 205 |
for (space = item; (space = strpbrk(space, " -")) != NULL; space++) |
| 206 |
item_buf[space - item + 2] = '_'; |
| 207 |
} else |
| 208 |
item_len = snprintf(item_buf, sizeof item_buf, " %s%s", str, need_comma ? "," : ""); |
| 209 |
if (line_len && line_len + item_len >= (int)sizeof line_buf) { |
| 210 |
if (as_json) |
| 211 |
printf(" %s\n", line_buf); |
| 212 |
else |
| 213 |
rprintf(f, " %s\n", line_buf); |
| 214 |
line_len = 0; |
| 215 |
} |
| 216 |
if (!str) |
| 217 |
break; |
| 218 |
if (*str == '*') { |
| 219 |
if (as_json) { |
| 220 |
if (as_json == 2) |
| 221 |
printf(" }"); |
| 222 |
else |
| 223 |
as_json = 2; |
| 224 |
printf(",\n \"%c%s\": {\n", toLower(str+1), str+2); |
| 225 |
} else |
| 226 |
rprintf(f, "%s:\n", str+1); |
| 227 |
} else { |
| 228 |
strlcpy(line_buf + line_len, item_buf, sizeof line_buf - line_len); |
| 229 |
line_len += item_len; |
| 230 |
} |
| 231 |
} |
| 232 |
if (as_json == 2) |
| 233 |
printf(" }"); |
| 234 |
} |
| 235 |
|
| 236 |
static void output_nno_list(enum logcode f, const char *name, struct name_num_obj *nno) |
| 237 |
{ |
| 238 |
char namebuf[64], tmpbuf[256]; |
| 239 |
char *tok, *next_tok, *comma = ","; |
| 240 |
char *cp; |
| 241 |
|
| 242 |
|
| 243 |
get_default_nno_list(nno, tmpbuf, sizeof tmpbuf - 1, '('); |
| 244 |
if (f != FNONE) { |
| 245 |
rprintf(f, "%s:\n", name); |
| 246 |
rprintf(f, " %s\n", tmpbuf); |
| 247 |
return; |
| 248 |
} |
| 249 |
|
| 250 |
strlcpy(namebuf, name, sizeof namebuf); |
| 251 |
for (cp = namebuf; *cp; cp++) { |
| 252 |
if (*cp == ' ') |
| 253 |
*cp = '_'; |
| 254 |
else if (isUpper(cp)) |
| 255 |
*cp = toLower(cp); |
| 256 |
} |
| 257 |
|
| 258 |
printf(",\n \"%s\": [\n ", namebuf); |
| 259 |
|
| 260 |
for (tok = strtok(tmpbuf, " "); tok; tok = next_tok) { |
| 261 |
next_tok = strtok(NULL, " "); |
| 262 |
if (*tok != '(') |
| 263 |
printf(" \"%s\"%s", tok, comma + (next_tok ? 0 : 1)); |
| 264 |
} |
| 265 |
|
| 266 |
printf("\n ]"); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
void print_rsync_version(enum logcode f) |
| 271 |
{ |
| 272 |
char copyright[] = "(C) 1996-" LATEST_YEAR " by Andrew Tridgell, Wayne Davison, and others."; |
| 273 |
char url[] = "https://rsync.samba.org/"; |
| 274 |
BOOL first_line = 1; |
| 275 |
|
| 276 |
#define json_line(name, value) \ |
| 277 |
do { \ |
| 278 |
printf("%c\n \"%s\": \"%s\"", first_line ? '{' : ',', name, value); \ |
| 279 |
first_line = 0; \ |
| 280 |
} while (0) |
| 281 |
|
| 282 |
if (f == FNONE) { |
| 283 |
char verbuf[32]; |
| 284 |
json_line("program", RSYNC_NAME); |
| 285 |
json_line("version", rsync_version()); |
| 286 |
(void)snprintf(verbuf, sizeof verbuf, "%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION); |
| 287 |
json_line("protocol", verbuf); |
| 288 |
json_line("copyright", copyright); |
| 289 |
json_line("url", url); |
| 290 |
} else { |
| 291 |
#if SUBPROTOCOL_VERSION != 0 |
| 292 |
char *subprotocol = istring(".PR%d", SUBPROTOCOL_VERSION); |
| 293 |
#else |
| 294 |
char *subprotocol = ""; |
| 295 |
#endif |
| 296 |
rprintf(f, "%s version %s protocol version %d%s\n", |
| 297 |
RSYNC_NAME, rsync_version(), PROTOCOL_VERSION, subprotocol); |
| 298 |
rprintf(f, "Copyright %s\n", copyright); |
| 299 |
rprintf(f, "Web site: %s\n", url); |
| 300 |
} |
| 301 |
|
| 302 |
print_info_flags(f); |
| 303 |
|
| 304 |
init_checksum_choices(); |
| 305 |
|
| 306 |
output_nno_list(f, "Checksum list", &valid_checksums); |
| 307 |
output_nno_list(f, "Compress list", &valid_compressions); |
| 308 |
output_nno_list(f, "Daemon auth list", &valid_auth_checksums); |
| 309 |
|
| 310 |
if (f == FNONE) { |
| 311 |
json_line("license", "GPLv3"); |
| 312 |
json_line("caveat", "rsync comes with ABSOLUTELY NO WARRANTY"); |
| 313 |
printf("\n}\n"); |
| 314 |
fflush(stdout); |
| 315 |
return; |
| 316 |
} |
| 317 |
|
| 318 |
#ifdef MAINTAINER_MODE |
| 319 |
rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
| 320 |
#endif |
| 321 |
|
| 322 |
#if SIZEOF_INT64 < 8 |
| 323 |
rprintf(f, "WARNING: no 64-bit integers on this platform!\n"); |
| 324 |
#endif |
| 325 |
if (sizeof (int64) != SIZEOF_INT64) { |
| 326 |
rprintf(f, |
| 327 |
"WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n", |
| 328 |
(int) SIZEOF_INT64, (int) sizeof (int64)); |
| 329 |
} |
| 330 |
|
| 331 |
rprintf(f,"\n"); |
| 332 |
rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"); |
| 333 |
rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n"); |
| 334 |
rprintf(f,"General Public Licence for details.\n"); |
| 335 |
} |
| 336 |
|
| 337 |
void usage(enum logcode F) |
| 338 |
{ |
| 339 |
print_rsync_version(F); |
| 340 |
|
| 341 |
rprintf(F,"\n"); |
| 342 |
rprintf(F,"rsync is a file transfer program capable of efficient remote update\n"); |
| 343 |
rprintf(F,"via a fast differencing algorithm.\n"); |
| 344 |
|
| 345 |
rprintf(F,"\n"); |
| 346 |
rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n"); |
| 347 |
rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n"); |
| 348 |
rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n"); |
| 349 |
rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n"); |
| 350 |
rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n"); |
| 351 |
rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n"); |
| 352 |
rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n"); |
| 353 |
rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n"); |
| 354 |
rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n"); |
| 355 |
rprintf(F,"\n"); |
| 356 |
rprintf(F,"Options\n"); |
| 357 |
#include "help-rsync.h" |
| 358 |
rprintf(F,"\n"); |
| 359 |
rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n"); |
| 360 |
rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) manpages for full documentation.\n"); |
| 361 |
rprintf(F,"See https://rsync.samba.org/ for updates, bug reports, and answers\n"); |
| 362 |
} |
| 363 |
|
| 364 |
void daemon_usage(enum logcode F) |
| 365 |
{ |
| 366 |
print_rsync_version(F); |
| 367 |
|
| 368 |
rprintf(F,"\n"); |
| 369 |
rprintf(F,"Usage: rsync --daemon [OPTION]...\n"); |
| 370 |
#include "help-rsyncd.h" |
| 371 |
rprintf(F,"\n"); |
| 372 |
rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n"); |
| 373 |
rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) manpage.\n"); |
| 374 |
} |
| 375 |
|
| 376 |
const char *rsync_version(void) |
| 377 |
{ |
| 378 |
char *ver; |
| 379 |
#ifdef RSYNC_GITVER |
| 380 |
ver = RSYNC_GITVER; |
| 381 |
#else |
| 382 |
ver = RSYNC_VERSION; |
| 383 |
#endif |
| 384 |
return *ver == 'v' ? ver+1 : ver; |
| 385 |
} |
| 386 |
|
| 387 |
const char *default_cvsignore(void) |
| 388 |
{ |
| 389 |
return DEFAULT_CVSIGNORE; |
| 390 |
} |