'Retrieve an active resource of model res_users with the specified
login. Create the user if it is not initially found.
:param dict conf: LDAP configuration
:param login: the user\'s login
:param tuple ldap_entry: single LDAP result (dn, attrs)
:return: res_users id
:rtype: int'

@api.model
def get_or_create_user(self, conf, login, ldap_entry):

    user_id = False
    login = tools.ustr(login.lower().strip())
    self.env.cr.execute('SELECT    id,    active    FROM    res_users    WHERE    lower(login)=%s', (login,))
    res = self.env.cr.fetchone()
    if res:
        if res[1]:
            user_id = res[0]
    elif conf['create_user']:
        _logger.debug(('Creating    new    Odoo    user    "%s"    from    LDAP' % login))
        values = self.map_ldap_attributes(conf, login, ldap_entry)
        SudoUser = self.env['res.users'].sudo()
        if conf['user']:
            values['active'] = True
            user_id = SudoUser.browse(conf['user'][0]).copy(default=values).id
        else:
            user_id = SudoUser.create(values).id
    return user_id
