Example #1
0
void test_hash_format(void)
{
	static const char *fail_input[] = {
		"%",
		"%A{sha1}",
		"%{sha1",
		"%{sha1:8",
		"%{sha1:8a}",
		"%{sha1:0}",
		"%{sha1:168}",
		NULL
	};
	static struct hash_format_test tests[] = {
		{ "%{sha1}", "8843d7f92416211de9ebb963ff4ce28125932878" },
		{ "*%{sha1}*", "*8843d7f92416211de9ebb963ff4ce28125932878*" },
		{ "*%{sha1:8}*", "*88*" },
		{ "%{sha1:152}", "8843d7f92416211de9ebb963ff4ce281259328" },
		{ "%X{size}", "6" },
		{ "%{sha256:80}", "c3ab8ff13720e8ad9047" },
		{ "%{sha512:80}", "0a50261ebd1a390fed2b" },
		{ "%{md4}", "547aefd231dcbaac398625718336f143" },
		{ "%{md5}", "3858f62230ac3c915f300c664312c63f" },
		{ "%{sha256:80}-%X{size}", "c3ab8ff13720e8ad9047-6" }
	};
	struct hash_format *format;
	string_t *str = t_str_new(128);
	const char *error;
	unsigned int i;

	test_begin("hash_format");
	for (i = 0; fail_input[i] != NULL; i++)
		test_assert(hash_format_init(fail_input[i], &format, &error) < 0);

	for (i = 0; i < N_ELEMENTS(tests); i++) {
		test_assert(hash_format_init(tests[i].input, &format, &error) == 0);
		hash_format_loop(format, "foo", 3);
		hash_format_loop(format, "bar", 3);
		str_truncate(str, 0);
		hash_format_deinit(&format, str);
		test_assert(strcmp(str_c(str), tests[i].output) == 0);
	}
	test_end();
}
Example #2
0
/* <settings checks> */
static bool mail_storage_settings_check(void *_set, pool_t pool ATTR_UNUSED,
					const char **error_r)
{
	struct mail_storage_settings *set = _set;
	struct hash_format *format;
	const char *p, *error;
	bool uidl_format_ok;
	char c;

	if (set->mailbox_idle_check_interval == 0) {
		*error_r = "mailbox_idle_check_interval must not be 0";
		return FALSE;
	}

	if (strcmp(set->mail_fsync, "optimized") == 0)
		set->parsed_fsync_mode = FSYNC_MODE_OPTIMIZED;
	else if (strcmp(set->mail_fsync, "never") == 0)
		set->parsed_fsync_mode = FSYNC_MODE_NEVER;
	else if (strcmp(set->mail_fsync, "always") == 0)
		set->parsed_fsync_mode = FSYNC_MODE_ALWAYS;
	else {
		*error_r = t_strdup_printf("Unknown mail_fsync: %s",
					   set->mail_fsync);
		return FALSE;
	}

	if (set->mail_nfs_index && !set->mmap_disable) {
		*error_r = "mail_nfs_index=yes requires mmap_disable=yes";
		return FALSE;
	}
	if (set->mail_nfs_index &&
	    set->parsed_fsync_mode != FSYNC_MODE_ALWAYS) {
		*error_r = "mail_nfs_index=yes requires mail_fsync=always";
		return FALSE;
	}

	if (!file_lock_method_parse(set->lock_method,
				    &set->parsed_lock_method)) {
		*error_r = t_strdup_printf("Unknown lock_method: %s",
					   set->lock_method);
		return FALSE;
	}

	uidl_format_ok = FALSE;
	for (p = set->pop3_uidl_format; *p != '\0'; p++) {
		if (p[0] != '%' || p[1] == '\0')
			continue;

		c = var_get_key(++p);
		switch (c) {
		case 'v':
		case 'u':
		case 'm':
		case 'f':
		case 'g':
			uidl_format_ok = TRUE;
			break;
		case '%':
			break;
		default:
			*error_r = t_strdup_printf(
				"Unknown pop3_uidl_format variable: %%%c", c);
			return FALSE;
		}
	}
	if (!uidl_format_ok) {
		*error_r = "pop3_uidl_format setting doesn't contain any "
			"%% variables.";
		return FALSE;
	}

	if (strchr(set->mail_attachment_hash, '/') != NULL) {
		*error_r = "mail_attachment_hash setting "
			"must not contain '/' characters";
		return FALSE;
	}
	if (hash_format_init(set->mail_attachment_hash, &format, &error) < 0) {
		*error_r = t_strconcat("Invalid mail_attachment_hash setting: ",
				       error, NULL);
		return FALSE;
	}
	if (strchr(set->mail_attachment_hash, '-') != NULL) {
		*error_r = "mail_attachment_hash setting "
			"must not contain '-' characters";
		return FALSE;
	}
	hash_format_deinit_free(&format);
#ifndef CONFIG_BINARY
	if (*set->ssl_client_ca_dir != '\0' &&
	    access(set->ssl_client_ca_dir, X_OK) < 0) {
		*error_r = t_strdup_printf(
			"ssl_client_ca_dir: access(%s) failed: %m",
			set->ssl_client_ca_dir);
		return FALSE;
	}
#endif
	return TRUE;
}