def _enable_sid(self, ldap, options): # the user must have the Replication Administrators privilege privilege = 'Replication Administrators' if not principal_has_privilege(self.api, context.principal, privilege): raise errors.ACIError( info=_("not allowed to enable SID generation")) # NetBIOS name is either taken from options or generated try: netbios_name, reset_netbios_name = set_and_check_netbios_name( options.get('netbios_name', None), True, self.api) except ScriptError: raise errors.ValidationError( name="NetBIOS name", error=_('Up to 15 characters and only uppercase ASCII letters' ', digits and dashes are allowed. Empty string is ' 'not allowed.')) _ret = 0 _stdout = '' _stderr = '' dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) method_options = [] if options.get('add_sids', False): method_options.extend(["--add-sids"]) method_options.extend(["--netbios-name", netbios_name]) if reset_netbios_name: method_options.append("--reset-netbios-name") # Dbus definition expects up to 10 arguments method_options.extend([''] * (10 - len(method_options))) try: bus = dbus.SystemBus() obj = bus.get_object('org.freeipa.server', '/', follow_name_owner_changes=True) server = dbus.Interface(obj, 'org.freeipa.server') _ret, _stdout, _stderr = server.config_enable_sid(*method_options) except dbus.DBusException as e: logger.error( 'Failed to call org.freeipa.server.config_enable_sid.' 'DBus exception is %s', str(e)) raise errors.ExecutionError(message=_('Failed to call DBus')) # The oddjob restarts dirsrv, we need to re-establish the conn if self.api.Backend.ldap2.isconnected(): self.api.Backend.ldap2.disconnect() self.api.Backend.ldap2.connect(ccache=context.ccache_name) if _ret != 0: logger.error("Helper config_enable_sid return code is %d", _ret) raise errors.ExecutionError( message=_('Configuration of SID failed. ' 'See details in the error log'))
def test_NetbiosName(self): """ Test set_and_check_netbios_name() using permutation of two inputs: - predefined and not defined NetBIOS name - unattended and interactive run As result, the function has to return expected NetBIOS name in all cases. For interactive run we override input to force what we expect. """ self.api.env.domain = 'example.com' expected_nname = 'EXAMPLE' # NetBIOS name, unattended, should set the name? tests = ((expected_nname, True, False), (None, True, True), (None, False, True), (expected_nname, False, False)) with mock.patch('sys.stdin', new_callable=StringIO) as stdin: stdin.write(expected_nname + '\r') for test in tests: nname, setname = set_and_check_netbios_name( test[0], test[1], self.api) assert expected_nname == nname assert setname == test[2]