Permalink
Browse files

Add win_shadow.py and some other changes so that Salt States can mana…

…ge users on Windows
  • Loading branch information...
1 parent 00dc996 commit 0daf69df96612f8e6028564064daa9bff098a937 @UtahDave committed Feb 24, 2012
Showing with 80 additions and 0 deletions.
  1. +13 −0 salt/modules/shadow.py
  2. +17 −0 salt/modules/win_file.py
  3. +50 −0 salt/modules/win_shadow.py
@@ -5,6 +5,19 @@
import os
import spwd
+def __virtual__():
+ '''
+ Only work on posix-like systems
+ '''
+
+ # Disable on these platforms, specific file modules exist:
+ disable = [
+ 'Windows',
+ ]
+ if __grains__['os'] in disable:
+ return False
+ return 'file'
+
def info(name):
'''
@@ -124,6 +124,23 @@ def get_uid(path):
owner_sid = secdesc.GetSecurityDescriptorOwner()
return win32security.ConvertSidToStringSid(owner_sid)
+def get_mode(path):
+ '''
+ Return the mode of a file
+
+ Right now we're just returning 0777
+ because Windows' doesn't have a mode
+ like Linux
+
+ CLI Example::
+
+ salt '*' file.get_mode /etc/passwd
+ '''
+ if not os.path.exists(path):
+ return -1
+ mode = 0777
+ return mode
+
def get_user(path):
'''
@@ -0,0 +1,50 @@
+'''
+Manage the shadow file
+'''
+
+import os
+
+def __virtual__():
+ '''
+ Only works on Windows systems
+ '''
+ if __grains__['os'] == 'Windows':
+ return 'shadow'
+ return False
+
+
+def info(name):
+ '''
+ Return information for the specified user
+ This is just returns dummy data so that it states can work.
+
+ CLI Example::
+
+ salt '*' shadow.info root
+ '''
+ ret = {
+ 'name': name,
+ 'pwd': '',
+ 'lstchg': '',
+ 'min': '',
+ 'max': '',
+ 'warn': '',
+ 'inact': '',
+ 'expire': ''}
+ return ret
+
+
+def set_password(name, password):
+ '''
+ Set the password for a named user. The password must be a properly defined
+ hash, the password hash can be generated with this command:
+ ``openssl passwd -1 <plaintext password>``
+
+ CLI Example::
+
+ salt '*' shadow.set_password root $1$UYCIxa628.9qXjpQCjM4a..
+ '''
+ cmd = 'net user {0} {1}'.format(name, password)
+ ret = __salt__['cmd.run_all'](cmd)
+
+ return not ret['retcode']

0 comments on commit 0daf69d

Please sign in to comment.