_symbolic_mode_to_octal- fix raising ValueError for invalid symbolic modes (#80449)

validate the full user and perm strings instead of just first character

fixes unhelpful unarchive error for some invalid modes
pull/80663/head
Sloane Hertel 1 year ago committed by GitHub
parent ed749cf0a0
commit d18d4f84ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- file modules - fix validating invalid symbolic modes.

@ -265,8 +265,8 @@ PASSWD_ARG_RE = re.compile(r'^[-]{0,2}pass[-]?(word|wd)?')
# Used for parsing symbolic file perms
MODE_OPERATOR_RE = re.compile(r'[+=-]')
USERS_RE = re.compile(r'[^ugo]')
PERMS_RE = re.compile(r'[^rwxXstugo]')
USERS_RE = re.compile(r'^[ugo]+$')
PERMS_RE = re.compile(r'^[rwxXstugo]*$')
#
@ -1063,14 +1063,14 @@ class AnsibleModule(object):
# Check if there are illegal characters in the user list
# They can end up in 'users' because they are not split
if USERS_RE.match(users):
if not USERS_RE.match(users):
raise ValueError("bad symbolic permission for mode: %s" % mode)
# Now we have two list of equal length, one contains the requested
# permissions and one with the corresponding operators.
for idx, perms in enumerate(permlist):
# Check if there are illegal characters in the permissions
if PERMS_RE.match(perms):
if not PERMS_RE.match(perms):
raise ValueError("bad symbolic permission for mode: %s" % mode)
for user in users:

@ -3,6 +3,29 @@
path: '{{remote_tmp_dir}}/test-unarchive-tar-gz'
state: directory
- name: test invalid modes
unarchive:
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
remote_src: yes
mode: "{{ item }}"
list_files: True
register: unarchive_mode_errors
ignore_errors: yes
loop:
- u=foo
- foo=r
- ufoo=r
- abc=r
- ao=r
- oa=r
- assert:
that:
- item.failed
- "'bad symbolic permission for mode: ' + item.item == item.details"
loop: "{{ unarchive_mode_errors.results }}"
- name: unarchive and set mode to 0600, directories 0700
unarchive:
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"

@ -192,6 +192,10 @@ UMASK_DATA = (
INVALID_DATA = (
(0o040000, u'a=foo', "bad symbolic permission for mode: a=foo"),
(0o040000, u'f=rwx', "bad symbolic permission for mode: f=rwx"),
(0o100777, u'of=r', "bad symbolic permission for mode: of=r"),
(0o100777, u'ao=r', "bad symbolic permission for mode: ao=r"),
(0o100777, u'oa=r', "bad symbolic permission for mode: oa=r"),
)

Loading…
Cancel
Save