philbertphotos / osticket-multildap-auth-plugin

Plugin for OS Ticket that allows for authentication with multiple domains.
GNU General Public License v3.0
28 stars 17 forks source link

Added users do not get auto registered and remain as guest even if they are in the Active Directory #36

Closed ScottishSamurai closed 3 years ago

ScottishSamurai commented 3 years ago

I am starting this new thread since this is a different issue from the non authentication for clients. Users who are have been added to OST are not getting auto registered when checked against the AD.

I have found the cause but I am not sure how to correct the issue in the code. When sync goes and checks the the users email address against the AD to add them to the sync table if the users email has uppercase letters in the email address it skips them as if its not a match. I have tested this against one of my accounts, that was still left as guest in OST, that had the uppercase letters and set it to all lower case and the system then auto registered.

Not sure if it is isolated to my environment, Linux/php. I know that Linux/PHP handles uppercase/lowercase names differently than MS Windows.

If I am not wrong I believe the code that handles this is:

        // Go thru every osTicket user and add them to the sync table if a match is found
        foreach (db_assoc_array($qry_ostusers, MYSQLI_ASSOC) as $sql_ostusers) {
            $key = trim(strtolower($sql_ostusers['mail'])); //Key value for matching users
            $user_ldap = $ad_users[$key];

            if (strtolower($key == $user_ldap->mail)) {
                //Lets check users and add them to the guid table if a match is found
                $result = db_query("SELECT id FROM " . TABLE_PREFIX . "ldap_sync WHERE id = '" . $sql_ostusers['user_id'] . "'");
                if (db_num_rows($result) == 0 && $key == $ad_users[$key]->mail) {
                    db_query("INSERT INTO " . TABLE_PREFIX . "ldap_sync(id, guid, updated)
                        values ('" . $sql_ostusers['user_id'] . "', '" . $ad_users[$key]->objectguid . "', '" . date('Y-m-d H:i:s') . "')
                        ON DUPLICATE KEY UPDATE id = \"" . $sql_ostusers['user_id'] . "\", guid = \"" . $ad_users[$key]->objectguid . "\", updated = \"" . date('Y-m-d H:i:s') . "\";");
                }
            }
        }
ScottishSamurai commented 3 years ago

Reviewing the code and Googling, I see now that you are using strtolower($sql_ostusers['mail'] to bring back the email address as all lower case. I am sure there was a specific reason for this however I think there might need to be a review then of how users are added. If users in the AD have uppercases in their email and they are added through the OST "add user" option or through adding a new ticket, it pulls in the email address with the uppercase. I would think we would want to have it add the address in those two areas with the lower cases as well if we are converting strtolower.

ScottishSamurai commented 3 years ago

image

philbertphotos commented 3 years ago

I will take a look at that ... there is a reason I have no idea any more but let me dig.

philbertphotos commented 3 years ago

This still works for me with a remote client. It fills in all the data and I am using the most recent update.

philbertphotos commented 3 years ago

Ok so if you notice in some areas when its "remote" I use the DN and the Local accounts use the mysql ID I am not sure Osticket supports adding remotes in some areas but I will check. It works find when its a new ticket but not collaboration for example.

image

philbertphotos commented 3 years ago

Ok this is either A bug in osticket or a feature that was never fully implemented I will have to open a ticket with the developers.

philbertphotos commented 3 years ago

@ScottishSamurai adding the "Remote" user works the issue is that you cant use the mouse. Its a bug in Osticket .... just use the keyboard and press Enter. I making a bug report.