/
ctl
executable file
·202 lines (165 loc) · 3.63 KB
/
ctl
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
#!/bin/sh
. /etc/rc.freenas
cifs_file="/tmp/.cifs_AD"
status_file="/var/run/directoryservice.activedirectory"
start_file="/tmp/.ad_start"
service=/usr/sbin/service
python=/usr/local/bin/python
notifier=/usr/local/bin/midclt
adctl_cmd()
{
local args="$*"
if [ -n "${args}" ]
then
logger -t ActiveDirectory "${args}"
${args}
return $?
fi
return 0
}
cifs_enabled()
{
srv_enabled cifs && return 0
return 1
}
cifs_start()
{
adctl_cmd ${python} ${notifier} call notifier.start cifs
return $?
}
cifs_stop()
{
adctl_cmd ${python} ${notifier} call notifier.stop cifs
return $?
}
cifs_restart()
{
adctl_cmd ${python} ${notifier} call notifier.stop cifs
adctl_cmd ${python} ${notifier} call notifier.start cifs
return $?
}
adctl_start()
{
local cifs_started=0
local ad_started=0
touch "${start_file}"
#56751 - verify that servers in /etc/directoryservice/ActiveDirectory/config
# are listening. If not, re-generate config.
if ! AD_validate_config
then
AD_remove_config
fi
if ! AD_init
then
activedirectory_set 1
srv_set cifs 1
rm "${start_file}"
return 1
fi
if cifs_enabled
then
cifs_started=1
cifs_stop
else
srv_set cifs 1
fi
if activedirectory_enabled
then
ad_started=1
else
activedirectory_set 1
fi
echo ${cifs_started} > "${cifs_file}"
adctl_cmd ${python} ${notifier} call etc.generate hostname
adctl_cmd ${service} ix-kerberos quietstart default "$(AD_get ad_krb_realm)"
adctl_cmd ${service} ix-nsswitch quietstart
adctl_cmd ${service} ix-ldap quietstart
adctl_cmd ${service} ix-kinit quietstart
if ! adctl_cmd ${service} ix-kinit status
then
rm "${start_file}"
return 1
fi
cifs_start
if ! adctl_cmd ${service} ix-activedirectory quietstart
then
rm "${start_file}"
return 1
fi
if ! adctl_cmd ${service} ix-activedirectory status
then
rm "${start_file}"
return 1
fi
cifs_restart
adctl_cmd ${service} ix-pam quietstart
adctl_cmd "${service} ix-cache quietstart &"
touch "${status_file}"
rm "${start_file}"
return 0
}
adctl_stop()
{
local cifs_started=1
local prev_cifs_started=0
AD_generate_config
if [ -s "${cifs_file}" ]
then
prev_cifs_started="$(cat "${cifs_file}")"
fi
if ! activedirectory_enabled
then
activedirectory_set 1
fi
if cifs_enabled
then
cifs_started=1
cifs_stop
fi
if [ "${prev_cifs_started}" = "0" -a "${cifs_started}" = "0" ]
then
adctl_cmd ${service} samba_server forcestop
srv_set cifs 0
activedirectory_set 0
adctl_cmd ${python} ${notifier} call etc.generate smb
elif [ "${prev_cifs_started}" = "0" -a "${cifs_started}" = "1" ]
then
adctl_cmd ${service} samba_server forcestop
srv_set cifs 0
activedirectory_set 0
adctl_cmd ${python} ${notifier} call etc.generate smb
elif [ "${prev_cifs_started}" = "1" -a "${cifs_started}" = "0" ]
then
adctl_cmd ${service} samba_server forcestop
activedirectory_set 0
srv_set cifs 1
cifs_start
elif [ "${prev_cifs_started}" = "1" -a "${cifs_started}" = "1" ]
then
adctl_cmd ${service} samba_server forcestop
activedirectory_set 0
srv_set cifs 1
cifs_start
fi
adctl_cmd ${service} ix-kinit forcestop
activedirectory_set 0
rm -f "${status_file}"
adctl_cmd ${python} ${notifier} call etc.generate hostname
adctl_cmd ${service} ix-kerberos restart
adctl_cmd ${service} ix-nsswitch quietstop
adctl_cmd ${service} ix-pam quietstop
adctl_cmd "${service} ix-cache quietstop &"
AD_remove_config
return 0
}
adctl_status()
{
adctl_cmd ${service} ix-activedirectory status
}
name="adctl"
start_cmd='adctl_start'
status_cmd='adctl_status'
stop_cmd='adctl_stop'
extra_commands='status'
load_rc_config $name
run_rc_command "$1"