~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/bin/sh

set -e

# Source debconf library
. /usr/share/debconf/confmodule

# This conf script is capable of backing up
db_version 2.0
db_capb backup

#COMMON-FUNCTIONS#

CLAMAVCONF='/etc/clamav/clamd.conf'

slurp_config "$CLAMAVCONF"

# Store conf file values as debconf answers - make sure user changes made 
# outside of debconf are preserved
if [ -n "$User" ]; then
  db_set clamav-base/User "$User" || true
  if ! [ "$User" = 'root' ]; then
    AddGroups=`groups "$User" | awk -F ':' '{print $2}' | sed -e s/"$User"//`
  fi
  if [ -n "$AddGroups" ]; then
    db_set clamav-base/AddGroups "$AddGroups" || true
  fi
fi
if [ -n "$TCPSocket" ]; then
  db_set clamav-base/TcpOrLocal TCP || true
elif [ -n "$LocalSocket" ]; then
  db_set clamav-base/TcpOrLocal UNIX || true
fi
if [ -n "$LocalSocket" ]; then
  db_set clamav-base/LocalSocket "$LocalSocket" || true
fi
if [ -n "$LocalSocketGroup" ]; then
  db_set clamav-base/LocalSocketGroup "$LocalSocketGroup" || true
fi
if [ -n "$LocalSocketMode" ]; then
  db_set clamav-base/LocalSocketMode "$LocalSocketMode" || true
fi
if [ "$FixStaleSocket" = "true" ]; then
  db_set clamav-base/FixStaleSocket true || true
fi
if [ -n "$TCPSocket" ]; then
  db_set clamav-base/TCPSocket "$TCPSocket" || true
fi
if [ -n "$TCPaddr" ]; then
  db_set clamav-base/TCPAddr "$TCPaddr" || true
fi
if [ "$ScanMail" = "true" ]; then
  db_set clamav-base/ScanMail true || true
fi
if [ "$ScanArchive" = "true" ]; then
  db_set clamav-base/ScanArchive true || true
fi
if [ -n "$StreamMaxLength" ]; then
  StreamMaxLength="`echo $StreamMaxLength | sed -e s/M//`"
  if [ "$StreamMaxLength" = "0" ]; then
    StreamMaxLength="25"
  fi
  db_set clamav-base/StreamMaxLength "$StreamMaxLength" || true
fi
if [ -n "$MaxDirectoryRecursion" ]; then
  db_set clamav-base/MaxDirectoryRecursion "$MaxDirectoryRecursion" || true
fi
if [ "$FollowDirectorySymlinks" = "true" ]; then
  db_set clamav-base/FollowDirectorySymlinks true || true
fi
if [ "$FollowFileSymlinks" = "true" ]; then
  db_set clamav-base/FollowFileSymlinks true || true
fi
if [ -n "$ReadTimeout" ] && [ -z "$ThreadTimeout" ]; then
  db_set clamav-base/ReadTimeout "$ReadTimeout" || true
elif
  [ -z "$ReadTimeout" ] && [ -n "$ThreadTimeout" ]; then
  ReadTimeout="$ThreadTimeout"
  db_set clamav-base/ReadTimeout "$ReadTimeout" || true
elif [ -n "$ReadTimeout" ]; then
  db_set clamav-base/ReadTimeout "$ReadTimeout" || true
fi
if [ -n "$MaxThreads" ]; then
  db_set clamav-base/MaxThreads "$MaxThreads" || true
fi
if [ -n "$MaxConnectionQueueLength" ]; then
  db_set clamav-base/MaxConnectionQueueLength "$MaxConnectionQueueLength" || true
fi
if [ "$LogSyslog" = "true" ]; then
  db_set clamav-base/LogSyslog true || true
fi
if [ -n "$LogFile" ]; then
  db_set clamav-base/LogFile "$LogFile" || true
fi
if [ "$LogTime" = "true" ]; then
  db_set clamav-base/LogTime true || true
fi
if [ "$Bytecode" = "true" ]; then
  db_set clamav-base/Bytecode true || true
fi
if [ -n "$BytecodeSecurity" ]; then
  db_set clamav-base/BytecodeSecurity "$BytecodeSecurity" || true
fi
if [ -n "$BytecodeTimeout" ]; then
  db_set clamav-base/BytecodeTimeout "$BytecodeTimeout" || true
fi

# States

StateDebconf()
{
  db_input medium clamav-base/debconf || true
  if ! db_go; then
    STATE="End"
  else
    db_get clamav-base/debconf || true
    if [ "$RET" = "false" ]; then
      STATE="End"
    else
      STATE="Socket"
    fi
  fi
}

StateSocket()
{
  db_input medium clamav-base/TcpOrLocal || true
  if ! db_go; then
    STATE="Debconf"
  else
    db_metaget clamav-base/TcpOrLocal value
    STATE=$RET
  fi
}

StateLocalSocketGroup()
{
  db_input low clamav-base/LocalSocketGroup || true
  if db_go; then
    db_metaget clamav-base/LocalSocketGroup value
    if [ "$RET" = "" ]; then
      db_set clamav-base/LocalSocketGroup "clamav" || true
    fi
    STATE="LocalSocketMode"
  else
    STATE="UNIX"
  fi
}

StateScanMail()
{
  db_input medium clamav-base/ScanMail || true
  if db_go; then
    STATE="ScanArchive"
  else
    db_metaget clamav-base/TcpOrLocal value
    if [ "$RET" = "TCP" ]; then
      STATE="TCPAddr"
    else
      STATE="FixStale"
    fi
  fi
}

