summaryrefslogtreecommitdiffstats
path: root/src/tools/tools_util.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-01-20 20:27:05 +0100
committerJakub Hrozek <jhrozek@redhat.com>2013-01-23 14:27:58 +0100
commit94cbf1cfb0f88c967f1fb0a4cf23723148868e4a (patch)
tree11f640bd1b848d8e3b295e62bcec69dea188cb69 /src/tools/tools_util.c
parent020bf88fd1c5bdac8fc671b37c7118f5378c7047 (diff)
downloadsssd-94cbf1cfb0f88c967f1fb0a4cf23723148868e4a.tar.gz
sssd-94cbf1cfb0f88c967f1fb0a4cf23723148868e4a.tar.xz
sssd-94cbf1cfb0f88c967f1fb0a4cf23723148868e4a.zip
TOOLS: Use file descriptor to avoid races when creating a home directory
When creating a home directory, the destination tree can be modified in various ways while it is being constructed because directory permissions are set before populating the directory. This can lead to file creation and permission changes outside the target directory tree, using hard links. This security problem was assigned CVE-2013-0219 https://fedorahosted.org/sssd/ticket/1782
Diffstat (limited to 'src/tools/tools_util.c')
-rw-r--r--src/tools/tools_util.c28
1 files changed, 1 insertions, 27 deletions
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 0151400d2..731b2d04f 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -477,33 +477,7 @@ int create_homedir(const char *skeldir,
selinux_file_context(homedir);
- ret = mkdir(homedir, 0);
- if (ret != 0) {
- ret = errno;
- DEBUG(1, ("Cannot create user's home directory: [%d][%s].\n",
- ret, strerror(ret)));
- goto done;
- }
-
- ret = chown(homedir, uid, gid);
- if (ret != 0) {
- ret = errno;
- DEBUG(1, ("Cannot chown user's home directory: [%d][%s].\n",
- ret, strerror(ret)));
- goto done;
- }
-
- ret = chmod(homedir, 0777 & ~default_umask);
- if (ret != 0) {
- ret = errno;
- DEBUG(1, ("Cannot chmod user's home directory: [%d][%s].\n",
- ret, strerror(ret)));
- goto done;
- }
-
- reset_selinux_file_context();
-
- ret = copy_tree(skeldir, homedir, uid, gid);
+ ret = copy_tree(skeldir, homedir, 0777 & ~default_umask, uid, gid);
if (ret != EOK) {
DEBUG(1, ("Cannot populate user's home directory: [%d][%s].\n",
ret, strerror(ret)));