From: Yu Watanabe Date: Wed, 30 Apr 2025 13:53:35 +0000 (+0900) Subject: userdb: introduce user/group_record_buildo() helper macros X-Git-Tag: v258-rc1~657^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dcc308fba57fe1070f5b83e63548bf3d0f8e914;p=thirdparty%2Fsystemd.git userdb: introduce user/group_record_buildo() helper macros --- diff --git a/src/shared/group-record.h b/src/shared/group-record.h index 54a08f99ead..bc45166b652 100644 --- a/src/shared/group-record.h +++ b/src/shared/group-record.h @@ -42,6 +42,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(GroupRecord*, group_record_unref); int group_record_load(GroupRecord *h, sd_json_variant *v, UserRecordLoadFlags flags); int group_record_build(GroupRecord **ret, ...); +#define group_record_buildo(ret, ...) \ + group_record_build((ret), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) int group_record_clone(GroupRecord *g, UserRecordLoadFlags flags, GroupRecord **ret); bool group_record_match(GroupRecord *h, const UserDBMatch *match); diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 725feba699b..246d02f062d 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -434,6 +434,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(UserRecord*, user_record_unref); int user_record_load(UserRecord *h, sd_json_variant *v, UserRecordLoadFlags flags); int user_record_build(UserRecord **ret, ...); +#define user_record_buildo(ret, ...) \ + user_record_build((ret), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) const char* user_record_user_name_and_realm(UserRecord *h); UserStorage user_record_storage(UserRecord *h); diff --git a/src/shared/userdb.c b/src/shared/userdb.c index 210aab641e9..5480caa4cf3 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -695,24 +695,24 @@ static int userdb_process( } static int synthetic_root_user_build(UserRecord **ret) { - return user_record_build( + return user_record_buildo( ret, - SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", JSON_BUILD_CONST_STRING("root")), - SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(0)), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(0)), - SD_JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/root")), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic")))); + SD_JSON_BUILD_PAIR("userName", JSON_BUILD_CONST_STRING("root")), + SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(0)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(0)), + SD_JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/root")), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic"))); } static int synthetic_nobody_user_build(UserRecord **ret) { - return user_record_build( + return user_record_buildo( ret, - SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", JSON_BUILD_CONST_STRING(NOBODY_USER_NAME)), - SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(UID_NOBODY)), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)), - SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)), - SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic")))); + SD_JSON_BUILD_PAIR("userName", JSON_BUILD_CONST_STRING(NOBODY_USER_NAME)), + SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(UID_NOBODY)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)), + SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)), + SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic"))); } static int synthetic_foreign_user_build(uid_t foreign_uid, UserRecord **ret) { @@ -731,16 +731,15 @@ static int synthetic_foreign_user_build(uid_t foreign_uid, UserRecord **ret) { if (asprintf(&rn, "Foreign System Image UID " UID_FMT, foreign_uid) < 0) return -ENOMEM; - return user_record_build( + return user_record_buildo( ret, - SD_JSON_BUILD_OBJECT( - SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(un)), - SD_JSON_BUILD_PAIR("realName", SD_JSON_BUILD_STRING(rn)), - SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_uid)), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_uid)), - SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)), - SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("foreign")))); + SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(un)), + SD_JSON_BUILD_PAIR("realName", SD_JSON_BUILD_STRING(rn)), + SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_uid)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_uid)), + SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)), + SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("foreign"))); } static int user_name_foreign_extract_uid(const char *name, uid_t *ret_uid) { @@ -1194,19 +1193,19 @@ int userdb_iterator_get(UserDBIterator *iterator, const UserDBMatch *match, User } static int synthetic_root_group_build(GroupRecord **ret) { - return group_record_build( + return group_record_buildo( ret, - SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("groupName", JSON_BUILD_CONST_STRING("root")), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(0)), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic")))); + SD_JSON_BUILD_PAIR("groupName", JSON_BUILD_CONST_STRING("root")), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(0)), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic"))); } static int synthetic_nobody_group_build(GroupRecord **ret) { - return group_record_build( + return group_record_buildo( ret, - SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("groupName", JSON_BUILD_CONST_STRING(NOBODY_GROUP_NAME)), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic")))); + SD_JSON_BUILD_PAIR("groupName", JSON_BUILD_CONST_STRING(NOBODY_GROUP_NAME)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("intrinsic"))); } static int synthetic_foreign_group_build(gid_t foreign_gid, GroupRecord **ret) { @@ -1225,13 +1224,12 @@ static int synthetic_foreign_group_build(gid_t foreign_gid, GroupRecord **ret) { if (asprintf(&d, "Foreign System Image GID " GID_FMT, foreign_gid) < 0) return -ENOMEM; - return group_record_build( + return group_record_buildo( ret, - SD_JSON_BUILD_OBJECT( - SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(gn)), - SD_JSON_BUILD_PAIR("description", SD_JSON_BUILD_STRING(d)), - SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_gid)), - SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("foreign")))); + SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(gn)), + SD_JSON_BUILD_PAIR("description", SD_JSON_BUILD_STRING(d)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(FOREIGN_UID_BASE + foreign_gid)), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("foreign"))); } static int query_append_gid_match(sd_json_variant **query, const UserDBMatch *match) {