PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/LinqDlrTests/testenv/perl/site/lib/win32/NetAdmin.pm

#
Perl | 418 lines | 292 code | 99 blank | 27 comment | 23 complexity | b740cf149849e531421ce186c8e791de MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. package Win32::NetAdmin;
  2. #
  3. #NetAdmin.pm
  4. #Written by Douglas_Lankshear@ActiveWare.com
  5. #
  6. $VERSION = '0.08';
  7. require Exporter;
  8. require DynaLoader;
  9. die "The Win32::NetAdmin module works only on Windows NT" if(!Win32::IsWinNT() );
  10. @ISA= qw( Exporter DynaLoader );
  11. # Items to export into callers namespace by default. Note: do not export
  12. # names by default without a very good reason. Use EXPORT_OK instead.
  13. # Do not simply export all your public functions/methods/constants.
  14. @EXPORT = qw(
  15. DOMAIN_ALIAS_RID_ACCOUNT_OPS
  16. DOMAIN_ALIAS_RID_ADMINS
  17. DOMAIN_ALIAS_RID_BACKUP_OPS
  18. DOMAIN_ALIAS_RID_GUESTS
  19. DOMAIN_ALIAS_RID_POWER_USERS
  20. DOMAIN_ALIAS_RID_PRINT_OPS
  21. DOMAIN_ALIAS_RID_REPLICATOR
  22. DOMAIN_ALIAS_RID_SYSTEM_OPS
  23. DOMAIN_ALIAS_RID_USERS
  24. DOMAIN_GROUP_RID_ADMINS
  25. DOMAIN_GROUP_RID_GUESTS
  26. DOMAIN_GROUP_RID_USERS
  27. DOMAIN_USER_RID_ADMIN
  28. DOMAIN_USER_RID_GUEST
  29. FILTER_TEMP_DUPLICATE_ACCOUNT
  30. FILTER_NORMAL_ACCOUNT
  31. FILTER_INTERDOMAIN_TRUST_ACCOUNT
  32. FILTER_WORKSTATION_TRUST_ACCOUNT
  33. FILTER_SERVER_TRUST_ACCOUNT
  34. SV_TYPE_WORKSTATION
  35. SV_TYPE_SERVER
  36. SV_TYPE_SQLSERVER
  37. SV_TYPE_DOMAIN_CTRL
  38. SV_TYPE_DOMAIN_BAKCTRL
  39. SV_TYPE_TIMESOURCE
  40. SV_TYPE_AFP
  41. SV_TYPE_NOVELL
  42. SV_TYPE_DOMAIN_MEMBER
  43. SV_TYPE_PRINT
  44. SV_TYPE_PRINTQ_SERVER
  45. SV_TYPE_DIALIN
  46. SV_TYPE_DIALIN_SERVER
  47. SV_TYPE_XENIX_SERVER
  48. SV_TYPE_NT
  49. SV_TYPE_WFW
  50. SV_TYPE_POTENTIAL_BROWSER
  51. SV_TYPE_BACKUP_BROWSER
  52. SV_TYPE_MASTER_BROWSER
  53. SV_TYPE_DOMAIN_MASTER
  54. SV_TYPE_DOMAIN_ENUM
  55. SV_TYPE_SERVER_UNIX
  56. SV_TYPE_SERVER_MFPN
  57. SV_TYPE_SERVER_NT
  58. SV_TYPE_SERVER_OSF
  59. SV_TYPE_SERVER_VMS
  60. SV_TYPE_WINDOWS
  61. SV_TYPE_DFS
  62. SV_TYPE_ALTERNATE_XPORT
  63. SV_TYPE_LOCAL_LIST_ONLY
  64. SV_TYPE_ALL
  65. UF_TEMP_DUPLICATE_ACCOUNT
  66. UF_NORMAL_ACCOUNT
  67. UF_INTERDOMAIN_TRUST_ACCOUNT
  68. UF_WORKSTATION_TRUST_ACCOUNT
  69. UF_SERVER_TRUST_ACCOUNT
  70. UF_MACHINE_ACCOUNT_MASK
  71. UF_ACCOUNT_TYPE_MASK
  72. UF_DONT_EXPIRE_PASSWD
  73. UF_SETTABLE_BITS
  74. UF_SCRIPT
  75. UF_ACCOUNTDISABLE
  76. UF_HOMEDIR_REQUIRED
  77. UF_LOCKOUT
  78. UF_PASSWD_NOTREQD
  79. UF_PASSWD_CANT_CHANGE
  80. USE_FORCE
  81. USE_LOTS_OF_FORCE
  82. USE_NOFORCE
  83. USER_PRIV_MASK
  84. USER_PRIV_GUEST
  85. USER_PRIV_USER
  86. USER_PRIV_ADMIN
  87. );
  88. @EXPORT_OK = qw(
  89. GetError
  90. GetDomainController
  91. GetAnyDomainController
  92. UserCreate
  93. UserDelete
  94. UserGetAttributes
  95. UserSetAttributes
  96. UserChangePassword
  97. UsersExist
  98. GetUsers
  99. GroupCreate
  100. GroupDelete
  101. GroupGetAttributes
  102. GroupSetAttributes
  103. GroupAddUsers
  104. GroupDeleteUsers
  105. GroupIsMember
  106. GroupGetMembers
  107. LocalGroupCreate
  108. LocalGroupDelete
  109. LocalGroupGetAttributes
  110. LocalGroupSetAttributes
  111. LocalGroupIsMember
  112. LocalGroupGetMembers
  113. LocalGroupGetMembersWithDomain
  114. LocalGroupAddUsers
  115. LocalGroupDeleteUsers
  116. GetServers
  117. GetTransports
  118. LoggedOnUsers
  119. GetAliasFromRID
  120. GetUserGroupFromRID
  121. GetServerDisks
  122. );
  123. $EXPORT_TAGS{ALL}= \@EXPORT_OK;
  124. =head1 NAME
  125. Win32::NetAdmin - manage network groups and users in perl
  126. =head1 SYNOPSIS
  127. use Win32::NetAdmin;
  128. =head1 DESCRIPTION
  129. This module offers control over the administration of groups and users over a
  130. network.
  131. =head1 FUNCTIONS
  132. =head2 NOTE
  133. All of the functions return false if they fail, unless otherwise noted.
  134. When a function fails call Win32::NetAdmin::GetError() rather than
  135. GetLastError() or $^E to retrieve the error code.
  136. C<server> is optional for all the calls below. If not given the local machine is
  137. assumed.
  138. =over 10
  139. =item GetError()
  140. Returns the error code of the last call to this module.
  141. =item GetDomainController(server, domain, returnedName)
  142. Returns the name of the domain controller for server.
  143. =item GetAnyDomainController(server, domain, returnedName)
  144. Returns the name of any domain controller for a domain that is directly trusted
  145. by the server.
  146. =item UserCreate(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  147. Creates a user on server with password, passwordAge, privilege, homeDir, comment,
  148. flags, and scriptPath.
  149. =item UserDelete(server, user)
  150. Deletes a user from server.
  151. =item UserGetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  152. Gets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  153. for user.
  154. =item UserSetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  155. Sets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  156. for user.
  157. =item UserChangePassword(domainname, username, oldpassword, newpassword)
  158. Changes a users password. Can be run under any account.
  159. =item UsersExist(server, userName)
  160. Checks if a user exists.
  161. =item GetUsers(server, filter, userRef)
  162. Fills userRef with user names if it is an array reference and with the user
  163. names and the full names if it is a hash reference.
  164. =item GroupCreate(server, group, comment)
  165. Creates a group.
  166. =item GroupDelete(server, group)
  167. Deletes a group.
  168. =item GroupGetAttributes(server, groupName, comment)
  169. Gets the comment.
  170. =item GroupSetAttributes(server, groupName, comment)
  171. Sets the comment.
  172. =item GroupAddUsers(server, groupName, users)
  173. Adds a user to a group.
  174. =item GroupDeleteUsers(server, groupName, users)
  175. Deletes a users from a group.
  176. =item GroupIsMember(server, groupName, user)
  177. Returns TRUE if user is a member of groupName.
  178. =item GroupGetMembers(server, groupName, userArrayRef)
  179. Fills userArrayRef with the members of groupName.
  180. =item LocalGroupCreate(server, group, comment)
  181. Creates a local group.
  182. =item LocalGroupDelete(server, group)
  183. Deletes a local group.
  184. =item LocalGroupGetAttributes(server, groupName, comment)
  185. Gets the comment.
  186. =item LocalGroupSetAttributes(server, groupName, comment)
  187. Sets the comment.
  188. =item LocalGroupIsMember(server, groupName, user)
  189. Returns TRUE if user is a member of groupName.
  190. =item LocalGroupGetMembers(server, groupName, userArrayRef)
  191. Fills userArrayRef with the members of groupName.
  192. =item LocalGroupGetMembersWithDomain(server, groupName, userRef)
  193. This function is similar LocalGroupGetMembers but accepts an array or
  194. a hash reference. Unlike LocalGroupGetMembers it returns each user name
  195. as C<DOMAIN\USERNAME>. If a hash reference is given, the function
  196. returns to each user or group name the type (group, user, alias etc.).
  197. The possible types are as follows:
  198. $SidTypeUser = 1;
  199. $SidTypeGroup = 2;
  200. $SidTypeDomain = 3;
  201. $SidTypeAlias = 4;
  202. $SidTypeWellKnownGroup = 5;
  203. $SidTypeDeletedAccount = 6;
  204. $SidTypeInvalid = 7;
  205. $SidTypeUnknown = 8;
  206. =item LocalGroupAddUsers(server, groupName, users)
  207. Adds a user to a group.
  208. =item LocalGroupDeleteUsers(server, groupName, users)
  209. Deletes a users from a group.
  210. =item GetServers(server, domain, flags, serverRef)
  211. Gets an array of server names or an hash with the server names and the
  212. comments as seen in the Network Neighborhood or the server manager.
  213. For flags, see SV_TYPE_* constants.
  214. =item GetTransports(server, transportRef)
  215. Enumerates the network transports of a computer. If transportRef is an array
  216. reference, it is filled with the transport names. If transportRef is a hash
  217. reference then a hash of hashes is filled with the data for the transports.
  218. =item LoggedOnUsers(server, userRef)
  219. Gets an array or hash with the users logged on at the specified computer. If
  220. userRef is a hash reference, the value is a semikolon separated string of
  221. username, logon domain and logon server.
  222. =item GetAliasFromRID(server, RID, returnedName)
  223. =item GetUserGroupFromRID(server, RID, returnedName)
  224. Retrieves the name of an alias (i.e local group) or a user group for a RID
  225. from the specified server. These functions can be used for example to get the
  226. account name for the administrator account if it is renamed or localized.
  227. Possible values for C<RID>:
  228. DOMAIN_ALIAS_RID_ACCOUNT_OPS
  229. DOMAIN_ALIAS_RID_ADMINS
  230. DOMAIN_ALIAS_RID_BACKUP_OPS
  231. DOMAIN_ALIAS_RID_GUESTS
  232. DOMAIN_ALIAS_RID_POWER_USERS
  233. DOMAIN_ALIAS_RID_PRINT_OPS
  234. DOMAIN_ALIAS_RID_REPLICATOR
  235. DOMAIN_ALIAS_RID_SYSTEM_OPS
  236. DOMAIN_ALIAS_RID_USERS
  237. DOMAIN_GROUP_RID_ADMINS
  238. DOMAIN_GROUP_RID_GUESTS
  239. DOMAIN_GROUP_RID_USERS
  240. DOMAIN_USER_RID_ADMIN
  241. DOMAIN_USER_RID_GUEST
  242. =item GetServerDisks(server, arrayRef)
  243. Returns an array with the disk drives of the specified server. The array
  244. contains two-character strings (drive letter followed by a colon).
  245. =back
  246. =head1 EXAMPLE
  247. # Simple script using Win32::NetAdmin to set the login script for
  248. # all members of the NT group "Domain Users". Only works if you
  249. # run it on the PDC. (From Robert Spier <rspier@seas.upenn.edu>)
  250. #
  251. # FILTER_TEMP_DUPLICATE_ACCOUNTS
  252. # Enumerates local user account data on a domain controller.
  253. #
  254. # FILTER_NORMAL_ACCOUNT
  255. # Enumerates global user account data on a computer.
  256. #
  257. # FILTER_INTERDOMAIN_TRUST_ACCOUNT
  258. # Enumerates domain trust account data on a domain controller.
  259. #
  260. # FILTER_WORKSTATION_TRUST_ACCOUNT
  261. # Enumerates workstation or member server account data on a domain
  262. # controller.
  263. #
  264. # FILTER_SERVER_TRUST_ACCOUNT
  265. # Enumerates domain controller account data on a domain controller.
  266. use Win32::NetAdmin qw(GetUsers GroupIsMember
  267. UserGetAttributes UserSetAttributes);
  268. my %hash;
  269. GetUsers("", FILTER_NORMAL_ACCOUNT , \%hash)
  270. or die "GetUsers() failed: $^E";
  271. foreach (keys %hash) {
  272. my ($password, $passwordAge, $privilege,
  273. $homeDir, $comment, $flags, $scriptPath);
  274. if (GroupIsMember("", "Domain Users", $_)) {
  275. print "Updating $_ ($hash{$_})\n";
  276. UserGetAttributes("", $_, $password, $passwordAge, $privilege,
  277. $homeDir, $comment, $flags, $scriptPath)
  278. or die "UserGetAttributes() failed: $^E";
  279. $scriptPath = "dnx_login.bat"; # this is the new login script
  280. UserSetAttributes("", $_, $password, $passwordAge, $privilege,
  281. $homeDir, $comment, $flags, $scriptPath)
  282. or die "UserSetAttributes() failed: $^E";
  283. }
  284. }
  285. =cut
  286. sub AUTOLOAD {
  287. my($constname);
  288. ($constname = $AUTOLOAD) =~ s/.*:://;
  289. #reset $! to zero to reset any current errors.
  290. $!=0;
  291. my $val = constant($constname);
  292. if ($! != 0) {
  293. if ($! =~ /Invalid/) {
  294. $AutoLoader::AUTOLOAD = $AUTOLOAD;
  295. goto &AutoLoader::AUTOLOAD;
  296. }
  297. else {
  298. ($pack,$file,$line) = caller;
  299. die "Your vendor has not defined Win32::NetAdmin macro $constname, used in $file at line $line.";
  300. }
  301. }
  302. eval "sub $AUTOLOAD { $val }";
  303. goto &$AUTOLOAD;
  304. }
  305. $SidTypeUser = 1;
  306. $SidTypeGroup = 2;
  307. $SidTypeDomain = 3;
  308. $SidTypeAlias = 4;
  309. $SidTypeWellKnownGroup = 5;
  310. $SidTypeDeletedAccount = 6;
  311. $SidTypeInvalid = 7;
  312. $SidTypeUnknown = 8;
  313. sub GetError() {
  314. our $__lastError;
  315. $__lastError;
  316. }
  317. bootstrap Win32::NetAdmin;
  318. 1;
  319. __END__