This is related to http://drupal.org/node/208888.

When an external auth module approves a new user, user_save() is called. After the user is created, user_module_invoke() is called with the insert op and the new $user.

profile_user() catches this and calls profile_save_profile() which calls _profile_get_fields() which calls user_access(). The call to user_access() fails because the new $user object is passed along the call chain until _profile_get_fields(), when it is lost.

So _profile_get_fields() calls user_access() without passing the new $user. user_access() has no choice but to run the access check on the global $user...which is the wrong user!

This patch passes the new $user along to _profile_get_fields() so that when user_access() is called, the new user account is the one being checked.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

looks good. needs testing.

birdmanx35’s picture

This still works cleanly against HEAD.

moshe weitzman’s picture

@birdmanx - if you tested and it works, please set to rtbc.

birdmanx35’s picture

Status: Needs review » Reviewed & tested by the community

@moshe weitzman. I wasn't sure, because I really have no idea what this patch is doing, or if it's good, or if it is written well. All I know is that it applies cleanly to HEAD.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

The fact that it applies cleanly does not make it ready. Needs testing.

birdmanx35’s picture

Yep, my apologies.

joshk’s picture

I'm dealing with this in a backport sense. It works, but I wonder if it doesn't also "break" the user_access. The question here is not supposed to be whether or not the user being modivied has the "admin users" pem -- which is what this patch sets the user_access hook to check -- but rather whether or not the user doing the modifying has that perm (which, outside this edge case, is stored in global $user).

I worry that this patch will actually break the ability for profile.module to use admin-only fields.

joshk’s picture

I've tested this and even though intuitively I still have a feeling that passing the $user object of the account being edited to user_access() should be causing issues with hidden/admin-only fields, it seems to work fine.

joshk’s picture

5.x-dev backport

jvandyk’s picture

"user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () /drupal/modules/user/user.module on line 500."

Tested using pubcookie as the external auth module, the error above is brought on by the fact that the wrong user is being checked (see explanation in #1). Here it manifests itself as a role error because we are halfway through user_save() when the 'insert' op is called. At this point the global $user has no roles; the passed $user (which will shortly become the global $user) does; thus we see this error.

Applying the patch results in no error.

dpearcefl’s picture

Is this still an issue in current D6?

Status: Needs review » Needs work

The last submitted patch, profile_auth_access_5.x-dev.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.