Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
8.6 KiB

  1. package Win32::NetAdmin;
  2. #
  3. #NetAdmin.pm
  4. #Written by [email protected]
  5. #
  6. $VERSION = '0.06';
  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 (0) if they fail, unless otherwise noted.
  134. C<server> is optional for all the calls below. If not given the local machine is
  135. assumed.
  136. =over 10
  137. =item GetDomainController(server, domain, returnedName)
  138. Returns the name of the domain controller for server.
  139. =item GetAnyDomainController(server, domain, returnedName)
  140. Returns the name of any domain controller for a domain that is directly trusted
  141. by the server.
  142. =item UserCreate(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  143. Creates a user on server with password, passwordAge, privilege, homeDir, comment,
  144. flags, and scriptPath.
  145. =item UserDelete(server, user)
  146. Deletes a user from server.
  147. =item UserGetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  148. Gets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  149. for user.
  150. =item UserSetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  151. Sets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  152. for user.
  153. =item UserChangePassword(domainname, username, oldpassword, newpassword)
  154. Changes a users password. Can be run under any account.
  155. =item UsersExist(server, userName)
  156. Checks if a user exists.
  157. =item GetUsers(server, filter, userRef)
  158. Fills userRef with user names if it is an array reference and with the user
  159. names and the full names if it is a hash reference.
  160. =item GroupCreate(server, group, comment)
  161. Creates a group.
  162. =item GroupDelete(server, group)
  163. Deletes a group.
  164. =item GroupGetAttributes(server, groupName, comment)
  165. Gets the comment.
  166. =item GroupSetAttributes(server, groupName, comment)
  167. Sets the comment.
  168. =item GroupAddUsers(server, groupName, users)
  169. Adds a user to a group.
  170. =item GroupDeleteUsers(server, groupName, users)
  171. Deletes a users from a group.
  172. =item GroupIsMember(server, groupName, user)
  173. Returns TRUE if user is a member of groupName.
  174. =item GroupGetMembers(server, groupName, userArrayRef)
  175. Fills userArrayRef with the members of groupName.
  176. =item LocalGroupCreate(server, group, comment)
  177. Creates a local group.
  178. =item LocalGroupDelete(server, group)
  179. Deletes a local group.
  180. =item LocalGroupGetAttributes(server, groupName, comment)
  181. Gets the comment.
  182. =item LocalGroupSetAttributes(server, groupName, comment)
  183. Sets the comment.
  184. =item LocalGroupIsMember(server, groupName, user)
  185. Returns TRUE if user is a member of groupName.
  186. =item LocalGroupGetMembers(server, groupName, userArrayRef)
  187. Fills userArrayRef with the members of groupName.
  188. =item LocalGroupGetMembersWithDomain(server, groupName, userRef)
  189. This function is similar LocalGroupGetMembers but accepts an array or
  190. a hash reference. Unlike LocalGroupGetMembers it returns each user name
  191. as C<DOMAIN\USERNAME>. If a hash reference is given, the function
  192. returns to each user or group name the type (group, user, alias etc.).
  193. The possible types are as follows:
  194. $SidTypeUser = 1;
  195. $SidTypeGroup = 2;
  196. $SidTypeDomain = 3;
  197. $SidTypeAlias = 4;
  198. $SidTypeWellKnownGroup = 5;
  199. $SidTypeDeletedAccount = 6;
  200. $SidTypeInvalid = 7;
  201. $SidTypeUnknown = 8;
  202. =item LocalGroupAddUsers(server, groupName, users)
  203. Adds a user to a group.
  204. =item LocalGroupDeleteUsers(server, groupName, users)
  205. Deletes a users from a group.
  206. =item GetServers(server, domain, flags, serverRef)
  207. Gets an array of server names or an hash with the server names and the
  208. comments as seen in the Network Neighborhood or the server manager.
  209. For flags, see SV_TYPE_* constants.
  210. =item GetTransports(server, transportRef)
  211. Enumerates the network transports of a computer. If transportRef is an array
  212. reference, it is filled with the transport names. If transportRef is a hash
  213. reference then a hash of hashes is filled with the data for the transports.
  214. =item LoggedOnUsers(server, userRef)
  215. Gets an array or hash with the users logged on at the specified computer. If
  216. userRef is a hash reference, the value is a semikolon separated string of
  217. username, logon domain and logon server.
  218. =item GetAliasFromRID(server, RID, returnedName)
  219. =item GetUserGroupFromRID(server, RID, returnedName)
  220. Retrieves the name of an alias (i.e local group) or a user group for a RID
  221. from the specified server. These functions can be used for example to get the
  222. account name for the administrator account if it is renamed or localized.
  223. Possible values for C<RID>:
  224. DOMAIN_ALIAS_RID_ACCOUNT_OPS
  225. DOMAIN_ALIAS_RID_ADMINS
  226. DOMAIN_ALIAS_RID_BACKUP_OPS
  227. DOMAIN_ALIAS_RID_GUESTS
  228. DOMAIN_ALIAS_RID_POWER_USERS
  229. DOMAIN_ALIAS_RID_PRINT_OPS
  230. DOMAIN_ALIAS_RID_REPLICATOR
  231. DOMAIN_ALIAS_RID_SYSTEM_OPS
  232. DOMAIN_ALIAS_RID_USERS
  233. DOMAIN_GROUP_RID_ADMINS
  234. DOMAIN_GROUP_RID_GUESTS
  235. DOMAIN_GROUP_RID_USERS
  236. DOMAIN_USER_RID_ADMIN
  237. DOMAIN_USER_RID_GUEST
  238. =item GetServerDisks(server, arrayRef)
  239. Returns an array with the disk drives of the specified server. The array
  240. contains two-character strings (drive letter followed by a colon).
  241. =back
  242. =cut
  243. sub AUTOLOAD {
  244. my($constname);
  245. ($constname = $AUTOLOAD) =~ s/.*:://;
  246. #reset $! to zero to reset any current errors.
  247. $!=0;
  248. my $val = constant($constname, @_ ? $_[0] : 0);
  249. if ($! != 0) {
  250. if ($! =~ /Invalid/) {
  251. $AutoLoader::AUTOLOAD = $AUTOLOAD;
  252. goto &AutoLoader::AUTOLOAD;
  253. }
  254. else {
  255. ($pack,$file,$line) = caller;
  256. die "Your vendor has not defined Win32::NetAdmin macro $constname, used in $file at line $line.";
  257. }
  258. }
  259. eval "sub $AUTOLOAD { $val }";
  260. goto &$AUTOLOAD;
  261. }
  262. $SidTypeUser = 1;
  263. $SidTypeGroup = 2;
  264. $SidTypeDomain = 3;
  265. $SidTypeAlias = 4;
  266. $SidTypeWellKnownGroup = 5;
  267. $SidTypeDeletedAccount = 6;
  268. $SidTypeInvalid = 7;
  269. $SidTypeUnknown = 8;
  270. bootstrap Win32::NetAdmin;
  271. 1;
  272. __END__