does it work if the course already exists with the matching code in idnumber? I am flat out at the moment with Eduforge-related development work (preview at http://ng.eduforge.org/ ) so I can't do much testing at this end. The code you have (the custom Moodle) is our production code, and has been doing LDAP enrolments since November.
Hmmm. I am not sure whether course _creation_ happens when users login. It *may* depend on running the enrolment cron. Shouldn't be the case, but I don't remember.