Improve format
This commit is contained in:
+22
-12
@@ -5,10 +5,10 @@
|
||||
|
||||
#include "ipc/ipc.h"
|
||||
|
||||
#include "process/scheduler.h"
|
||||
#include "io/debug.h"
|
||||
#include "assert.h"
|
||||
#include "fcntl.h"
|
||||
#include "io/debug.h"
|
||||
#include "process/scheduler.h"
|
||||
|
||||
int ipc_check_perm(
|
||||
task_struct *task,
|
||||
@@ -21,22 +21,28 @@ int ipc_check_perm(
|
||||
assert(perm && "Received a NULL perm.");
|
||||
int check_parent = (perm->key < 0) && task->parent && (task->parent->pid != 0);
|
||||
if (perm->mode & usr) {
|
||||
if ((perm->uid == task->uid) || (perm->cuid == task->uid))
|
||||
if ((perm->uid == task->uid) || (perm->cuid == task->uid)) {
|
||||
return 1;
|
||||
if (check_parent && ((perm->uid == task->parent->uid) || (perm->cuid == task->parent->uid)))
|
||||
}
|
||||
if (check_parent && ((perm->uid == task->parent->uid) || (perm->cuid == task->parent->uid))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (perm->mode & grp) {
|
||||
if ((perm->gid == task->gid) || (perm->cgid == task->gid))
|
||||
if ((perm->gid == task->gid) || (perm->cgid == task->gid)) {
|
||||
return 1;
|
||||
if (check_parent && ((perm->gid == task->parent->gid) || (perm->cgid == task->parent->gid)))
|
||||
}
|
||||
if (check_parent && ((perm->gid == task->parent->gid) || (perm->cgid == task->parent->gid))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (perm->mode & oth) {
|
||||
if (check_parent && ((perm->uid != task->parent->uid) || (perm->cuid != task->parent->uid)))
|
||||
if (check_parent && ((perm->uid != task->parent->uid) || (perm->cuid != task->parent->uid))) {
|
||||
return 1;
|
||||
if (check_parent && ((perm->gid != task->parent->gid) || (perm->cgid != task->parent->gid)))
|
||||
}
|
||||
if (check_parent && ((perm->gid != task->parent->gid) || (perm->cgid != task->parent->gid))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -47,15 +53,19 @@ int ipc_valid_permissions(int flags, struct ipc_perm *perm)
|
||||
task_struct *task = scheduler_get_current_process();
|
||||
assert(task && "Failed to get the current running process.");
|
||||
// Init, and all root processes have full permissions.
|
||||
if ((task->pid == 0) || (task->uid == 0) || (task->gid == 0))
|
||||
if ((task->pid == 0) || (task->uid == 0) || (task->gid == 0)) {
|
||||
return 1;
|
||||
}
|
||||
// Check permissions.
|
||||
if (((flags & O_RDONLY) == O_RDONLY) && ipc_check_perm(task, perm, S_IRUSR, S_IRGRP, S_IROTH))
|
||||
if (((flags & O_RDONLY) == O_RDONLY) && ipc_check_perm(task, perm, S_IRUSR, S_IRGRP, S_IROTH)) {
|
||||
return 1;
|
||||
if (((flags & O_WRONLY) == O_WRONLY) && ipc_check_perm(task, perm, S_IWUSR, S_IWGRP, S_IWOTH))
|
||||
}
|
||||
if (((flags & O_WRONLY) == O_WRONLY) && ipc_check_perm(task, perm, S_IWUSR, S_IWGRP, S_IWOTH)) {
|
||||
return 1;
|
||||
if (((flags & O_RDWR) == O_RDWR) && ipc_check_perm(task, perm, S_IRUSR | S_IWUSR, S_IRGRP | S_IWGRP, S_IROTH | S_IWOTH))
|
||||
}
|
||||
if (((flags & O_RDWR) == O_RDWR) && ipc_check_perm(task, perm, S_IRUSR | S_IWUSR, S_IRGRP | S_IWGRP, S_IROTH | S_IWOTH)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+12
-10
@@ -38,18 +38,18 @@
|
||||
#include "io/debug.h" // Include debugging functions.
|
||||
// ============================================================================
|
||||
|
||||
#include "sys/sem.h"
|
||||
#include "ipc/ipc.h"
|
||||
#include "sys/sem.h"
|
||||
|
||||
#include "process/scheduler.h"
|
||||
#include "process/process.h"
|
||||
#include "assert.h"
|
||||
#include "fcntl.h"
|
||||
#include "klib/list.h"
|
||||
#include "sys/errno.h"
|
||||
#include "process/process.h"
|
||||
#include "process/scheduler.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "assert.h"
|
||||
#include "stdio.h"
|
||||
#include "fcntl.h"
|
||||
#include "sys/errno.h"
|
||||
|
||||
///@brief A value to compute the semid value.
|
||||
int __sem_id = 0;
|
||||
@@ -135,8 +135,9 @@ static inline sem_info_t *__list_find_sem_info_by_id(int semid)
|
||||
// Get the current entry.
|
||||
sem_info = list_entry(it, sem_info_t, list);
|
||||
// If semaphore set is valid, check the id.
|
||||
if (sem_info && (sem_info->id == semid))
|
||||
if (sem_info && (sem_info->id == semid)) {
|
||||
return sem_info;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -153,8 +154,9 @@ static inline sem_info_t *__list_find_sem_info_by_key(key_t key)
|
||||
// Get the current entry.
|
||||
sem_info = list_entry(it, sem_info_t, list);
|
||||
// If semaphore set is valid, check the id.
|
||||
if (sem_info && (sem_info->semid.sem_perm.key == key))
|
||||
if (sem_info && (sem_info->semid.sem_perm.key == key)) {
|
||||
return sem_info;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -196,7 +198,7 @@ long sys_semget(key_t key, int nsems, int semflg)
|
||||
if (key == IPC_PRIVATE) {
|
||||
// Exit when i find a unique key.
|
||||
do {
|
||||
key = -rand();
|
||||
key = (int)-rand();
|
||||
} while (__list_find_sem_info_by_key(key));
|
||||
// We have a unique key, create the semaphore set.
|
||||
sem_info = __sem_info_alloc(key, nsems, semflg);
|
||||
|
||||
Reference in New Issue
Block a user