summaryrefslogtreecommitdiffstats
path: root/debian/setoption.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:31 +0000
commit236cb75e4430569627585a5818d9ce9bc85640f8 (patch)
treef84b5c0335eb76eb9df1e6c2c0004d7d9667c6e4 /debian/setoption.py
parentAdding upstream version 2:4.17.12+dfsg. (diff)
downloadsamba-236cb75e4430569627585a5818d9ce9bc85640f8.tar.xz
samba-236cb75e4430569627585a5818d9ce9bc85640f8.zip
Adding debian version 2:4.17.12+dfsg-0+deb12u1.debian/2%4.17.12+dfsg-0+deb12u1debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/setoption.py')
-rwxr-xr-xdebian/setoption.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/debian/setoption.py b/debian/setoption.py
new file mode 100755
index 0000000..a3f3695
--- /dev/null
+++ b/debian/setoption.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+# Helper to set a global option in the samba configuration file
+# Eventually this should be replaced by a call to samba-tool, but
+# for the moment that doesn't support setting individual configuration options.
+
+import optparse
+import os
+import re
+import shutil
+import stat
+import tempfile
+
+parser = optparse.OptionParser()
+parser.add_option("--configfile", type=str, metavar="CONFFILE",
+ help="Configuration file to use", default="/etc/samba/smb.conf")
+
+(opts, args) = parser.parse_args()
+if len(args) != 2:
+ parser.print_usage()
+
+(key, value) = args
+inglobal = False
+done = False
+
+inf = open(opts.configfile, 'r')
+(fd, fn) = tempfile.mkstemp()
+outf = os.fdopen(fd, 'w')
+
+for l in inf.readlines():
+ m = re.match(r"^\s*\[([^]]+)\]$", l)
+ if m:
+ if inglobal and not done:
+ outf.write(" %s = %s\n" % (key, value))
+ done = True
+ inglobal = (m.groups(1)[0] in ("global", "globals"))
+ elif inglobal and re.match(r"^(\s*)" + key + r"(\s*)=.*$", l):
+ l = re.sub(r"^(\s*)" + key + r"(\s*)=.*$",
+ r"\1" + key + r"\2=\2" + value, l)
+ done = True
+ outf.write(l)
+
+if not done:
+ outf.write("%s = %s\n" % (key, value))
+
+os.fchmod(fd, stat.S_IMODE(os.stat(opts.configfile).st_mode))
+outf.close()
+shutil.move(fn, opts.configfile)