diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-17 13:35:58 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-20 10:30:24 +0100 |
commit | e02d5dd9b3143b2e72d2c71e914d7bd96a47bf7b (patch) | |
tree | c7f966aea6a8d1ef261010f7b12c6e838075a619 /cpukit/libcsupport | |
parent | shell: Do chroot() after successful login (diff) | |
download | rtems-e02d5dd9b3143b2e72d2c71e914d7bd96a47bf7b.tar.bz2 |
Ensure security of default user environment
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/src/base_fs.c | 5 | ||||
-rw-r--r-- | cpukit/libcsupport/src/pwdgrp.c | 17 |
2 files changed, 13 insertions, 9 deletions
diff --git a/cpukit/libcsupport/src/base_fs.c b/cpukit/libcsupport/src/base_fs.c index 5a0e67b158..16fa9b8a88 100644 --- a/cpukit/libcsupport/src/base_fs.c +++ b/cpukit/libcsupport/src/base_fs.c @@ -49,12 +49,9 @@ void rtems_filesystem_initialize( void ) * Traditionally RTEMS devices are under "/dev" so install this directory. * * If the mkdir() fails, we can't print anything so just fatal error. - * - * NOTE: UNIX root is 755 and owned by root/root (0/0). It is actually - * created that way by the IMFS. */ - rv = mkdir( "/dev", 0777); + rv = mkdir( "/dev", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); if ( rv != 0 ) rtems_fatal_error_occurred( 0xABCD0003 ); diff --git a/cpukit/libcsupport/src/pwdgrp.c b/cpukit/libcsupport/src/pwdgrp.c index ea240975b4..e1e08662d6 100644 --- a/cpukit/libcsupport/src/pwdgrp.c +++ b/cpukit/libcsupport/src/pwdgrp.c @@ -26,6 +26,7 @@ #include <pwd.h> #include <grp.h> #include <errno.h> +#include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h> @@ -41,11 +42,17 @@ static pthread_once_t pwdgrp_once = PTHREAD_ONCE_INIT; static void init_file(const char *name, const char *content) { - FILE *fp = fopen(name, "wx"); + /* + * Unlike to standard UNIX systems, these files are only readable and + * writeable for the root user. This way we avoid the need for an + * /etc/shadow. In case more UNIX compatibility is desired, this can be + * added on demand. + */ + int fd = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR); - if (fp != NULL) { - fputs(content, fp); - fclose(fp); + if (fd >= 0) { + write(fd, content, strlen(content)); + close(fd); } } @@ -54,7 +61,7 @@ static void init_file(const char *name, const char *content) */ static void pwdgrp_init(void) { - mkdir("/etc", 0777); + mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* * Initialize /etc/passwd |