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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
$NetBSD: patch-ai,v 1.1.1.1 2008/06/16 16:04:25 taca Exp $
--- smbldap_tools.pm.orig 2008-04-22 17:13:29.000000000 +0900
+++ smbldap_tools.pm
@@ -27,28 +27,9 @@ use Net::LDAP;
use Crypt::SmbHash;
use Unicode::MapUTF8 qw(to_utf8 from_utf8);
-my $smbldap_conf;
-if ( -e "/etc/smbldap-tools/smbldap.conf" ) {
- $smbldap_conf = "/etc/smbldap-tools/smbldap.conf";
-}
-else {
- $smbldap_conf = "/etc/opt/IDEALX/smbldap-tools/smbldap.conf";
-}
-
-my $smbldap_bind_conf;
-if ( -e "/etc/smbldap-tools/smbldap_bind.conf" ) {
- $smbldap_bind_conf = "/etc/smbldap-tools/smbldap_bind.conf";
-}
-else {
- $smbldap_bind_conf = "/etc/opt/IDEALX/smbldap-tools/smbldap_bind.conf";
-}
-my $samba_conf;
-if ( -e "/etc/samba/smb.conf" ) {
- $samba_conf = "/etc/samba/smb.conf";
-}
-else {
- $samba_conf = "/usr/local/samba/lib/smb.conf";
-}
+my $smbldap_conf = "@PKG_SYSCONFDIR@/smbldap.conf";
+my $smbldap_bind_conf = "@PKG_SYSCONFDIR@/smbldap_bind.conf";
+my $samba_conf = "@PREFIX@/etc/samba/smb.conf";
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
use Exporter;
@@ -267,6 +248,15 @@ $config{groupsdn} = get_parameter( "ldap
if ( $config{groupsdn} !~ m/,/ ) {
$config{groupsdn} = $config{groupsdn} . "," . $config{suffix};
}
+if ( ! defined $config{groupsclasses} ) {
+ $config{groupsclasses} = "top posixGroup";
+}
+if ( defined $config{groupsdefaultmember} ) {
+ if ( $config{groupsdefaultmember} !~ m/,/ ) {
+ $config{groupsdefaultmember} =
+ $config{groupsdefaultmember} . "," . $config{suffix};
+ }
+}
$config{computersdn} = get_parameter( "ldap machine suffix", "computersdn" );
if ( $config{computersdn} !~ m/,/ ) {
$config{computersdn} = $config{computersdn} . "," . $config{suffix};
@@ -606,8 +596,8 @@ sub add_posix_machine {
'uid' => "$user",
'uidNumber' => "$uid",
'gidNumber' => "$gid",
- 'homeDirectory' => '/dev/null',
- 'loginShell' => '/bin/false',
+ 'homeDirectory' => '/nonexistent',
+ 'loginShell' => '/sbin/nologin',
'description' => 'Computer',
'gecos' => 'Computer',
]
@@ -764,15 +754,22 @@ sub group_add {
if ( $nscd_status == 0 ) {
system "/etc/init.d/nscd start > /dev/null 2>&1";
}
- my $modify = $ldap->add(
- "cn=$gname,$config{groupsdn}",
- attrs => [
- objectClass => [ 'top', 'posixGroup' ],
- cn => "$gname",
- gidNumber => "$gid"
- ]
+
+ my $entry = Net::LDAP::Entry->new();
+ $entry->dn("cn=$gname,$config{groupsdn}");
+ $entry->add(
+ objectClass => [ split(' ', $config{groupsclasses}) ],
+ cn => "$gname",
+ gidNumber => "$gid"
);
+ if ($config{groupsdefaultmember}) {
+ $entry->add(
+ member => $config{groupsdefaultmember}
+ );
+ }
+ my $modify = $ldap->add($entry);
+
$modify->code && die "failed to add entry: ", $modify->error;
return $gid;
}
@@ -1159,6 +1156,22 @@ sub get_next_id($$) {
my $found = 0;
my $next_uid_mesg;
my $nextuid;
+
+ # retry number
+ my $retrv = 5;
+ # lock directory path
+ my $lockdir = "/tmp/smbldap-useradd";
+ # wait time
+ my $wtime = 3;
+ # create the lockdir
+ while (!mkdir($lockdir,0755)) {
+ if (--$retrv <= 0) {
+ die "System busy and failed to add entry";
+ }
+ # if exist the lockdir, wait x second
+ sleep($wtime);
+ }
+
if ( $ldap_base_dn =~ m/$config{usersdn}/i ) {
# when adding a new user, we'll check if the uidNumber available is not
@@ -1198,9 +1211,14 @@ sub get_next_id($$) {
# now, look if the id or gid is not already used in /etc/passwd or /etc/group
if ( !getpwuid($nextuid) ) {
$found = 1;
+
+ # remove the lockdir
+ rmdir($lockdir);
return $nextuid;
}
}
+ # remove the lockdir
+ rmdir($lockdir);
$tries++;
print
"Cannot confirm $attribute $nextuid is free: checking for the next one\n";
|