]> git.seodisparate.com - SimpleArchiver/commitdiff
Impl UID/GID remap for file format v1
authorStephen Seo <seo.disparate@gmail.com>
Wed, 8 Jan 2025 06:58:38 +0000 (15:58 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 8 Jan 2025 06:58:38 +0000 (15:58 +0900)
TODO: Remap on extract.

src/archiver.c

index 4c03757d2bca41df87ca4a19c7dd1433e4264347..4616471b677a0f5ff74a7ea6ddac93cb5f9223e5 100644 (file)
@@ -2816,12 +2816,42 @@ int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state,
       // Forced UID/GID is already handled by "symlinks_and_files_from_files".
 
       u32 = file_info_struct->uid;
+      if ((state->parsed->flags & 0x400) == 0) {
+        uint32_t mapped_uid;
+        if (simple_archiver_get_uid_mapping(state->parsed->mappings,
+                                            state->parsed->users_infos,
+                                            u32,
+                                            &mapped_uid,
+                                            NULL) == 0) {
+          //fprintf(stderr,
+          //        "NOTICE: Mapped UID %" PRIu32 " to %" PRIu32 " for %s\n",
+          //        u32,
+          //        mapped_uid,
+          //        file_info_struct->filename);
+          u32 = mapped_uid;
+        }
+      }
       simple_archiver_helper_32_bit_be(&u32);
       if (fwrite(&u32, 4, 1, out_f) != 1) {
         return SDAS_FAILED_TO_WRITE;
       }
 
       u32 = file_info_struct->gid;
+      if ((state->parsed->flags & 0x800) == 0) {
+        uint32_t mapped_gid;
+        if (simple_archiver_get_gid_mapping(state->parsed->mappings,
+                                            state->parsed->users_infos,
+                                            u32,
+                                            &mapped_gid,
+                                            NULL) == 0) {
+          //fprintf(stderr,
+          //        "NOTICE: Mapped GID %" PRIu32 " to %" PRIu32 " for %s\n",
+          //        u32,
+          //        mapped_gid,
+          //        file_info_struct->filename);
+          u32 = mapped_gid;
+        }
+      }
       simple_archiver_helper_32_bit_be(&u32);
       if (fwrite(&u32, 4, 1, out_f) != 1) {
         return SDAS_FAILED_TO_WRITE;