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