home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2459 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.5 KB  |  57 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import win32api
  6. import win32net
  7. import win32netcon
  8. import optparse
  9. from pprint import pprint
  10.  
  11. def main():
  12.     parser = optparse.OptionParser('%prog [options] add|change ...', description = 'A win32net.NetValidatePasswordPolicy demo.')
  13.     parser.add_option('-u', '--username', action = 'store', help = 'The username to pass to the function (only for the change command')
  14.     parser.add_option('-p', '--password', action = 'store', help = "The clear-text password to pass to the function (only for the 'change' command)")
  15.     parser.add_option('-m', '--password-matched', action = 'store_false', default = True, help = "Used to specify the password does NOT match (ie, uses False for the PasswordMatch/PasswordMatched arg, both 'auth' and 'change' commands)")
  16.     parser.add_option('-s', '--server', action = 'store', help = 'The name of the server to execute the command on')
  17.     parser.add_option('-f', '--show_fields', action = 'store_true', default = False, help = 'Print the NET_VALIDATE_PERSISTED_FIELDS returned')
  18.     (options, args) = parser.parse_args()
  19.     if not args:
  20.         parser.error('You must supply an arg')
  21.     
  22.     for arg in args:
  23.         if arg == 'auth':
  24.             input = {
  25.                 'PasswordMatched': options.password_matched }
  26.             val_type = win32netcon.NetValidateAuthentication
  27.         elif arg == 'change':
  28.             input = {
  29.                 'ClearPassword': options.password,
  30.                 'PasswordMatch': options.password_matched,
  31.                 'UserAccountName': options.username }
  32.             val_type = win32netcon.NetValidatePasswordChange
  33.         else:
  34.             parser.error("Invalid arg - must be 'auth' or 'change'")
  35.         
  36.         try:
  37.             (fields, status) = win32net.NetValidatePasswordPolicy(options.server, None, val_type, input)
  38.         except NotImplementedError:
  39.             print 'NetValidatePasswordPolicy not implemented on this platform.'
  40.             return 1
  41.             except win32net.error:
  42.                 exc = None
  43.                 print 'NetValidatePasswordPolicy failed: ', exc
  44.                 return 1
  45.             elif options.show_fields:
  46.                 print 'NET_VALIDATE_PERSISTED_FIELDS fields:'
  47.                 pprint(fields)
  48.             
  49.  
  50.         print 'Result of %r validation is %d: %s' % (arg, status, win32api.FormatMessage(status).strip())
  51.     
  52.     return 0
  53.  
  54. if __name__ == '__main__':
  55.     sys.exit(main())
  56.  
  57.