options.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  1. /*
  2. * Command-line (and received via daemon-socket) option parsing.
  3. *
  4. * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
  5. * Copyright (C) 2000, 2001, 2002 Martin Pool <mbp@samba.org>
  6. * Copyright (C) 2002-2011 Wayne Davison
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, visit the http://fsf.org website.
  20. */
  21. #include "rsync.h"
  22. #include "ifuncs.h"
  23. #include <popt.h>
  24. #include "zlib/zlib.h"
  25. extern int module_id;
  26. extern int local_server;
  27. extern int sanitize_paths;
  28. extern int daemon_over_rsh;
  29. extern unsigned int module_dirlen;
  30. extern struct filter_list_struct filter_list;
  31. extern struct filter_list_struct daemon_filter_list;
  32. int make_backups = 0;
  33. /**
  34. * If 1, send the whole file as literal data rather than trying to
  35. * create an incremental diff.
  36. *
  37. * If -1, then look at whether we're local or remote and go by that.
  38. *
  39. * @sa disable_deltas_p()
  40. **/
  41. int whole_file = -1;
  42. int append_mode = 0;
  43. int keep_dirlinks = 0;
  44. int copy_dirlinks = 0;
  45. int copy_links = 0;
  46. int preserve_links = 0;
  47. int preserve_hard_links = 0;
  48. int preserve_acls = 0;
  49. int preserve_xattrs = 0;
  50. int preserve_perms = 0;
  51. int preserve_executability = 0;
  52. int preserve_devices = 0;
  53. int preserve_specials = 0;
  54. int preserve_uid = 0;
  55. int preserve_gid = 0;
  56. int preserve_times = 0;
  57. int update_only = 0;
  58. int cvs_exclude = 0;
  59. int dry_run = 0;
  60. int do_xfers = 1;
  61. int ignore_times = 0;
  62. int delete_mode = 0;
  63. int delete_during = 0;
  64. int delete_before = 0;
  65. int delete_after = 0;
  66. int delete_excluded = 0;
  67. int remove_source_files = 0;
  68. int one_file_system = 0;
  69. int protocol_version = PROTOCOL_VERSION;
  70. int sparse_files = 0;
  71. int do_compression = 0;
  72. int def_compress_level = Z_DEFAULT_COMPRESSION;
  73. int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */
  74. int am_server = 0;
  75. int am_sender = 0;
  76. int am_starting_up = 1;
  77. int relative_paths = -1;
  78. int implied_dirs = 1;
  79. int numeric_ids = 0;
  80. int allow_8bit_chars = 0;
  81. int force_delete = 0;
  82. int io_timeout = 0;
  83. int prune_empty_dirs = 0;
  84. int use_qsort = 0;
  85. char *files_from = NULL;
  86. int filesfrom_fd = -1;
  87. char *filesfrom_host = NULL;
  88. int eol_nulls = 0;
  89. int protect_args = 0;
  90. int human_readable = 0;
  91. int recurse = 0;
  92. int allow_inc_recurse = 1;
  93. int xfer_dirs = -1;
  94. int am_daemon = 0;
  95. int do_stats = 0;
  96. int do_progress = 0;
  97. int connect_timeout = 0;
  98. int keep_partial = 0;
  99. int safe_symlinks = 0;
  100. int copy_unsafe_links = 0;
  101. int size_only = 0;
  102. int daemon_bwlimit = 0;
  103. int bwlimit = 0;
  104. int fuzzy_basis = 0;
  105. size_t bwlimit_writemax = 0;
  106. int ignore_existing = 0;
  107. int ignore_non_existing = 0;
  108. int need_messages_from_generator = 0;
  109. int max_delete = INT_MIN;
  110. OFF_T max_size = 0;
  111. OFF_T min_size = 0;
  112. int ignore_errors = 0;
  113. int modify_window = 0;
  114. int blocking_io = -1;
  115. int checksum_seed = 0;
  116. int inplace = 0;
  117. int delay_updates = 0;
  118. long block_size = 0; /* "long" because popt can't set an int32. */
  119. char *skip_compress = NULL;
  120. /** Network address family. **/
  121. int default_af_hint
  122. #ifdef INET6
  123. = 0; /* Any protocol */
  124. #else
  125. = AF_INET; /* Must use IPv4 */
  126. # ifdef AF_INET6
  127. # undef AF_INET6
  128. # endif
  129. # define AF_INET6 AF_INET /* make -6 option a no-op */
  130. #endif
  131. /** Do not go into the background when run as --daemon. Good
  132. * for debugging and required for running as a service on W32,
  133. * or under Unix process-monitors. **/
  134. int no_detach
  135. #if defined _WIN32 || defined __WIN32__
  136. = 1;
  137. #else
  138. = 0;
  139. #endif
  140. int write_batch = 0;
  141. int read_batch = 0;
  142. int backup_dir_len = 0;
  143. int backup_suffix_len;
  144. unsigned int backup_dir_remainder;
  145. char *backup_suffix = NULL;
  146. char *tmpdir = NULL;
  147. char *partial_dir = NULL;
  148. char *basis_dir[MAX_BASIS_DIRS+1];
  149. char *config_file = NULL;
  150. char *shell_cmd = NULL;
  151. char *logfile_name = NULL;
  152. char *logfile_format = NULL;
  153. char *stdout_format = NULL;
  154. char *password_file = NULL;
  155. char *rsync_path = RSYNC_PATH;
  156. char *backup_dir = NULL;
  157. char backup_dir_buf[MAXPATHLEN];
  158. char *sockopts = NULL;
  159. int rsync_port = 0;
  160. int compare_dest = 0;
  161. int copy_dest = 0;
  162. int link_dest = 0;
  163. int basis_dir_cnt = 0;
  164. char *dest_option = NULL;
  165. int verbose = 0;
  166. int quiet = 0;
  167. int output_motd = 1;
  168. int log_before_transfer = 0;
  169. int stdout_format_has_i = 0;
  170. int stdout_format_has_o_or_i = 0;
  171. int logfile_format_has_i = 0;
  172. int logfile_format_has_o_or_i = 0;
  173. int always_checksum = 0;
  174. int list_only = 0;
  175. #define MAX_BATCH_NAME_LEN 256 /* Must be less than MAXPATHLEN-13 */
  176. char *batch_name = NULL;
  177. int need_unsorted_flist = 0;
  178. #ifdef ICONV_OPTION
  179. char *iconv_opt = ICONV_OPTION;
  180. #endif
  181. struct chmod_mode_struct *chmod_modes = NULL;
  182. static int daemon_opt; /* sets am_daemon after option error-reporting */
  183. static int omit_dir_times = 0;
  184. static int F_option_cnt = 0;
  185. static int modify_window_set;
  186. static int itemize_changes = 0;
  187. static int refused_delete, refused_archive_part, refused_compress;
  188. static int refused_partial, refused_progress, refused_delete_before;
  189. static int refused_delete_during;
  190. static int refused_inplace, refused_no_iconv;
  191. static char *max_size_arg, *min_size_arg;
  192. static char tmp_partialdir[] = ".~tmp~";
  193. /** Local address to bind. As a character string because it's
  194. * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
  195. * address, or a hostname. **/
  196. char *bind_address;
  197. static void print_rsync_version(enum logcode f)
  198. {
  199. char *subprotocol = "";
  200. char const *got_socketpair = "no ";
  201. char const *have_inplace = "no ";
  202. char const *hardlinks = "no ";
  203. char const *symtimes = "no ";
  204. char const *acls = "no ";
  205. char const *xattrs = "no ";
  206. char const *links = "no ";
  207. char const *iconv = "no ";
  208. char const *ipv6 = "no ";
  209. STRUCT_STAT *dumstat;
  210. #if SUBPROTOCOL_VERSION != 0
  211. if (asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION) < 0)
  212. out_of_memory("print_rsync_version");
  213. #endif
  214. #ifdef HAVE_SOCKETPAIR
  215. got_socketpair = "";
  216. #endif
  217. #ifdef HAVE_FTRUNCATE
  218. have_inplace = "";
  219. #endif
  220. #ifdef SUPPORT_HARD_LINKS
  221. hardlinks = "";
  222. #endif
  223. #ifdef SUPPORT_ACLS
  224. acls = "";
  225. #endif
  226. #ifdef SUPPORT_XATTRS
  227. xattrs = "";
  228. #endif
  229. #ifdef SUPPORT_LINKS
  230. links = "";
  231. #endif
  232. #ifdef INET6
  233. ipv6 = "";
  234. #endif
  235. #ifdef ICONV_OPTION
  236. iconv = "";
  237. #endif
  238. #ifdef CAN_SET_SYMLINK_TIMES
  239. symtimes = "";
  240. #endif
  241. rprintf(f, "%s version %s protocol version %d%s\n",
  242. RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol);
  243. rprintf(f, "Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.\n");
  244. rprintf(f, "Web site: http://rsync.samba.org/\n");
  245. rprintf(f, "Capabilities:\n");
  246. rprintf(f, " %d-bit files, %d-bit inums, %d-bit timestamps, %d-bit long ints,\n",
  247. (int)(sizeof (OFF_T) * 8),
  248. (int)(sizeof dumstat->st_ino * 8), /* Don't check ino_t! */
  249. (int)(sizeof (time_t) * 8),
  250. (int)(sizeof (int64) * 8));
  251. rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
  252. got_socketpair, hardlinks, links, ipv6, have_inplace);
  253. rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv, %ssymtimes\n",
  254. have_inplace, acls, xattrs, iconv, symtimes);
  255. #ifdef MAINTAINER_MODE
  256. rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
  257. #endif
  258. #if SIZEOF_INT64 < 8
  259. rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
  260. #endif
  261. if (sizeof (int64) != SIZEOF_INT64) {
  262. rprintf(f,
  263. "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
  264. (int) SIZEOF_INT64, (int) sizeof (int64));
  265. }
  266. rprintf(f,"\n");
  267. rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n");
  268. rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n");
  269. rprintf(f,"General Public Licence for details.\n");
  270. }
  271. void usage(enum logcode F)
  272. {
  273. print_rsync_version(F);
  274. rprintf(F,"\n");
  275. rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
  276. rprintf(F,"via a fast differencing algorithm.\n");
  277. rprintf(F,"\n");
  278. rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
  279. rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
  280. rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
  281. rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
  282. rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
  283. rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
  284. rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
  285. rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
  286. rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n");
  287. rprintf(F,"\n");
  288. rprintf(F,"Options\n");
  289. rprintf(F," -v, --verbose increase verbosity\n");
  290. rprintf(F," -q, --quiet suppress non-error messages\n");
  291. rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
  292. rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
  293. rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
  294. rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
  295. rprintf(F," -r, --recursive recurse into directories\n");
  296. rprintf(F," -R, --relative use relative path names\n");
  297. rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n");
  298. rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
  299. rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
  300. rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
  301. rprintf(F," -u, --update skip files that are newer on the receiver\n");
  302. rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
  303. rprintf(F," --append append data onto shorter files\n");
  304. rprintf(F," --append-verify like --append, but with old data in file checksum\n");
  305. rprintf(F," -d, --dirs transfer directories without recursing\n");
  306. rprintf(F," -l, --links copy symlinks as symlinks\n");
  307. rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
  308. rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n");
  309. rprintf(F," --safe-links ignore symlinks that point outside the source tree\n");
  310. rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n");
  311. rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
  312. rprintf(F," -H, --hard-links preserve hard links\n");
  313. rprintf(F," -p, --perms preserve permissions\n");
  314. rprintf(F," -E, --executability preserve the file's executability\n");
  315. rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
  316. #ifdef SUPPORT_ACLS
  317. rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
  318. #endif
  319. #ifdef SUPPORT_XATTRS
  320. rprintf(F," -X, --xattrs preserve extended attributes\n");
  321. #endif
  322. rprintf(F," -o, --owner preserve owner (super-user only)\n");
  323. rprintf(F," -g, --group preserve group\n");
  324. rprintf(F," --devices preserve device files (super-user only)\n");
  325. rprintf(F," --specials preserve special files\n");
  326. rprintf(F," -D same as --devices --specials\n");
  327. rprintf(F," -t, --times preserve modification times\n");
  328. rprintf(F," -O, --omit-dir-times omit directories from --times\n");
  329. rprintf(F," --super receiver attempts super-user activities\n");
  330. #ifdef SUPPORT_XATTRS
  331. rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
  332. #endif
  333. rprintf(F," -S, --sparse handle sparse files efficiently\n");
  334. rprintf(F," -n, --dry-run perform a trial run with no changes made\n");
  335. rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n");
  336. rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
  337. rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
  338. rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
  339. rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n");
  340. rprintf(F," --existing skip creating new files on receiver\n");
  341. rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
  342. rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
  343. rprintf(F," --del an alias for --delete-during\n");
  344. rprintf(F," --delete delete extraneous files from destination dirs\n");
  345. rprintf(F," --delete-before receiver deletes before transfer, not during\n");
  346. rprintf(F," --delete-during receiver deletes during transfer (default)\n");
  347. rprintf(F," --delete-delay find deletions during, delete after\n");
  348. rprintf(F," --delete-after receiver deletes after transfer, not during\n");
  349. rprintf(F," --delete-excluded also delete excluded files from destination dirs\n");
  350. rprintf(F," --ignore-errors delete even if there are I/O errors\n");
  351. rprintf(F," --force force deletion of directories even if not empty\n");
  352. rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
  353. rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
  354. rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n");
  355. rprintf(F," --partial keep partially transferred files\n");
  356. rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
  357. rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
  358. rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
  359. rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
  360. rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n");
  361. rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n");
  362. rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
  363. rprintf(F," --size-only skip files that match in size\n");
  364. rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
  365. rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
  366. rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
  367. rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
  368. rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
  369. rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
  370. rprintf(F," -z, --compress compress file data during the transfer\n");
  371. rprintf(F," --compress-level=NUM explicitly set compression level\n");
  372. rprintf(F," --skip-compress=LIST skip compressing files with a suffix in LIST\n");
  373. rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n");
  374. rprintf(F," -f, --filter=RULE add a file-filtering RULE\n");
  375. rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n");
  376. rprintf(F," repeated: --filter='- .rsync-filter'\n");
  377. rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
  378. rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n");
  379. rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
  380. rprintf(F," --include-from=FILE read include patterns from FILE\n");
  381. rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
  382. rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
  383. rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
  384. rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
  385. rprintf(F," --port=PORT specify double-colon alternate port number\n");
  386. rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
  387. rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
  388. rprintf(F," --stats give some file-transfer stats\n");
  389. rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
  390. rprintf(F," -h, --human-readable output numbers in a human-readable format\n");
  391. rprintf(F," --progress show progress during transfer\n");
  392. rprintf(F," -P same as --partial --progress\n");
  393. rprintf(F," -i, --itemize-changes output a change-summary for all updates\n");
  394. rprintf(F," --out-format=FORMAT output updates using the specified FORMAT\n");
  395. rprintf(F," --log-file=FILE log what we're doing to the specified FILE\n");
  396. rprintf(F," --log-file-format=FMT log updates using the specified FMT\n");
  397. rprintf(F," --password-file=FILE read daemon-access password from FILE\n");
  398. rprintf(F," --list-only list the files instead of copying them\n");
  399. rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
  400. rprintf(F," --write-batch=FILE write a batched update to FILE\n");
  401. rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
  402. rprintf(F," --read-batch=FILE read a batched update from FILE\n");
  403. rprintf(F," --protocol=NUM force an older protocol version to be used\n");
  404. #ifdef ICONV_OPTION
  405. rprintf(F," --iconv=CONVERT_SPEC request charset conversion of filenames\n");
  406. #endif
  407. rprintf(F," -4, --ipv4 prefer IPv4\n");
  408. rprintf(F," -6, --ipv6 prefer IPv6\n");
  409. rprintf(F," --version print version number\n");
  410. rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
  411. rprintf(F,"\n");
  412. rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
  413. rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
  414. rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
  415. }
  416. enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
  417. OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
  418. OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
  419. OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
  420. OPT_NO_D, OPT_APPEND, OPT_NO_ICONV,
  421. OPT_SERVER, OPT_REFUSED_BASE = 9000};
  422. static struct poptOption long_options[] = {
  423. /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
  424. {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 },
  425. {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
  426. {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
  427. {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
  428. {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
  429. {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
  430. {"motd", 0, POPT_ARG_VAL, &output_motd, 1, 0, 0 },
  431. {"no-motd", 0, POPT_ARG_VAL, &output_motd, 0, 0, 0 },
  432. {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
  433. {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
  434. {"no-human-readable",0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
  435. {"no-h", 0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
  436. {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
  437. {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 },
  438. {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 },
  439. {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
  440. {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
  441. {"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
  442. {"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
  443. {"i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
  444. {"no-i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
  445. {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
  446. {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
  447. {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
  448. {"old-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 4, 0, 0 },
  449. {"old-d", 0, POPT_ARG_VAL, &xfer_dirs, 4, 0, 0 },
  450. {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
  451. {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
  452. {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
  453. {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
  454. {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
  455. {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
  456. {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
  457. {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
  458. {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
  459. {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
  460. {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
  461. {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
  462. {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
  463. {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
  464. {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
  465. {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
  466. {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
  467. {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
  468. {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
  469. {"fake-super", 0, POPT_ARG_VAL, &am_root, -1, 0, 0 },
  470. {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
  471. {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
  472. {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
  473. {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 },
  474. {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
  475. {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
  476. {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 },
  477. {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
  478. {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
  479. {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
  480. {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
  481. {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
  482. {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
  483. {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
  484. {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
  485. {"copy-links", 'L', POPT_ARG_NONE, &copy_links, 0, 0, 0 },
  486. {"copy-unsafe-links",0, POPT_ARG_NONE, &copy_unsafe_links, 0, 0, 0 },
  487. {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
  488. {"copy-dirlinks", 'k', POPT_ARG_NONE, &copy_dirlinks, 0, 0, 0 },
  489. {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
  490. {"hard-links", 'H', POPT_ARG_NONE, 0, 'H', 0, 0 },
  491. {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
  492. {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
  493. {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
  494. {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
  495. {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
  496. {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
  497. {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
  498. {"i-d", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
  499. {"no-i-d", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
  500. {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
  501. {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
  502. {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
  503. {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
  504. {"no-one-file-system",0, POPT_ARG_VAL, &one_file_system, 0, 0, 0 },
  505. {"no-x", 0, POPT_ARG_VAL, &one_file_system, 0, 0, 0 },
  506. {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
  507. {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
  508. {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
  509. {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
  510. {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
  511. {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
  512. {"sparse", 'S', POPT_ARG_VAL, &sparse_files, 1, 0, 0 },
  513. {"no-sparse", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
  514. {"no-S", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
  515. {"inplace", 0, POPT_ARG_VAL, &inplace, 1, 0, 0 },
  516. {"no-inplace", 0, POPT_ARG_VAL, &inplace, 0, 0, 0 },
  517. {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 },
  518. {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 },
  519. {"no-append", 0, POPT_ARG_VAL, &append_mode, 0, 0, 0 },
  520. {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
  521. {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
  522. {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 },
  523. {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 },
  524. {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 },
  525. {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
  526. {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
  527. {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */
  528. {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 },
  529. {"force", 0, POPT_ARG_VAL, &force_delete, 1, 0, 0 },
  530. {"no-force", 0, POPT_ARG_VAL, &force_delete, 0, 0, 0 },
  531. {"ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 1, 0, 0 },
  532. {"no-ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 0, 0, 0 },
  533. {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
  534. {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
  535. {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
  536. {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
  537. {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
  538. {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
  539. {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
  540. {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
  541. {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
  542. {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
  543. {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
  544. {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
  545. {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
  546. {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
  547. {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
  548. {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
  549. {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
  550. {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
  551. {"fuzzy", 'y', POPT_ARG_VAL, &fuzzy_basis, 1, 0, 0 },
  552. {"no-fuzzy", 0, POPT_ARG_VAL, &fuzzy_basis, 0, 0, 0 },
  553. {"no-y", 0, POPT_ARG_VAL, &fuzzy_basis, 0, 0, 0 },
  554. {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
  555. {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
  556. {"no-z", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
  557. {"skip-compress", 0, POPT_ARG_STRING, &skip_compress, 0, 0, 0 },
  558. {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
  559. {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
  560. {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
  561. {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
  562. {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
  563. {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
  564. {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
  565. {"delay-updates", 0, POPT_ARG_VAL, &delay_updates, 1, 0, 0 },
  566. {"no-delay-updates", 0, POPT_ARG_VAL, &delay_updates, 0, 0, 0 },
  567. {"prune-empty-dirs",'m', POPT_ARG_VAL, &prune_empty_dirs, 1, 0, 0 },
  568. {"no-prune-empty-dirs",0,POPT_ARG_VAL, &prune_empty_dirs, 0, 0, 0 },
  569. {"no-m", 0, POPT_ARG_VAL, &prune_empty_dirs, 0, 0, 0 },
  570. {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
  571. {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
  572. {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 },
  573. {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */
  574. {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
  575. {"no-itemize-changes",0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
  576. {"no-i", 0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
  577. {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
  578. {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
  579. {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
  580. {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
  581. {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
  582. {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
  583. {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
  584. {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
  585. {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
  586. {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
  587. {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
  588. {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
  589. {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
  590. {"protect-args", 's', POPT_ARG_VAL, &protect_args, 1, 0, 0},
  591. {"no-protect-args", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
  592. {"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
  593. {"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
  594. {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
  595. {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
  596. {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
  597. {"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 },
  598. {"no-contimeout", 0, POPT_ARG_VAL, &connect_timeout, 0, 0, 0 },
  599. {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
  600. {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
  601. {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
  602. #ifdef ICONV_OPTION
  603. {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 },
  604. {"no-iconv", 0, POPT_ARG_NONE, 0, OPT_NO_ICONV, 0, 0 },
  605. #endif
  606. {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
  607. {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
  608. {"8-bit-output", '8', POPT_ARG_VAL, &allow_8bit_chars, 1, 0, 0 },
  609. {"no-8-bit-output", 0, POPT_ARG_VAL, &allow_8bit_chars, 0, 0, 0 },
  610. {"no-8", 0, POPT_ARG_VAL, &allow_8bit_chars, 0, 0, 0 },
  611. {"qsort", 0, POPT_ARG_NONE, &use_qsort, 0, 0, 0 },
  612. {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
  613. {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
  614. {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
  615. {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
  616. {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
  617. {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
  618. {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
  619. {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
  620. {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
  621. {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
  622. /* All the following options switch us into daemon-mode option-parsing. */
  623. {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
  624. {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
  625. {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
  626. {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
  627. {0,0,0,0, 0, 0, 0}
  628. };
  629. static void daemon_usage(enum logcode F)
  630. {
  631. print_rsync_version(F);
  632. rprintf(F,"\n");
  633. rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
  634. rprintf(F," --address=ADDRESS bind to the specified address\n");
  635. rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
  636. rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
  637. rprintf(F," --no-detach do not detach from the parent\n");
  638. rprintf(F," --port=PORT listen on alternate port number\n");
  639. rprintf(F," --log-file=FILE override the \"log file\" setting\n");
  640. rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
  641. rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
  642. rprintf(F," -v, --verbose increase verbosity\n");
  643. rprintf(F," -4, --ipv4 prefer IPv4\n");
  644. rprintf(F," -6, --ipv6 prefer IPv6\n");
  645. rprintf(F," --help show this help screen\n");
  646. rprintf(F,"\n");
  647. rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n");
  648. rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
  649. }
  650. static struct poptOption long_daemon_options[] = {
  651. /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
  652. {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
  653. {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
  654. {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
  655. {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
  656. {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
  657. {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
  658. {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
  659. {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
  660. {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
  661. {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
  662. {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
  663. {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
  664. {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
  665. {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
  666. {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
  667. {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
  668. {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
  669. {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
  670. {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
  671. {0,0,0,0, 0, 0, 0}
  672. };
  673. static char err_buf[200];
  674. /**
  675. * Store the option error message, if any, so that we can log the
  676. * connection attempt (which requires parsing the options), and then
  677. * show the error later on.
  678. **/
  679. void option_error(void)
  680. {
  681. if (!err_buf[0]) {
  682. strlcpy(err_buf, "Error parsing options: option may "
  683. "be supported on client but not on server?\n",
  684. sizeof err_buf);
  685. }
  686. rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
  687. msleep(20);
  688. }
  689. /**
  690. * Tweak the option table to disable all options that the rsyncd.conf
  691. * file has told us to refuse.
  692. **/
  693. static void set_refuse_options(char *bp)
  694. {
  695. struct poptOption *op;
  696. char *cp, shortname[2];
  697. int is_wild, found_match;
  698. shortname[1] = '\0';
  699. while (1) {
  700. while (*bp == ' ') bp++;
  701. if (!*bp)
  702. break;
  703. if ((cp = strchr(bp, ' ')) != NULL)
  704. *cp= '\0';
  705. is_wild = strpbrk(bp, "*?[") != NULL;
  706. found_match = 0;
  707. for (op = long_options; ; op++) {
  708. *shortname = op->shortName;
  709. if (!op->longName && !*shortname)
  710. break;
  711. if ((op->longName && wildmatch(bp, op->longName))
  712. || (*shortname && wildmatch(bp, shortname))) {
  713. if (op->argInfo == POPT_ARG_VAL)
  714. op->argInfo = POPT_ARG_NONE;
  715. op->val = (op - long_options) + OPT_REFUSED_BASE;
  716. found_match = 1;
  717. /* These flags are set to let us easily check
  718. * an implied option later in the code. */
  719. switch (*shortname) {
  720. case 'r': case 'd': case 'l': case 'p':
  721. case 't': case 'g': case 'o': case 'D':
  722. refused_archive_part = op->val;
  723. break;
  724. case 'z':
  725. refused_compress = op->val;
  726. break;
  727. case '\0':
  728. if (wildmatch("delete", op->longName))
  729. refused_delete = op->val;
  730. else if (wildmatch("delete-before", op->longName))
  731. refused_delete_before = op->val;
  732. else if (wildmatch("delete-during", op->longName))
  733. refused_delete_during = op->val;
  734. else if (wildmatch("partial", op->longName))
  735. refused_partial = op->val;
  736. else if (wildmatch("progress", op->longName))
  737. refused_progress = op->val;
  738. else if (wildmatch("inplace", op->longName))
  739. refused_inplace = op->val;
  740. else if (wildmatch("no-iconv", op->longName))
  741. refused_no_iconv = op->val;
  742. break;
  743. }
  744. if (!is_wild)
  745. break;
  746. }
  747. }
  748. if (!found_match) {
  749. rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
  750. bp);
  751. }
  752. if (!cp)
  753. break;
  754. *cp = ' ';
  755. bp = cp + 1;
  756. }
  757. }
  758. static int count_args(const char **argv)
  759. {
  760. int i = 0;
  761. if (argv) {
  762. while (argv[i] != NULL)
  763. i++;
  764. }
  765. return i;
  766. }
  767. static OFF_T parse_size_arg(char **size_arg, char def_suf)
  768. {
  769. int reps, mult, make_compatible = 0;
  770. const char *arg;
  771. OFF_T size = 1;
  772. for (arg = *size_arg; isDigit(arg); arg++) {}
  773. if (*arg == '.')
  774. for (arg++; isDigit(arg); arg++) {}
  775. switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
  776. case 'b': case 'B':
  777. reps = 0;
  778. break;
  779. case 'k': case 'K':
  780. reps = 1;
  781. break;
  782. case 'm': case 'M':
  783. reps = 2;
  784. break;
  785. case 'g': case 'G':
  786. reps = 3;
  787. break;
  788. default:
  789. return -1;
  790. }
  791. if (*arg == 'b' || *arg == 'B')
  792. mult = 1000, make_compatible = 1, arg++;
  793. else if (!*arg || *arg == '+' || *arg == '-')
  794. mult = 1024;
  795. else if (strncasecmp(arg, "ib", 2) == 0)
  796. mult = 1024, arg += 2;
  797. else
  798. return -1;
  799. while (reps--)
  800. size *= mult;
  801. size *= atof(*size_arg);
  802. if ((*arg == '+' || *arg == '-') && arg[1] == '1')
  803. size += atoi(arg), make_compatible = 1, arg += 2;
  804. if (*arg)
  805. return -1;
  806. if (size > 0 && make_compatible) {
  807. /* We convert this manually because we may need %lld precision,
  808. * and that's not a portable sprintf() escape. */
  809. char buf[128], *s = buf + sizeof buf - 1;
  810. OFF_T num = size;
  811. *s = '\0';
  812. while (num) {
  813. *--s = (char)(num % 10) + '0';
  814. num /= 10;
  815. }
  816. if (!(*size_arg = strdup(s)))
  817. out_of_memory("parse_size_arg");
  818. }
  819. return size;
  820. }
  821. static void create_refuse_error(int which)
  822. {
  823. /* The "which" value is the index + OPT_REFUSED_BASE. */
  824. struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];
  825. int n = snprintf(err_buf, sizeof err_buf,
  826. "The server is configured to refuse --%s\n",
  827. op->longName) - 1;
  828. if (op->shortName) {
  829. snprintf(err_buf + n, sizeof err_buf - n,
  830. " (-%c)\n", op->shortName);
  831. }
  832. }
  833. /**
  834. * Process command line arguments. Called on both local and remote.
  835. *
  836. * @retval 1 if all options are OK; with globals set to appropriate
  837. * values
  838. *
  839. * @retval 0 on error, with err_buf containing an explanation
  840. **/
  841. int parse_arguments(int *argc_p, const char ***argv_p)
  842. {
  843. static poptContext pc;
  844. char *ref = lp_refuse_options(module_id);
  845. const char *arg, **argv = *argv_p;
  846. int argc = *argc_p;
  847. int opt;
  848. if (ref && *ref)
  849. set_refuse_options(ref);
  850. if (am_daemon) {
  851. set_refuse_options("log-file*");
  852. #ifdef ICONV_OPTION
  853. if (!*lp_charset(module_id))
  854. set_refuse_options("iconv");
  855. #endif
  856. }
  857. #ifdef ICONV_OPTION
  858. if (!am_daemon && !protect_args && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
  859. iconv_opt = strdup(arg);
  860. #endif
  861. /* TODO: Call poptReadDefaultConfig; handle errors. */
  862. /* The context leaks in case of an error, but if there's a
  863. * problem we always exit anyhow. */
  864. if (pc)
  865. poptFreeContext(pc);
  866. pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
  867. if (!am_server)
  868. poptReadDefaultConfig(pc, 0);
  869. while ((opt = poptGetNextOpt(pc)) != -1) {
  870. /* most options are handled automatically by popt;
  871. * only special cases are returned and listed here. */
  872. switch (opt) {
  873. case OPT_VERSION:
  874. print_rsync_version(FINFO);
  875. exit_cleanup(0);
  876. case OPT_SERVER:
  877. if (!am_server) {
  878. /* Disable popt aliases on the server side and
  879. * then start parsing the options again. */
  880. poptFreeContext(pc);
  881. pc = poptGetContext(RSYNC_NAME, argc, argv,
  882. long_options, 0);
  883. am_server = 1;
  884. }
  885. #ifdef ICONV_OPTION
  886. iconv_opt = NULL;
  887. #endif
  888. break;
  889. case OPT_SENDER:
  890. if (!am_server) {
  891. usage(FERROR);
  892. exit_cleanup(RERR_SYNTAX);
  893. }
  894. am_sender = 1;
  895. break;
  896. case OPT_DAEMON:
  897. if (am_daemon) {
  898. strlcpy(err_buf,
  899. "Attempt to hack rsync thwarted!\n",
  900. sizeof err_buf);
  901. return 0;
  902. }
  903. #ifdef ICONV_OPTION
  904. iconv_opt = NULL;
  905. #endif
  906. poptFreeContext(pc);
  907. pc = poptGetContext(RSYNC_NAME, argc, argv,
  908. long_daemon_options, 0);
  909. while ((opt = poptGetNextOpt(pc)) != -1) {
  910. switch (opt) {
  911. case 'h':
  912. daemon_usage(FINFO);
  913. exit_cleanup(0);
  914. case 'v':
  915. verbose++;
  916. break;
  917. default:
  918. rprintf(FERROR,
  919. "rsync: %s: %s (in daemon mode)\n",
  920. poptBadOption(pc, POPT_BADOPTION_NOALIAS),
  921. poptStrerror(opt));
  922. goto daemon_error;
  923. }
  924. }
  925. if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
  926. snprintf(err_buf, sizeof err_buf,
  927. "the --temp-dir path is WAY too long.\n");
  928. return 0;
  929. }
  930. if (!daemon_opt) {
  931. rprintf(FERROR, "Daemon option(s) used without --daemon.\n");
  932. daemon_error:
  933. rprintf(FERROR,
  934. "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");
  935. exit_cleanup(RERR_SYNTAX);
  936. }
  937. *argv_p = argv = poptGetArgs(pc);
  938. *argc_p = argc = count_args(argv);
  939. am_starting_up = 0;
  940. daemon_opt = 0;
  941. am_daemon = 1;
  942. return 1;
  943. case OPT_MODIFY_WINDOW:
  944. /* The value has already been set by popt, but
  945. * we need to remember that we're using a
  946. * non-default setting. */
  947. modify_window_set = 1;
  948. break;
  949. case OPT_FILTER:
  950. parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
  951. break;
  952. case OPT_EXCLUDE:
  953. parse_rule(&filter_list, poptGetOptArg(pc),
  954. 0, XFLG_OLD_PREFIXES);
  955. break;
  956. case OPT_INCLUDE:
  957. parse_rule(&filter_list, poptGetOptArg(pc),
  958. MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
  959. break;
  960. case OPT_EXCLUDE_FROM:
  961. case OPT_INCLUDE_FROM:
  962. arg = poptGetOptArg(pc);
  963. if (sanitize_paths)
  964. arg = sanitize_path(NULL, arg, NULL, 0, SP_DEFAULT);
  965. if (daemon_filter_list.head) {
  966. int rej;
  967. char *dir, *cp = strdup(arg);
  968. if (!cp)
  969. out_of_memory("parse_arguments");
  970. if (!*cp)
  971. goto options_rejected;
  972. dir = cp + (*cp == '/' ? module_dirlen : 0);
  973. clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
  974. rej = check_filter(&daemon_filter_list, FLOG, dir, 0) < 0;
  975. free(cp);
  976. if (rej)
  977. goto options_rejected;
  978. }
  979. parse_filter_file(&filter_list, arg,
  980. opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
  981. XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
  982. break;
  983. case 'a':
  984. if (refused_archive_part) {
  985. create_refuse_error(refused_archive_part);
  986. return 0;
  987. }
  988. if (!recurse) /* preserve recurse == 2 */
  989. recurse = 1;
  990. #ifdef SUPPORT_LINKS
  991. preserve_links = 1;
  992. #endif
  993. preserve_perms = 1;
  994. preserve_times = 1;
  995. preserve_gid = 1;
  996. preserve_uid = 1;
  997. preserve_devices = 1;
  998. preserve_specials = 1;
  999. break;
  1000. case 'D':
  1001. preserve_devices = preserve_specials = 1;
  1002. break;
  1003. case OPT_NO_D:
  1004. preserve_devices = preserve_specials = 0;
  1005. break;
  1006. case 'h':
  1007. human_readable++;
  1008. break;
  1009. case 'H':
  1010. preserve_hard_links++;
  1011. break;
  1012. case 'i':
  1013. itemize_changes++;
  1014. break;
  1015. case 'v':
  1016. verbose++;
  1017. break;
  1018. case 'q':
  1019. quiet++;
  1020. break;
  1021. case 'x':
  1022. one_file_system++;
  1023. break;
  1024. case 'F':
  1025. switch (++F_option_cnt) {
  1026. case 1:
  1027. parse_rule(&filter_list,": /.rsync-filter",0,0);
  1028. break;
  1029. case 2:
  1030. parse_rule(&filter_list,"- .rsync-filter",0,0);
  1031. break;
  1032. }
  1033. break;
  1034. case 'P':
  1035. if (refused_partial || refused_progress) {
  1036. create_refuse_error(refused_partial
  1037. ? refused_partial : refused_progress);
  1038. return 0;
  1039. }
  1040. do_progress = 1;
  1041. keep_partial = 1;
  1042. break;
  1043. case 'z':
  1044. if (def_compress_level < Z_DEFAULT_COMPRESSION
  1045. || def_compress_level > Z_BEST_COMPRESSION) {
  1046. snprintf(err_buf, sizeof err_buf,
  1047. "--compress-level value is invalid: %d\n",
  1048. def_compress_level);
  1049. return 0;
  1050. }
  1051. do_compression = def_compress_level != Z_NO_COMPRESSION;
  1052. if (do_compression && refused_compress) {
  1053. create_refuse_error(refused_compress);
  1054. return 0;
  1055. }
  1056. break;
  1057. case OPT_WRITE_BATCH:
  1058. /* batch_name is already set */
  1059. write_batch = 1;
  1060. break;
  1061. case OPT_ONLY_WRITE_BATCH:
  1062. /* batch_name is already set */
  1063. write_batch = -1;
  1064. break;
  1065. case OPT_READ_BATCH:
  1066. /* batch_name is already set */
  1067. read_batch = 1;
  1068. break;
  1069. case OPT_NO_ICONV:
  1070. #ifdef ICONV_OPTION
  1071. iconv_opt = NULL;
  1072. #endif
  1073. break;
  1074. case OPT_MAX_SIZE:
  1075. if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
  1076. snprintf(err_buf, sizeof err_buf,
  1077. "--max-size value is invalid: %s\n",
  1078. max_size_arg);
  1079. return 0;
  1080. }
  1081. break;
  1082. case OPT_MIN_SIZE:
  1083. if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) {
  1084. snprintf(err_buf, sizeof err_buf,
  1085. "--min-size value is invalid: %s\n",
  1086. min_size_arg);
  1087. return 0;
  1088. }
  1089. break;
  1090. case OPT_APPEND:
  1091. if (am_server)
  1092. append_mode++;
  1093. else
  1094. append_mode = 1;
  1095. break;
  1096. case OPT_LINK_DEST:
  1097. #ifdef SUPPORT_HARD_LINKS
  1098. link_dest = 1;
  1099. dest_option = "--link-dest";
  1100. goto set_dest_dir;
  1101. #else
  1102. snprintf(err_buf, sizeof err_buf,
  1103. "hard links are not supported on this %s\n",
  1104. am_server ? "server" : "client");
  1105. return 0;
  1106. #endif
  1107. case OPT_COPY_DEST:
  1108. copy_dest = 1;
  1109. dest_option = "--copy-dest";
  1110. goto set_dest_dir;
  1111. case OPT_COMPARE_DEST:
  1112. compare_dest = 1;
  1113. dest_option = "--compare-dest";
  1114. set_dest_dir:
  1115. if (basis_dir_cnt >= MAX_BASIS_DIRS) {
  1116. snprintf(err_buf, sizeof err_buf,
  1117. "ERROR: at most %d %s args may be specified\n",
  1118. MAX_BASIS_DIRS, dest_option);
  1119. return 0;
  1120. }
  1121. /* We defer sanitizing this arg until we know what
  1122. * our destination directory is going to be. */
  1123. basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc);
  1124. break;
  1125. case OPT_CHMOD:
  1126. arg = poptGetOptArg(pc);
  1127. if (!parse_chmod(arg, &chmod_modes)) {
  1128. snprintf(err_buf, sizeof err_buf,
  1129. "Invalid argument passed to --chmod (%s)\n",
  1130. arg);
  1131. return 0;
  1132. }
  1133. break;
  1134. case OPT_HELP:
  1135. usage(FINFO);
  1136. exit_cleanup(0);
  1137. case 'A':
  1138. #ifdef SUPPORT_ACLS
  1139. preserve_acls = 1;
  1140. preserve_perms = 1;
  1141. break;
  1142. #else
  1143. /* FIXME: this should probably be ignored with a
  1144. * warning and then countermeasures taken to
  1145. * restrict group and other access in the presence
  1146. * of any more restrictive ACLs, but this is safe
  1147. * for now */
  1148. snprintf(err_buf,sizeof(err_buf),
  1149. "ACLs are not supported on this %s\n",
  1150. am_server ? "server" : "client");
  1151. return 0;
  1152. #endif
  1153. case 'X':
  1154. #ifdef SUPPORT_XATTRS
  1155. preserve_xattrs++;
  1156. break;
  1157. #else
  1158. snprintf(err_buf,sizeof(err_buf),
  1159. "extended attributes are not supported on this %s\n",
  1160. am_server ? "server" : "client");
  1161. return 0;
  1162. #endif
  1163. default:
  1164. /* A large opt value means that set_refuse_options()
  1165. * turned this option off. */
  1166. if (opt >= OPT_REFUSED_BASE) {
  1167. create_refuse_error(opt);
  1168. return 0;
  1169. }
  1170. snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
  1171. am_server ? "on remote machine: " : "",
  1172. poptBadOption(pc, POPT_BADOPTION_NOALIAS),
  1173. poptStrerror(opt));
  1174. return 0;
  1175. }
  1176. }
  1177. if (human_readable && argc == 2 && !am_server) {
  1178. /* Allow the old meaning of 'h' (--help) on its own. */
  1179. usage(FINFO);
  1180. exit_cleanup(0);
  1181. }
  1182. #ifdef ICONV_OPTION
  1183. if (iconv_opt && protect_args != 2) {
  1184. if (!am_server && strcmp(iconv_opt, "-") == 0)
  1185. iconv_opt = NULL;
  1186. else
  1187. need_unsorted_flist = 1;
  1188. }
  1189. if (refused_no_iconv && !iconv_opt) {
  1190. create_refuse_error(refused_no_iconv);
  1191. return 0;
  1192. }
  1193. #endif
  1194. if (protect_args == 1 && am_server)
  1195. return 1;
  1196. *argv_p = argv = poptGetArgs(pc);
  1197. *argc_p = argc = count_args(argv);
  1198. #ifndef SUPPORT_LINKS
  1199. if (preserve_links && !am_sender) {
  1200. snprintf(err_buf, sizeof err_buf,
  1201. "symlinks are not supported on this %s\n",
  1202. am_server ? "server" : "client");
  1203. return 0;
  1204. }
  1205. #endif
  1206. #ifndef SUPPORT_HARD_LINKS
  1207. if (preserve_hard_links) {
  1208. snprintf(err_buf, sizeof err_buf,
  1209. "hard links are not supported on this %s\n",
  1210. am_server ? "server" : "client");
  1211. return 0;
  1212. }
  1213. #endif
  1214. #ifdef SUPPORT_XATTRS
  1215. if (am_root < 0 && preserve_xattrs > 1) {
  1216. snprintf(err_buf, sizeof err_buf,
  1217. "--fake-super conflicts with -XX\n");
  1218. return 0;
  1219. }
  1220. #else
  1221. if (am_root < 0) {
  1222. snprintf(err_buf, sizeof err_buf,
  1223. "--fake-super requires an rsync with extended attributes enabled\n");
  1224. return 0;
  1225. }
  1226. #endif
  1227. if (write_batch && read_batch) {
  1228. snprintf(err_buf, sizeof err_buf,
  1229. "--write-batch and --read-batch can not be used together\n");
  1230. return 0;
  1231. }
  1232. if (write_batch > 0 || read_batch) {
  1233. if (am_server) {
  1234. rprintf(FINFO,
  1235. "ignoring --%s-batch option sent to server\n",
  1236. write_batch ? "write" : "read");
  1237. /* We don't actually exit_cleanup(), so that we can
  1238. * still service older version clients that still send
  1239. * batch args to server. */
  1240. read_batch = write_batch = 0;
  1241. batch_name = NULL;
  1242. } else if (dry_run)
  1243. write_batch = 0;
  1244. } else if (write_batch < 0 && dry_run)
  1245. write_batch = 0;
  1246. if (read_batch && files_from) {
  1247. snprintf(err_buf, sizeof err_buf,
  1248. "--read-batch cannot be used with --files-from\n");
  1249. return 0;
  1250. }
  1251. if (read_batch && remove_source_files) {
  1252. snprintf(err_buf, sizeof err_buf,
  1253. "--read-batch cannot be used with --remove-%s-files\n",
  1254. remove_source_files == 1 ? "source" : "sent");
  1255. return 0;
  1256. }
  1257. if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
  1258. snprintf(err_buf, sizeof err_buf,
  1259. "the batch-file name must be %d characters or less.\n",
  1260. MAX_BATCH_NAME_LEN);
  1261. return 0;
  1262. }
  1263. if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
  1264. snprintf(err_buf, sizeof err_buf,
  1265. "the --temp-dir path is WAY too long.\n");
  1266. return 0;
  1267. }
  1268. if (max_delete < 0 && max_delete != INT_MIN) {
  1269. /* Negative numbers are treated as "no deletions". */
  1270. max_delete = 0;
  1271. }
  1272. if (compare_dest + copy_dest + link_dest > 1) {
  1273. snprintf(err_buf, sizeof err_buf,
  1274. "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
  1275. return 0;
  1276. }
  1277. if (files_from) {
  1278. if (recurse == 1) /* preserve recurse == 2 */
  1279. recurse = 0;
  1280. if (xfer_dirs < 0)
  1281. xfer_dirs = 1;
  1282. }
  1283. if (argc < 2 && !read_batch && !am_server)
  1284. list_only |= 1;
  1285. if (xfer_dirs >= 4) {
  1286. parse_rule(&filter_list, "- /*/*", 0, 0);
  1287. recurse = xfer_dirs = 1;
  1288. } else if (recurse)
  1289. xfer_dirs = 1;
  1290. else if (xfer_dirs < 0)
  1291. xfer_dirs = list_only ? 1 : 0;
  1292. if (relative_paths < 0)
  1293. relative_paths = files_from? 1 : 0;
  1294. if (!relative_paths)
  1295. implied_dirs = 0;
  1296. if (delete_before + !!delete_during + delete_after > 1) {
  1297. snprintf(err_buf, sizeof err_buf,
  1298. "You may not combine multiple --delete-WHEN options.\n");
  1299. return 0;
  1300. }
  1301. if (delete_before || delete_during || delete_after)
  1302. delete_mode = 1;
  1303. else if (delete_mode || delete_excluded) {
  1304. /* Only choose now between before & during if one is refused. */
  1305. if (refused_delete_before) {
  1306. if (!refused_delete_during)
  1307. delete_during = 1;
  1308. else {
  1309. create_refuse_error(refused_delete_before);
  1310. return 0;
  1311. }
  1312. } else if (refused_delete_during)
  1313. delete_before = 1;
  1314. delete_mode = 1;
  1315. }
  1316. if (!xfer_dirs && delete_mode) {
  1317. snprintf(err_buf, sizeof err_buf,
  1318. "--delete does not work without --recursive (-r) or --dirs (-d).\n");
  1319. return 0;
  1320. }
  1321. if (delete_mode && refused_delete) {
  1322. create_refuse_error(refused_delete);
  1323. return 0;
  1324. }
  1325. if (remove_source_files) {
  1326. /* We only want to infer this refusal of --remove-source-files
  1327. * via the refusal of "delete", not any of the "delete-FOO"
  1328. * options. */
  1329. if (refused_delete && am_sender) {
  1330. create_refuse_error(refused_delete);
  1331. return 0;
  1332. }
  1333. need_messages_from_generator = 1;
  1334. }
  1335. if (sanitize_paths) {
  1336. int i;
  1337. for (i = argc; i-- > 0; )
  1338. argv[i] = sanitize_path(NULL, argv[i], "", 0, SP_KEEP_DOT_DIRS);
  1339. if (tmpdir)
  1340. tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, SP_DEFAULT);
  1341. if (backup_dir)
  1342. backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, SP_DEFAULT);
  1343. }
  1344. if (daemon_filter_list.head && !am_sender) {
  1345. struct filter_list_struct *elp = &daemon_filter_list;
  1346. if (tmpdir) {
  1347. char *dir;
  1348. if (!*tmpdir)
  1349. goto options_rejected;
  1350. dir = tmpdir + (*tmpdir == '/' ? module_dirlen : 0);
  1351. clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
  1352. if (check_filter(elp, FLOG, dir, 1) < 0)
  1353. goto options_rejected;
  1354. }
  1355. if (backup_dir) {
  1356. char *dir;
  1357. if (!*backup_dir)
  1358. goto options_rejected;
  1359. dir = backup_dir + (*backup_dir == '/' ? module_dirlen : 0);
  1360. clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
  1361. if (check_filter(elp, FLOG, dir, 1) < 0)
  1362. goto options_rejected;
  1363. }
  1364. }
  1365. if (!backup_suffix)
  1366. backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
  1367. backup_suffix_len = strlen(backup_suffix);
  1368. if (strchr(backup_suffix, '/') != NULL) {
  1369. snprintf(err_buf, sizeof err_buf,
  1370. "--suffix cannot contain slashes: %s\n",
  1371. backup_suffix);
  1372. return 0;
  1373. }
  1374. if (backup_dir) {
  1375. size_t len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
  1376. if (len > sizeof backup_dir_buf - 128) {
  1377. snprintf(err_buf, sizeof err_buf,
  1378. "the --backup-dir path is WAY too long.\n");
  1379. return 0;
  1380. }
  1381. backup_dir_len = (int)len;
  1382. if (backup_dir_buf[backup_dir_len - 1] != '/') {
  1383. backup_dir_buf[backup_dir_len++] = '/';
  1384. backup_dir_buf[backup_dir_len] = '\0';
  1385. }
  1386. backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
  1387. if (verbose > 1 && !am_sender)
  1388. rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
  1389. } else if (!backup_suffix_len && (!am_server || !am_sender)) {
  1390. snprintf(err_buf, sizeof err_buf,
  1391. "--suffix cannot be a null string without --backup-dir\n");
  1392. return 0;
  1393. } else if (make_backups && delete_mode && !delete_excluded && !am_server) {
  1394. snprintf(backup_dir_buf, sizeof backup_dir_buf,
  1395. "P *%s", backup_suffix);
  1396. parse_rule(&filter_list, backup_dir_buf, 0, 0);
  1397. }
  1398. if (preserve_times) {
  1399. preserve_times = PRESERVE_FILE_TIMES;
  1400. if (!omit_dir_times)
  1401. preserve_times |= PRESERVE_DIR_TIMES;
  1402. #ifdef CAN_SET_SYMLINK_TIMES
  1403. preserve_times |= PRESERVE_LINK_TIMES;
  1404. #endif
  1405. }
  1406. if (make_backups && !backup_dir) {
  1407. omit_dir_times = 0; /* Implied, so avoid -O to sender. */
  1408. preserve_times &= ~PRESERVE_DIR_TIMES;
  1409. }
  1410. if (stdout_format) {
  1411. if (am_server && log_format_has(stdout_format, 'I'))
  1412. stdout_format_has_i = 2;
  1413. else if (log_format_has(stdout_format, 'i'))
  1414. stdout_format_has_i = itemize_changes | 1;
  1415. if (!log_format_has(stdout_format, 'b')
  1416. && !log_format_has(stdout_format, 'c'))
  1417. log_before_transfer = !am_server;
  1418. } else if (itemize_changes) {
  1419. stdout_format = "%i %n%L";
  1420. stdout_format_has_i = itemize_changes;
  1421. log_before_transfer = !am_server;
  1422. }
  1423. if (do_progress && !verbose && !log_before_transfer && !am_server)
  1424. verbose = 1;
  1425. if (dry_run)
  1426. do_xfers = 0;
  1427. set_io_timeout(io_timeout);
  1428. if (verbose && !stdout_format) {
  1429. stdout_format = "%n%L";
  1430. log_before_transfer = !am_server;
  1431. }
  1432. if (stdout_format_has_i || log_format_has(stdout_format, 'o'))
  1433. stdout_format_has_o_or_i = 1;
  1434. if (logfile_name && !am_daemon) {
  1435. if (!logfile_format) {
  1436. logfile_format = "%i %n%L";
  1437. logfile_format_has_i = logfile_format_has_o_or_i = 1;
  1438. } else {
  1439. if (log_format_has(logfile_format, 'i'))
  1440. logfile_format_has_i = 1;
  1441. if (logfile_format_has_i || log_format_has(logfile_format, 'o'))
  1442. logfile_format_has_o_or_i = 1;
  1443. }
  1444. log_init(0);
  1445. } else if (!am_daemon)
  1446. logfile_format = NULL;
  1447. if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
  1448. bwlimit = daemon_bwlimit;
  1449. if (bwlimit) {
  1450. bwlimit_writemax = (size_t)bwlimit * 128;
  1451. if (bwlimit_writemax < 512)
  1452. bwlimit_writemax = 512;
  1453. }
  1454. if (sparse_files && inplace) {
  1455. /* Note: we don't check for this below, because --append is
  1456. * OK with --sparse (as long as redos are handled right). */
  1457. snprintf(err_buf, sizeof err_buf,
  1458. "--sparse cannot be used with --inplace\n");
  1459. return 0;
  1460. }
  1461. if (append_mode) {
  1462. if (whole_file > 0) {
  1463. snprintf(err_buf, sizeof err_buf,
  1464. "--append cannot be used with --whole-file\n");
  1465. return 0;
  1466. }
  1467. if (refused_inplace) {
  1468. create_refuse_error(refused_inplace);
  1469. return 0;
  1470. }
  1471. inplace = 1;
  1472. }
  1473. if (delay_updates && !partial_dir)
  1474. partial_dir = tmp_partialdir;
  1475. if (inplace) {
  1476. #ifdef HAVE_FTRUNCATE
  1477. if (partial_dir) {
  1478. snprintf(err_buf, sizeof err_buf,
  1479. "--%s cannot be used with --%s\n",
  1480. append_mode ? "append" : "inplace",
  1481. delay_updates ? "delay-updates" : "partial-dir");
  1482. return 0;
  1483. }
  1484. /* --inplace implies --partial for refusal purposes, but we
  1485. * clear the keep_partial flag for internal logic purposes. */
  1486. if (refused_partial) {
  1487. create_refuse_error(refused_partial);
  1488. return 0;
  1489. }
  1490. keep_partial = 0;
  1491. #else
  1492. snprintf(err_buf, sizeof err_buf,
  1493. "--%s is not supported on this %s\n",
  1494. append_mode ? "append" : "inplace",
  1495. am_server ? "server" : "client");
  1496. return 0;
  1497. #endif
  1498. } else {
  1499. if (keep_partial && !partial_dir && !am_server) {
  1500. if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
  1501. partial_dir = strdup(arg);
  1502. }
  1503. if (partial_dir) {
  1504. if (*partial_dir)
  1505. clean_fname(partial_dir, CFN_COLLAPSE_DOT_DOT_DIRS);
  1506. if (!*partial_dir || strcmp(partial_dir, ".") == 0)
  1507. partial_dir = NULL;
  1508. if (!partial_dir && refused_partial) {
  1509. create_refuse_error(refused_partial);
  1510. return 0;
  1511. }
  1512. keep_partial = 1;
  1513. }
  1514. }
  1515. if (files_from) {
  1516. char *h, *p;
  1517. int q;
  1518. if (argc > 2 || (!am_daemon && argc == 1)) {
  1519. usage(FERROR);
  1520. exit_cleanup(RERR_SYNTAX);
  1521. }
  1522. if (strcmp(files_from, "-") == 0) {
  1523. filesfrom_fd = 0;
  1524. if (am_server)
  1525. filesfrom_host = ""; /* reading from socket */
  1526. } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
  1527. if (am_server) {
  1528. snprintf(err_buf, sizeof err_buf,
  1529. "The --files-from sent to the server cannot specify a host.\n");
  1530. return 0;
  1531. }
  1532. files_from = p;
  1533. filesfrom_host = h;
  1534. if (strcmp(files_from, "-") == 0) {
  1535. snprintf(err_buf, sizeof err_buf,
  1536. "Invalid --files-from remote filename\n");
  1537. return 0;
  1538. }
  1539. } else {
  1540. if (sanitize_paths)
  1541. files_from = sanitize_path(NULL, files_from, NULL, 0, SP_DEFAULT);
  1542. if (daemon_filter_list.head) {
  1543. char *dir;
  1544. if (!*files_from)
  1545. goto options_rejected;
  1546. dir = files_from + (*files_from == '/' ? module_dirlen : 0);
  1547. clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
  1548. if (check_filter(&daemon_filter_list, FLOG, dir, 0) < 0)
  1549. goto options_rejected;
  1550. }
  1551. filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
  1552. if (filesfrom_fd < 0) {
  1553. snprintf(err_buf, sizeof err_buf,
  1554. "failed to open files-from file %s: %s\n",
  1555. files_from, strerror(errno));
  1556. return 0;
  1557. }
  1558. }
  1559. }
  1560. am_starting_up = 0;
  1561. return 1;
  1562. options_rejected:
  1563. snprintf(err_buf, sizeof err_buf,
  1564. "Your options have been rejected by the server.\n");
  1565. return 0;
  1566. }
  1567. /**
  1568. * Construct a filtered list of options to pass through from the
  1569. * client to the server.
  1570. *
  1571. * This involves setting options that will tell the server how to
  1572. * behave, and also filtering out options that are processed only
  1573. * locally.
  1574. **/
  1575. void server_options(char **args, int *argc_p)
  1576. {
  1577. static char argstr[64];
  1578. int ac = *argc_p;
  1579. char *arg;
  1580. int i, x;
  1581. /* This should always remain first on the server's command-line. */
  1582. args[ac++] = "--server";
  1583. if (daemon_over_rsh > 0) {
  1584. args[ac++] = "--daemon";
  1585. *argc_p = ac;
  1586. /* if we're passing --daemon, we're done */
  1587. return;
  1588. }
  1589. if (!am_sender)
  1590. args[ac++] = "--sender";
  1591. x = 1;
  1592. argstr[0] = '-';
  1593. if (protect_args)
  1594. argstr[x++] = 's';
  1595. for (i = 0; i < verbose; i++)
  1596. argstr[x++] = 'v';
  1597. /* the -q option is intentionally left out */
  1598. if (make_backups)
  1599. argstr[x++] = 'b';
  1600. if (update_only)
  1601. argstr[x++] = 'u';
  1602. if (!do_xfers) /* Note: NOT "dry_run"! */
  1603. argstr[x++] = 'n';
  1604. if (preserve_links)
  1605. argstr[x++] = 'l';
  1606. if ((xfer_dirs >= 2 && xfer_dirs < 4)
  1607. || (xfer_dirs && !recurse && (list_only || (delete_mode && am_sender))))
  1608. argstr[x++] = 'd';
  1609. if (am_sender) {
  1610. if (keep_dirlinks)
  1611. argstr[x++] = 'K';
  1612. if (prune_empty_dirs)
  1613. argstr[x++] = 'm';
  1614. if (omit_dir_times)
  1615. argstr[x++] = 'O';
  1616. } else {
  1617. if (copy_links)
  1618. argstr[x++] = 'L';
  1619. if (copy_dirlinks)
  1620. argstr[x++] = 'k';
  1621. }
  1622. if (whole_file > 0)
  1623. argstr[x++] = 'W';
  1624. /* We don't need to send --no-whole-file, because it's the
  1625. * default for remote transfers, and in any case old versions
  1626. * of rsync will not understand it. */
  1627. if (preserve_hard_links) {
  1628. argstr[x++] = 'H';
  1629. if (preserve_hard_links > 1)
  1630. argstr[x++] = 'H';
  1631. }
  1632. if (preserve_uid)
  1633. argstr[x++] = 'o';
  1634. if (preserve_gid)
  1635. argstr[x++] = 'g';
  1636. if (preserve_devices) /* ignore preserve_specials here */
  1637. argstr[x++] = 'D';
  1638. if (preserve_times)
  1639. argstr[x++] = 't';
  1640. if (preserve_perms)
  1641. argstr[x++] = 'p';
  1642. else if (preserve_executability && am_sender)
  1643. argstr[x++] = 'E';
  1644. #ifdef SUPPORT_ACLS
  1645. if (preserve_acls)
  1646. argstr[x++] = 'A';
  1647. #endif
  1648. #ifdef SUPPORT_XATTRS
  1649. if (preserve_xattrs) {
  1650. argstr[x++] = 'X';
  1651. if (preserve_xattrs > 1)
  1652. argstr[x++] = 'X';
  1653. }
  1654. #endif
  1655. if (recurse)
  1656. argstr[x++] = 'r';
  1657. if (always_checksum)
  1658. argstr[x++] = 'c';
  1659. if (cvs_exclude)
  1660. argstr[x++] = 'C';
  1661. if (ignore_times)
  1662. argstr[x++] = 'I';
  1663. if (relative_paths)
  1664. argstr[x++] = 'R';
  1665. if (one_file_system) {
  1666. argstr[x++] = 'x';
  1667. if (one_file_system > 1)
  1668. argstr[x++] = 'x';
  1669. }
  1670. if (sparse_files)
  1671. argstr[x++] = 'S';
  1672. if (do_compression)
  1673. argstr[x++] = 'z';
  1674. set_allow_inc_recurse();
  1675. /* Checking the pre-negotiated value allows --protocol=29 override. */
  1676. if (protocol_version >= 30) {
  1677. /* We make use of the -e option to let the server know about
  1678. * any pre-release protocol version && some behavior flags. */
  1679. argstr[x++] = 'e';
  1680. #if SUBPROTOCOL_VERSION != 0
  1681. if (protocol_version == PROTOCOL_VERSION) {
  1682. x += snprintf(argstr+x, sizeof argstr - x,
  1683. "%d.%d",
  1684. PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
  1685. } else
  1686. #endif
  1687. argstr[x++] = '.';
  1688. if (allow_inc_recurse)
  1689. argstr[x++] = 'i';
  1690. #ifdef CAN_SET_SYMLINK_TIMES
  1691. argstr[x++] = 'L';
  1692. #endif
  1693. #ifdef ICONV_OPTION
  1694. argstr[x++] = 's';
  1695. #endif
  1696. argstr[x++] = 'f';
  1697. }
  1698. if (x >= (int)sizeof argstr) { /* Not possible... */
  1699. rprintf(FERROR, "argstr overflow in server_options().\n");
  1700. exit_cleanup(RERR_MALLOC);
  1701. }
  1702. argstr[x] = '\0';
  1703. if (x > 1)
  1704. args[ac++] = argstr;
  1705. #ifdef ICONV_OPTION
  1706. if (iconv_opt) {
  1707. char *set = strchr(iconv_opt, ',');
  1708. if (set)
  1709. set++;
  1710. else
  1711. set = iconv_opt;
  1712. if (asprintf(&arg, "--iconv=%s", set) < 0)
  1713. goto oom;
  1714. args[ac++] = arg;
  1715. }
  1716. #endif
  1717. if (protect_args && !local_server) /* unprotected args stop here */
  1718. args[ac++] = NULL;
  1719. if (list_only > 1)
  1720. args[ac++] = "--list-only";
  1721. /* This makes sure that the remote rsync can handle deleting with -d
  1722. * sans -r because the --no-r option was added at the same time. */
  1723. if (xfer_dirs && !recurse && delete_mode && am_sender)
  1724. args[ac++] = "--no-r";
  1725. if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
  1726. if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
  1727. goto oom;
  1728. args[ac++] = arg;
  1729. }
  1730. if (preserve_devices) {
  1731. /* Note: sending "--devices" would not be backward-compatible. */
  1732. if (!preserve_specials)
  1733. args[ac++] = "--no-specials"; /* -D is already set. */
  1734. } else if (preserve_specials)
  1735. args[ac++] = "--specials";
  1736. /* The server side doesn't use our log-format, but in certain
  1737. * circumstances they need to know a little about the option. */
  1738. if (stdout_format && am_sender) {
  1739. /* Use --log-format, not --out-format, for compatibility. */
  1740. if (stdout_format_has_i > 1)
  1741. args[ac++] = "--log-format=%i%I";
  1742. else if (stdout_format_has_i)
  1743. args[ac++] = "--log-format=%i";
  1744. else if (stdout_format_has_o_or_i)
  1745. args[ac++] = "--log-format=%o";
  1746. else if (!verbose)
  1747. args[ac++] = "--log-format=X";
  1748. }
  1749. if (block_size) {
  1750. if (asprintf(&arg, "-B%lu", block_size) < 0)
  1751. goto oom;
  1752. args[ac++] = arg;
  1753. }
  1754. if (io_timeout) {
  1755. if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
  1756. goto oom;
  1757. args[ac++] = arg;
  1758. }
  1759. if (bwlimit) {
  1760. if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
  1761. goto oom;
  1762. args[ac++] = arg;
  1763. }
  1764. if (backup_dir) {
  1765. args[ac++] = "--backup-dir";
  1766. args[ac++] = backup_dir;
  1767. }
  1768. /* Only send --suffix if it specifies a non-default value. */
  1769. if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
  1770. /* We use the following syntax to avoid weirdness with '~'. */
  1771. if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
  1772. goto oom;
  1773. args[ac++] = arg;
  1774. }
  1775. if (am_sender) {
  1776. if (max_delete > 0) {
  1777. if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
  1778. goto oom;
  1779. args[ac++] = arg;
  1780. } else if (max_delete == 0)
  1781. args[ac++] = "--max-delete=-1";
  1782. if (min_size) {
  1783. args[ac++] = "--min-size";
  1784. args[ac++] = min_size_arg;
  1785. }
  1786. if (max_size) {
  1787. args[ac++] = "--max-size";
  1788. args[ac++] = max_size_arg;
  1789. }
  1790. if (delete_before)
  1791. args[ac++] = "--delete-before";
  1792. else if (delete_during == 2)
  1793. args[ac++] = "--delete-delay";
  1794. else if (delete_during)
  1795. args[ac++] = "--delete-during";
  1796. else if (delete_after)
  1797. args[ac++] = "--delete-after";
  1798. else if (delete_mode && !delete_excluded)
  1799. args[ac++] = "--delete";
  1800. if (delete_excluded)
  1801. args[ac++] = "--delete-excluded";
  1802. if (force_delete)
  1803. args[ac++] = "--force";
  1804. if (write_batch < 0)
  1805. args[ac++] = "--only-write-batch=X";
  1806. if (am_root > 1)
  1807. args[ac++] = "--super";
  1808. if (size_only)
  1809. args[ac++] = "--size-only";
  1810. } else {
  1811. if (skip_compress) {
  1812. if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
  1813. goto oom;
  1814. args[ac++] = arg;
  1815. }
  1816. }
  1817. if (modify_window_set) {
  1818. if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
  1819. goto oom;
  1820. args[ac++] = arg;
  1821. }
  1822. if (checksum_seed) {
  1823. if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
  1824. goto oom;
  1825. args[ac++] = arg;
  1826. }
  1827. if (partial_dir && am_sender) {
  1828. if (partial_dir != tmp_partialdir) {
  1829. args[ac++] = "--partial-dir";
  1830. args[ac++] = partial_dir;
  1831. }
  1832. if (delay_updates)
  1833. args[ac++] = "--delay-updates";
  1834. } else if (keep_partial && am_sender)
  1835. args[ac++] = "--partial";
  1836. if (ignore_errors)
  1837. args[ac++] = "--ignore-errors";
  1838. if (copy_unsafe_links)
  1839. args[ac++] = "--copy-unsafe-links";
  1840. if (safe_symlinks)
  1841. args[ac++] = "--safe-links";
  1842. if (numeric_ids)
  1843. args[ac++] = "--numeric-ids";
  1844. if (use_qsort)
  1845. args[ac++] = "--use-qsort";
  1846. if (am_sender) {
  1847. if (ignore_existing)
  1848. args[ac++] = "--ignore-existing";
  1849. /* Backward compatibility: send --existing, not --ignore-non-existing. */
  1850. if (ignore_non_existing)
  1851. args[ac++] = "--existing";
  1852. if (tmpdir) {
  1853. args[ac++] = "--temp-dir";
  1854. args[ac++] = tmpdir;
  1855. }
  1856. if (basis_dir[0]) {
  1857. /* the server only needs this option if it is not the sender,
  1858. * and it may be an older version that doesn't know this
  1859. * option, so don't send it if client is the sender.
  1860. */
  1861. for (i = 0; i < basis_dir_cnt; i++) {
  1862. args[ac++] = dest_option;
  1863. args[ac++] = basis_dir[i];
  1864. }
  1865. }
  1866. }
  1867. if (append_mode) {
  1868. if (append_mode > 1)
  1869. args[ac++] = "--append";
  1870. args[ac++] = "--append";
  1871. } else if (inplace)
  1872. args[ac++] = "--inplace";
  1873. if (files_from && (!am_sender || filesfrom_host)) {
  1874. if (filesfrom_host) {
  1875. args[ac++] = "--files-from";
  1876. args[ac++] = files_from;
  1877. if (eol_nulls)
  1878. args[ac++] = "--from0";
  1879. } else {
  1880. args[ac++] = "--files-from=-";
  1881. args[ac++] = "--from0";
  1882. }
  1883. if (!relative_paths)
  1884. args[ac++] = "--no-relative";
  1885. }
  1886. /* It's OK that this checks the upper-bound of the protocol_version. */
  1887. if (relative_paths && !implied_dirs && (!am_sender || protocol_version >= 30))
  1888. args[ac++] = "--no-implied-dirs";
  1889. if (fuzzy_basis && am_sender)
  1890. args[ac++] = "--fuzzy";
  1891. if (remove_source_files == 1)
  1892. args[ac++] = "--remove-source-files";
  1893. else if (remove_source_files)
  1894. args[ac++] = "--remove-sent-files";
  1895. if (ac > MAX_SERVER_ARGS) { /* Not possible... */
  1896. rprintf(FERROR, "argc overflow in server_options().\n");
  1897. exit_cleanup(RERR_MALLOC);
  1898. }
  1899. *argc_p = ac;
  1900. return;
  1901. oom:
  1902. out_of_memory("server_options");
  1903. }
  1904. /* If str points to a valid hostspec, return allocated memory containing the
  1905. * [USER@]HOST part of the string, and set the path_start_ptr to the part of
  1906. * the string after the host part. Otherwise, return NULL. If port_ptr is
  1907. * non-NULL, we must be parsing an rsync:// URL hostname, and we will set
  1908. * *port_ptr if a port number is found. Note that IPv6 IPs will have their
  1909. * (required for parsing) [ and ] chars elided from the returned string. */
  1910. static char *parse_hostspec(char *str, char **path_start_ptr, int *port_ptr)
  1911. {
  1912. char *s, *host_start = str;
  1913. int hostlen = 0, userlen = 0;
  1914. char *ret;
  1915. for (s = str; ; s++) {
  1916. if (!*s) {
  1917. /* It is only OK if we run out of string with rsync:// */
  1918. if (!port_ptr)
  1919. return NULL;
  1920. if (!hostlen)
  1921. hostlen = s - host_start;
  1922. break;
  1923. }
  1924. if (*s == ':' || *s == '/') {
  1925. if (!hostlen)
  1926. hostlen = s - host_start;
  1927. if (*s++ == '/') {
  1928. if (!port_ptr)
  1929. return NULL;
  1930. } else if (port_ptr) {
  1931. *port_ptr = atoi(s);
  1932. while (isDigit(s)) s++;
  1933. if (*s && *s++ != '/')
  1934. return NULL;
  1935. }
  1936. break;
  1937. }
  1938. if (*s == '@') {
  1939. userlen = s - str + 1;
  1940. host_start = s + 1;
  1941. } else if (*s == '[') {
  1942. if (s != host_start++)
  1943. return NULL;
  1944. while (*s && *s != ']' && *s != '/') s++; /*SHARED ITERATOR*/
  1945. hostlen = s - host_start;
  1946. if (*s != ']' || (s[1] && s[1] != '/' && s[1] != ':') || !hostlen)
  1947. return NULL;
  1948. }
  1949. }
  1950. *path_start_ptr = s;
  1951. ret = new_array(char, userlen + hostlen + 1);
  1952. if (userlen)
  1953. strlcpy(ret, str, userlen + 1);
  1954. strlcpy(ret + userlen, host_start, hostlen + 1);
  1955. return ret;
  1956. }
  1957. /* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or
  1958. * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated
  1959. * memory with the HOST. If a daemon-accessing spec was specified, the value
  1960. * of *port_ptr will contain a non-0 port number, otherwise it will be set to
  1961. * 0. The return value is a pointer to the PATH. Note that the HOST spec can
  1962. * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or
  1963. * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */
  1964. char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
  1965. {
  1966. char *path;
  1967. if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
  1968. *host_ptr = parse_hostspec(s + strlen(URL_PREFIX), &path, port_ptr);
  1969. if (*host_ptr) {
  1970. if (!*port_ptr)
  1971. *port_ptr = RSYNC_PORT;
  1972. return path;
  1973. }
  1974. }
  1975. *host_ptr = parse_hostspec(s, &path, NULL);
  1976. if (!*host_ptr)
  1977. return NULL;
  1978. if (*path == ':') {
  1979. if (port_ptr && !*port_ptr)
  1980. *port_ptr = RSYNC_PORT;
  1981. return path + 1;
  1982. }
  1983. if (port_ptr)
  1984. *port_ptr = 0;
  1985. return path;
  1986. }