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
+3
View File
@@ -183,6 +183,9 @@ int main(int argc, char **argv)
return 1;
}
setgid(pwd->pw_gid);
setuid(pwd->pw_uid);
char *_argv[] = { pwd->pw_shell, (char *)NULL };
if (execv(pwd->pw_shell, _argv) == -1) {
printf("%s: Failed to execute the shell.\n", argv[0]);
+2 -1
View File
@@ -5,6 +5,7 @@
/// See LICENSE.md for details.
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <strerror.h>
@@ -23,7 +24,7 @@ int main(int argc, char *argv[])
printf(" %s <directory>\n", argv[0]);
return 0;
}
if (mkdir(argv[1], 0)) {
if (mkdir(argv[1], S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
printf("%s: cannot create directory '%s': %s\n", argv[0], argv[1], strerror(errno));
}
return 0;
+1 -1
View File
@@ -747,7 +747,7 @@ int main(int argc, char *argv[])
if (cpid == 0) {
// Makes the new process a group leader
pid_t pid = getpid();
setgid(pid);
setpgid(cpid, pid);
if (execvp(_argv[0], _argv) == -1) {
printf("\nUnknown command: %s\n", _argv[0]);
+1 -1
View File
@@ -27,7 +27,7 @@ int main(int argc, char** argv)
}
int fd = open(argv[1], O_RDONLY, 0);
if (fd < 0) {
fd = open(argv[1], O_CREAT, 0);
fd = open(argv[1], O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
if (fd >= 0) {
close(fd);
}