def ldap_authentification(admin=False): """ Return True if user is well authentified [email protected] password=xxxxx """ if SERVER_OPTS['ldap']: credentials = data2map() if credentials.has_key('realname'): realname = unquote_plus(credentials['realname']) else: return False, 'Error: No realname option given.' if credentials.has_key('password'): password = unquote_plus(credentials['password']) else: return False, 'Error: No password option given.' if password == '': return False, 'Error: password is empty.' ldap_conn = ldap_open(SERVER_OPTS['ldap_host'], port=int(SERVER_OPTS['ldap_port'])) try: ldap_conn.bind_s(SERVER_OPTS['ldap_bind_dn'], SERVER_OPTS['ldap_bind_password']) except Exception as e: return False, 'Error: LDAP Bind DN (%s)' % e try: entries = ldap_conn.search_s( SERVER_OPTS['ldap_base_dn'], SCOPE_SUBTREE, filterstr='(&(%s=%s)%s)' % (SERVER_OPTS['ldap_username_field'], realname, SERVER_OPTS['ldap_search_filter'])) if len(entries) == 0: return False, 'Error: LDAP User not found %s' % e else: for entry in entries: if entry[1][ SERVER_OPTS['ldap_username_field']][0] == realname: user_dn = entry[0] except Exception as e: return False, 'Error: LDAP user search (%s)' % e try: ldap_conn_user = ldap_open(SERVER_OPTS['ldap_host'], port=int(SERVER_OPTS['ldap_port'])) ldap_conn_user.bind_s(user_dn, password) ldap_conn_user.unbind() except Exception as e: return False, 'Error: Unable to bind User DN (%s)' % e if admin: memberof_admin_list = ldap_conn.search_s( SERVER_OPTS['ldap_groups_base_dn'], SCOPE_SUBTREE, filterstr='(&(cn=%s)(%s=%s))' % (SERVER_OPTS['ldap_admin_cn'], SERVER_OPTS['ldap_membership_field'], user_dn)) if not memberof_admin_list: return False, 'Error: user %s is not an admin.' % realname return True, 'OK'
def ldap_authentification(admin=False): """ Return True if user is well authentified [email protected] password=xxxxx """ if SERVER_OPTS['ldap']: if web_input().has_key('realname'): realname = web_input()['realname'] else: return False, 'Error: No realname option given.' if web_input().has_key('password'): password = web_input()['password'] else: return False, 'Error: No password option given.' if password == '': return False, 'Error: password is empty.' ldap_conn = ldap_open(SERVER_OPTS['ldap_host']) try: ldap_conn.bind_s(realname, password) except Exception as e: return False, 'Error: %s' % e if admin and SERVER_OPTS['ldap_admin_cn'] not in\ ldap_conn.search_s(SERVER_OPTS['ldap_bind_dn'], 2, filterstr='(%s=%s)' % (SERVER_OPTS['filterstr'], realname) )[0][1]['memberOf']: return False, 'Error: user %s is not an admin.' % realname return True, 'OK'
def ldap_authentification(admin=False): """ Return True if user is well authentified [email protected] password=xxxxx """ if SERVER_OPTS['ldap']: credentials = data2map() if credentials.has_key('realname'): realname = unquote_plus(credentials['realname']) else: return False, 'Error: No realname option given.' if credentials.has_key('password'): password = unquote_plus(credentials['password']) else: return False, 'Error: No password option given.' if password == '': return False, 'Error: password is empty.' ldap_conn = ldap_open(SERVER_OPTS['ldap_host']) try: ldap_conn.bind_s(realname, password) except Exception as e: return False, 'Error: %s' % e if admin: memberof_admin_list = ldap_conn.search_s( SERVER_OPTS['ldap_bind_dn'], SCOPE_SUBTREE, filterstr='(&(%s=%s)(memberOf=%s))' % (SERVER_OPTS['filterstr'], realname, SERVER_OPTS['ldap_admin_cn'])) if not memberof_admin_list: return False, 'Error: user %s is not an admin.' % realname return True, 'OK'
akademosWSDL = "http://akademos2.uci.cu/servicios/v3/AkademosWS.wsdl" client = Client(akademosWSDL, doctor = doc) grupos = client.service.ObtenerGrupos() i = 0 grupo = None while i < len(grupos) and not grupo: if grupos[i].NombreGrupo == nombre_grupo: grupo = grupos[i] i += 1 if not grupo: print >>stderr, "\nGrupo no encontrado: rectifique formato de entrada\n" exit(1) estudiantes = client.service.ObtenerEstudiantesDadoFiltro(grupo) no_mail = [] duplicated = [] ldap = ldap_open("ldap.uci.cu") for estudiante in estudiantes: unicode_cn = u"%s %s %s %s" % \ (estudiante.PrimerNombre, estudiante.SegundoNombre, estudiante.PrimerApellido, estudiante.SegundoApellido) unicode_cn = unicode_cn.replace(" ", " ").replace(" - ", " ") cn = unicode_cn.encode("ascii", "replace").replace("?", "*") try: id = ldap.search("", SCOPE_SUBTREE, "cn=%s" % cn, ["mail"]) st, data = ldap.result(id, 10) if len(data) < 1: no_mail.append(unicode_cn) elif len(data) > 1: duplicated.append(unicode_cn) else: line = "%s <%s>" % (unicode_cn, data[0][1]["mail"][0])