The `uid_t` and `gid_t` don't readily map to each other.
I would love to simplify the code and have a single function call in several cases when using both `uid_t` and `gid_t`.
This provides interchangeable types `f_id_t`, `f_uid_t`, and `f_gid_t`.
The standard behavior is that `f_uid_t` and `f_gid_t` are both sub-types of `f_id_t`.
The `f_id_t` is by default an unsigned 32-bit integer.
#define _di_f_fll_idss_delete_callback_
#define _di_f_fll_idss_destroy_callback_
#define _di_f_fll_idss_t_
+#define _di_f_gid_t_
+#define _di_f_gids_t_
+#define _di_f_gidss_delete_callback_
+#define _di_f_gidss_destroy_callback_
+#define _di_f_gidss_t_
+#define _di_f_id_t_
+#define _di_f_ids_t_
+#define _di_f_idss_delete_callback_
+#define _di_f_idss_destroy_callback_
+#define _di_f_idss_t_
//#define _di_f_int128_t_
//#define _di_f_int128s_t_
#define _di_f_int128ss_delete_callback_
//#define _di_f_type_file_flag_d_
//#define _di_f_type_number_64_t_
//#define _di_f_type_sizes_d_
+#define _di_f_uid_t_
+#define _di_f_uids_t_
+#define _di_f_uidss_delete_callback_
+#define _di_f_uidss_destroy_callback_
+#define _di_f_uidss_t_
//#define _di_f_uint128_t_
#define _di_f_uint128s_t_
#define _di_f_uint128ss_delete_callback_
#define _di_f_fll_idss_delete_callback_
#define _di_f_fll_idss_destroy_callback_
#define _di_f_fll_idss_t_
+#define _di_f_gid_t_
+#define _di_f_gids_t_
+#define _di_f_gidss_delete_callback_
+#define _di_f_gidss_destroy_callback_
+#define _di_f_gidss_t_
+#define _di_f_id_t_
+#define _di_f_ids_t_
+#define _di_f_idss_delete_callback_
+#define _di_f_idss_destroy_callback_
+#define _di_f_idss_t_
//#define _di_f_int128_t_
//#define _di_f_int128s_t_
#define _di_f_int128ss_delete_callback_
//#define _di_f_type_file_flag_d_
//#define _di_f_type_number_64_t_
//#define _di_f_type_sizes_d_
+#define _di_f_uid_t_
+#define _di_f_uids_t_
+#define _di_f_uidss_delete_callback_
+#define _di_f_uidss_destroy_callback_
+#define _di_f_uidss_t_
//#define _di_f_uint128_t_
#define _di_f_uint128s_t_
#define _di_f_uint128ss_delete_callback_
#define _di_f_fll_idss_delete_callback_
#define _di_f_fll_idss_destroy_callback_
#define _di_f_fll_idss_t_
+//#define _di_f_gid_t_
+#define _di_f_gids_t_
+#define _di_f_gidss_delete_callback_
+#define _di_f_gidss_destroy_callback_
+#define _di_f_gidss_t_
+//#define _di_f_id_t_
+#define _di_f_ids_t_
+#define _di_f_idss_delete_callback_
+#define _di_f_idss_destroy_callback_
+#define _di_f_idss_t_
//#define _di_f_fss_apply_delimit_
#define _di_f_fss_apply_delimit_range_
//#define _di_f_fss_complete_e_
//#define _di_f_type_file_flag_d_
//#define _di_f_type_number_64_t_
//#define _di_f_type_sizes_d_
+//#define _di_f_uid_t_
+#define _di_f_uids_t_
+#define _di_f_uidss_delete_callback_
+#define _di_f_uidss_destroy_callback_
+#define _di_f_uidss_t_
//#define _di_f_uint128_t_
#define _di_f_uint128s_t_
#define _di_f_uint128ss_delete_callback_
#define _di_f_fll_idss_delete_callback_
#define _di_f_fll_idss_destroy_callback_
#define _di_f_fll_idss_t_
+//#define _di_f_gid_t_
+#define _di_f_gids_t_
+#define _di_f_gidss_delete_callback_
+#define _di_f_gidss_destroy_callback_
+#define _di_f_gidss_t_
+//#define _di_f_id_t_
+#define _di_f_ids_t_
+#define _di_f_idss_delete_callback_
+#define _di_f_idss_destroy_callback_
+#define _di_f_idss_t_
//#define _di_f_fss_apply_delimit_
#define _di_f_fss_apply_delimit_range_
//#define _di_f_fss_complete_e_
//#define _di_f_type_file_flag_d_
//#define _di_f_type_number_64_t_
//#define _di_f_type_sizes_d_
+//#define _di_f_uid_t_
+#define _di_f_uids_t_
+#define _di_f_uidss_delete_callback_
+#define _di_f_uidss_destroy_callback_
+#define _di_f_uidss_t_
//#define _di_f_uint128_t_
#define _di_f_uint128s_t_
#define _di_f_uint128ss_delete_callback_
#define _di_f_fll_idss_delete_callback_
#define _di_f_fll_idss_destroy_callback_
#define _di_f_fll_idss_t_
+#define _di_f_gid_t_
+#define _di_f_gids_t_
+#define _di_f_gidss_delete_callback_
+#define _di_f_gidss_destroy_callback_
+#define _di_f_gidss_t_
+#define _di_f_id_t_
+#define _di_f_ids_t_
+#define _di_f_idss_delete_callback_
+#define _di_f_idss_destroy_callback_
+#define _di_f_idss_t_
//#define _di_f_int128_t_
//#define _di_f_int128s_t_
#define _di_f_int128ss_delete_callback_
//#define _di_f_type_file_flag_d_
//#define _di_f_type_number_64_t_
//#define _di_f_type_sizes_d_
+#define _di_f_uid_t_
+#define _di_f_uids_t_
+#define _di_f_uidss_delete_callback_
+#define _di_f_uidss_destroy_callback_
+#define _di_f_uidss_t_
//#define _di_f_uint128_t_
#define _di_f_uint128s_t_
#define _di_f_uint128ss_delete_callback_
#endif
#ifndef _di_f_account_by_id_
- f_status_t f_account_by_id(const uid_t id, f_account_t * const account) {
+ f_status_t f_account_by_id(const f_uid_t id, f_account_t * const account) {
#ifndef _di_level_0_parameter_checking_
if (!account) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
errno = 0;
char buffer[length];
- const int result = getpwuid_r(id, &password, buffer, length, &pointer);
+ const int result = getpwuid_r((uid_t) id, &password, buffer, length, &pointer);
if (result) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
char buffer[F_account_pwd_length_fallback_second_d];
- const int result = getpwuid_r(id, &password, buffer, length, &pointer);
+ const int result = getpwuid_r((uid_t) id, &password, buffer, length, &pointer);
if (result) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
#endif // _di_f_account_by_name_
#ifndef _di_f_account_group_id_by_name_
- f_status_t f_account_group_id_by_name(const f_string_static_t name, gid_t * const id) {
+ f_status_t f_account_group_id_by_name(const f_string_static_t name, f_gid_t * const id) {
#ifndef _di_level_0_parameter_checking_
if (!id) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
else {
if (!pointer) return F_exist_not;
- *id = group_data.gr_gid;
+ *id = (f_gid_t) group_data.gr_gid;
return F_okay;
}
#endif // _di_f_account_group_id_by_name_
#ifndef _di_f_account_group_name_by_id_
- f_status_t f_account_group_name_by_id(const gid_t id, f_string_dynamic_t * const name) {
+ f_status_t f_account_group_name_by_id(const f_gid_t id, f_string_dynamic_t * const name) {
#ifndef _di_level_0_parameter_checking_
if (!name) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
char buffer[length];
- const int result = getgrgid_r(id, &group_data, buffer, length, &pointer);
+ const int result = getgrgid_r((gid_t) id, &group_data, buffer, length, &pointer);
if (result) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
char buffer[F_account_pwd_length_fallback_second_d];
- const int result = getgrgid_r(id, &group_data, buffer, length, &pointer);
+ const int result = getgrgid_r((gid_t) id, &group_data, buffer, length, &pointer);
if (result) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
#endif // _di_f_account_group_name_by_id_
#ifndef _di_f_account_id_by_name_
- f_status_t f_account_id_by_name(const f_string_static_t name, uid_t * const id) {
+ f_status_t f_account_id_by_name(const f_string_static_t name, f_uid_t * const id) {
#ifndef _di_level_0_parameter_checking_
if (!id) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
else {
if (!pointer) return F_exist_not;
- *id = password.pw_uid;
+ *id = (f_uid_t) password.pw_uid;
return F_okay;
}
if (!pointer) return F_exist_not;
- *id = password.pw_uid;
+ *id = (f_uid_t) password.pw_uid;
return F_okay;
}
#endif // _di_f_account_id_by_name_
#ifndef _di_f_account_name_by_id_
- f_status_t f_account_name_by_id(const uid_t id, f_string_dynamic_t * const name) {
+ f_status_t f_account_name_by_id(const f_uid_t id, f_string_dynamic_t * const name) {
#ifndef _di_level_0_parameter_checking_
if (!name) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
char buffer[length];
- const int result = getpwuid_r(id, &password, buffer, length, &pointer);
+ const int result = getpwuid_r((uid_t) id, &password, buffer, length, &pointer);
if (result) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
* @see f_memory_array_increase_by()
*/
#ifndef _di_f_account_by_id_
- extern f_status_t f_account_by_id(const uid_t id, f_account_t * const account);
+ extern f_status_t f_account_by_id(const f_uid_t id, f_account_t * const account);
#endif // _di_f_account_by_id_
/**
* @see getgrnam_r()
*/
#ifndef _di_f_account_group_id_by_name_
- extern f_status_t f_account_group_id_by_name(const f_string_static_t name, gid_t * const id);
+ extern f_status_t f_account_group_id_by_name(const f_string_static_t name, f_gid_t * const id);
#endif // _di_f_account_group_id_by_name_
/**
* @see f_memory_array_increase_by()
*/
#ifndef _di_f_account_group_name_by_id_
- extern f_status_t f_account_group_name_by_id(const gid_t id, f_string_dynamic_t * const name);
+ extern f_status_t f_account_group_name_by_id(const f_gid_t id, f_string_dynamic_t * const name);
#endif // _di_f_account_group_name_by_id_
/**
* @see getpwnam_r()
*/
#ifndef _di_f_account_id_by_name_
- extern f_status_t f_account_id_by_name(const f_string_static_t name, uid_t * const id);
+ extern f_status_t f_account_id_by_name(const f_string_static_t name, f_uid_t * const id);
#endif // _di_f_account_id_by_name_
/**
* @see f_memory_array_increase_by()
*/
#ifndef _di_f_account_name_by_id_
- extern f_status_t f_account_name_by_id(const uid_t id, f_string_dynamic_t * const name);
+ extern f_status_t f_account_name_by_id(const f_uid_t id, f_string_dynamic_t * const name);
#endif // _di_f_account_name_by_id_
#ifdef __cplusplus
*/
#ifndef _di_f_account_t_
typedef struct {
- uid_t id_user;
- gid_t id_group;
+ f_uid_t id_user;
+ f_gid_t id_group;
f_string_dynamic_t home;
f_string_dynamic_t label;
} f_account_t;
#define f_account_t_initialize { \
- 0, \
- 0, \
+ f_uid_t_initialize, \
+ f_gid_t_initialize, \
f_string_dynamic_t_initialize, \
f_string_dynamic_t_initialize, \
f_string_dynamic_t_initialize, \
}
#define macro_f_account_t_clear(account) \
- account.id_user = 0; \
- account.id_group = 0; \
+ macro_f_uid_t_clear(account.id_user); \
+ macro_f_gid_t_clear(account.id_group); \
macro_f_account_t_clear(account.home); \
macro_f_account_t_clear(account.label); \
macro_f_account_t_clear(account.name); \
mock_unwrap = 1;
const long size = 20;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_account_t account = f_account_t_initialize;
int errnos[] = {
const long size = 20;
struct passwd password;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_account_t account = f_account_t_initialize;
{
const long size = 20;
struct passwd password;
struct passwd pointer;
- uid_t uid = 1;
+ f_uid_t uid = 1;
f_account_t account = f_account_t_initialize;
password.pw_uid = uid;
void test__f_account_group_id_by_name__fails(void **state) {
const long size = 20;
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_t name_string = "name";
f_string_static_t name = f_string_static_t_initialize;
const long size = 20;
struct group group_data;
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_t name_string = "name";
f_string_static_t name = f_string_static_t_initialize;
struct group group_data;
struct group pointer;
char *pointers[] = { "gr_mem", 0 };
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_static_t name = f_string_static_t_initialize;
void test__f_account_group_name_by_id__fails(void **state) {
const long size = 20;
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
int errnos[] = {
const long size = 20;
struct group group_data;
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
{
struct group group_data;
struct group pointer;
char *pointers[] = { "gr_mem", 0 };
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
group_data.gr_gid = 1;
void test__f_account_id_by_name__fails(void **state) {
const long size = 20;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_t name_string = "name";
f_string_static_t name = f_string_static_t_initialize;
const long size = 20;
struct passwd password;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_t name_string = "name";
f_string_static_t name = f_string_static_t_initialize;
const long size = 20;
struct passwd password;
struct passwd pointer;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_static_t name = f_string_static_t_initialize;
void test__f_account_name_by_id__fails(void **state) {
const long size = 20;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
int errnos[] = {
const long size = 20;
struct passwd password;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
{
const long size = 20;
struct passwd password;
struct passwd pointer;
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
f_string_dynamic_t name = f_string_dynamic_t_initialize;
password.pw_uid = 1;
#if defined(_di_libcap_) || defined(_libcap_legacy_only_)
#ifndef _di_f_capability_groups_set_
- f_status_t f_capability_groups_set(const gid_t id_group, const size_t total, const gid_t id_groups[]) {
+ f_status_t f_capability_groups_set(const f_gid_t id_group, const size_t total, const f_gid_t id_groups[]) {
return F_status_set_error(F_implement_not);
}
#endif // _di_f_capability_groups_set_
#endif // _di_f_capability_mode_set_
#ifndef _di_f_capability_owner_get_
- f_status_t f_capability_owner_get(const f_capability_t capability, uid_t * const id_user) {
+ f_status_t f_capability_owner_get(const f_capability_t capability, f_uid_t * const id_user) {
#ifndef _di_level_0_parameter_checking_
if (!id_user) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
#endif // _di_f_capability_owner_get_
#ifndef _di_f_capability_owner_set_
- f_status_t f_capability_owner_set(const f_capability_t capability, const uid_t id_user) {
+ f_status_t f_capability_owner_set(const f_capability_t capability, const f_uid_t id_user) {
return F_status_set_error(F_implement_not);
}
#endif // _di_f_capability_owner_set_
#if defined(_di_libcap_) || defined(_libcap_legacy_only_)
#ifndef f_capability_user_set
- f_status_t f_capability_user_set(const uid_t id_user) {
+ f_status_t f_capability_user_set(const f_uid_t id_user) {
return F_status_set_error(F_implement_not);
}
#endif // f_capability_user_set
#if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
#ifndef _di_f_capability_groups_set_
- f_status_t f_capability_groups_set(const gid_t id_group, const size_t total, const gid_t id_groups[]) {
+ f_status_t f_capability_groups_set(const f_gid_t id_group, const size_t total, const f_gid_t id_groups[]) {
- if (cap_setgroups(id_group, total, id_groups) == -1) {
+ if (cap_setgroups((gid_t) id_group, total, id_groups) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
if (errno == ENOMEM) return F_status_set_error(F_memory_not);
if (errno == ERANGE) return F_status_set_error(F_range_not);
#endif // _di_f_capability_mode_set_
#ifndef _di_f_capability_owner_get_
- f_status_t f_capability_owner_get(const f_capability_t capability, uid_t * const id_user) {
+ f_status_t f_capability_owner_get(const f_capability_t capability, f_uid_t * const id_user) {
#ifndef _di_level_0_parameter_checking_
if (!id_user) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- *id_user = cap_get_nsowner(capability);
+ *id_user = (f_uid_t) cap_get_nsowner(capability);
return F_okay;
}
#endif // _di_f_capability_owner_get_
#ifndef _di_f_capability_owner_set_
- f_status_t f_capability_owner_set(const f_capability_t capability, const uid_t id_user) {
+ f_status_t f_capability_owner_set(const f_capability_t capability, const f_uid_t id_user) {
- if (cap_set_nsowner(capability, id_user) == -1) {
+ if (cap_set_nsowner(capability, (uid_t) id_user) == -1) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADFD) return F_status_set_error(F_descriptor_not);
if (errno == ENAMETOOLONG) return F_status_set_error(F_name_not);
#if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
#ifndef _di_f_capability_user_set_
- f_status_t f_capability_user_set(const uid_t id_user) {
+ f_status_t f_capability_user_set(const f_uid_t id_user) {
- if (cap_setuid(id_user) == -1) {
+ if (cap_setuid((uid_t) id_user) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
if (errno == ENOMEM) return F_status_set_error(F_memory_not);
if (errno == EPERM) return F_status_set_error(F_prohibited);
* @see setgroups()
*/
#ifndef _di_f_capability_groups_set_
- extern f_status_t f_capability_groups_set(const gid_t id_group, const size_t total, const gid_t id_groups[]);
+ extern f_status_t f_capability_groups_set(const f_gid_t id_group, const size_t total, const f_gid_t id_groups[]);
#endif // _di_f_capability_groups_set_
/**
* @see cap_get_owner()
*/
#ifndef _di_f_capability_owner_get_
- extern f_status_t f_capability_owner_get(const f_capability_t capability, uid_t * const id_user);
+ extern f_status_t f_capability_owner_get(const f_capability_t capability, f_uid_t * const id_user);
#endif // _di_f_capability_owner_get_
/**
* @see cap_set_owner()
*/
#ifndef _di_f_capability_owner_set_
- extern f_status_t f_capability_owner_set(const f_capability_t capability, const uid_t id_user);
+ extern f_status_t f_capability_owner_set(const f_capability_t capability, const f_uid_t id_user);
#endif // _di_f_capability_owner_set_
/**
* @see setuid()
*/
#ifndef _di_f_capability_user_set_
- extern f_status_t f_capability_user_set(const uid_t id_user);
+ extern f_status_t f_capability_user_set(const f_uid_t id_user);
#endif // _di_f_capability_user_set_
#ifdef __cplusplus
void test__f_capability_groups_set__fails(void **state) {
#if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
- const gid_t group = 1;
+ const f_gid_t group = 1;
const size_t total = 2;
- const gid_t groups[] = { 3, 4 };
+ const f_gid_t groups[] = { 3, 4 };
int errnos[] = {
EINVAL,
void test__f_capability_groups_set__works(void **state) {
- const gid_t group = 1;
+ const f_gid_t group = 1;
const size_t total = 2;
- const gid_t groups[] = { 3, 4 };
+ const f_gid_t groups[] = { 3, 4 };
#if defined(_di_libcap_) || defined(_libcap_legacy_only_)
printf("[ WARN ] f_capability_groups_set() is not implemented and cannot be fully tested.\n");
void test__f_capability_owner_get__works(void **state) {
const f_capability_t capability = f_capability_t_initialize;
- uid_t id;
+ f_uid_t id = f_uid_t_initialize;
#if defined(_di_libcap_) || defined(_libcap_legacy_only_)
printf("[ WARN ] f_capability_owner_get() is not implemented and cannot be fully tested.\n");
#if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
const f_capability_t capability = f_capability_t_initialize;
- const uid_t id;
+ const f_uid_t id = f_uid_t_initialize;
int errnos[] = {
EACCES,
void test__f_capability_owner_set__works(void **state) {
const f_capability_t capability = f_capability_t_initialize;
- const uid_t id = 0;
+ const f_uid_t id = f_uid_t_initialize;
#if defined(_di_libcap_) || defined(_libcap_legacy_only_)
printf("[ WARN ] f_capability_owner_set() is not implemented and cannot be fully tested.\n");
*
* The callbacks must take care to properly modify the structure or they could cause security, integrity, or functionality problems.
*
+ * This provides f_directory_recurse_do_call_t (and f_directory_recurse_do_call_t_initialize) to simplify the function callback usage.
+ *
* Properties:
* - depth: A number representing the depth recursed thus far (generally assigned internally).
* - depth_max: The maximum recursion depth to use.
#ifndef _di_f_directory_recurse_do_t_
typedef struct f_directory_recurse_do_t_ f_directory_recurse_do_t;
+ typedef void (*f_directory_recurse_do_call_t)(f_directory_recurse_do_t * const recurse, const f_string_static_t name, const uint16_t flag);
+
struct f_directory_recurse_do_t_ {
f_number_unsigned_t depth;
f_number_unsigned_t depth_max;
f_string_dynamic_t path_cache;
const f_string_static_t *path_top;
- void (*action)(f_directory_recurse_do_t * const recurse, const f_string_static_t name, const uint16_t flag);
- void (*handle)(f_directory_recurse_do_t * const recurse, const f_string_static_t name, const uint16_t flag);
+ f_directory_recurse_do_call_t action;
+ f_directory_recurse_do_call_t handle;
} ;
+ #define f_directory_recurse_do_call_t_initialize 0
+
#define f_directory_recurse_do_t_initialize { \
0, \
F_directory_max_recurse_depth_d, \
f_string_dynamic_t_initialize, \
f_string_dynamic_t_initialize, \
0, \
- 0, \
- 0, \
+ f_directory_recurse_do_call_t_initialize, \
+ f_directory_recurse_do_call_t_initialize, \
}
#define macro_f_directory_recurse_do_t_initialize_1(depth, depth_max, flag, mode, state, listing, path, path_cache, path_top, action, handle) { \
#endif // _di_f_file_flush_
#ifndef _di_f_file_group_read_
- f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, gid_t * const group) {
+ f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, f_gid_t * const group) {
#ifndef _di_level_0_parameter_checking_
if (!group) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
if (F_status_is_error(status)) return status;
}
- *group = stat_file.st_gid;
+ *group = (f_gid_t) stat_file.st_gid;
return F_okay;
}
#endif // _di_f_file_open_at_
#ifndef _di_f_file_owner_read_
- f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, uid_t * const owner) {
+ f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, f_uid_t * const owner) {
#ifndef _di_level_0_parameter_checking_
if (!owner) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
if (F_status_is_error(status)) return status;
}
- *owner = stat_file.st_uid;
+ *owner = (f_uid_t) stat_file.st_uid;
return F_okay;
}
#endif // _di_f_file_rename_at_
#ifndef _di_f_file_role_change_
- f_status_t f_file_role_change(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference) {
+ f_status_t f_file_role_change(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference) {
if ((uid == -1 && gid == -1) || !path.used) return F_data_not;
#endif // _di_f_file_role_change_
#ifndef _di_f_file_role_change_at_
- f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
+ f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const int flag) {
if (directory.id == -1) return F_file_descriptor_not;
if ((uid == -1 && gid == -1) || !path.used) return F_data_not;
* @see stat()
*/
#ifndef _di_f_file_group_read_
- extern f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, uid_t * const group);
+ extern f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, f_uid_t * const group);
#endif // _di_f_file_group_read_
/**
* @see stat()
*/
#ifndef _di_f_file_owner_read_
- extern f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, uid_t * const owner);
+ extern f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, f_uid_t * const owner);
#endif // _di_f_file_owner_read_
/**
* @see lchown()
*/
#ifndef _di_f_file_role_change_
- extern f_status_t f_file_role_change(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference);
+ extern f_status_t f_file_role_change(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference);
#endif // _di_f_file_role_change_
/**
* @see fchownat()
*/
#ifndef _di_f_file_role_change_at_
- extern f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag);
+ extern f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const int flag);
#endif // _di_f_file_role_change_at_
/**
#endif // !defined(_di_f_file_create_at_) || !defined(_di_f_file_open_at_)
#if !defined(_di_f_file_role_change_) || !defined(_di_f_file_copy_)
- f_status_t private_f_file_role_change(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference) {
+ f_status_t private_f_file_role_change(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference) {
int result = 0;
if (uid != -1) {
if (dereference) {
- result = chown(path.string, uid, -1);
+ result = chown(path.string, (uid_t) uid, -1);
}
else {
- result = lchown(path.string, uid, -1);
+ result = lchown(path.string, (uid_t) uid, -1);
}
if (result < 0 && errno == EPERM) {
if (result == 0 && gid != -1) {
if (dereference) {
- result = chown(path.string, -1, gid);
+ result = chown(path.string, -1, (gid_t) gid);
}
else {
- result = lchown(path.string, -1, gid);
+ result = lchown(path.string, -1, (gid_t) gid);
}
if (result < 0 && errno == EPERM) {
#endif // !defined(_di_f_file_role_change_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_role_change_at_)
- f_status_t private_f_file_role_change_at(const f_file_t file, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
+ f_status_t private_f_file_role_change_at(const f_file_t file, const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const int flag) {
int result = 0;
if (uid != -1) {
- result = fchownat(file.id, path.string, uid, -1, flag);
+ result = fchownat(file.id, path.string, (uid_t) uid, -1, flag);
if (result < 0 && errno == EPERM) {
return F_status_set_error(F_access_owner);
}
if (result == 0 && gid != -1) {
- result = fchownat(file.id, path.string, -1, gid, flag);
+ result = fchownat(file.id, path.string, -1, (gid_t) gid, flag);
if (result < 0 && errno == EPERM) {
return F_status_set_error(F_access_group);
* @see f_file_role_change()
*/
#if !defined(_di_f_file_role_change_) || !defined(_di_f_file_copy_)
- extern f_status_t private_f_file_role_change(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_role_change(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_role_change_) || !defined(_di_f_file_copy_)
/**
* @see f_file_role_change_at()
*/
#if !defined(_di_f_file_role_change_at_)
- extern f_status_t private_f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const int flag) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_role_change_at_)
/**
for (int i = 0; i < 9; ++i) {
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
will_return(__wrap_stat, true);
will_return(__wrap_stat, errnos[i]);
void test__f_file_group_read__returns_data_not(void **state) {
{
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
const f_status_t status = f_file_group_read(f_string_empty_s, F_false, &id);
const f_string_static_t path = macro_f_string_static_t_initialize_1("test", 0, 4);
{
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
struct stat statistics;
for (int i = 0; i < 9; ++i) {
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
will_return(__wrap_stat, true);
will_return(__wrap_stat, errnos[i]);
void test__f_file_owner_read__returns_data_not(void **state) {
{
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, &id);
const f_string_static_t path = macro_f_string_static_t_initialize_1("test", 0, 4);
{
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
struct stat statistics;
#include <fll/level_0/type/range_double.h>
#include <fll/level_0/type/state.h>
#include <fll/level_0/type/time.h>
+#include <fll/level_0/type/void.h>
#ifdef __cplusplus
extern "C" {
#define macro_f_uint128ss_t_initialize_2(array, length) { array, length, length }
#endif // _di_f_uint128ss_t_
+/**
+ * The uid_t type is not easily interchangeable with gid_t.
+ *
+ * The default size is expected to be a 32-bit unsigned integer.
+ * Override these for different sizes, such as 64-bit unsigned integer.
+ * Some systems might define uid_t and gid_t as signed integers rather than unsigned integers.
+ *
+ * These are expected to be cast back to uid_t and gid_t, which makes it unsafe to define this as some value that does not safely map to uid_t and gid_t.
+ *
+ * The f_id_t is a type intended to be mapped to both uid_t and gid_t.
+ *
+ * The f_gid_t is intended to be mapped directly to gid_t.
+ * The f_uid_t is intended to be mapped directly to uid_t.
+ *
+ * These IDs are generally expected to be initialized to -1.
+ * Using the initializer define is highly recommended.
+ *
+ * Using f_gid_t instead of f_id_t should be safer in case some systems use different type sizes for gid_t and uid_t.
+ * For such systems, the f_gid_t should instead be mapped directly to gid_t and f_uid_t should instead be mapped directly to uid_t.
+ * This, however, does introduce additional cooncerns with certain functions if f_uid_t and f_gid_t are interchanged.
+ * In such cases, make the main type f_id_t the larger of the two so that casting into f_id_t should be safe.
+ * Casting from f_id_t into the smaller of the two may incur problems.
+ *
+ * Be sure to cast f_id_t, f_uid_t, and f_gid_t to the appropriate uid_t or gid_t when using anything outside of this project, such as system calls or POSIX functions.
+ */
+#ifndef _di_f_id_t_
+ typedef uint32_t f_id_t;
+
+ #define f_id_t_initialize -1
+
+ #define macro_f_id_t_clear(id) id = -1;
+
+ /**
+ * The f_gid_t type, see f_id_t documentation.
+ */
+ #ifndef _di_f_gid_t_
+ typedef f_id_t f_gid_t;
+
+ #define f_gid_t_initialize -1
+
+ #define macro_f_gid_t_clear(id) id = -1;
+ #endif // _di_f_gid_t_
+
+ /**
+ * The f_uid_t type, see f_id_t documentation.
+ */
+ #ifndef _di_f_uid_t_
+ typedef f_id_t f_uid_t;
+
+ #define f_uid_t_initialize -1
+
+ #define macro_f_uid_t_clear(id) id = -1;
+ #endif // _di_f_uid_t_
+#endif // _di_f_id_t_
+
+/**
+ * Array type for f_id_t.
+ *
+ * See the f_id_t documentation for further details.
+ */
+#ifndef _di_f_ids_t_
+ typedef f_uint32s_t f_ids_t;
+
+ #define f_ids_t_initialize f_uint32s_t_initialize
+
+ #define macro_f_ids_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_ids_t_initialize_2(array, length) { array, length, length }
+
+ /**
+ * The f_gids_t type, see f_ids_t documentation.
+ */
+ #ifndef _di_f_gids_t_
+ typedef f_ids_t f_gids_t;
+
+ #define f_gids_t_initialize f_ids_t_initialize
+
+ #define macro_f_gids_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_gids_t_initialize_2(array, length) { array, length, length }
+ #endif // _di_f_gids_t_
+
+ /**
+ * The f_uids_t type, see f_ids_t documentation.
+ */
+ #ifndef _di_f_uids_t_
+ typedef f_ids_t f_uids_t;
+
+ #define f_uids_t_initialize f_ids_t_initialize
+
+ #define macro_f_uids_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_uids_t_initialize_2(array, length) { array, length, length }
+ #endif // _di_f_uids_t_
+#endif // _di_f_ids_t_
+
+/**
+ * Array type for f_ids_t.
+ *
+ * See the f_ids_t documentation for further details.
+ */
+#ifndef _di_f_idss_t_
+ typedef f_uint32ss_t f_idss_t;
+
+ #define f_idss_t_initialize f_uint32ss_t_initialize
+
+ #define macro_f_idss_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_idss_t_initialize_2(array, length) { array, length, length }
+
+ /**
+ * The f_gidss_t type, see f_idss_t documentation.
+ */
+ #ifndef _di_f_gidss_t_
+ typedef f_idss_t f_gidss_t;
+
+ #define f_gidss_t_initialize f_idss_t_initialize
+
+ #define macro_f_gidss_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_gidss_t_initialize_2(array, length) { array, length, length }
+ #endif // _di_f_gids_t_
+
+ /**
+ * The f_uidss_t type, see f_idss_t documentation.
+ */
+ #ifndef _di_f_uidss_t_
+ typedef f_idss_t f_uidss_t;
+
+ #define f_uidss_t_initialize f_idss_t_initialize
+
+ #define macro_f_uidss_t_initialize_1(array, size, used) { array, size, used }
+ #define macro_f_uidss_t_initialize_2(array, length) { array, length, length }
+ #endif // _di_f_uidss_t_
+#endif // _di_f_idss_t_
+
#ifdef __cplusplus
} // extern "C"
#endif
* This response is handled within f_talk().
* The f_talk() function will then set the state.status when done and might immediately set state.status to F_interrupt (with error bit) if bob_interrupts() returns F_interrupt (with/without error bit).
*
+ * This provides f_state_call_t (and f_state_call_t_initialize) to simplify the function callback usage.
+ *
* Properties:
* - step_large: The allocation step to use for large buffers.
* - step_small: The allocation step to use for small buffers.
#ifndef _di_f_state_t_
typedef struct f_state_t_ f_state_t;
+ typedef void (*f_state_call_t)(f_state_t * const state, void * const internal);
+
struct f_state_t_ {
uint16_t step_large;
uint16_t step_small;
uint64_t flag;
uint64_t code;
- void (*handle)(f_state_t * const state, void * const internal);
- void (*interrupt)(f_state_t * const state, void * const internal);
+ f_state_call_t handle;
+ f_state_call_t interrupt;
void *callbacks;
void *custom;
void *data;
};
+ #define f_state_call_t_initialize 0
+
#define f_state_t_initialize { \
F_memory_default_allocation_large_d, \
F_memory_default_allocation_small_d, \
build_libraries -lc
-build_sources_headers type.h type/cell.h type/file.h type/fll.h type/mode.h type/number.h type/pid.h type/quantity.h type/range.h type/range_double.h type/state.h type/status.h type/time.h
+build_sources_headers type.h type/cell.h type/file.h type/fll.h type/mode.h type/number.h type/pid.h type/quantity.h type/range.h type/range_double.h type/state.h type/status.h type/time.h type/void.h
build_script yes
build_shared yes
extern f_status_t f_uint32ss_destroy_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array);
#endif // _di_f_uint32ss_destroy_callback_
+/**
+ * Delete callback macros mapping functions for the f_id_t, f_uid_t, and f_gid_t array type callbacks.
+ */
+#ifndef _di_f_idss_delete_callback_
+ #define f_idss_delete_callback f_uint32ss_delete_callback
+
+ #ifndef _di_f_gidss_delete_callback_
+ #define f_gidss_delete_callback f_idss_delete_callback
+ #endif // _di_f_gidss_delete_callback_
+
+ #ifndef _di_f_gidss_delete_callback_
+ #define f_gidss_delete_callback f_idss_delete_callback
+ #endif // _di_f_gidss_delete_callback_
+
+ #ifndef _di_f_uidss_destroy_callback_
+ #define f_uidss_destroy_callback f_idss_destroy_callback
+ #endif // _di_f_uidss_destroy_callback_
+
+ #ifndef _di_f_uidss_destroy_callback_
+ #define f_uidss_destroy_callback f_idss_destroy_callback
+ #endif // _di_f_uidss_destroy_callback_
+#endif // _di_f_idss_delete_callback_
+
#ifdef __cplusplus
} // extern "C"
#endif
#ifndef _di_fl_execute_as_t_
typedef struct {
int *nice;
- uid_t *id_user;
- gid_t *id_group;
+ f_uid_t *id_user;
+ f_gid_t *id_group;
f_int32s_t *affinity;
f_capability_t capability;
#endif // _di_fll_file_mode_set_all_
#ifndef _di_fll_file_role_change_all_
- f_status_t fll_file_role_change_all(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max) {
+ f_status_t fll_file_role_change_all(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference, const f_number_unsigned_t depth_max) {
#ifndef _di_level_2_parameter_checking_
if (uid == -1 && gid == -1) return F_status_set_error(F_parameter);
#endif // _di_level_2_parameter_checking_
* Errors (with error bit) from: fl_directory_list().
*/
#ifndef _di_fll_file_role_change_all_
- extern f_status_t fll_file_role_change_all(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max);
+ extern f_status_t fll_file_role_change_all(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference, const f_number_unsigned_t depth_max);
#endif // _di_fll_file_role_change_all_
#ifdef __cplusplus
#endif // !defined(_di_fll_file_mode_set_all_)
#if !defined(_di_fll_file_role_change_all_)
- f_status_t private_fll_file_role_change_all(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) {
+ f_status_t private_fll_file_role_change_all(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) {
f_status_t status = F_okay;
* F_failure (with error bit) for any other error.
*/
#if !defined(_di_fll_file_role_change_all_)
- extern f_status_t private_fll_file_role_change_all(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) F_attribute_visibility_internal_d;
+ extern f_status_t private_fll_file_role_change_all(const f_string_static_t path, const f_uid_t uid, const f_gid_t gid, const bool dereference, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) F_attribute_visibility_internal_d;
#endif // !defined(_di_fll_file_role_change_all_)
#ifdef __cplusplus
// When the buffer is not a number, then check to see if this is a group or owner name.
if (F_status_set_fine(main->setting.state.status) == F_number) {
if (is_owner) {
- uid_t uid = 0;
+ f_uid_t uid = f_uid_t_initialize;
main->setting.state.status = f_account_id_by_name(buffer, &uid);
}
else {
- gid_t gid = 0;
+ f_gid_t gid = f_gid_t_initialize;
main->setting.state.status = f_account_group_id_by_name(buffer, &gid);
}
*
* @return
* The detected owner id or group id.
- * When is_owner is TRUE, then this should be cast to type (uid_t *).
- * When is_owner is TRUE, then this should be cast to type (gid_t *).
+ * When is_owner is TRUE, then this should be cast to type (f_uid_t *) or (f_id_t *).
+ * When is_owner is FALSE, then this should be cast to type (f_gid_t *) or (f_id_t *).
* This is set to 0 on any error, check data_make.main->setting.state.status for error.
*
* @see f_account_group_id_by_name()
fake_main_t * const main = data_make->main;
- gid_t id = 0;
+ f_gid_t id = f_gid_t_initialize;
bool dereference = F_true;
f_number_unsigned_t i = 0;
dereference = F_false;
}
- id = (gid_t) fake_make_get_id(data_make, F_false, main->cache_arguments.array[i++]);
+ id = (f_gid_t) fake_make_get_id(data_make, F_false, main->cache_arguments.array[i++]);
if (F_status_is_error(main->setting.state.status)) {
main->setting.state.status = F_status_set_error(F_failure);
fake_main_t * const main = data_make->main;
- uid_t id = 0;
+ f_uid_t id = f_uid_t_initialize;
f_number_unsigned_t i = if_not ? 2 : 1;
bool dereference = F_true;
dereference = F_false;
}
- id = (uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
+ id = (f_uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
if (F_status_is_error(main->setting.state.status)) {
state_process->condition_result = fake_condition_result_error_e;
state_process->condition_result = fake_condition_result_true_e;
- for (uid_t id_file = 0; i < main->cache_arguments.used; ++i, id_file = 0) {
+ for (f_uid_t id_file = 0; i < main->cache_arguments.used; ++i, id_file = 0) {
main->setting.state.status = f_file_group_read(main->cache_arguments.array[i], dereference, &id_file);
fake_main_t * const main = data_make->main;
- uid_t id = 0;
+ f_uid_t id = f_uid_t_initialize;
f_number_unsigned_t i = if_not ? 2 : 1;
bool dereference = F_true;
dereference = F_false;
}
- id = (uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
+ id = (f_uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
if (F_status_is_error(main->setting.state.status)) {
state_process->condition_result = fake_condition_result_error_e;
state_process->condition_result = fake_condition_result_true_e;
- for (uid_t id_file = 0; i < main->cache_arguments.used; ++i, id_file = 0) {
+ for (f_uid_t id_file = 0; i < main->cache_arguments.used; ++i, id_file = 0) {
main->setting.state.status = f_file_owner_read(main->cache_arguments.array[i], dereference, &id_file);
fake_main_t * const main = data_make->main;
- uid_t id = 0;
+ f_uid_t id = f_uid_t_initialize;
bool dereference = F_true;
f_number_unsigned_t i = 0;
dereference = F_false;
}
- id = (uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
+ id = (f_uid_t) fake_make_get_id(data_make, F_true, main->cache_arguments.array[i++]);
if (F_status_is_error(main->setting.state.status)) {
fake_print_error(&main->program.error, macro_fake_f(fake_make_get_id));