Moodle

Moodle cannot create a new record on user table when a new LDAP entry wants to authenticate

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.8.5, 1.8.6, 1.8.7, 1.9, 1.9.1, 1.9.2, 1.9.3
  • Fix Version/s: 1.8.8, 1.9.4
  • Component/s: Authentication
  • Labels:
    None
  • URL:
    cvs:/lib/moodlelib.php
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE

Description

Environment: a new LDAP entry try to authenticate for the first time in Moodle and still there isn't a record in mdl_user table.

When this new user try to authenticate, authenticate_user_login function is called. If the credentials are correct, it search the correct record in mdl_user table without success and it calls create_user_record.
This function try to create a new record, but this is the error message:

Field 'city' doesn't have a default value

INSERT INTO mdl_user ( AUTH, CONFIRMED, MNETHOSTID, USERNAME, FIRSTNAME, LASTNAME, LANG, LASTIP, TIMEMODIFIED ) VALUES ( 'ldap', 1, 1, 'd.eliseo', 'Donato', 'Eliseo', 'it_utf8', '10.250.1.21', 1229596730 )
line 1425 of lib/dmllib.php: call to debugging()
line 2603 of lib/moodlelib.php: call to insert_record()
line 2787 of lib/moodlelib.php: call to create_user_record()
line 126 of login/form.php: call to authenticate_user_login()

infact City Field is a nonull param as you see in cvs:/lib/db/install.xml without default value

Solution: adding something like:
$newuser->city = '';
in create_user_record function in cvs:/lib/moodlelib.php

Issue Links

Activity

Hide
Petr Škoda (skodak) added a comment -

should be fixed in cvs, please test and reopen if needed.

thanks for the report!

Show
Petr Škoda (skodak) added a comment - should be fixed in cvs, please test and reopen if needed. thanks for the report!
Hide
Hannes Fuchs added a comment -

i have the same problem, but use a 1.9.4+ version and have checked and found the described fix in source of lib/moodlelib.php

with older 1.9.2+ the ldap connection with creating users works and now after upgrading it seems to be broken.
if i add the user directly to user table with following minimum fields set auth=ldap, confimed=1, mnethostid set an username set, then i am able to login with the ldap provided user with all correct data from ldap (password, firstname, surname and so on). without adding him i could not log in. already existing users in user-table works with no problem.

are there other new fields like 'city' which are required since v1.9.2?

regards
hannes

Show
Hannes Fuchs added a comment - i have the same problem, but use a 1.9.4+ version and have checked and found the described fix in source of lib/moodlelib.php with older 1.9.2+ the ldap connection with creating users works and now after upgrading it seems to be broken. if i add the user directly to user table with following minimum fields set auth=ldap, confimed=1, mnethostid set an username set, then i am able to login with the ldap provided user with all correct data from ldap (password, firstname, surname and so on). without adding him i could not log in. already existing users in user-table works with no problem. are there other new fields like 'city' which are required since v1.9.2? regards hannes
Hide
Petr Škoda (skodak) added a comment -

there should not be any changes in user table structure in 1.9.x, could you please try to turn on full debugging and look up the error in logs?

you can put following into config.php if you want to turn on full debug temporarily:
@ini_set('display_errors', '1');
$CFG->debug = (32768 | 4096 |E_ALL);
$CFG->debugdisplay = true;
@error_reporting($CFG->debug);

Show
Petr Škoda (skodak) added a comment - there should not be any changes in user table structure in 1.9.x, could you please try to turn on full debugging and look up the error in logs? you can put following into config.php if you want to turn on full debug temporarily: @ini_set('display_errors', '1'); $CFG->debug = (32768 | 4096 |E_ALL); $CFG->debugdisplay = true; @error_reporting($CFG->debug);
Hide
Hannes Fuchs added a comment -

i got the following...

Column 'lastip' cannot be null

INSERT INTO seminare_elatest___user ( AUTH, CONFIRMED, MNETHOSTID, USERNAME, FIRSTNAME, LASTNAME, EMAIL, CITY, COUNTRY, LANG, LASTIP, TIMEMODIFIED ) VALUES ( 'ldap', 1, 1, 'XXXuserXXX', 'XXXpwXXX', 'XXX', 'XXXX@schule.at', 'XXX', 'AT', 'de_utf8', null, 1235165215 )

  • line 1554 of lib/dmllib.php: call to debugging()
  • line 2911 of lib/moodlelib.php: call to insert_record()
  • line 3143 of lib/moodlelib.php: call to create_user_record()
  • line 128 of login/index.php: call to authenticate_user_login()
Show
Hannes Fuchs added a comment - i got the following... Column 'lastip' cannot be null INSERT INTO seminare_elatest___user ( AUTH, CONFIRMED, MNETHOSTID, USERNAME, FIRSTNAME, LASTNAME, EMAIL, CITY, COUNTRY, LANG, LASTIP, TIMEMODIFIED ) VALUES ( 'ldap', 1, 1, 'XXXuserXXX', 'XXXpwXXX', 'XXX', 'XXXX@schule.at', 'XXX', 'AT', 'de_utf8', null, 1235165215 )
  • line 1554 of lib/dmllib.php: call to debugging()
  • line 2911 of lib/moodlelib.php: call to insert_record()
  • line 3143 of lib/moodlelib.php: call to create_user_record()
  • line 128 of login/index.php: call to authenticate_user_login()
Hide
Hannes Fuchs added a comment -

it seems that getremoteaddr() runs through the whole function and returns the null value.
maybe this return value can be edited to an allowed value like '0.0.0.0' or '255.255.255.255'

i have made a simple patch in my local lib/moodlelib.php now, so it now runs again.

      1. within create_user_record() ###
        $newuser->lastip = getremoteaddr();

if (!isset($newuser->lastip)) { $newuser->lastip = '0.0.0.0'; }
###

Show
Hannes Fuchs added a comment - it seems that getremoteaddr() runs through the whole function and returns the null value. maybe this return value can be edited to an allowed value like '0.0.0.0' or '255.255.255.255' i have made a simple patch in my local lib/moodlelib.php now, so it now runs again.
      1. within create_user_record() ### $newuser->lastip = getremoteaddr();
if (!isset($newuser->lastip)) { $newuser->lastip = '0.0.0.0'; } ###

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: