Skip to content

win_lgpo: read/write advanced audit policy via advapi32, not auditpol.exe#68935

Merged
dwoz merged 6 commits intosaltstack:3006.xfrom
twangboy:fix/68354/3006.x
Apr 23, 2026
Merged

win_lgpo: read/write advanced audit policy via advapi32, not auditpol.exe#68935
dwoz merged 6 commits intosaltstack:3006.xfrom
twangboy:fix/68354/3006.x

Conversation

@twangboy
Copy link
Copy Markdown
Contributor

What does this PR do?

Read auditpol /backup output with locale.getencoding() (Python 3.11+) or mbcs fallback so CSV is decoded with the system ANSI encoding instead of fopen's default UTF-8. Prevents UnicodeDecodeError when lgpo.get runs on non-English Windows (e.g. German).

What issues does this PR fix or reference?

Fixes #68354

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@twangboy twangboy requested a review from a team as a code owner April 13, 2026 19:39
@twangboy twangboy self-assigned this Apr 13, 2026
@twangboy twangboy added the test:full Run the full test suite label Apr 13, 2026
@twangboy twangboy added this to the Sulpher v3006.24 milestone Apr 13, 2026
@twangboy twangboy changed the title Fix auditpol backup CSV encoding for localized Windows win_lgpo: read/write advanced audit policy via advapi32, not auditpol.exe Apr 21, 2026
Read auditpol /backup output with locale.getencoding() (Python 3.11+)
or mbcs fallback so CSV is decoded with the system ANSI encoding
instead of fopen's default UTF-8. Prevents UnicodeDecodeError when
lgpo.get runs on non-English Windows (e.g. German).

Fixes saltstack#68354
….exe

Replace locale-dependent parsing of auditpol.exe output with ctypes calls
to advapi32 (AuditQuerySystemPolicy, AuditSetSystemPolicy, AuditFree).
Enable SeSecurityPrivilege only while applying changes. Keep a static
GUID-to-English subcategory map in win_lgpo_auditpol; expose bitmask
settings and get_advaudit_policy_rows() for structured consumers.

win_lgpo._get_advaudit_defaults now uses those rows instead of CSV from
get_auditpol_dump; get_auditpol_dump remains a UTF-8 CSV serializer for
compatibility. Bindings on the lazy API object use PascalCase to match
Win32 exports. Update win_auditpol messaging and LGPO unit test mocks.
@dwoz dwoz force-pushed the fix/68354/3006.x branch from 65b7028 to 227e0a6 Compare April 23, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants