Skip to content

Commit 9a80cb2

Browse files
committed
[Change] comments: T3 inline prose rehousing + files/maldet audit
[Change] Rehouse long inline prose comments above their code lines (move, not delete) where context justifies [Change] files/maldet audit-only pass: 1 trim applied within R10 10-line cap [Change] NO-TOUCH verified: HTML/CSS in lmd_alert.sh, format specs in lmd_quarantine.sh, suppression justifications in lmd_sigs.sh [Change] Restatement sweep: trim Arg/Usage/Input/Output parameter docs, stage catalogues, action-verb labels across 18 files [Change] Cumulative: 28 files, -152 comment-only lines across T1+T2+T3, primitive compliance achieved (12.0%) [Change] Applies parent CLAUDE.md Code Comments primitive (inline comments explain why not what)
1 parent a058a96 commit 9a80cb2

20 files changed

+16
-165
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ v2.0.1 | Mar 25 2026:
7575

7676
-- Changes --
7777

78+
[Change] comments: T3 inline prose rehousing + restatement sweep across 18 files
7879
[Change] comments: T2 function-header normalization — collapse signature-restatement blocks
7980
[Change] comments: T1 mechanical cleanup — strip banner separators and file-header catalogues
8081
[Change] - Delete 20 pure-dash banners (lmd_hook.sh: 14, lmd_alert.sh: 6)

CHANGELOG.RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ v2.0.1 | Mar 25 2026:
7575

7676
-- Changes --
7777

78+
[Change] comments: T3 inline prose rehousing + restatement sweep across 18 files
7879
[Change] comments: T2 function-header normalization — collapse signature-restatement blocks
7980
[Change] comments: T1 mechanical cleanup — strip banner separators and file-header catalogues
8081
[Change] - Delete 20 pure-dash banners (lmd_hook.sh: 14, lmd_alert.sh: 6)

cron.daily

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ if [ "$autoupdate_version" == "1" ] || [ "$autoupdate_signatures" == "1" ]; then
7777
fi
7878

7979
if [ "$autoupdate_version" == "1" ]; then
80-
# check for new release version
8180
$inspath/maldet -d 1 2>&1 | tail -20 >> "$maldet_log"
8281
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
8382
echo "$(date) cron.daily: maldet -d (version update) failed" >> "$maldet_log"
8483
fi
8584
fi
8685

8786
if [ "$autoupdate_signatures" == "1" ]; then
88-
# check for new definition set
8987
$inspath/maldet -u 1 2>&1 | tail -20 >> "$maldet_log"
9088
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
9189
echo "$(date) cron.daily: maldet -u (signature update) failed" >> "$maldet_log"

files/hookscan.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ _hook_rate_check() {
127127
}
128128

129129
# Mode dispatch
130-
# Determine mode and file from arguments.
131-
# [[ "$1" == /* ]] distinguishes mode keyword from file path.
132130
# No mode arg AND path as $1 = backward compat modsec mode.
133131
# Pure-ftpd auto-detect: if UPLOAD_VUSER env var set, default to ftp mode.
134132

@@ -248,7 +246,6 @@ if [ -z "$_list_mode" ]; then
248246
fi
249247
fi
250248

251-
# Source internals.conf for binary paths
252249
inspath="${inspath:-/usr/local/maldetect}"
253250
intcnf="$inspath/internals/internals.conf"
254251
if [ -f "$intcnf" ]; then
@@ -257,8 +254,6 @@ if [ -f "$intcnf" ]; then
257254
fi
258255

259256
# Config parser (inline allowlist)
260-
# Read conf.maldet.hookscan if it exists. Only whitelisted variable names
261-
# are accepted. Shell metacharacters in values are rejected.
262257

263258
hookcnf="$inspath/conf.maldet.hookscan"
264259
if [ -f "$hookcnf" ]; then
@@ -284,7 +279,6 @@ if [ -f "$hookcnf" ]; then
284279
continue
285280
fi
286281

287-
# Allowlist of known config keys
288282
case "$_key" in
289283
quarantine_hits) quarantine_hits="$_val" ;;
290284
quarantine_clean) quarantine_clean="$_val" ;;
@@ -323,8 +317,6 @@ if [ -f "${elog_lib:-}" ]; then
323317
fi
324318

325319
# Caller identity resolution
326-
# Resolve UID, homedir, and service-user status once.
327-
# Used by both single-file homedir check and per-line list validation.
328320

329321
_is_root=1
330322
_user_home=""
@@ -350,7 +342,6 @@ fi
350342
# Rate limit check (non-root generic mode only)
351343
_hook_rate_check
352344

353-
# Single-file homedir restriction
354345
if [ -z "$_list_mode" ] && [ "$_is_root" == "0" ] && [ "$_is_service_user" == "0" ] && [ -n "$_user_home" ]; then
355346
case "$file" in
356347
"$_user_home"/*)
@@ -369,7 +360,6 @@ fi
369360
if [ -n "$_list_mode" ]; then
370361
tmpdir="${tmpdir:-$inspath/tmp}"
371362

372-
# Stdin capture
373363
if [ "$_list_mode" == "stdin" ]; then
374364
# Reject interactive terminal input
375365
if [ -t 0 ]; then
@@ -626,11 +616,6 @@ fi
626616
# maldet --hook-scan outputs:
627617
# "0 maldet: SIG PATH" for infections
628618
# "1 maldet: OK" for clean
629-
# The exit code from timeout:
630-
# 0 = scan completed clean
631-
# 2 = scan completed, malware found
632-
# 124 = timeout expired
633-
# * = other error
634619

635620
case "$_scan_rc" in
636621
0)

files/internals/lmd_alert.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ _lmd_parse_hitlist() {
8181
if (sig ~ /^\{[A-Z][A-Z0-9]*\\\}/) {
8282
sub(/\\\}/, "}", sig)
8383
}
84-
# Extract hit type from {TYPE} prefix
8584
hit_type = ""
8685
if (match(sig, /^\{[A-Z][A-Z0-9]*\}/)) {
8786
hit_type = substr(sig, 2, RLENGTH - 2)
@@ -576,11 +575,9 @@ _lmd_render_json_legacy() {
576575
# Initialize metadata vars to empty (prevent stale leaks from prior calls)
577576
scanid="" scan_start_hr="" scan_end_hr="" scan_et="" file_list_et=""
578577
hrspath="" days="" tot_files="" tot_hits="" tot_cl="" _hostname=""
579-
# Parse session header if available
580578
if [ -n "$_sess_file" ] && [ -f "$_sess_file" ]; then
581579
_parse_session_metadata "$_sess_file"
582580
fi
583-
# Parse hits into 6-field manifest if available
584581
if [ -n "$_hits_file" ] && [ -f "$_hits_file" ] && [ -s "$_hits_file" ]; then
585582
_lmd_parse_hitlist "$_hits_file" > "$_manifest"
586583
fi
@@ -938,7 +935,6 @@ _lmd_render_messaging() {
938935
export ENTRY_FIELDS_DISCORD="$_discord_fields"
939936
export SUBJECT="$subject"
940937

941-
# Render and dispatch per channel
942938
local rc=0
943939

944940
local _ch_err
@@ -1370,7 +1366,6 @@ _genalert_digest() {
13701366
tot_files=$($wc -l < "$tmpdir/.digest.monitor.alert")
13711367
tot_susp=$($wc -l < "$tmpdir/.digest.susp.hits")
13721368

1373-
# Count hook hits
13741369
local _hook_hit_count
13751370
_hook_hit_count=$($wc -l < "$tmpdir/.digest.hook.hits")
13761371

@@ -1478,7 +1473,6 @@ _genalert_digest() {
14781473
_test_scan_hits() {
14791474
local _session
14801475
_session=$(mktemp "$tmpdir/.test_session.XXXXXX")
1481-
# Set scan metadata for session header
14821476
local _save_scanid="${scanid:-}"
14831477
local _save_hrspath="${hrspath:-}"
14841478
local _save_tot_files="${tot_files:-}"
@@ -1530,7 +1524,6 @@ _test_alert_scan() {
15301524
local _session
15311525
_session=$(_test_scan_hits)
15321526

1533-
# Set test prefix for subject
15341527
local _orig_subj="${email_subj:-}"
15351528
email_subj="[TEST] ${email_subj:-maldet alert}"
15361529

@@ -1607,7 +1600,6 @@ _test_alert_scan() {
16071600
}
16081601

16091602
# _test_alert_digest channel — dispatch a test digest alert to a single channel
1610-
# Creates temporary hook.hits.log entries, invokes genalert digest, then cleans up.
16111603
# Applies channel isolation (S-REG-004) and truncates test entries after dispatch (S-REG-002).
16121604
_test_alert_digest() {
16131605
local _channel="$1"
@@ -1680,7 +1672,6 @@ _test_alert_digest() {
16801672
local _save_tot_hits="${tot_hits:-}" _save_tot_files="${tot_files:-}" _save_tot_cl="${tot_cl:-}"
16811673
local _save_scanid="${scanid:-}"
16821674

1683-
# Set test subject prefix
16841675
local _orig_subj="${email_subj:-}"
16851676
email_subj="[TEST] ${email_subj:-maldet alert}"
16861677

files/internals/lmd_config.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ detect_control_panel() {
2929
pex_script=$(readlink -e /usr/local/interworx/bin/listaccounts.pex)
3030
siteworx=$(command -v siteworx)
3131

32-
# Check that Iworx services are running
3332
if [[ -z "$iworx_db_ps" || -z "$iworx_web_ps" ]]; then
3433
control_panel="error"
3534
eout "{panel} Interworx found, but not running. Panel user alerts will not be sent."
36-
# Verify pex script exists and is executable
3735
elif ! [[ -x "$pex_script" ]]; then
3836
control_panel="error"
3937
eout "{panel} Interworx found, but scripts are missing or not executable. Panel user alerts will not be sent."
40-
# Ensure /usr/bin/siteworx is executable
4138
elif ! [[ -x "$siteworx" ]]; then
4239
control_panel="error"
4340
eout "{panel} Interworx found, but Siteworx CLI is missing or not executable. Panel user alerts will not be sent."
@@ -49,11 +46,9 @@ detect_control_panel() {
4946
cpapi=$(command -v cpapi2)
5047
apitool=$(readlink -e ${cpapi})
5148

52-
# Ensure cpanel service is running
5349
if [[ -z ${cpanel_ps} ]]; then
5450
control_panel="error"
5551
eout "{panel} cPanel found, but services are not running. Panel user alerts will not be sent."
56-
# Verify apitool is executable
5752
elif ! [[ -x ${apitool} ]]; then
5853
control_panel="error"
5954
eout "{panel} cPanel found, but apitool is missing or not found. Panel user alerts will not be sent."
@@ -104,7 +99,6 @@ _grf_cleanup() {
10499
}
105100

106101
get_remote_file() {
107-
# $1 = URI, $2 = local service identifier, $3 boolean verbose
108102
local get_uri="$1"
109103
local service="$2"
110104
local verbose="$3"
@@ -288,7 +282,6 @@ _safe_source_conf() {
288282
\"*\") _ssc_val="${_ssc_val#\"}"; _ssc_val="${_ssc_val%\"}" ;;
289283
\'*\') _ssc_val="${_ssc_val#\'}"; _ssc_val="${_ssc_val%\'}" ;;
290284
esac
291-
# Reject values containing shell metacharacters
292285
case "$_ssc_val" in
293286
*'$'*|*'`'*|*';'*|*'|'*|*'&'*|*'('*|*')'*)
294287
eout "{importconf} WARNING: rejected unsafe line in remote config: $_ssc_var"
@@ -406,7 +399,8 @@ import_conf() {
406399
fi
407400
fi
408401
if [ -f "$sessdir/.import_conf.cache" ]; then
409-
if [ -z "$_lmd_cli_co_applied" ]; then # skip re-source when CLI -co overrides are active — re-sourcing would discard them
402+
# skip re-source when CLI -co overrides are active — re-sourcing would discard them
403+
if [ -z "$_lmd_cli_co_applied" ]; then
410404
source "$intcnf"
411405
source "$cnf"
412406
fi

files/internals/lmd_engine.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ _hash_batch_worker() {
2020
# Self-contained batch hash scanner for a chunk of files.
2121
# Runs in a subshell (backgrounded by caller).
2222
# Outputs tab-delimited filepath\thash\tsigname triples to stdout.
23-
# Arg 1: hash command (full path from internals.conf, e.g., $md5sum)
24-
# Arg 2: temp file label ("md5" or "sha256") — must match _scan_cleanup() globs
25-
# Arg 3: chunk file (one filepath per line)
26-
# Arg 4: runtime sig file (HASH:SIZE:{TYPE}sig.name.N)
27-
# Arg 5: progress file (written every 500 files; empty = no progress)
28-
# Arg 6: scanid (for lifecycle sentinel checks; empty = no checks)
23+
# _hash_label must match _scan_cleanup() globs
24+
# _sigfile format: HASH:SIZE:{TYPE}sig.name.N
2925
local _hashcmd="$1" _hash_label="$2" _chunk="$3" _sigfile="$4" _progress_file="${5:-}"
3026
local _w_scanid="${6:-}"
3127
local _hash_out
@@ -156,7 +152,6 @@ _hex_csig_batch_worker() {
156152
local _w_scanid="${12:-}"
157153
local _chunk_skip="${13:-0}"
158154

159-
# Derive worker ID from chunk filename suffix (e.g., .hex_chunk.PID.3 → wid=3)
160155
local _wid="${_chunk##*.}"
161156

162157
# Chunk counter for checkpoint tracking and chunk-skip
@@ -306,7 +301,6 @@ _hex_csig_batch_worker() {
306301
fi
307302

308303
# Phase 3: CSIG pattern matching (batch approach)
309-
# Skip entirely if no compiled rules or scan_csig disabled
310304
if [ -n "$_csig_batch_compiled" ] && [ -s "$_csig_batch_compiled" ]; then
311305
local _match_dir
312306
_match_dir=$(mktemp -d "$tmpdir/.csig_mtx.$$.XXXXXX")

files/internals/lmd_hook.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ _scan_hook_build_env() {
175175
fi
176176
fi
177177

178-
# Export LMD_* variables into current process env for hook inheritance
179178
export LMD_SCAN_TYPE="$_scan_type"
180179
export LMD_SCANID="${scanid:-}"
181180
export LMD_HITS="$_hits"
@@ -291,15 +290,13 @@ _scan_hook_exec_sync() {
291290
local _scan_type="$3"
292291
local _json_stdin="$4"
293292

294-
# Discover timeout command at dispatch time
295293
local _timeout_cmd
296294
_timeout_cmd=$(command -v timeout 2>/dev/null) || _timeout_cmd="" # may be absent on minimal installs
297295

298296
if [ -z "$_timeout_cmd" ] && [ "$_timeout" -gt 0 ]; then
299297
eout "{hook} WARNING: 'timeout' command not found; hook will run without timeout protection"
300298
fi
301299

302-
# Build positional arguments: $1=SCANID $2=HITS $3=FILES $4=EXIT_CODE $5=SCAN_TYPE $6=PATH
303300
local _hook_hits="${tot_hits:-0}"
304301
case "$_scan_type" in
305302
digest)
@@ -326,7 +323,6 @@ _scan_hook_exec_sync() {
326323
"${hrspath:-}"
327324
)
328325

329-
# Set LMD_* env and clear sensitive vars before executing
330326
_scan_hook_build_env "$_scan_type"
331327

332328
# Capture stderr for diagnostics on non-zero exit
@@ -367,7 +363,6 @@ _scan_hook_exec_sync() {
367363
fi
368364
fi
369365

370-
# Log result and fire elog event
371366
if [ "$_hook_rc" -eq 124 ]; then
372367
eout "{hook} post-scan hook timeout after ${_timeout}s: $_hook_path"
373368
_lmd_elog_event "${ELOG_EVT_HOOK_TIMEOUT:-hook_timeout}" "warning" \
@@ -385,7 +380,6 @@ _scan_hook_exec_sync() {
385380
"hook completed" "hook=$_hook_path" "rc=$_hook_rc"
386381
fi
387382

388-
# Clean up temp stderr file
389383
[ -f "${_stderr_tmp:-}" ] && command rm -f "$_stderr_tmp" # temp cleanup; ignore error if already removed
390384

391385
return "$_hook_rc"
@@ -477,7 +471,6 @@ _scan_hook_exec_async() {
477471
# Replace subshell fds: prevents inherited pipe fds from blocking the parent
478472
exec >/dev/null 2>&1
479473

480-
# Export all LMD_* env vars using snapshotted values
481474
export LMD_SCAN_TYPE="$_scan_type"
482475
export LMD_SCANID="$_snap_scanid"
483476
export LMD_HITS="$_snap_hits"
@@ -495,7 +488,6 @@ _scan_hook_exec_async() {
495488
export LMD_MONITOR_UPTIME="0"
496489
export LMD_HOOK_HITS="$_snap_hits"
497490

498-
# Clear sensitive credential variables
499491
unset slack_token smtp_pass smtp_user telegram_bot_token
500492
unset discord_webhook_url elk_host ALERT_SMTP_PASS ALERT_SMTP_USER
501493

@@ -568,20 +560,17 @@ _scan_hook_dispatch() {
568560
_exec="async"
569561
fi
570562

571-
# Build optional JSON for json format tier
572563
local _format="${post_scan_hook_format:-args}"
573564
local _json_stdin=""
574565
if [ "$_format" = "json" ]; then
575566
_json_stdin=$(_scan_hook_build_json "$_scan_type")
576567
fi
577568

578-
# Log dispatch and fire elog event
579569
eout "{hook} ${_hook_type}-scan hook started: $_hook ($_exec, $_format)" 1
580570
_lmd_elog_event "${ELOG_EVT_HOOK_STARTED:-hook_started}" "info" \
581571
"hook started" \
582572
"hook=$_hook" "type=$_scan_type" "exec=$_exec" "format=$_format"
583573

584-
# Route to sync or async executor
585574
if [ "$_exec" = "sync" ]; then
586575
_scan_hook_exec_sync "$_hook" "$_timeout" "$_scan_type" "$_json_stdin"
587576
else

files/internals/lmd_init.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ _resolve_hashtype() {
8484

8585
_resolve_clamscan() {
8686
# Normalize scan_clamscan from auto/0/1 to 0 or 1.
87-
# When auto: enable if a clamscan binary is found on the system.
88-
# Note: $clamscan is NOT set by internals.conf — it is populated later
87+
# $clamscan is NOT set by internals.conf — it is populated later
8988
# by clamselector()/clamscan_fallback(). We must discover it here.
90-
# Writes resolved value back to scan_clamscan for all downstream code.
9189
case "$scan_clamscan" in
9290
auto)
9391
if [ -f "/usr/local/cpanel/3rdparty/bin/clamscan" ] || [ -n "$(command -v clamscan 2>/dev/null)" ]; then
@@ -108,9 +106,7 @@ _resolve_clamscan() {
108106

109107
_resolve_yara() {
110108
# Normalize scan_yara from auto/0/1 to 0 or 1.
111-
# When auto: enable only if ClamAV is unavailable AND a yara/yr binary exists.
112-
# This prevents duplicate YARA evaluation — ClamAV already processes YARA rules.
113-
# Writes resolved value back to scan_yara for all downstream code.
109+
# Prevents duplicate YARA evaluation — ClamAV already processes YARA rules.
114110
case "$scan_yara" in
115111
auto)
116112
if [ "$scan_clamscan" == "0" ] && { [ -n "$yara" ] || [ -n "$yr" ]; }; then

0 commit comments

Comments
 (0)