Commit 27ed20f7 authored by Wayne Davison's avatar Wayne Davison

Fixed the "refuse options" setting in the daemon after Fabrice Bellet

identified what was wrong.
parent f567e9b3
...@@ -414,35 +414,28 @@ void option_error(void) ...@@ -414,35 +414,28 @@ void option_error(void)
/** /**
* Check to see if we should refuse this option * Tweak the option table to disable all options that the rsyncd.conf
* file has told us to refuse.
**/ **/
static int check_refuse_options(char *ref, int opt) static void set_refuse_options(char *bp)
{ {
int i, len; struct poptOption *op;
char *p; char *cp;
const char *name;
while (1) {
for (i = 0; long_options[i].longName; i++) { if ((cp = strchr(bp, ' ')) != NULL)
if (long_options[i].val == opt) *cp= '\0';
break; for (op = long_options; op->longName; op++) {
} if (strcmp(bp, op->longName) == 0) {
op->val = -(op - long_options) - 1;
if (!long_options[i].longName) break;
return 0; }
name = long_options[i].longName;
len = strlen(name);
while ((p = strstr(ref,name))) {
if ((p==ref || p[-1]==' ') &&
(p[len] == ' ' || p[len] == 0)) {
snprintf(err_buf, sizeof err_buf,
"The '%s' option is not supported by this server\n", name);
return 1;
} }
ref += len; if (!cp)
break;
*cp = ' ';
bp = cp + 1;
} }
return 0;
} }
...@@ -471,6 +464,9 @@ int parse_arguments(int *argc, const char ***argv, int frommain) ...@@ -471,6 +464,9 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
char *ref = lp_refuse_options(module_id); char *ref = lp_refuse_options(module_id);
poptContext pc; poptContext pc;
if (ref && *ref)
set_refuse_options(ref);
/* TODO: Call poptReadDefaultConfig; handle errors. */ /* TODO: Call poptReadDefaultConfig; handle errors. */
/* The context leaks in case of an error, but if there's a /* The context leaks in case of an error, but if there's a
...@@ -478,9 +474,6 @@ int parse_arguments(int *argc, const char ***argv, int frommain) ...@@ -478,9 +474,6 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0); pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0);
while ((opt = poptGetNextOpt(pc)) != -1) { while ((opt = poptGetNextOpt(pc)) != -1) {
if (ref && check_refuse_options(ref, opt))
return 0;
/* most options are handled automatically by popt; /* most options are handled automatically by popt;
* only special cases are returned and listed here. */ * only special cases are returned and listed here. */
...@@ -577,13 +570,25 @@ int parse_arguments(int *argc, const char ***argv, int frommain) ...@@ -577,13 +570,25 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
return 0; return 0;
#endif #endif
default: default:
snprintf(err_buf, sizeof err_buf, /* A negative opt value means that set_refuse_options()
"%s%s: %s\n", * turned this option off (-opt-1 is its index). */
am_server ? "on remote machine: " : "", if (opt < 0) {
poptBadOption(pc, POPT_BADOPTION_NOALIAS), struct poptOption *op = &long_options[-opt-1];
poptStrerror(opt)); int n = snprintf(err_buf, sizeof err_buf,
"This server does not support --%s\n",
op->longName) - 1;
if (op->shortName) {
snprintf(err_buf+n, sizeof err_buf-n,
" (-%c)\n", op->shortName);
}
} else {
snprintf(err_buf, sizeof err_buf,
"%s%s: %s\n",
am_server ? "on remote machine: " : "",
poptBadOption(pc, POPT_BADOPTION_NOALIAS),
poptStrerror(opt));
}
return 0; return 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment