Mstdlib-1.24.0
Permissions

Functions

M_fs_perms_tM_fs_perms_create (void) M_MALLOC
 
M_fs_perms_tM_fs_perms_dup (const M_fs_perms_t *perms) M_MALLOC
 
void M_fs_perms_merge (M_fs_perms_t **dest, M_fs_perms_t *src) M_FREE(2)
 
void M_fs_perms_destroy (M_fs_perms_t *perms) M_FREE(1)
 
M_fs_error_t M_fs_perms_can_access (const char *path, M_uint32 mode)
 
M_fs_error_t M_fs_perms_set_perms (const M_fs_perms_t *perms, const char *path)
 
M_fs_error_t M_fs_perms_set_perms_file (const M_fs_perms_t *perms, M_fs_file_t *fd)
 
const char * M_fs_perms_get_user (const M_fs_perms_t *perms)
 
const char * M_fs_perms_get_group (const M_fs_perms_t *perms)
 
M_uint32 M_fs_perms_get_mode (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_fs_perms_type_t M_fs_perms_get_type (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_bool M_fs_perms_get_isset (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_uint32 M_fs_perms_get_dir_mode (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_fs_perms_type_t M_fs_perms_get_dir_type (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_bool M_fs_perms_get_dir_isset (const M_fs_perms_t *perms, M_fs_perms_who_t who)
 
M_fs_error_t M_fs_perms_set_user (M_fs_perms_t *perms, const char *user)
 
M_fs_error_t M_fs_perms_set_group (M_fs_perms_t *perms, const char *group)
 
void M_fs_perms_set_mode (M_fs_perms_t *perms, M_uint32 mode, M_fs_perms_who_t who, M_fs_perms_type_t type)
 
void M_fs_perms_set_dir_mode (M_fs_perms_t *perms, M_uint32 mode, M_fs_perms_who_t who, M_fs_perms_type_t type)
 
void M_fs_perms_unset_mode (M_fs_perms_t *perms, M_fs_perms_who_t who)
 
void M_fs_perms_unset_dir_mode (M_fs_perms_t *perms, M_fs_perms_who_t who)
 

Detailed Description

Function Documentation

◆ M_fs_perms_create()

M_fs_perms_t * M_fs_perms_create ( void  )

Create a perms object.

Returns
A perms object.

◆ M_fs_perms_dup()

M_fs_perms_t * M_fs_perms_dup ( const M_fs_perms_t perms)

Duplicate a perms object.

Parameters
[in]permsThe perms object to duplicate.
Returns
A new perms object with the same information as the original.

◆ M_fs_perms_merge()

void M_fs_perms_merge ( M_fs_perms_t **  dest,
M_fs_perms_t src 
)

Merge two perms objects together.

The second (src) perms will be destroyed automatically upon completion of this function.

This is intended for dest to hold exact permissions. In this case, when src is exact then src will replace the permissions in dest. If src is an add or remove it will modify dest accordingly.

When the perms in dest are not set then the permissions from src will be used.

When dest is a modifier (add or remove) then the permissions from src will replace the permission in dest. This happens regardless of the permissions in src being exact or a modifier.

When the permissions in src are not set then dest will not be modified.

Parameters
[in,out]destPointer by reference to the perms receiving the values. if this is NULL, the pointer will simply be switched out for src.
[in,out]srcPointer to the perms giving up its values.

◆ M_fs_perms_destroy()

void M_fs_perms_destroy ( M_fs_perms_t perms)

Destroy a perms object.

Parameters
[in]permsThe perms.

◆ M_fs_perms_can_access()

M_fs_error_t M_fs_perms_can_access ( const char *  path,
M_uint32  mode 
)

Can the process access the path with the given perms.

Warning
using this function incorrectly can lead to security issues. This is an implementation of the POSIX access() function and the security considerations apply.

This function should not be used to make access control decisions due to Time-of-check Time-of-use (TOCTOU) race condition attacks.

Parameters
[in]pathThe path to access.
[in]modeM_fs_perms_mode_t permissions to be checked. Optional, pass 0 if only checking if the path exists.
Returns
Result.

◆ M_fs_perms_set_perms()

M_fs_error_t M_fs_perms_set_perms ( const M_fs_perms_t perms,
const char *  path 
)

Apply perms to a path.

This will set/change/modify the perms on a path.

Parameters
[in]permsThe perms.
[in]pathThe path.
Returns
Result.

◆ M_fs_perms_set_perms_file()

M_fs_error_t M_fs_perms_set_perms_file ( const M_fs_perms_t perms,
M_fs_file_t fd 
)

Apply perms to open file.

This will set/change/modify the perms on a file.

Parameters
[in]permsThe perms.
[in]fdThe file.
Returns
Result.

◆ M_fs_perms_get_user()

const char * M_fs_perms_get_user ( const M_fs_perms_t perms)

Get the user associated with the perms.

Parameters
[in]permsThe perms.
Returns
The user. NULL if no user is set.

◆ M_fs_perms_get_group()

const char * M_fs_perms_get_group ( const M_fs_perms_t perms)

Get the group associated with the perms.

Parameters
[in]permsThe perms.
Returns
The group. NULL if not group is set.

◆ M_fs_perms_get_mode()

M_uint32 M_fs_perms_get_mode ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Get the mode associated with the perms for the given permission.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
A bit map of M_fs_perms_mode_t values which are the permissions that are set.

◆ M_fs_perms_get_type()

M_fs_perms_type_t M_fs_perms_get_type ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Get the type (exact/add/remove) associated with the perms for the given permission.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
The permission type.

◆ M_fs_perms_get_isset()

M_bool M_fs_perms_get_isset ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Check if a given permission is set.

If not set the permission will be ignored during merge, set and other operation that use the permissions.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
M_TRUE if the permission are set. Otherwise M_FALSE.

◆ M_fs_perms_get_dir_mode()

M_uint32 M_fs_perms_get_dir_mode ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Get the directory override mode associated with the perms for the given permission.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
A bit map of M_fs_perms_mode_t values which are the permissions that are set.

◆ M_fs_perms_get_dir_type()

M_fs_perms_type_t M_fs_perms_get_dir_type ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Get the directory override type (exact/add/remove) associated with the perms for the given permission.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
The permission type.

◆ M_fs_perms_get_dir_isset()

M_bool M_fs_perms_get_dir_isset ( const M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Check if a given directory override permission is set.

If not set the permission will be ignored during merge, set and other operation that use the permissions.

Parameters
[in]permsThe perms.
[in]whoThe permissions this applies to.
Returns
M_TRUE if the permission are set. Otherwise M_FALSE.

◆ M_fs_perms_set_user()

M_fs_error_t M_fs_perms_set_user ( M_fs_perms_t perms,
const char *  user 
)

Set the user.

Parameters
[in]permsThe perms.
[in]userThe user.
Returns
Result.

◆ M_fs_perms_set_group()

M_fs_error_t M_fs_perms_set_group ( M_fs_perms_t perms,
const char *  group 
)

Set the group.

Parameters
[in]permsThe perms.
[in]groupThe group.
Returns
Result.

◆ M_fs_perms_set_mode()

void M_fs_perms_set_mode ( M_fs_perms_t perms,
M_uint32  mode,
M_fs_perms_who_t  who,
M_fs_perms_type_t  type 
)

Set the mode for the perms.

Parameters
[in]permsThe perms.
[in]modeM_fs_file_mode_t modes.
[in]whoWho this applies to.
[in]typeThe type permissions being set.

◆ M_fs_perms_set_dir_mode()

void M_fs_perms_set_dir_mode ( M_fs_perms_t perms,
M_uint32  mode,
M_fs_perms_who_t  who,
M_fs_perms_type_t  type 
)

Set the directory override mode for the perms.

Parameters
[in]permsThe perms.
[in]modeM_fs_file_mode_t modes.
[in]whoWho this applies to.
[in]typeThe type permissions being set.

◆ M_fs_perms_unset_mode()

void M_fs_perms_unset_mode ( M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Unset permissions.

This is different than setting no permissions.

This will also unset the equivalent directory override permissions.

Parameters
[in]permsThe perms.
[in]whoWho this applies to.

◆ M_fs_perms_unset_dir_mode()

void M_fs_perms_unset_dir_mode ( M_fs_perms_t perms,
M_fs_perms_who_t  who 
)

Unset directory override permissions.

This is different than setting no permissions.

Parameters
[in]permsThe perms.
[in]whoWho this applies to.