def stop(self): for iface in Interface.objects.all(): if not iface.configured: logger.debug("%s is not configured" % iface.name) continue with root(): run('/sbin/ifdown --force %s' % iface.name)
def save(self): # Save con files self.smbconf.write() with root(): shutil.copy2(self.SMB_KRB5CONF_FILE, self.KRB5CONF_FILE) # XXX FIXME move this to network run("echo 'nameserver 127.0.0.1' > /etc/resolv.conf")
def start(self): for iface in Interface.objects.all(): if not iface.configured: logger.debug("%s is not configured" % iface.name) continue with root(): # we run ifup in background # it can wait indefinitely for DHCP requests run('/sbin/ifup --force %s' % iface.name, background=True)
def samdb_connect(): """ Open and return a SamDB connection """ with root(): lp = samba.param.LoadParm() lp.load("/etc/samba/smb.conf") creds = Credentials() creds.guess(lp) session = system_session() samdb = SamDB("/var/lib/samba/private/sam.ldb", session_info=session, credentials=creds, lp=lp) return samdb
def install(self): """ Installation procedure, it writes basic smb.conf and uses samba-tool to provision the domain """ domain_settings = DomainSettings.get() with root(): if os.path.exists(self.SMBCONF_FILE): os.remove(self.SMBCONF_FILE) if domain_settings.mode == "ad": domain_settings.adminpass = make_password(15) domain_settings.save() run( "samba-tool domain provision " "--domain='%s' " "--workgroup='%s' " "--realm='%s' " "--use-xattrs=yes " "--use-rfc2307 " "--server-role='domain controller' " "--use-ntvfs " "--adminpass='******'" % ( domain_settings.domain, domain_settings.workgroup, domain_settings.realm, domain_settings.adminpass, ) ) self.smbconf.write() shutil.copy2(self.SMB_KRB5CONF_FILE, self.KRB5CONF_FILE) # XXX FIXME move this to network run("echo 'nameserver 127.0.0.1' > /etc/resolv.conf") # TODO manage shares run("touch /etc/samba/shares.conf") elif domain_settings.mode == "member": # TODO pass
def install(self): """ Installation procedure, it writes basic smb.conf and uses samba-tool to provision the domain """ domain_settings = DomainSettings.get() with root(): if os.path.exists(self.SMBCONF_FILE): os.remove(self.SMBCONF_FILE) if domain_settings.mode == 'ad': domain_settings.adminpass = make_password(15) domain_settings.save() run("samba-tool domain provision " "--domain='%s' " "--workgroup='%s' " "--realm='%s' " "--use-xattrs=yes " "--use-rfc2307 " "--server-role='domain controller' " "--use-ntvfs " "--adminpass='******'" % (domain_settings.domain, domain_settings.workgroup, domain_settings.realm, domain_settings.adminpass)) self.smbconf.write() shutil.copy2(self.SMB_KRB5CONF_FILE, self.KRB5CONF_FILE) # XXX FIXME move this to network run("echo 'nameserver 127.0.0.1' > /etc/resolv.conf") # TODO manage shares run("touch /etc/samba/shares.conf") elif domain_settings.mode == 'member': # TODO pass
def test_with_root(self): set_euid() self.assertNotEqual(os.geteuid(), 0) with root(): self.assertEqual(os.getuid(), 0)
def tearDown(self): with root(): shutil.rmtree(self.tmpdir)