The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
permission.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * file permissions: who may read, write and run a file.
5 *
6 * the effective user id picks the class: the owner's bits if it owns the
7 * file, the group's bits if the effective group id is the file's group,
8 * else the bits for others. root (effective uid 0) may read and write
9 * anything, and run anything with at least one execute bit (or a
10 * directory: search it).
11 *
12 * path permissions are checked on the file itself and its parent
13 * directory; directories higher up are not searched for execute rights.
14 */
15
16#include "common/stdint.h"
17#include "kernel/fs/fs.h"
18
19struct process;
20
21#define MAY_EXEC 1
22#define MAY_WRITE 2
23#define MAY_READ 4
24
25#define S_ISUID 04000 // run with the owner's user id
26#define S_ISGID 02000 // run with the file's group id
27#define S_ISVTX 01000 // sticky: in a directory, only owners remove entries
28
29/**
30 * check an access against a file's mode and owner.
31 * @param st the file's stat.
32 * @param uid the user id to check as (effective, or real for access()).
33 * @param gid the group id to check as.
34 * @param want MAY_* bits.
35 * @return 0, or -EACCES.
36 */
38
39/**
40 * check an access to a path for the current process (effective ids).
41 * @return 0, -EACCES, or the error of finding the file (-ENOENT).
42 */
43int32_t permission_check_path(const char *path, uint32_t want);
44
45/**
46 * check that the current process may add or remove an entry of a
47 * directory: write and search rights on the parent of path. for a removal
48 * (victim true) in a sticky directory, it must also own the entry or the
49 * directory.
50 * @return 0, -EACCES, -EPERM, or the error of finding the parent.
51 */
52int32_t permission_check_parent(const char *path, bool victim);
53
54/**
55 * the parent directory of an absolute path ("/a/b" -> "/a", "/a" -> "/").
56 * @param path the path.
57 * @param out receives the parent.
58 * @param size size of out.
59 */
60void permission_parent_path(const char *path, char *out, uint32_t size);
struct fs_stat fs_stat_t
Definition fs.h:37
unsigned int uint32_t
Definition fb.h:17
int int32_t
Definition stdint.h:14
int32_t permission_check(const fs_stat_t *st, uint32_t uid, uint32_t gid, uint32_t want)
check an access against a file's mode and owner.
Definition permission.c:10
int32_t permission_check_path(const char *path, uint32_t want)
check an access to a path for the current process (effective ids).
Definition permission.c:32
void permission_parent_path(const char *path, char *out, uint32_t size)
the parent directory of an absolute path ("/a/b" -> "/a", "/a" -> "/").
Definition permission.c:43
int32_t permission_check_parent(const char *path, bool victim)
check that the current process may add or remove an entry of a directory: write and search rights on ...
Definition permission.c:60
process control block.
Definition process.h:69
uint32_t uid
Definition process.h:89
uint32_t gid
Definition process.h:90