Skip to content

Commit

Permalink
WIP UID/GID remap, impl helper get fns in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Seo committed Jan 7, 2025
1 parent ec38ffa commit 71779de
Show file tree
Hide file tree
Showing 3 changed files with 700 additions and 0 deletions.
196 changes: 196 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,3 +1252,199 @@ int simple_archiver_handle_map_user_or_group(

return 0;
}

int simple_archiver_get_uid_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
uint32_t uid,
uint32_t *out_uid,
char **out_user) {
uint32_t *get_uid = simple_archiver_hash_map_get(mappings.UidToUid,
&uid,
sizeof(uint32_t));
const char *get_user;
if (get_uid) {
*out_uid = *get_uid;
if (out_user) {
if (*out_user) {
free(*out_user);
}
get_user = simple_archiver_hash_map_get(users_infos.UidToUname,
get_uid,
sizeof(uint32_t));
if (get_user) {
*out_user = strdup(get_user);
} else {
*out_user = NULL;
}
}
return 0;
}

get_user = simple_archiver_hash_map_get(mappings.UidToUname,
&uid,
sizeof(uint32_t));
if (get_user) {
get_uid = simple_archiver_hash_map_get(users_infos.UnameToUid,
get_user,
strlen(get_user) + 1);
if (get_uid) {
*out_uid = *get_uid;
if (out_user) {
if (*out_user) {
free(*out_user);
}
*out_user = strdup(get_user);
}
return 0;
}
}

return 1;
}

int simple_archiver_get_user_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
const char *user,
uint32_t *out_uid,
char **out_user) {
uint32_t *get_uid = simple_archiver_hash_map_get(mappings.UnameToUid,
user,
strlen(user) + 1);
char *get_user;
if (get_uid) {
*out_uid = *get_uid;
if (out_user) {
if (*out_user) {
free(*out_user);
}
get_user = simple_archiver_hash_map_get(users_infos.UidToUname,
get_uid,
sizeof(uint32_t));
if (get_user) {
*out_user = strdup(get_user);
} else {
*out_user = NULL;
}
}
return 0;
}

get_user = simple_archiver_hash_map_get(mappings.UnameToUname,
user,
strlen(user) + 1);
if (get_user) {
get_uid = simple_archiver_hash_map_get(users_infos.UnameToUid,
get_user,
strlen(get_user) + 1);
if (get_uid) {
*out_uid = *get_uid;
if (out_user) {
if (*out_user) {
free(*out_user);
}
*out_user = strdup(get_user);
}
return 0;
}
}

return 1;
}

int simple_archiver_get_gid_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
uint32_t gid,
uint32_t *out_gid,
char **out_group) {
uint32_t *get_gid = simple_archiver_hash_map_get(mappings.GidToGid,
&gid,
sizeof(uint32_t));
char *get_group;
if (get_gid) {
*out_gid = *get_gid;
if (out_group) {
if (*out_group) {
free(*out_group);
}
get_group = simple_archiver_hash_map_get(users_infos.GidToGname,
get_gid,
sizeof(uint32_t));
if (get_group) {
*out_group = strdup(get_group);
} else {
*out_group = NULL;
}
}
return 0;
}

get_group = simple_archiver_hash_map_get(mappings.GidToGname,
&gid,
sizeof(uint32_t));
if (get_group) {
get_gid = simple_archiver_hash_map_get(users_infos.GnameToGid,
get_group,
strlen(get_group) + 1);
if (get_gid) {
*out_gid = *get_gid;
if (out_group) {
if (*out_group) {
free(*out_group);
}
*out_group = strdup(get_group);
}
return 0;
}
}

return 1;
}

int simple_archiver_get_group_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
const char *group,
uint32_t *out_gid,
char **out_group) {
uint32_t *get_gid = simple_archiver_hash_map_get(mappings.GnameToGid,
group,
strlen(group) + 1);
char *get_group;
if (get_gid) {
*out_gid = *get_gid;
if (out_group) {
if (*out_group) {
free(*out_group);
}
get_group = simple_archiver_hash_map_get(users_infos.GidToGname,
get_gid,
sizeof(uint32_t));
if (get_group) {
*out_group = strdup(get_group);
} else {
*out_group = NULL;
}
}
return 0;
}

get_group = simple_archiver_hash_map_get(mappings.GnameToGname,
group,
strlen(group) + 1);
if (get_group) {
get_gid = simple_archiver_hash_map_get(users_infos.GnameToGid,
get_group,
strlen(get_group) + 1);
if (get_gid) {
*out_gid = *get_gid;
if (out_group) {
if (*out_group) {
free(*out_group);
}
*out_group = strdup(get_group);
}
return 0;
}
}

return 1;
}
31 changes: 31 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,35 @@ int simple_archiver_handle_map_user_or_group(
SDArchiverHashMap *IDToID,
SDArchiverHashMap *NameToName);

/// Returns 0 on success. out_user is used if not NULL. out_user may hold NULL
/// if username is not found. On success, `*out_user` must be free'd.
int simple_archiver_get_uid_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
uint32_t uid,
uint32_t *out_uid,
char **out_user);

/// Returns 0 on success. out_user is used if not NULL. out_user may hold NULL
/// if username is not found. On success, `*out_user` must be free'd.
int simple_archiver_get_user_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
const char *user,
uint32_t *out_uid,
char **out_user);

/// Returns 0 on success. out_group is used if not NULL. out_group may hold
/// NULL if groupname is not found. On success `*out_group` must be free'd.
int simple_archiver_get_gid_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
uint32_t gid,
uint32_t *out_gid,
char **out_group);

/// Returns 0 on success. out_group is used if not NULL. out_group may hold
/// NULL if groupname is not found. On success `*out_group` must be free'd.
int simple_archiver_get_group_mapping(SDA_UGMapping mappings,
UsersInfos users_infos,
const char *group,
uint32_t *out_gid,
char **out_group);
#endif
Loading

0 comments on commit 71779de

Please sign in to comment.