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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#!/bin/sh
# Initial configuration script for Samba.
# This script should be run once, immediately after Samba is installed,
# to get a basic smb.conf script into place. Subsequent modification
# of this initial configuration should be done by swat.
#
# It is expected that in future versions of Samba, swat will be able to
# do the initial configuration as well, and this script will become
# unnecessary.
CONF_SRC=/usr/lib/samba/lib/smb.conf.default
CONF=/usr/lib/samba/lib/smb.conf
# getyn: ask a question, return value indicates response
getyn () {
while true; do
echo "$1 [$2] \c"
read answer
[ -z "$answer" ] && answer=$2
case $answer in
[Yy]*) echo; return 0;
;;
[Nn]*) echo; return 1;
;;
*) echo "Please answer yes or no."
continue
;;
esac
done
}
# conf_replace: call sed to replace strings in smb.conf file with new
# values, and if necessary uncomment the lines in which those strings
# appear. For this to work, the source file needs to contain unique
# placeholder strings to be replaced, e.g., %%WORKGROUP%%
conf_replace () {
sed -e 's/^;*\(.*\)'$1'\(.*\)$/\1'$2'\2/' < $CONF > /tmp/smb.conf.$$
cp -f /tmp/smb.conf.$$ $CONF
rm -f /tmp/smb.conf.$$
}
# Begin main
# Check whether conf file has already been edited
if [ -f $CONF ]; then
cmp -s $CONF_SRC $CONF || {
echo "The file $CONF appears to have been previously edited.
If you continue, this file will be restored to its original
state and any changes you have made may be lost.\n"
if getyn "Continue?" No; then
echo "Backing up $CONF to ${CONF}-\n"
cp -f $CONF ${CONF}-
cp -f $CONF_SRC $CONF
else
exit 0
fi
}
else
cp -f $CONF_SRC $CONF
fi
# Question 1: Workgroup/Domain Name
# Default is MYGROUP. Responses must begin with an alphabetical
# character and contain no punctuation.
while true; do
default=MYGROUP
echo "Enter Workgroup/NT-Domain name: [$default] \c"
read workgroup
if [ -z "$workgroup" ]; then
workgroup=$default
fi
set -- $workgroup
if [ $# -gt 1 ]; then
echo "ERROR: Workgroup names cannot contain spaces or punctuation.\n"
continue
fi
workgroup=`echo $workgroup | tr a-z A-Z | tr -d [:punct:]`
if expr "$workgroup" : '[^A-Z]' >&-; then
echo "ERROR: Workgroup name must begin with an alphabetic character.\n"
continue
fi
echo "Workgroup name set to \"$workgroup\".\n"
break
done
# Question 2: Machine Name
# Default is the uname, forced to capital letters and with punctuation
# excised. Responses must begin with an alphabetical
# character and contain no punctuation.
while true; do
default=`uname -n | tr a-z A-Z | tr -d [:punct:]`
echo "Enter Machine name: [$default] \c"
read name
if [ -z "$name" ]; then
name=$default
fi
set -- $name
if [ $# -gt 1 ]; then
echo "ERROR: Machine names cannot contain spaces or punctuation.\n"
continue
fi
name=`echo $name | tr a-z A-Z | tr -d [:punct:]`
if expr "$name" : '[^A-Z]' >&-; then
echo "ERROR: Machine name must begin with an alphabetic character.\n"
continue
fi
echo "Machine name set to \"$name\".\n"
break
done
# Question 3: use WINS?
wins=false
if getyn "Will this system use WINS (recommended)?" Yes; then
wins=true
fi
# Optional questions, asked only if WINS will be used
if [ "$wins" = "true" ]; then
# Question 3.1: Are we the WINS server?
echo "NOTE: A workgroup can have only one WINS server."
wins_svr=false
if getyn "Will this system be the WINS server for your workgroup?" No; then
wins_svr=true
fi
# Question 3.2: Who is the WINS server?
if [ "$wins_svr" = "false" ]; then
while true; do
echo "Enter the address of the primary WINS server for your workgroup: \c"
read wins_addr
if expr "$wins_addr" : '[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*$' >&- ; then
echo
break
fi
echo "ERROR: Invalid IP address format.\n"
done
fi
fi
# Question 4: Which interfaces will be active?
iflist=`ifconfig -a | grep -v LOOPBACK | grep '^[^ ]*:' | cut -f1 -d:`
set -- $iflist
if [ "$#" -eq 0 ]; then
echo "FATAL ERROR: No network interfaces"
exit 1
elif [ "$#" -eq 1 ]; then
interfaces=$1
else
while true; do
interfaces=""
echo "Which of the following interfaces should Samba run on?\n"
for i in $iflist; do
addr=`ifconfig $i | grep "inet " | sed 's/inet \([^ ]*\) .*$/\1/'`
echo "\t$i:\t$addr"
done
echo "\nList all interfaces to activate (e.g., net0, net1, etc): \c"
read response
for i in $response; do
found=false
for j in $iflist; do
if [ "$i" = "$j" ]; then
found=true
break
fi
done
if [ "$found" = "true" ]; then
interfaces="$interfaces $j"
else
echo "ERROR: Invalid interface name $i\n"
continue 2
fi
done
interfaces="$interfaces lo0 atl0"
break
done
fi
# Question 5: Are we part of an existing security domain or active # directory?
domain_exists=false
if getyn "Will this system be part of a currently existing Microsoft Security\n\
Domain or Active Directory?" No; then
domain_exists=true
fi
# Optional questions, depending on response to question 5
if [ "$domain_exists" = "true" ]; then
# Question 5.1: (if yes to 5) Who's the PDC?
default='*'
echo "Enter the name of the Primary Domain Controller: [*] \c"
read pdc
if [ -z "$pdc" ]; then
pdc=$default
else
pdc=`echo $pdc | tr a-z A-Z | tr -d [:punct:]`
fi
echo "Primary Domain Controller set to \"$pdc\".\n"
else
# Question 5.2: (if no to 5) Are we going to be the PDC?
domain_master=false
if getyn "Will this system be the domain controller for a new Microsoft\n\
Security Domain?" No; then
domain_master=true
fi
fi
# Done asking questions.
# Edit conf file with new values
conf_replace %%WORKGROUP%% "$workgroup"
conf_replace %%NBNAME%% "$name"
if [ "$wins" = true ]; then
if [ "$wins_svr" = true ]; then
conf_replace %%WINSSUPPORT%% yes
else
conf_replace %%WINSSERVER%% $wins_addr
fi
fi
conf_replace %%INTERFACES%% "$interfaces"
conf_replace %%BINDONLY%% yes
if [ "$domain_exists" = true ]; then
conf_replace %%SECURITY%% domain
conf_replace %%PWSERVER%% "$pdc"
else
conf_replace %%SECURITY%% user
fi
if [ "$domain_master" = true ]; then
conf_replace %%DOMAINMASTER%% yes
conf_replace %%DOMAINLOGONS%% yes
conf_replace %%OSLEVEL%% 33
else
conf_replace %%OSLEVEL%% 20
fi
|