{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/32781691","id":32781691,"diff_hunk":"@@ -0,0 +1,146 @@\n+#!powershell\n+# This file is part of Ansible\n+#\n+# Copyright 2014, Phil Schwartz <schwartzmx@gmail.com>\n+#\n+# Ansible is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# Ansible is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n+\n+# WANT_JSON\n+# POWERSHELL_COMMON\n+\n+# win_acl module (File/Resources Permission Additions/Removal)\n+$params = Parse-Args $args;\n+\n+$result = New-Object psobject @{\n+    win_acl = New-Object psobject\n+    changed = $false\n+}\n+\n+If ($params.src) {\n+    $src = $params.src.toString()\n+\n+    If (-Not (Test-Path -Path $src -PathType Leaf -Or Test-Path -Path $src -PathType Container)) {\n+        Fail-Json $result \"$src is not a valid file or directory on the host\"\n+    }\n+}\n+Else {\n+    Fail-Json $result \"missing required argument: src\"\n+}\n+\n+If ($params.user) {\n+    $user = $params.user.toString()\n+\n+    # Test that the user/group exists on the local machine\n+    $localComputer = [ADSI](\"WinNT://\"+[System.Net.Dns]::GetHostName())\n+    $list = ($localComputer.psbase.children | Where-Object { (($_.psBase.schemaClassName -eq \"User\") -Or ($_.psBase.schemaClassName -eq \"Group\"))} | Select-Object -expand Name)\n+    If (-Not ($list -contains \"$user\")) {\n+        Fail-Json $result \"$user is not a valid user or group on the host machine\"\n+    }\n+}\n+Else {\n+    Fail-Json $result \"missing required argument: user.  specify the user or group to apply permission changes.\"\n+}\n+\n+If ($params.type -eq \"allow\") {\n+    $type = $true\n+}\n+ElseIf ($params.type -eq \"deny\") {\n+    $type = $false\n+}\n+Else {\n+    Fail-Json $result \"missing required argument: type. specify whether to allow or deny the specified rights.\"\n+}\n+\n+If ($params.inherit) {\n+    # If it's a file then no flags can be set or an exception will be thrown\n+    If (Test-Path -Path $src -PathType Leaf) {\n+        $inherit = \"None\"\n+    }\n+    Else {\n+        $inherit = $params.inherit.toString()\n+    }\n+}\n+Else {\n+    # If it's a file then no flags can be set or an exception will be thrown\n+    If (Test-Path -Path $src -PathType Leaf) {\n+        $inherit = \"None\"\n+    }\n+    Else {\n+        $inherit = \"ContainerInherit, ObjectInherit\"\n+    }\n+}\n+\n+If ($params.propagation) {\n+    $propagation = $params.propagation.toString()\n+}\n+Else {\n+    $propagation = \"None\"\n+}\n+\n+If ($params.rights) {\n+    $rights = $params.rights.toString()\n+}\n+Else {\n+    Fail-Json $result \"missing required argument: rights\"\n+}\n+\n+If ($params.state -eq \"absent\") {\n+    $state = \"remove\"\n+}\n+Else {\n+    $state = \"add\"\n+}\n+\n+Try {\n+    $colRights = [System.Security.AccessControl.FileSystemRights]$rights\n+    $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]$inherit\n+    $PropagationFlag = [System.Security.AccessControl.PropagationFlags]$propagation\n+\n+    If ($type) {\n+        $objType =[System.Security.AccessControl.AccessControlType]::Allow\n+    }\n+    Else {\n+        $objType =[System.Security.AccessControl.AccessControlType]::Deny\n+    }\n+\n+    $objUser = New-Object System.Security.Principal.NTAccount($user)\n+    $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)\n+    $objACL = Get-ACL $src\n+\n+    If ($state -eq \"add\") {\n+        Try {\n+            $objACL.AddAccessRule($objACE)\n+        }\n+        Catch {\n+            Fail-Json $result \"an exception occured when adding the specified rule.  it may already exist.\"\n+        }\n+    }\n+    Else {\n+        Try {\n+            $objACL.RemoveAccessRule($objACE)\n+        }\n+        Catch {\n+            Fail-Json $result \"an exception occured when removing the specified rule.  it may not exist.\"\n+        }\n+    }\n+\n+    Set-ACL $src $objACL\n+\n+    $result.changed = $true","path":"windows/win_acl.ps1","position":140,"original_position":140,"commit_id":"4ece7362fba8286a032fb4e70e02dff381ca5087","original_commit_id":"4ece7362fba8286a032fb4e70e02dff381ca5087","user":{"login":"elventear","id":45383,"avatar_url":"https://avatars.githubusercontent.com/u/45383?v=3","gravatar_id":"","url":"https://api.github.com/users/elventear","html_url":"https://github.com/elventear","followers_url":"https://api.github.com/users/elventear/followers","following_url":"https://api.github.com/users/elventear/following{/other_user}","gists_url":"https://api.github.com/users/elventear/gists{/gist_id}","starred_url":"https://api.github.com/users/elventear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elventear/subscriptions","organizations_url":"https://api.github.com/users/elventear/orgs","repos_url":"https://api.github.com/users/elventear/repos","events_url":"https://api.github.com/users/elventear/events{/privacy}","received_events_url":"https://api.github.com/users/elventear/received_events","type":"User","site_admin":false},"body":"I haven't tested it, but what happens if you run the module two times in a row? Ideally the second time should not be marked as changed.\r\n\r\nI glanced quickly at the API, and you could use `$objACL.GetAccessRules` to get a collection of `AccessRule`s. Then it is a matter of testing if the `AccessRule` you wanted to add already exists or not.","created_at":"2015-06-18T21:39:13Z","updated_at":"2015-06-18T21:39:13Z","html_url":"https://github.com/ansible/ansible-modules-extras/pull/200#discussion_r32781691","pull_request_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/32781691"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/200#discussion_r32781691"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200","id":27405743,"html_url":"https://github.com/ansible/ansible-modules-extras/pull/200","diff_url":"https://github.com/ansible/ansible-modules-extras/pull/200.diff","patch_url":"https://github.com/ansible/ansible-modules-extras/pull/200.patch","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/200","number":200,"state":"open","locked":false,"title":"win_acl Module","user":{"login":"schwartzmx","id":6064408,"avatar_url":"https://avatars.githubusercontent.com/u/6064408?v=3","gravatar_id":"","url":"https://api.github.com/users/schwartzmx","html_url":"https://github.com/schwartzmx","followers_url":"https://api.github.com/users/schwartzmx/followers","following_url":"https://api.github.com/users/schwartzmx/following{/other_user}","gists_url":"https://api.github.com/users/schwartzmx/gists{/gist_id}","starred_url":"https://api.github.com/users/schwartzmx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schwartzmx/subscriptions","organizations_url":"https://api.github.com/users/schwartzmx/orgs","repos_url":"https://api.github.com/users/schwartzmx/repos","events_url":"https://api.github.com/users/schwartzmx/events{/privacy}","received_events_url":"https://api.github.com/users/schwartzmx/received_events","type":"User","site_admin":false},"body":"module `win_acl`:  __Access Control__\r\n  - Module allows for adding or removing `Allow`/`Deny` rules (permissions) on files and/or directories on Windows hosts.\r\n\r\nSee `win_acl.py` for documentation on `params`.\r\n\r\nSuggestions, concerns, comments, anything? Let me know please.\r\n\r\nPhil","created_at":"2015-01-15T04:34:22Z","updated_at":"2015-06-18T21:39:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8151c03611907d6ae2cae8aabe5f1f7fc90c9d23","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/200/comments","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/4ece7362fba8286a032fb4e70e02dff381ca5087","head":{"label":"schwartzmx:module/win_acl","ref":"module/win_acl","sha":"4ece7362fba8286a032fb4e70e02dff381ca5087","user":{"login":"schwartzmx","id":6064408,"avatar_url":"https://avatars.githubusercontent.com/u/6064408?v=3","gravatar_id":"","url":"https://api.github.com/users/schwartzmx","html_url":"https://github.com/schwartzmx","followers_url":"https://api.github.com/users/schwartzmx/followers","following_url":"https://api.github.com/users/schwartzmx/following{/other_user}","gists_url":"https://api.github.com/users/schwartzmx/gists{/gist_id}","starred_url":"https://api.github.com/users/schwartzmx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schwartzmx/subscriptions","organizations_url":"https://api.github.com/users/schwartzmx/orgs","repos_url":"https://api.github.com/users/schwartzmx/repos","events_url":"https://api.github.com/users/schwartzmx/events{/privacy}","received_events_url":"https://api.github.com/users/schwartzmx/received_events","type":"User","site_admin":false},"repo":{"id":28633990,"name":"ansible-modules-extras","full_name":"schwartzmx/ansible-modules-extras","owner":{"login":"schwartzmx","id":6064408,"avatar_url":"https://avatars.githubusercontent.com/u/6064408?v=3","gravatar_id":"","url":"https://api.github.com/users/schwartzmx","html_url":"https://github.com/schwartzmx","followers_url":"https://api.github.com/users/schwartzmx/followers","following_url":"https://api.github.com/users/schwartzmx/following{/other_user}","gists_url":"https://api.github.com/users/schwartzmx/gists{/gist_id}","starred_url":"https://api.github.com/users/schwartzmx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schwartzmx/subscriptions","organizations_url":"https://api.github.com/users/schwartzmx/orgs","repos_url":"https://api.github.com/users/schwartzmx/repos","events_url":"https://api.github.com/users/schwartzmx/events{/privacy}","received_events_url":"https://api.github.com/users/schwartzmx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/schwartzmx/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":true,"url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras","forks_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/schwartzmx/ansible-modules-extras/releases{/id}","created_at":"2014-12-30T14:39:30Z","updated_at":"2015-01-10T17:59:45Z","pushed_at":"2015-06-18T21:21:14Z","git_url":"git://github.com/schwartzmx/ansible-modules-extras.git","ssh_url":"git@github.com:schwartzmx/ansible-modules-extras.git","clone_url":"https://github.com/schwartzmx/ansible-modules-extras.git","svn_url":"https://github.com/schwartzmx/ansible-modules-extras","homepage":"","size":5784,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"86f2124c0d62359a0672fa0a81f85c0850c05dd1","user":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"repo":{"id":24474138,"name":"ansible-modules-extras","full_name":"ansible/ansible-modules-extras","owner":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ansible/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":false,"url":"https://api.github.com/repos/ansible/ansible-modules-extras","forks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/ansible/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/ansible/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible-modules-extras/releases{/id}","created_at":"2014-09-25T20:28:42Z","updated_at":"2015-06-18T09:28:21Z","pushed_at":"2015-06-18T21:21:14Z","git_url":"git://github.com/ansible/ansible-modules-extras.git","ssh_url":"git@github.com:ansible/ansible-modules-extras.git","clone_url":"https://github.com/ansible/ansible-modules-extras.git","svn_url":"https://github.com/ansible/ansible-modules-extras","homepage":"","size":22370,"stargazers_count":234,"watchers_count":234,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":500,"mirror_url":null,"open_issues_count":192,"forks":500,"open_issues":192,"watchers":234,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/200"},"issue":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/200"},"comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/200/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/200/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/4ece7362fba8286a032fb4e70e02dff381ca5087"}}}}