gzuncompress
|
Server IP : 172.19.0.2 / Your IP : 216.73.216.178 Web Server : Apache/2.4 System : Linux 880f91b28fd7 5.15.0-117-generic #127~20.04.1-Ubuntu SMP Thu Jul 11 15:36:12 UTC 2024 x86_64 User : tomlinde ( 155017) PHP Version : 5.6.40 Disable Function : dl, syslog, opcache_get_status MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /bin/../share/samba/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] | [ Lock Shell ] | [ Logout ] |
|---|
#!/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)