return TRUE;
}
+#define doveadm_cmd_param_int64_cast(type, check) \
+bool doveadm_cmd_param_##type(const struct doveadm_cmd_context *cctx, \
+ const char *name, type##_t *value_r) \
+{ \
+ int64_t value; \
+ bool ret = doveadm_cmd_param_int64(cctx, name, &value); \
+ if (ret) { \
+ i_assert(check); \
+ *value_r = (type##_t) value; \
+ } \
+ return ret; \
+}
+
+doveadm_cmd_param_int64_cast(uint64, value >= 0)
+doveadm_cmd_param_int64_cast(uint32, value >= 0 && value <= UINT32_MAX)
+doveadm_cmd_param_int64_cast(int32, value >= INT32_MIN && value <= INT32_MAX)
+
bool doveadm_cmd_param_int64(const struct doveadm_cmd_context *cctx,
const char *name, int64_t *value_r)
{
"Invalid number: %s", value);
return -1;
}
+ if ((param->flags & CMD_PARAM_FLAG_UNSIGNED) != 0 &&
+ param->value.v_int64 < 0) {
+ param->value_set = FALSE;
+ *error_r = t_strdup_printf(
+ "Cannot be negative: %s", value);
+ param->value_set = FALSE;
+ return -1;
+ }
break;
case CMD_PARAM_IP:
if (net_addr2ip(value, ¶m->value.v_ip) != 0) {
CMD_PARAM_FLAG_NONE = 0x0,
CMD_PARAM_FLAG_POSITIONAL = 0x1,
CMD_PARAM_FLAG_DO_NOT_EXPOSE = 0x2,
+ CMD_PARAM_FLAG_UNSIGNED = 0x4, /* int64 checked to be non negative */
} doveadm_cmd_param_flag_t;
typedef enum {
bool doveadm_cmd_param_int64(const struct doveadm_cmd_context *cctx,
const char *name, int64_t *value_r);
+bool doveadm_cmd_param_uint64(const struct doveadm_cmd_context *cctx,
+ const char *name, uint64_t *value_r);
+bool doveadm_cmd_param_int32(const struct doveadm_cmd_context *cctx,
+ const char *name, int32_t *value_r);
+bool doveadm_cmd_param_uint32(const struct doveadm_cmd_context *cctx,
+ const char *name, uint32_t *value_r);
bool doveadm_cmd_param_str(const struct doveadm_cmd_context *cctx,
const char *name, const char **value_r);
bool doveadm_cmd_param_ip(const struct doveadm_cmd_context *cctx,
.usage = "[-u <user>] [-t <timestamp-nsecs>] <dict uri> <key> <value>",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0)
-DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('\0', "dict-uri", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "value", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
.usage = "[-u <user>] [-t <timestamp-nsecs>] <dict uri> <key>",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0)
-DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('\0', "dict-uri", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAMS_END
.usage = "[-u <user>] [-t <timestamp-nsecs>] <dict uri> <key> <diff>",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0)
-DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('t', "timestamp", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('\0', "dict-uri", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "difference", CMD_PARAM_INT64, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('a', "socket-path", CMD_PARAM_STR, 0)
DOVEADM_CMD_PARAM('F', "force-flush", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM('\0', "max-parallel", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('\0', "max-parallel", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('\0', "host", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAMS_END
},
.usage = "[-R] [-n <count>] <fs-driver> <fs-args> <path> [<path> ...]",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('R', "recursive", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM('n', "max-parallel", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('n', "max-parallel", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
.usage = "[-s <min_timestamp>]",
.cmd = cmd_log_errors,
DOVEADM_CMD_PARAMS_START
-DOVEADM_CMD_PARAM('s', "since", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('s', "since", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAMS_END
}
};
const char *scheme = NULL;
const char *plaintext = NULL;
const char *test_hash = NULL;
- bool list_schemes = FALSE, reverse_verify = FALSE;
- int64_t rounds_int64;
+ bool list_schemes = FALSE;
struct module_dir_load_settings mod_set;
struct password_generate_params gen_params;
i_zero(&gen_params);
(void)doveadm_cmd_param_bool(cctx, "list", &list_schemes);
(void)doveadm_cmd_param_str(cctx, "plaintext", &plaintext);
- if (doveadm_cmd_param_int64(cctx, "rounds", &rounds_int64)) {
- if (rounds_int64 > UINT_MAX)
- i_fatal("Invalid number of rounds: %"PRId64, rounds_int64);
- gen_params.rounds = rounds_int64;
- }
+ (void)doveadm_cmd_param_uint32(cctx, "rounds", &gen_params.rounds);
(void)doveadm_cmd_param_str(cctx, "scheme", &scheme);
- if (doveadm_cmd_param_str(cctx, "test-hash", &test_hash))
- reverse_verify = TRUE;
(void)doveadm_cmd_param_str(cctx, "user", &gen_params.user);
- (void)doveadm_cmd_param_bool(cctx, "reverse-verify", &reverse_verify);
+ bool reverse_verify =
+ doveadm_cmd_param_flag(cctx, "reverse-verify") ||
+ doveadm_cmd_param_str(cctx, "test-hash", &test_hash);
if (list_schemes) {
ARRAY_TYPE(password_scheme_p) arr;
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('l', "list", CMD_PARAM_BOOL, 0)
DOVEADM_CMD_PARAM('p', "plaintext", CMD_PARAM_STR, 0)
-DOVEADM_CMD_PARAM('r', "rounds", CMD_PARAM_INT64, 0)
+DOVEADM_CMD_PARAM('r', "rounds", CMD_PARAM_INT64, CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAM('s', "scheme", CMD_PARAM_STR, 0)
DOVEADM_CMD_PARAM('t', "test-hash", CMD_PARAM_STR, 0)
DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0)
.usage = "<host> [<port>]",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('\0', "host", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM('\0', "port", CMD_PARAM_INT64, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "port", CMD_PARAM_INT64, CMD_PARAM_FLAG_POSITIONAL|CMD_PARAM_FLAG_UNSIGNED)
DOVEADM_CMD_PARAMS_END
};