diff --git a/src/home/home-util.h b/src/home/home-util.h index 5e633ea4af4..ca4c068f371 100644 --- a/src/home/home-util.h +++ b/src/home/home-util.h @@ -12,6 +12,13 @@ #define HOME_UID_MIN 60001 #define HOME_UID_MAX 60513 +/* Put some limits on disk sizes: not less than 5M, not more than 5T */ +#define USER_DISK_SIZE_MIN (UINT64_C(5)*1024*1024) +#define USER_DISK_SIZE_MAX (UINT64_C(5)*1024*1024*1024*1024) + +/* The default disk size to use when nothing else is specified, relative to free disk space */ +#define USER_DISK_SIZE_DEFAULT_PERCENT 85 + bool suitable_user_name(const char *name); int suitable_realm(const char *realm); int suitable_image_path(const char *path); diff --git a/src/home/user-record-util.c b/src/home/user-record-util.c index 464f1dbb7a0..276caaa172b 100644 --- a/src/home/user-record-util.c +++ b/src/home/user-record-util.c @@ -639,9 +639,6 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) { if (!h->json) return -EUNATCH; - if (disk_size < USER_DISK_SIZE_MIN || disk_size > USER_DISK_SIZE_MAX) - return -ERANGE; - r = sd_id128_get_machine(&mid); if (r < 0) return r; diff --git a/src/shared/user-record.c b/src/shared/user-record.c index b68b6a98d26..e16395f0327 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -563,26 +563,6 @@ static int json_dispatch_storage(const char *name, JsonVariant *variant, JsonDis return 0; } -static int json_dispatch_disk_size(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { - uint64_t *size = userdata; - uintmax_t k; - - if (json_variant_is_null(variant)) { - *size = UINT64_MAX; - return 0; - } - - if (!json_variant_is_unsigned(variant)) - return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name)); - - k = json_variant_unsigned(variant); - if (k < USER_DISK_SIZE_MIN || k > USER_DISK_SIZE_MAX) - return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' is not in valid range %" PRIu64 "…%" PRIu64 ".", strna(name), USER_DISK_SIZE_MIN, USER_DISK_SIZE_MAX); - - *size = k; - return 0; -} - static int json_dispatch_tasks_or_memory_max(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { uint64_t *limit = userdata; uintmax_t k; @@ -1135,7 +1115,7 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp { "notBeforeUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_before_usec), 0 }, { "notAfterUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_after_usec), 0 }, { "storage", JSON_VARIANT_STRING, json_dispatch_storage, offsetof(UserRecord, storage), 0 }, - { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_disk_size, offsetof(UserRecord, disk_size), 0 }, + { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size), 0 }, { "diskSizeRelative", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size_relative), 0 }, { "skeletonDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(UserRecord, skeleton_directory), 0 }, { "accessMode", JSON_VARIANT_UNSIGNED, json_dispatch_access_mode, offsetof(UserRecord, access_mode), 0 }, @@ -1484,7 +1464,7 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla { "notBeforeUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_before_usec), 0 }, { "notAfterUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_after_usec), 0 }, { "storage", JSON_VARIANT_STRING, json_dispatch_storage, offsetof(UserRecord, storage), 0 }, - { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_disk_size, offsetof(UserRecord, disk_size), 0 }, + { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size), 0 }, { "diskSizeRelative", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size_relative), 0 }, { "skeletonDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(UserRecord, skeleton_directory), 0 }, { "accessMode", JSON_VARIANT_UNSIGNED, json_dispatch_access_mode, offsetof(UserRecord, access_mode), 0 }, diff --git a/src/shared/user-record.h b/src/shared/user-record.h index c72bef4a725..22a6bb28f42 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -10,13 +10,6 @@ #include "missing_resource.h" #include "time-util.h" -/* But some limits on disk sizes: not less than 5M, not more than 5T */ -#define USER_DISK_SIZE_MIN (UINT64_C(5)*1024*1024) -#define USER_DISK_SIZE_MAX (UINT64_C(5)*1024*1024*1024*1024) - -/* The default disk size to use when nothing else is specified, relative to free disk space */ -#define USER_DISK_SIZE_DEFAULT_PERCENT 85 - typedef enum UserDisposition { USER_INTRINSIC, /* root and nobody */ USER_SYSTEM, /* statically allocated users for system services */