1 A fairly decent attempt to add two new daemon module options:
4 postxfer-exec = COMMAND
6 The prexfer-exec command runs before the transfer happens, while the
7 postxfer-exec command runs after the transfer completes, even if the
8 transfer failed. The following environment variables will be set in
11 RSYNC_MODULE_NAME -- The name of the module being accessed
12 RSYNC_MODULE_PATH -- The path configured for the module
14 These environment variables will also be set for the postxfer-exec
17 RSYNC_EXIT_STATUS -- rsync's exit value. This will be 0 for a
18 successful run, a positive value for an error
19 that rsync returned (e.g. 23=partial xfer),
20 or a -1 if rsync failed to exit properly.
21 RSYNC_RAW_STATUS -- the raw exit value from waitpid()
23 Both commands are run by the user that started the daemon (not the
24 module's uid/gid setting) without any chroot() restrictions (even if
25 the module will/has run chroot()ed).
27 BUILD NOTE: You'll want to run "make proto" after applying this patch.
29 --- orig/clientserver.c 2005-06-10 21:33:27
30 +++ clientserver.c 2005-07-19 20:46:59
31 @@ -226,7 +226,7 @@ static int rsync_module(int f_in, int f_
32 char line[MAXPATHLEN];
33 uid_t uid = (uid_t)-2; /* canonically "nobody" */
34 gid_t gid = (gid_t)-2;
37 char *addr = client_addr(f_in);
38 char *host = client_name(f_in);
39 char *name = lp_name(i);
40 @@ -347,6 +347,49 @@ static int rsync_module(int f_in, int f_
44 + s = lp_prexfer_exec(i);
45 + p = lp_postxfer_exec(i);
46 + if ((s && *s) || (p && *p)) {
47 + char *modname, *modpath;
49 + if (asprintf(&modname, "RSYNC_MODULE_NAME=%s", name) < 0)
50 + out_of_memory("rsync_module");
52 + if (asprintf(&modpath, "RSYNC_MODULE_PATH=%s", lp_path(i)) < 0)
53 + out_of_memory("rsync_module");
57 + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
58 + rprintf(FLOG, "prexfer-exec failed\n");
59 + io_printf(f_out, "@ERROR: prexfer-exec failed\n");
66 + rsyserr(FLOG, errno, "fork failed");
67 + io_printf(f_out, "@ERROR: fork failed\n");
72 + waitpid(pid, &status, 0);
73 + if (asprintf(&ret1, "RSYNC_RAW_STATUS=%d", status) > 0)
75 + if (WIFEXITED(status))
76 + status = WEXITSTATUS(status);
79 + if (asprintf(&ret2, "RSYNC_EXIT_STATUS=%d", status) > 0)
89 * XXX: The 'use chroot' flag is a fairly reliable
90 --- orig/loadparm.c 2005-06-10 21:33:28
91 +++ loadparm.c 2005-07-19 20:05:26
92 @@ -140,6 +140,8 @@ typedef struct
97 + char *postxfer_exec;
101 @@ -175,6 +177,8 @@ static service sDefault =
102 "%o %h [%a] %m (%u) %f %l", /* log format */
103 NULL, /* refuse options */
104 "*.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz", /* dont compress */
105 + NULL, /* prexfer_exec */
106 + NULL, /* postxfer_exec */
108 0, /* max connections */
109 1, /* max verbosity */
110 @@ -298,6 +302,8 @@ static struct parm_struct parm_table[] =
111 {"log format", P_STRING, P_LOCAL, &sDefault.log_format, NULL, 0},
112 {"refuse options", P_STRING, P_LOCAL, &sDefault.refuse_options,NULL, 0},
113 {"dont compress", P_STRING, P_LOCAL, &sDefault.dont_compress,NULL, 0},
114 + {"prexfer-exec", P_STRING, P_LOCAL, &sDefault.prexfer_exec, NULL, 0},
115 + {"postxfer-exec", P_STRING, P_LOCAL, &sDefault.postxfer_exec,NULL, 0},
116 {NULL, P_BOOL, P_NONE, NULL, NULL, 0}
119 @@ -379,6 +385,8 @@ FN_LOCAL_STRING(lp_include_from, include
120 FN_LOCAL_STRING(lp_log_format, log_format)
121 FN_LOCAL_STRING(lp_refuse_options, refuse_options)
122 FN_LOCAL_STRING(lp_dont_compress, dont_compress)
123 +FN_LOCAL_STRING(lp_prexfer_exec, prexfer_exec)
124 +FN_LOCAL_STRING(lp_postxfer_exec, postxfer_exec)
125 FN_LOCAL_INTEGER(lp_timeout, timeout)
126 FN_LOCAL_INTEGER(lp_max_connections, max_connections)
127 FN_LOCAL_INTEGER(lp_max_verbosity, max_verbosity)