URL: https://github.com/freeipa/freeipa/pull/726
Author: Akasurde
 Title: #726: Add check for directory name
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/726/head:pr726
git checkout pr726
From 8032a7a989c3172bec8a19b34413d601032d08a6 Mon Sep 17 00:00:00 2001
From: Abhijeet Kasurde <akasu...@redhat.com>
Date: Fri, 21 Apr 2017 10:11:38 +0530
Subject: [PATCH] Add check for directory name

Fix adds check to verify if user provided input is not
a directory when filename is required.

Fixes: https://pagure.io/freeipa/issue/6883

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
---
 ipalib/util.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ipalib/util.py b/ipalib/util.py
index e9d4105..db59ddf 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -170,6 +170,10 @@ def check_writable_file(filename):
     """
     if filename is None:
         raise errors.FileError(reason=_('Filename is empty'))
+
+    if os.path.isdir(filename):
+        raise errors.FileError(reason=_('Expected file but {fname} is a '
+                                        'directory'.format(fname=filename))
     try:
         if os.path.exists(filename):
             if not os.access(filename, os.W_OK):
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to