Fix difference between PGID and GID. Correctly set UID and GID of new processes. Implement set/get PGID and GID.

This commit is contained in:
Enrico Fraccaroli
2021-12-27 00:49:28 +01:00
parent 2226eebdc8
commit 7c4a4ac0ba
20 changed files with 216 additions and 92 deletions
+4
View File
@@ -89,8 +89,12 @@ add_library(
${PROJECT_SOURCE_DIR}/src/unistd/exit.c
${PROJECT_SOURCE_DIR}/src/unistd/setsid.c
${PROJECT_SOURCE_DIR}/src/unistd/getsid.c
${PROJECT_SOURCE_DIR}/src/unistd/setpgid.c
${PROJECT_SOURCE_DIR}/src/unistd/getpgid.c
${PROJECT_SOURCE_DIR}/src/unistd/setgid.c
${PROJECT_SOURCE_DIR}/src/unistd/getgid.c
${PROJECT_SOURCE_DIR}/src/unistd/setuid.c
${PROJECT_SOURCE_DIR}/src/unistd/getuid.c
${PROJECT_SOURCE_DIR}/src/unistd/fork.c
${PROJECT_SOURCE_DIR}/src/unistd/read.c
${PROJECT_SOURCE_DIR}/src/unistd/write.c
+15 -14
View File
@@ -20,20 +20,21 @@
/// @brief The file modes.
/// @{
#define S_IRWXU 0000700U ///< RWX mask for user.
#define S_IRUSR 0000400U ///< R for user.
#define S_IWUSR 0000200U ///< W for user.
#define S_IXUSR 0000100U ///< X for user.
#define S_IRWXG 0000070U ///< RWX mask for group.
#define S_IRGRP 0000040U ///< R for group.
#define S_IWGRP 0000020U ///< W for group.
#define S_IXGRP 0000010U ///< X for group.
#define S_IRWXO 0000007U ///< RWX mask for group.
#define S_IROTH 0000004U ///< R for group.
#define S_IWOTH 0000002U ///< W for group.
#define S_IXOTH 0000001U ///< X for group.
#define S_ISUID 0x0800 ///< Set user id on execution
#define S_ISGID 0x0400 ///< Set group id on execution
#define S_ISVTX 0x0200 ///< Save swapped text even after use (Sticky Bit)
#define S_IRWXU 0x01C0 ///< rwx------- : User can read/write/execute
#define S_IRUSR 0x0100 ///< -r-------- : User can read
#define S_IWUSR 0x0080 ///< --w------- : User can write
#define S_IXUSR 0x0040 ///< ---x------ : User can execute
#define S_IRWXG 0x0038 ///< ----rwx--- : Group can read/write/execute
#define S_IRGRP 0x0020 ///< ----r----- : Group can read
#define S_IWGRP 0x0010 ///< -----w---- : Group can write
#define S_IXGRP 0x0008 ///< ------x--- : Group can execute
#define S_IRWXO 0x0007 ///< -------rwx : Others can read/write/execute
#define S_IROTH 0x0004 ///< -------r-- : Others can read
#define S_IWOTH 0x0002 ///< --------w- : Others can write
#define S_IXOTH 0x0001 ///< ---------x : Others can execute
#define S_ISDIR(m) (((m)&0170000) == 0040000) ///< directory.
#define S_ISCHR(m) (((m)&0170000) == 0020000) ///< char special
+23
View File
@@ -84,6 +84,19 @@ extern pid_t getsid(pid_t pid);
/// Otherwise return -1 with errno : EPERM
extern pid_t setsid();
///@brief returns the Process Group ID (PGID) of the process specified by pid.
/// If pid is zero, the process ID of the calling process is used.
/// @param pid process of which we want to know the PGID.
/// @return the PGID of the specified process.
pid_t getpgid(pid_t pid);
/// @brief Sets the Process Group ID (PGID) of the process specified by pid.
/// If pid is zero, the process ID of the calling process is used.
/// @param pid process of which we want to set the PGID.
/// @param pgid the PGID we want to set.
/// @return returns zero. On error, -1 is returned, and errno is set appropriately.
int setpgid(pid_t pid, pid_t pgid);
///@brief returns the group ID of the calling process.
///@return GID of the current process
extern pid_t getgid();
@@ -94,6 +107,16 @@ extern pid_t getgid();
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
extern int setgid(pid_t pid);
///@brief Returns the User ID of the calling process.
///@return User ID of the current process.
extern uid_t getuid();
///@brief Sets the effective User ID of the calling process.
///@param uid the new User ID.
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
extern int setuid(uid_t uid);
/// @brief Returns the parent process ID (PPID) of the calling process.
/// @return pid_t parent process identifier.
extern pid_t getppid();
+11
View File
@@ -0,0 +1,11 @@
/// MentOS, The Mentoring Operating system project
/// @file getpgid.c
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "system/syscall_types.h"
#include "sys/errno.h"
_syscall1(pid_t, getpgid, pid_t, pid)
+11
View File
@@ -0,0 +1,11 @@
/// MentOS, The Mentoring Operating system project
/// @file getuid.c
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "system/syscall_types.h"
#include "sys/errno.h"
_syscall0(uid_t, getuid)
+11
View File
@@ -0,0 +1,11 @@
/// MentOS, The Mentoring Operating system project
/// @file setpgid.c
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "system/syscall_types.h"
#include "sys/errno.h"
_syscall2(int, setpgid, pid_t, pid, pid_t, pgid)
+11
View File
@@ -0,0 +1,11 @@
/// MentOS, The Mentoring Operating system project
/// @file setuid.c
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "system/syscall_types.h"
#include "sys/errno.h"
_syscall1(int, setuid, uid_t, pid)