Skip to content

Commit

Permalink
WIP user/group mapping, more mapping validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Seo committed Jan 6, 2025
1 parent a52e827 commit ee3c160
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,54 @@ 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,
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: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,
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: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;

Expand Down

0 comments on commit ee3c160

Please sign in to comment.