| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Samba::LDAP::Machine; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Returned by Perl::MinimumVersion 0.11 |
|
4
|
|
|
|
|
|
|
require 5.006; |
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
57722
|
use warnings; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
202
|
|
|
7
|
3
|
|
|
3
|
|
51
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
126
|
|
|
8
|
3
|
|
|
3
|
|
17
|
use Carp qw(carp croak); |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
1312
|
|
|
9
|
3
|
|
|
3
|
|
873
|
use Readonly; |
|
|
3
|
|
|
|
|
7751
|
|
|
|
3
|
|
|
|
|
147
|
|
|
10
|
3
|
|
|
3
|
|
2155
|
use Regexp::DefaultFlags; |
|
|
3
|
|
|
|
|
5269
|
|
|
|
3
|
|
|
|
|
24
|
|
|
11
|
3
|
|
|
3
|
|
3165
|
use Crypt::SmbHash; |
|
|
3
|
|
|
|
|
49608
|
|
|
|
3
|
|
|
|
|
352
|
|
|
12
|
3
|
|
|
3
|
|
49
|
use base qw(Samba::LDAP::Base); |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
2191
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# Add Log::Log4perl to all our classes!!!! |
|
18
|
|
|
|
|
|
|
# |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Our usage messages |
|
21
|
|
|
|
|
|
|
Readonly my $ADD_POSIX_MACHINE_USAGE => |
|
22
|
|
|
|
|
|
|
'Usage: add_posix_machine( |
|
23
|
|
|
|
|
|
|
host => \'linux1\', uid => \'1015\', gid => \'1015\', );'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#======================================================================== |
|
26
|
|
|
|
|
|
|
# -- PUBLIC METHODS -- |
|
27
|
|
|
|
|
|
|
#======================================================================== |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
30
|
|
|
|
|
|
|
# add_posix_machine() |
|
31
|
|
|
|
|
|
|
# |
|
32
|
|
|
|
|
|
|
# Add a workstation to the Directory |
|
33
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_posix_machine { |
|
36
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
37
|
0
|
|
|
|
|
|
my %machine_args = ( |
|
38
|
|
|
|
|
|
|
time_to_wait => 0, |
|
39
|
|
|
|
|
|
|
@_, # argument pair list goes here |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $host = $machine_args{host}; |
|
43
|
0
|
|
|
|
|
|
my $uid = $machine_args{uid}; |
|
44
|
0
|
|
|
|
|
|
my $gid = $machine_args{gid}; |
|
45
|
0
|
|
|
|
|
|
my $wait = $machine_args{time_to_wait}; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Required arguments |
|
48
|
0
|
|
|
|
|
|
my @required_args = ( $host, $uid, $gid ); |
|
49
|
0
|
|
|
|
|
|
croak $ADD_POSIX_MACHINE_USAGE |
|
50
|
0
|
0
|
|
|
|
|
if any {!defined $_} @required_args; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $ldap = Samba::LDAP->new(); |
|
53
|
0
|
|
|
|
|
|
$ldap = $ldap->connect_ldap_master(); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $add = $ldap->add ( "uid=$host,$self->{computersdn}", |
|
56
|
|
|
|
|
|
|
attr => [ |
|
57
|
|
|
|
|
|
|
'objectclass' => ['top', 'person', |
|
58
|
|
|
|
|
|
|
'organizationalPerson', 'inetOrgPerson', 'posixAccount'], |
|
59
|
|
|
|
|
|
|
'cn' => "$host", |
|
60
|
|
|
|
|
|
|
'sn' => "$host", |
|
61
|
|
|
|
|
|
|
'uid' => "$host", |
|
62
|
|
|
|
|
|
|
'uidNumber' => "$uid", |
|
63
|
|
|
|
|
|
|
'gidNumber' => "$gid", |
|
64
|
|
|
|
|
|
|
'homeDirectory' => '/dev/null', |
|
65
|
|
|
|
|
|
|
'loginShell' => '/bin/false', |
|
66
|
|
|
|
|
|
|
'description' => 'Computer', |
|
67
|
|
|
|
|
|
|
'gecos' => 'Computer', |
|
68
|
|
|
|
|
|
|
] |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
$add->code && warn "failed to add entry: ", $add->error ; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# take the session down |
|
74
|
0
|
|
|
|
|
|
$add->unbind; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
sleep($wait); |
|
77
|
0
|
|
|
|
|
|
return 1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
81
|
|
|
|
|
|
|
# add_samba_machine( $host, $uid ) |
|
82
|
|
|
|
|
|
|
# |
|
83
|
|
|
|
|
|
|
# Add a workstation to the Domain |
|
84
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_samba_machine { |
|
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
88
|
0
|
|
|
|
|
|
my $host = shift; |
|
89
|
0
|
|
|
|
|
|
my $uid = shift; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $sambaSID = 2 * $uid + 1000; |
|
92
|
0
|
|
|
|
|
|
my ($name) = $host =~ s/.$//s; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my ($lmpassword,$ntpassword) = ntlmgen $name; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $ldap = Samba::LDAP->new(); |
|
97
|
0
|
|
|
|
|
|
$ldap = $ldap->connect_ldap_master(); |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $modify = $ldap->modify ( "uid=$host,$self->{computersdn}", |
|
100
|
|
|
|
|
|
|
changes => [ |
|
101
|
|
|
|
|
|
|
replace => [objectClass => ['inetOrgPerson', 'posixAccount', 'sambaSAMAccount']], |
|
102
|
|
|
|
|
|
|
add => [sambaPwdLastSet => '0'], |
|
103
|
|
|
|
|
|
|
add => [sambaLogonTime => '0'], |
|
104
|
|
|
|
|
|
|
add => [sambaLogoffTime => '2147483647'], |
|
105
|
|
|
|
|
|
|
add => [sambaKickoffTime => '2147483647'], |
|
106
|
|
|
|
|
|
|
add => [sambaPwdCanChange => '0'], |
|
107
|
|
|
|
|
|
|
add => [sambaPwdMustChange => '0'], |
|
108
|
|
|
|
|
|
|
add => [sambaAcctFlags => '[W ]'], |
|
109
|
|
|
|
|
|
|
add => [sambaLMPassword => "$lmpassword"], |
|
110
|
|
|
|
|
|
|
add => [sambaNTPassword => "$ntpassword"], |
|
111
|
|
|
|
|
|
|
add => [sambaSID => "$self->{SID}-$sambaSID"], |
|
112
|
|
|
|
|
|
|
add => [sambaPrimaryGroupSID => "$self->{SID}-0"] |
|
113
|
|
|
|
|
|
|
] |
|
114
|
|
|
|
|
|
|
); |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
$modify->code && die "failed to add entry: ", $modify->error ; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return 1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
122
|
|
|
|
|
|
|
# add_samba_machine_smbpasswd() |
|
123
|
|
|
|
|
|
|
# |
|
124
|
|
|
|
|
|
|
# Set the workstations password |
|
125
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub add_samba_machine_smbpasswd { |
|
128
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |