LDAP/Machine.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 28 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« LDAP/Group.pm ↑ Summary LDAP/User.pm »
1 package Samba::LDAP::Machine;
2  
3 # Returned by Perl::MinimumVersion 0.11
4 require 5.006;
5  
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Regexp::DefaultFlags;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Crypt::SmbHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use base qw(Samba::LDAP::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 my $self = shift;
37 my %machine_args = (
38 time_to_wait => 0,
39 @_, # argument pair list goes here
40 );
41  
42 my $host = $machine_args{host};
43 my $uid = $machine_args{uid};
44 my $gid = $machine_args{gid};
45 my $wait = $machine_args{time_to_wait};
46  
47 # Required arguments
48 my @required_args = ( $host, $uid, $gid );
49 croak $ADD_POSIX_MACHINE_USAGE
50 if any {!defined $_} @required_args;
51  
52 my $ldap = Samba::LDAP->new();
53 $ldap = $ldap->connect_ldap_master();
54  
55 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 $add->code && warn "failed to add entry: ", $add->error ;
72
73 # take the session down
74 $add->unbind;
75  
76 sleep($wait);
77 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 my $self = shift;
88 my $host = shift;
89 my $uid = shift;
90  
91 my $sambaSID = 2 * $uid + 1000;
92 my ($name) = $host =~ s/.$//s;
93  
94 my ($lmpassword,$ntpassword) = ntlmgen $name;
95  
96 my $ldap = Samba::LDAP->new();
97 $ldap = $ldap->connect_ldap_master();
98  
99 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 $modify->code && die "failed to add entry: ", $modify->error ;
117  
118 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 my $self = shift;
129 }
130  
131 1; # Magic true value required at end of module
132  
133 __END__
« LDAP/Group.pm ↑ Summary LDAP/User.pm »