示例#1
0
static void time_parse(struct xt_option_call *cb)
{
	struct xt_time_info *info = cb->data;

	xtables_option_parse(cb);
	switch (cb->entry->id) {
	case O_DATE_START:
		info->date_start = time_parse_date(cb->arg, false);
		break;
	case O_DATE_STOP:
		info->date_stop = time_parse_date(cb->arg, true);
		break;
	case O_TIME_START:
		info->daytime_start = time_parse_minutes(cb->arg);
		break;
	case O_TIME_STOP:
		info->daytime_stop = time_parse_minutes(cb->arg);
		break;
	case O_TIME_CONTIGUOUS:
		info->flags |= XT_TIME_CONTIGUOUS;
		break;
	case O_LOCAL_TZ:
		fprintf(stderr, "WARNING: --localtz is being replaced by "
		        "--kerneltz, since \"local\" is ambiguous. Note the "
		        "kernel timezone has caveats - "
		        "see manpage for details.\n");
		/* fallthrough */
	case O_KERNEL_TZ:
		info->flags |= XT_TIME_LOCAL_TZ;
		break;
	case O_MONTHDAYS:
		info->monthdays_match = time_parse_monthdays(cb->arg);
		if (cb->invert)
			info->monthdays_match ^= XT_TIME_ALL_MONTHDAYS;
		break;
	case O_WEEKDAYS:
		info->weekdays_match = time_parse_weekdays(cb->arg);
		if (cb->invert)
			info->weekdays_match ^= XT_TIME_ALL_WEEKDAYS;
		break;
	}
}
static int time_parse(int c, char **argv, int invert, unsigned int *flags,
                      const void *entry, struct xt_entry_match **match)
{
	struct xt_time_info *info = (void *)(*match)->data;

	switch (c) {
	case 'D': /* --datestart */
		if (*flags & F_DATE_START)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --datestart twice");
		if (invert)
			xtables_error(PARAMETER_PROBLEM,
			           "Unexpected \"!\" with --datestart");
		info->date_start = time_parse_date(optarg, false);
		*flags |= F_DATE_START;
		return 1;
	case 'E': /* --datestop */
		if (*flags & F_DATE_STOP)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --datestop more than once");
		if (invert)
			xtables_error(PARAMETER_PROBLEM,
			           "unexpected \"!\" with --datestop");
		info->date_stop = time_parse_date(optarg, true);
		*flags |= F_DATE_STOP;
		return 1;
	case 'X': /* --timestart */
		if (*flags & F_TIME_START)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --timestart more than once");
		if (invert)
			xtables_error(PARAMETER_PROBLEM,
			           "Unexpected \"!\" with --timestart");
		info->daytime_start = time_parse_minutes(optarg);
		*flags |= F_TIME_START;
		return 1;
	case 'Y': /* --timestop */
		if (*flags & F_TIME_STOP)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --timestop more than once");
		if (invert)
			xtables_error(PARAMETER_PROBLEM,
			           "Unexpected \"!\" with --timestop");
		info->daytime_stop = time_parse_minutes(optarg);
		*flags |= F_TIME_STOP;
		return 1;
	case 'l': /* --localtz */
		if (*flags & F_TIMEZONE)
			xtables_error(PARAMETER_PROBLEM,
			           "Can only specify exactly one of --localtz or --utc");
		info->flags |= XT_TIME_LOCAL_TZ;
		*flags |= F_TIMEZONE;
		return 1;
	case 'm': /* --monthdays */
		if (*flags & F_MONTHDAYS)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --monthdays more than once");
		info->monthdays_match = time_parse_monthdays(optarg);
		if (invert)
			info->monthdays_match ^= XT_TIME_ALL_MONTHDAYS;
		*flags |= F_MONTHDAYS;
		return 1;
	case 'w': /* --weekdays */
		if (*flags & F_WEEKDAYS)
			xtables_error(PARAMETER_PROBLEM,
			           "Cannot specify --weekdays more than once");
		info->weekdays_match = time_parse_weekdays(optarg);
		if (invert)
			info->weekdays_match ^= XT_TIME_ALL_WEEKDAYS;
		*flags |= F_WEEKDAYS;
		return 1;
	case 'u': /* --utc */
		if (*flags & F_TIMEZONE)
			xtables_error(PARAMETER_PROBLEM,
			           "Can only specify exactly one of --localtz or --utc");
		info->flags &= ~XT_TIME_LOCAL_TZ;
		*flags |= F_TIMEZONE;
		return 1;
	}
	return 0;
}