Basic Solution File System - BSFS
Loading...
Searching...
No Matches
permissions_bsfs.h File Reference

Permission helper routines for BSFS (POSIX-like rwx bits). More...

Macros

#define S_IXOTH   0001
#define S_IWOTH   0002
#define S_IROTH   0004
#define S_IXGRP   0010
#define S_IWGRP   0020
#define S_IRGRP   0040
#define S_IXUSR   0100
#define S_IWUSR   0200
#define S_IRUSR   0400
#define S_ISVTX   01000
#define S_ISGID   02000
#define S_ISUID   04000

Functions

uint16_t bsfs_effective_mode (const inode_t *ino, uint16_t uid, uint16_t gid)
 Compute the effective rwx mode (3 bits) for a caller on an inode.
int bsfs_can_read_file (const inode_t *file, uint16_t uid, uint16_t gid)
 Check if caller can read a regular file.
int bsfs_can_write_file (const inode_t *file, uint16_t uid, uint16_t gid)
 Check if caller can write to a regular file.
int bsfs_can_exec_file (const inode_t *file, uint16_t uid, uint16_t gid)
 Check if caller can execute a regular file.
int bsfs_can_traverse_dir (const inode_t *dir, uint16_t uid, uint16_t gid)
 Check if caller can traverse (search) a directory.
int bsfs_can_list_dir (const inode_t *dir, uint16_t uid, uint16_t gid)
 Check if caller can list entries in a directory.
int bsfs_can_modify_dir (const inode_t *dir, uint16_t uid, uint16_t gid)
 Check if caller can modify entries within a directory (w+x).
int bsfs_can_unlink_in_sticky (const inode_t *dir, const inode_t *entry, uint16_t uid, uint16_t gid)
 Check unlink/rename permission in a sticky directory.

Detailed Description

Permission helper routines for BSFS (POSIX-like rwx bits).

Provides centralized checks to enforce discretionary access control (DAC) using classic rwx bits on inodes. These helpers should be called from path traversal and API entry points (mkdir/rmdir/create/remove/move/open, etc.) rather than from low-level I/O primitives.

Macro Definition Documentation

◆ S_IRGRP

#define S_IRGRP   0040

Read permission for group.

◆ S_IROTH

#define S_IROTH   0004

Read permission for others.

◆ S_IRUSR

#define S_IRUSR   0400

Read permission for owner.

◆ S_ISGID

#define S_ISGID   02000

Set-GID bit.

◆ S_ISUID

#define S_ISUID   04000

Set-UID bit.

◆ S_ISVTX

#define S_ISVTX   01000

Sticky bit (restricts unlink/rename in dir).

◆ S_IWGRP

#define S_IWGRP   0020

Write permission for group.

◆ S_IWOTH

#define S_IWOTH   0002

Write permission for others.

◆ S_IWUSR

#define S_IWUSR   0200

Write permission for owner.

◆ S_IXGRP

#define S_IXGRP   0010

Execute/search permission for group.

◆ S_IXOTH

#define S_IXOTH   0001

Execute/search permission for others.

◆ S_IXUSR

#define S_IXUSR   0100

Execute/search permission for owner.

Function Documentation

◆ bsfs_can_exec_file()

int bsfs_can_exec_file ( const inode_t * file,
uint16_t uid,
uint16_t gid )

Check if caller can execute a regular file.

Parameters
fileTarget inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_can_list_dir()

int bsfs_can_list_dir ( const inode_t * dir,
uint16_t uid,
uint16_t gid )

Check if caller can list entries in a directory.

Parameters
dirDirectory inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_can_modify_dir()

int bsfs_can_modify_dir ( const inode_t * dir,
uint16_t uid,
uint16_t gid )

Check if caller can modify entries within a directory (w+x).

Parameters
dirDirectory inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_can_read_file()

int bsfs_can_read_file ( const inode_t * file,
uint16_t uid,
uint16_t gid )

Check if caller can read a regular file.

Parameters
fileTarget inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_can_traverse_dir()

int bsfs_can_traverse_dir ( const inode_t * dir,
uint16_t uid,
uint16_t gid )

Check if caller can traverse (search) a directory.

Parameters
dirDirectory inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_can_unlink_in_sticky()

int bsfs_can_unlink_in_sticky ( const inode_t * dir,
const inode_t * entry,
uint16_t uid,
uint16_t gid )

Check unlink/rename permission in a sticky directory.

If the directory has sticky bit set (S_ISVTX), only root, the directory owner, or the entry owner may remove/rename entries inside it.

Parameters
dirParent directory inode.
entryEntry inode (file or subdirectory) to remove/rename.
uidCaller user id.
gidCaller group id (unused here).
Returns
1 if allowed, 0 otherwise.

◆ bsfs_can_write_file()

int bsfs_can_write_file ( const inode_t * file,
uint16_t uid,
uint16_t gid )

Check if caller can write to a regular file.

Parameters
fileTarget inode.
uidCaller user id.
gidCaller group id.
Returns
1 if allowed; 0 otherwise.

◆ bsfs_effective_mode()

uint16_t bsfs_effective_mode ( const inode_t * ino,
uint16_t uid,
uint16_t gid )

Compute the effective rwx mode (3 bits) for a caller on an inode.

Parameters
inoTarget inode.
uidCaller user id.
gidCaller group id.
Returns
3-bit mask (r=4, w=2, x=1) for the caller class; root returns 7.