Exemplo n.º 1
0
def get_userdn_by_username(username):
	lo, po = get_machine_connection()
	if lo:
		# get the LDAP DN of the authorized user
		ldap_dn = lo.searchDn('(&(uid=%s)(objectClass=posixAccount))' % escape_filter_chars(username))
		if not ldap_dn:
			CORE.info('The LDAP DN for user %s could not be found' % (username))
			return
		CORE.info('The LDAP DN for user %s is %s' % (username, ldap_dn))
		return ldap_dn[0]
def set_locale(locale):
	try:
		locale = str(Locale(locale))
		setlocale(LC_MESSAGES, locale)
		CORE.info("Successful load specified locale (%s)" % (locale,))
	except LocaleError:
		CORE.warn("Specified locale is not available (%s)" % (locale,))
		CORE.warn("Falling back to C")
		setlocale(LC_MESSAGES, 'C')
		return False
	else:
		return True
	def set_language(self, language):
		success = True
		for language in [language, 'C']:
			CORE.info('Setting language: %s' % (language,))
			try:
				self.core_i18n.set_language(language)
				self.i18n.set_locale(language)
			except (I18N_Error, AttributeError, TypeError):
				CORE.warn('Setting locale to specified locale failed (%s)' % (language,))
				success = False
			else:
				break
		return success