From 0e98ce11c4cbb758e6634db66aa183962da2d922 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 13 Jun 2016 09:41:43 -0700 Subject: [PATCH] Comment on is_executable's limitations and change logic to only use bit-manipulations This is clearer to anyone who understands that unix file modes are bitfields. --- lib/ansible/module_utils/basic.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 362142ab7c5..0122c736e86 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -511,10 +511,17 @@ def heuristic_log_sanitize(data, no_log_values=None): return output def is_executable(path): - '''is the given path executable?''' - return (stat.S_IXUSR & os.stat(path)[stat.ST_MODE] - or stat.S_IXGRP & os.stat(path)[stat.ST_MODE] - or stat.S_IXOTH & os.stat(path)[stat.ST_MODE]) + '''is the given path executable? + + Limitations: + * Does not account for FSACLs. + * Most times we really want to know "Can the current user execute this + file" This function does not tell us that, only if an execute bit is set. + ''' + # These are all bitfields so first bitwise-or all the permissions we're + # looking for, then bitwise-and with the file's mode to determine if any + # execute bits are set. + return ((stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & os.stat(path)[stat.ST_MODE]) def _load_params(): ''' read the modules parameters and store them globally.