Determine AuthMySQL* directives in script?

Determine AuthMySQL* directives in script?

am 19.04.2007 00:33:01 von Dwight Altman

Is there an existing way via a function or variable to determine Apache
mod_auth_mysql directives (specifically AuthMySQLDB) in use for the current
script?

On our servers, some directories use a basic .htaccess file while some use a
database under mod_auth_mysql while the latest user management system uses a
different database still using mod_auth_mysql.

I would like to have my PHP script determine which .htaccess technique is
being used for its directory, so that the script checks the correct database
for more fine grained ACL role privileges.

An alternative is that I'd have to write a routine to parse the .htaccess
file to check for the directive in a regular expression (and if that
directive is in use {regardless of whitespace} or commented out and not in
use).



Regards,
Dwight


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Determine AuthMySQL* directives in script?

am 19.04.2007 02:28:11 von dmagick

Dwight Altman wrote:
> Is there an existing way via a function or variable to determine Apache
> mod_auth_mysql directives (specifically AuthMySQLDB) in use for the current
> script?
>
> On our servers, some directories use a basic .htaccess file while some use a
> database under mod_auth_mysql while the latest user management system uses a
> different database still using mod_auth_mysql.
>
> I would like to have my PHP script determine which .htaccess technique is
> being used for its directory, so that the script checks the correct database
> for more fine grained ACL role privileges.
>
> An alternative is that I'd have to write a routine to parse the .htaccess
> file to check for the directive in a regular expression (and if that
> directive is in use {regardless of whitespace} or commented out and not in
> use).

Depends. How are you specifying the variables in the .htaccess file?

Are they 'ENV' variables? Do a print_r($_ENV); and they should show up..


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Determine AuthMySQL* directives in script?

am 19.04.2007 16:40:06 von Dwight Altman

I only agree to it "depending" if I have to write my own function using a
regular expression to parse the .htaccess file, but I was wondering if it is
already available from a PHP function or variable.

In the .htaccess file, the AuthMySQLDB directive:
1) may not be present
2) may be commented out
3) may appear like the following starting in the first columns:
AuthMySQL...
AuthMySQLDB aDataBaseName
AuthMySQL...
4) may be commented out with a valid entry present
#AuthMySQLDB oldInactiveDataBaseName
AuthMySQLDB newActiveDataBaseName
5) who knows? -- it may have other "white space" and not start in the first
column
AuthMySQLDB newActiveDataBaseName

Is that what you meant? How else can it be specified in the .htaccess file?

It does not appear in $_ENV.
I also didn't see anything in the Apache specific functions catching my eye,
however I did see the mod_auth_mysql module loaded with
"apache_get_modules()" (but I can't rely on this because I need to know
which database is being used).

apache_getenv seems to load what I already see in phpinfo(). I just don't
see an AuthMySQLDB entry.



Regards,
Dwight
> -----Original Message-----
> From: Chris [mailto:dmagick@gmail.com]
> Sent: Wednesday, April 18, 2007 7:28 PM
> To: Dwight Altman
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Determine AuthMySQL* directives in script?
>
> Dwight Altman wrote:
> > Is there an existing way via a function or variable to determine Apache
> > mod_auth_mysql directives (specifically AuthMySQLDB) in use for the
> current
> > script?
> >
> > On our servers, some directories use a basic .htaccess file while some
> use a
> > database under mod_auth_mysql while the latest user management system
> uses a
> > different database still using mod_auth_mysql.
> >
> > I would like to have my PHP script determine which .htaccess technique
> is
> > being used for its directory, so that the script checks the correct
> database
> > for more fine grained ACL role privileges.
> >
> > An alternative is that I'd have to write a routine to parse the
> .htaccess
> > file to check for the directive in a regular expression (and if that
> > directive is in use {regardless of whitespace} or commented out and not
> in
> > use).
>
> Depends. How are you specifying the variables in the .htaccess file?
>
> Are they 'ENV' variables? Do a print_r($_ENV); and they should show up..
>
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Determine AuthMySQL* directives in script?

am 20.04.2007 02:20:23 von dmagick

Dwight Altman wrote:
> I only agree to it "depending" if I have to write my own function using a
> regular expression to parse the .htaccess file, but I was wondering if it is
> already available from a PHP function or variable.
>
> In the .htaccess file, the AuthMySQLDB directive:
> 1) may not be present
> 2) may be commented out
> 3) may appear like the following starting in the first columns:
> AuthMySQL...
> AuthMySQLDB aDataBaseName
> AuthMySQL...
> 4) may be commented out with a valid entry present
> #AuthMySQLDB oldInactiveDataBaseName
> AuthMySQLDB newActiveDataBaseName
> 5) who knows? -- it may have other "white space" and not start in the first
> column
> AuthMySQLDB newActiveDataBaseName
>
> Is that what you meant? How else can it be specified in the .htaccess file?

No, I meant it depends on how it is defined in the htaccess file.

http://httpd.apache.org/docs/1.3/mod/mod_env.html

SetEnv AuthMySQLDB dbName

would allow you to:

