-
Notifications
You must be signed in to change notification settings - Fork 9
/
createuser.pl
50 lines (43 loc) · 1.38 KB
/
createuser.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
######################################################################
#
# CreateUser($fullname, $comment, $user, $passwd)
# $fullname, full name of user to be created (George Smith)
# $comment, comment about the account (I just put user account created
May 19, 1998)
# $user, username of the account to be created (gsmith)
# $password, initial password to be assigned to the account
(gsmithpasswd)
#
# return values:
# 1 success
# -1 $user exists
# -2 $user account create failed
# -3 $user account set password failed
#
######################################################################
sub CreateUser {
my ($full, $comment, $user, $passwd) = @_;
use strict;
use Win32::NetAdmin;
use Win32::AdminMisc;
my $flags = UF_NORMAL_ACCOUNT | UF_SCRIPT | UF_DONT_EXPIRE_PASSWD;
my $home;
my $oldpasswd;
my $passwdAge;
my $privilege;
my $server = '';
my $scriptPath;
if (Win32::NetAdmin::UserGetAttributes($server, $user, $oldpasswd,
$passwdAge, $privilege, $home, $comment, $flags, $scriptPath))
return(-1); }
$home = '';
$passwdAge = 0;
$privilege = USER_PRIV_USER;
$scriptPath = '';
if (not Win32::NetAdmin::UserCreate($server, $user, $passwd,
$passwdAge, $privilege, $home, $comment, $flags, $scriptPath))
return(-2); }
if (not(Win32::AdminMisc::UserSetMiscAttributes($server, $user,
Win32::AdminMisc::USER_FULL_NAME => $full))) { return(-3); }
return(1);
}