]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdb: introduce user/group_record_buildo() helper macros
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Apr 2025 13:53:35 +0000 (22:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 May 2025 03:10:28 +0000 (12:10 +0900)
src/shared/group-record.h
src/shared/user-record.h
src/shared/userdb.c

index 54a08f99eadb7ecedf300dd0915dede3ce042ecb..bc45166b65272aa3f5c3c2491dd7f4bd91ab34e5 100644 (file)
@@ -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);
index 725feba699bcab91758d67567d8450d77ec8f7b9..246d02f062d8ac04bba11478499a9c0c344053f1 100644 (file)
@@ -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);
index 210aab641e99e5a475f6e11cac28f2a6112d2b89..5480caa4cf39c1d1fe8eef03e32e4fd7da1cf310 100644 (file)
@@ -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) {