$dbname = getenv('AuthMySQLDB');


Apart from that I'm out of ideas :)

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Determine AuthMySQL* directives in script?

am 20.04.2007 16:31:44 von Dwight Altman

Cool alternative.

We don't write .htaccess files like that though.

Anyway, I actually wrote a function to parse the .htaccess file, but I will
try this SetEnv/getenv technique also.

Thanks.

Regards,
Dwight
> -----Original Message-----
> From: Chris [mailto:dmagick@gmail.com]
> Sent: Thursday, April 19, 2007 7:20 PM
> To: Dwight Altman
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Determine AuthMySQL* directives in script?
>
> Dwight Altman wrote:
> > I only agree to it "depending" if I have to write my own function using
> a
> > regular expression to parse the .htaccess file, but I was wondering if
> it is
> > already available from a PHP function or variable.
> >
> > In the .htaccess file, the AuthMySQLDB directive:
> > 1) may not be present
> > 2) may be commented out
> > 3) may appear like the following starting in the first columns:
> > AuthMySQL...
> > AuthMySQLDB aDataBaseName
> > AuthMySQL...
> > 4) may be commented out with a valid entry present
> > #AuthMySQLDB oldInactiveDataBaseName
> > AuthMySQLDB newActiveDataBaseName
> > 5) who knows? -- it may have other "white space" and not start in the
> first
> > column
> > AuthMySQLDB newActiveDataBaseName
> >
> > Is that what you meant? How else can it be specified in the .htaccess
> file?
>
> No, I meant it depends on how it is defined in the htaccess file.
>
> http://httpd.apache.org/docs/1.3/mod/mod_env.html
>
> SetEnv AuthMySQLDB dbName
>
> would allow you to:
>
> $dbname = getenv('AuthMySQLDB');
>
>
> Apart from that I'm out of ideas :)
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Determine AuthMySQL* directives in script?

am 20.04.2007 18:32:16 von Dwight Altman

It appears that Apache still needs the directive without the SetEnv prefix
to actually use the mod_auth_mysql authentication, but an additional line
with the SetEnv directive will pass that variable to the script.

AuthMySQLDB aDataBaseName
SetEnv AuthMySQLDB aDataBaseName
SetEnv ApparentlyAnyVariableName aValue

So it isn't really reading the Apache AuthMySQLDB directive in use, and we'd
have to hope that whoever wrote the .htaccess file included the correct
database name.

The following could happen:

#AuthMySQLDB oldDataBaseNameNotBeingUsedSinceItIsCommentedOut
AuthMySQLDB newDataBaseNameBeingUsed
SetEnv AuthMySQLDB wrongDataBaseNamePassedToScript

So if anyone knows a function or variable to definitely get the Apache
AuthMySQLDB directive in use for the current script, it may be safer than my
attempt to parse the .htaccess file.


Regards,
Dwight
> -----Original Message-----
> From: Dwight Altman [mailto:dwight@multicam.com]
> Sent: Friday, April 20, 2007 9:32 AM
> To: php-db@lists.php.net
> Subject: RE: [PHP-DB] Determine AuthMySQL* directives in script?
>
> Cool alternative.
>
> We don't write .htaccess files like that though.
>
> Anyway, I actually wrote a function to parse the .htaccess file, but I
> will
> try this SetEnv/getenv technique also.
>
> Thanks.
>
> Regards,
> Dwight
> > -----Original Message-----
> > From: Chris [mailto:dmagick@gmail.com]
> > Sent: Thursday, April 19, 2007 7:20 PM
> > To: Dwight Altman
> > Cc: php-db@lists.php.net
> > Subject: Re: [PHP-DB] Determine AuthMySQL* directives in script?
> >
> > Dwight Altman wrote:
> > > I only agree to it "depending" if I have to write my own function
> using
> > a
> > > regular expression to parse the .htaccess file, but I was wondering if
> > it is
> > > already available from a PHP function or variable.
> > >
> > > In the .htaccess file, the AuthMySQLDB directive:
> > > 1) may not be present
> > > 2) may be commented out
> > > 3) may appear like the following starting in the first columns:
> > > AuthMySQL...
> > > AuthMySQLDB aDataBaseName
> > > AuthMySQL...
> > > 4) may be commented out with a valid entry present
> > > #AuthMySQLDB oldInactiveDataBaseName
> > > AuthMySQLDB newActiveDataBaseName
> > > 5) who knows? -- it may have other "white space" and not start in the
> > first
> > > column
> > > AuthMySQLDB newActiveDataBaseName
> > >
> > > Is that what you meant? How else can it be specified in the .htaccess
> > file?
> >
> > No, I meant it depends on how it is defined in the htaccess file.
> >
> > http://httpd.apache.org/docs/1.3/mod/mod_env.html
> >
> > SetEnv AuthMySQLDB dbName
> >
> > would allow you to:
> >
> > $dbname = getenv('AuthMySQLDB');
> >
> >
> > Apart from that I'm out of ideas :)
> >
> > --
> > Postgresql & php tutorials
> > http://www.designmagick.com/
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php