StateScanArchive()
{
  db_input low clamav-base/ScanArchive || true
  if db_go; then
    db_metaget clamav-base/ScanArchive value
    if [ "$RET" = "true" ]; then
      STATE="StreamMaxLength"
    else
      STATE="MaxDirectoryRecursion"
    fi
  else
    STATE="ScanMail"
  fi
}

StateMaxDirectoryRecursion()
{
  if inputdigit low clamav-base/MaxDirectoryRecursion; then
    db_metaget clamav-base/MaxDirectoryRecursion value
    if [ "$RET" = "0" ]; then
      STATE="FollowDirectorySymlinks"
    else
      STATE="FollowFileSymlinks"
    fi
  else
      STATE="ScanArchive"
  fi
}

StateFollowFileSymlinks()
{
  db_input low clamav-base/FollowFileSymlinks || true
  if db_go; then
    STATE="ReadTimeout"
  else
    db_metaget clamav-base/MaxDirectoryRecursion value;
    if [ "$RET" = "0" ]; then
      STATE="FollowDirectorySymlinks"
    else
      STATE="MaxDirectoryRecursion"
    fi
  fi
}

StateLogFile()
{
  db_input low clamav-base/LogFile || true
  if db_go; then
    db_metaget clamav-base/LogFile value
    if [ "$RET" = "" ]; then
      db_set clamav-base/LogFile "/var/log/clamav/clamav.log" || true
      STATE="LogTime"
    elif [ "$RET" = 'none' ]; then
      db_set clamav-base/LogFile "" || true
      STATE="SelfCheck"
    else
      STATE="LogTime"
    fi
  else
    STATE="LogSyslog"
  fi
}

StateUser()
{
  db_input medium clamav-base/User || true
  if db_go; then
    db_metaget clamav-base/User value
    if [ "$RET" = "" ]; then
      db_set clamav-base/User "clamav" || true
    fi
    STATE="AddGroups"
  else
    STATE="SelfCheck"
  fi
}

StateBytecode()
{
  db_input low clamav-base/Bytecode || true
  if db_go; then
    db_metaget clamav-base/Bytecode value
    if [ "$RET" = "true" ]; then
      STATE="BytecodeSecurity"
    else
      STATE="End"
    fi
  else
    STATE="AddGroups"
  fi
}

# To many options to configure at configure
if [ "$1" = "reconfigure" ]; then
  STATE="Init"
elif [ -n "$2" ]; then
  if [ -z "$User" ]; then
    STATE="User"
  fi
else
  STATE="End"
fi

[ -z "$STATE" ] && STATE='End'

# This is the statemachine that controls execution. All the 'real' work is 
# performed by subfunctions above. 

while [ "$STATE" != "End" ]; do
  case "$STATE" in
    "Init")
    StateDebconf
    ;;
    "Socket")
    StateSocket
    ;;
    "TCP")
    StateGenericDigit low clamav-base/TCPSocket TCPAddr Socket
    ;;
    "TCPAddr")
    StateGeneric low clamav-base/TCPAddr ScanMail TCP
    ;;
    "UNIX")
    StateGeneric low clamav-base/LocalSocket LocalSocketGroup Socket
    ;;
    "LocalSocketGroup")
    StateLocalSocketGroup
    ;;
    "LocalSocketMode")
    StateGenericDigit low clamav-base/LocalSocketMode FixStale LocalSocketGroup
    ;;
    "FixStale")
    StateGeneric low clamav-base/FixStaleSocket ScanMail LocalSocketMode
    ;;
    "ScanMail")
    StateScanMail
    ;;
    "ScanArchive")
    StateScanArchive
    ;;
    "StreamMaxLength")
    StateGenericDigit low clamav-base/StreamMaxLength MaxDirectoryRecursion ScanArchive
    ;;
    "MaxDirectoryRecursion")
    StateMaxDirectoryRecursion
    ;;
    "FollowDirectorySymlinks")
    StateGeneric low clamav-base/FollowDirectorySymlinks FollowFileSymlinks MaxDirectoryRecursion
    ;;
    "FollowFileSymlinks")
    StateFollowFileSymlinks
    ;;
    "ReadTimeout")
    StateGenericDigit low clamav-base/ReadTimeout MaxThreads FollowFileSymlinks
    ;;
    "MaxThreads")
    StateGenericDigit low clamav-base/MaxThreads MaxConnectionQueueLength ReadTimeout
    ;;
    "MaxConnectionQueueLength")
    StateGenericDigit low clamav-base/MaxConnectionQueueLength LogSyslog MaxThreads
    ;;
    "LogSyslog")
    StateGeneric medium clamav-base/LogSyslog LogFile MaxConnectionQueueLength
    ;;
    "LogFile")
    StateLogFile
    ;;
    "LogTime")
    StateGeneric low clamav-base/LogTime SelfCheck LogFile
    ;;
    "SelfCheck")
    StateGeneric low clamav-base/SelfCheck User LogFile
    ;;
    "User")
    StateUser
    ;;
    "AddGroups")
    StateGeneric medium clamav-base/AddGroups Bytecode User
    ;;
    "Bytecode")
    StateBytecode
    ;;
    "BytecodeSecurity")
    StateGeneric low clamav-base/BytecodeSecurity BytecodeTimeout Bytecode
    ;;
    "BytecodeTimeout")
    StateGenericDigit low clamav-base/BytecodeTimeout End BytecodeSecurity
    ;;
  esac
done
db_stop || true
exit 0