]> git.seodisparate.com - SimpleArchiver/commitdiff
WIP user/group mapping, more mapping validation
authorStephen Seo <seo.disparate@gmail.com>
Mon, 6 Jan 2025 05:20:11 +0000 (14:20 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 6 Jan 2025 05:20:11 +0000 (14:20 +0900)
src/parser.c
src/test.c

index c922951d8e77aff0a182b5fe67f06b3c482e915d..9b387532cb8f5d352f43dc4d4ca636e3eb8b5aad 100644 (file)
@@ -1079,7 +1079,8 @@ int simple_archiver_handle_map_user_or_group(
   }
 
   if (first_is_numeric && last_is_numeric) {
-    if (simple_archiver_hash_map_get(IDToID, first_id, sizeof(uint32_t))) {
+    if (simple_archiver_hash_map_get(IDToID, first_id, sizeof(uint32_t))
+        || simple_archiver_hash_map_get(IDToName, first_id, sizeof(uint32_t))) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
               *first_id);
@@ -1103,7 +1104,8 @@ int simple_archiver_handle_map_user_or_group(
     last_id = NULL;
     first_id = NULL;
   } else if (first_is_numeric) {
-    if (simple_archiver_hash_map_get(IDToName, first_id, sizeof(uint32_t))) {
+    if (simple_archiver_hash_map_get(IDToName, first_id, sizeof(uint32_t))
+        || simple_archiver_hash_map_get(IDToID, first_id, sizeof(uint32_t))) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
               *first_id);
@@ -1129,7 +1131,10 @@ int simple_archiver_handle_map_user_or_group(
   } else if (last_is_numeric) {
     if (simple_archiver_hash_map_get(NameToID,
                                      first_buf,
-                                     strlen(first_buf) + 1)) {
+                                     strlen(first_buf) + 1)
+        || simple_archiver_hash_map_get(NameToName,
+                                        first_buf,
+                                        strlen(first_buf) + 1)) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%s\" already exists!\n",
             first_buf);
@@ -1155,7 +1160,10 @@ int simple_archiver_handle_map_user_or_group(
   } else {
     if (simple_archiver_hash_map_get(NameToName,
                                      first_buf,
-                                     strlen(first_buf) + 1)) {
+                                     strlen(first_buf) + 1)
+        || simple_archiver_hash_map_get(NameToID,
+                                        first_buf,
+                                        strlen(first_buf) + 1)) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%s\" already exists!\n",
             first_buf);
index 6c5c643c700c0fb571de53858e5c59292d8fb58d..cde869953ee29c32aea3400ee4f933d7fe6f1fa8 100644 (file)
@@ -169,6 +169,13 @@ int main(void) {
       parsed.mappings.UidToUid,
       parsed.mappings.UnameToUname) != 0);
     fprintf(stderr, "Expecting ERROR output on next line:\n");
+    CHECK_TRUE(simple_archiver_handle_map_user_or_group(
+      "1000:other",
+      parsed.mappings.UidToUname,
+      parsed.mappings.UnameToUid,
+      parsed.mappings.UidToUid,
+      parsed.mappings.UnameToUname) != 0);
+    fprintf(stderr, "Expecting ERROR output on next line:\n");
     CHECK_TRUE(simple_archiver_handle_map_user_or_group(
       "1002:user00",
       parsed.mappings.UidToUname,
@@ -176,6 +183,13 @@ int main(void) {
       parsed.mappings.UidToUid,
       parsed.mappings.UnameToUname) != 0);
     fprintf(stderr, "Expecting ERROR output on next line:\n");
+    CHECK_TRUE(simple_archiver_handle_map_user_or_group(
+      "1002:100",
+      parsed.mappings.UidToUname,
+      parsed.mappings.UnameToUid,
+      parsed.mappings.UidToUid,
+      parsed.mappings.UnameToUname) != 0);
+    fprintf(stderr, "Expecting ERROR output on next line:\n");
     CHECK_TRUE(simple_archiver_handle_map_user_or_group(
       "user1:1033",
       parsed.mappings.UidToUname,
@@ -183,12 +197,26 @@ int main(void) {
       parsed.mappings.UidToUid,
       parsed.mappings.UnameToUname) != 0);
     fprintf(stderr, "Expecting ERROR output on next line:\n");
+    CHECK_TRUE(simple_archiver_handle_map_user_or_group(
+      "user1:user10",
+      parsed.mappings.UidToUname,
+      parsed.mappings.UnameToUid,
+      parsed.mappings.UidToUid,
+      parsed.mappings.UnameToUname) != 0);
+    fprintf(stderr, "Expecting ERROR output on next line:\n");
     CHECK_TRUE(simple_archiver_handle_map_user_or_group(
       "user2:us3r3",
       parsed.mappings.UidToUname,
       parsed.mappings.UnameToUid,
       parsed.mappings.UidToUid,
       parsed.mappings.UnameToUname) != 0);
+    fprintf(stderr, "Expecting ERROR output on next line:\n");
+    CHECK_TRUE(simple_archiver_handle_map_user_or_group(
+      "user2:3",
+      parsed.mappings.UidToUname,
+      parsed.mappings.UnameToUid,
+      parsed.mappings.UidToUid,
+      parsed.mappings.UnameToUname) != 0);
     uint32_t id_check = 1000;
     uint32_t *id_get;