views:

447

answers:

2

I'm writing a simple in-house frontend to Subversion. We've got an Apache setup serving up the SVN repositories thanks to WebDAV. Also, authentication is done through an Apache realm and Open Directory. For what it's worth, this is basically a pretty vanilla Mac OS X Server 10.6 setup.

Now, some of the tasks our front end is responsible of kicking off need to know the username of the user calling the action. For instance, creating a repository needs it so that we get proper logs of who actually created it. If I don't supply this information, SVN just uses the process that created it which in our case is the user running httpd.

I'm doing this in php, but I don't necessarily have to implement this using php. If I can get the information in a shell script that's fine too. What matters is that I somehow get the information. The solution I first developed, which I assumed worked since it correctly reported my user name, is simply calling:

get_current_user();

However, this seems to always return my user name, even though some other user is kicking off the action while being logged in to the realm. Is there a way to get the correct user?

+1  A: 

EDIT: I may have been a bit too quick to jump the gun here. It looks as though the former variable doesn't get set after a certain amount of time. However, the user is still logged in as there is no request to login. Thus, the below suggested solution is not really applicable.


Now I feel like an idjit. This simple snippet worked (although it was difficult to find):

$username = $_SERVER["PHP_AUTH_USER"];

However, this did not:

$username = apache_getenv("REMOTE_USER");

Anyone got an idea as to why the latter doesn't work? The only docs I could find suggest that this only works on Apache 2. However, I am in fact running Apache 2 so that couldn't be it.

macke
+1  A: 

So, after having googled for a long while I've realized that the method for getting the user name have changed with pretty much every passing PHP version. The current solution which seems to be the one is to get the data from the following variable:

$_SERVER['REMOTE_USER'];

However, this variable may or may not be set. The reason why I probably did see the information correctly was that the information was sent in the headers when I logged in to the realm and then visited the PHP script which was outside of said realm. The information did arrive, but wasn't reliable.

The Apache docs actually tell you this in an "Oh BTW"-fashion. I'm not sure if the authentication is carried over across multiple realms on the same host, but in any case, that solved the problem.

macke