Bug 15848 - Crash when listing an empty MOTD GPO
Summary: Crash when listing an empty MOTD GPO
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Tools (show other bugs)
Version: 4.21.4
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-15 20:28 UTC by Andreas Hasenack
Modified: 2025-04-15 20:37 UTC (History)
0 users

See Also:


Attachments
fix crash when listing empty MOTD GPO (1.13 KB, patch)
2025-04-15 20:37 UTC, Andreas Hasenack
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Hasenack 2025-04-15 20:28:36 UTC
Trying to list a MOTD GPO after having cleared it returns a traceback:


# Clearing the MOTD text
root@p-gpo:~# samba-tool gpo manage motd set {31B2F340-016D-11D2-945F-00C04FB984F9} "" -U Administrator%Passw0rd
WARNING: Using passwords on command line is insecure. Installing the setproctitle python module will hide these from shortly after program start.

# Listing
root@p-gpo:~# samba-tool gpo manage motd list '{31B2F340-016D-11D2-945F-00C04FB984F9}'
ERROR(<class 'TypeError'>): uncaught exception - write() argument must be str, not None
  File "/usr/lib/python3/dist-packages/samba/netcmd/__init__.py", line 353, in _run
    return self.run(*args, **kwargs)
           ~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/samba/netcmd/gpo.py", line 3751, in run
    self.outf.write(text.text)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^
root@p-gpo:~#



Something like this should fix it I hope:

--- python/samba/netcmd/gpo.py.py.orig 2025-04-15 19:35:07.051084668 +0000
+++ python/samba/netcmd/gpo.py.py  2025-04-15 19:35:08.665997025 +0000
@@ -3748,7 +3748,9 @@
         policy = xml_data.find('policysetting')
         data = policy.find('data')
         text = data.find('text')
-        self.outf.write(text.text)
+        if text is not None:
+            if text.text is not None:
+                self.outf.write(text.text)
 
 class cmd_set_motd(GPOCommand):
     """Sets a VGP MOTD Group Policy to the sysvol


I'll format it properly as a patch.
Comment 1 Andreas Hasenack 2025-04-15 20:37:14 UTC
Created attachment 18632 [details]
fix crash when listing empty MOTD GPO