Project

General

Profile

Actions

Feature #2163

closed

Multiple use of '?' in mysql-vhost.sql

Added by phpmysqlfreak about 14 years ago. Updated over 7 years ago.

Status:
Fixed
Priority:
Normal
Category:
mod_mysql_vhost
Target version:
ASK QUESTIONS IN Forums:

Description

Can someone please rewrite the code for mod_mysql_vhost to parse at least two or more occurrences of the questionmark?

in trunk it should be line 142 (now) and in branches it should be following link:

http://redmine.lighttpd.net/projects/lighttpd/repository/entry/branches/lighttpd-1.4.x/src/mod_mysql_vhost.c#L225

PS:
The destination version could be 1.4.x or later.


Files

mod_mysql_vhost.c (11.2 KB) mod_mysql_vhost.c Modified version of mod_vhost_mysql.c changed from the file of 1.4.19 phpmysqlfreak, 2010-02-11 19:25
lighttpd_feature_2163.diff (2.51 KB) lighttpd_feature_2163.diff lonnyk, 2010-07-07 05:16
mod_mysql_vhost.c (13.1 KB) mod_mysql_vhost.c tronox@hotmail.com, 2013-09-09 00:25
mod_mysql_vhost.c (14.6 KB) mod_mysql_vhost.c tronox@hotmail.com, 2013-09-09 05:10

Related issues 1 (0 open1 closed)

Has duplicate Bug #2512: mysql_vhosts Complex SQLDuplicate2013-09-08Actions
Actions #1

Updated by phpmysqlfreak about 14 years ago

depending on the sources of 1.4.19 - installed on my system - i tried to change some things.
now i get some other errors like following, while testing some testbuilds.

Feb 11 18:01:51 atom019 kernel: lighttpd[1613]: segfault at 0 ip b7519bbf sp bffe9b20 error 6 in libc-2.7.so[b74a7000+138000]
Feb 11 18:06:33 atom019 kernel: lighttpd[2515]: segfault at 0 ip b747dbbf sp bfe5c3b0 error 6 in libc-2.7.so[b740b000+138000]
Feb 11 18:10:29 atom019 kernel: lighttpd[2558]: segfault at 0 ip b7505bbf sp bff5f510 error 6 in libc-2.7.so[b7493000+138000]
Feb 11 18:10:34 atom019 kernel: lighttpd[2572]: segfault at 0 ip b7497bbf sp bfb8b830 error 6 in libc-2.7.so[b7425000+138000]
Feb 11 18:19:04 atom019 kernel: lighttpd[2599]: segfault at 0 ip b7458bbf sp bf909600 error 6 in libc-2.7.so[b73e6000+138000]
Feb 11 18:19:50 atom019 kernel: lighttpd[2616]: segfault at 0 ip b74adbbf sp bfe44700 error 6 in libc-2.7.so[b743b000+138000]
Feb 11 18:26:44 atom019 kernel: lighttpd[2642]: segfault at 0 ip b74e4bbf sp bfc5cf50 error 6 in libc-2.7.so[b7472000+138000]
Feb 11 18:32:18 atom019 kernel: lighttpd[2668]: segfault at 0 ip b7475bbf sp bfc30540 error 6 in libc-2.7.so[b7403000+138000]
Feb 11 18:35:49 atom019 kernel: lighttpd[2687]: segfault at 0 ip b74ecbbf sp bfe081c0 error 6 in libc-2.7.so[b747a000+138000]
Feb 11 18:37:47 atom019 kernel: lighttpd[2706]: segfault at 0 ip b749bbbf sp bfc38f60 error 6 in libc-2.7.so[b7429000+138000]
Feb 11 19:05:48 atom019 kernel: lighttpd[2749]: segfault at 0 ip b74b5bbf sp bf856320 error 6 in libc-2.7.so[b7443000+138000]

The attached file has some modifications - first I added mysql_mid between mysql_pre/post. to assemble the complete query i replicated some lines at about line 370.
with some output to the error log i verified, that the string is splittet into 3 parts (for me enough, but normally a dirty version with strrchr) - not 2, like before.

Actions #2

Updated by lonnyk over 13 years ago

I was just looking into this and I'm not sure how this can be used in real life with two '?'.

Keep in mind, the '?' is replaced by the URI (hostname) that is being used to hit the server. So if you had:
mysql-vhost.sql = "SELECT docroot FROM domains WHERE domain='?';"
And my site hit the server the query ran would be:
SELECT docroot FROM domains WHERE domain='lonnylot.com';

I don't see how having that in two separate places would make any sense. Can you please post the query you're running as well as an example MySQL table so I can see why this is needed before adding the feature?

Actions #3

Updated by phpmysqlfreak over 13 years ago

My Setup is the following:

MySQL-Table:

id      subdomain       domain
2015    www             example.tld
2016    www2            example.tld

the mysql-table contains some data more (for ftp-access, etc.), while the username contains the user-id - in all services.

Now I want this module using a query like this:

SELECT CONCAT("/webs/",id) AS docroot FROM users WHERE CONCAT(subdomain,".",domain) = '?' OR CONCAT("web-",id,".",domain) = '?';

One questionmark was not changed, so I tried to change the code. But while running the updated mod, I got the errors mentioned above, so I opened this feature-request.

So one webspace should be accessible by two names:
web-2015.example.tld OR www.example.tld should give the content of /webs/2015/
web-2016.example.tld OR www2.example.tld should give the content of /webs/2016/

Actions #4

Updated by lonnyk over 13 years ago

Attached is a diff for this feature against the version in 1.4.26

Let me know what you think.

Actions #5

Updated by phpmysqlfreak over 13 years ago

I applied the patch with following summary:
The query is set to right format. All occurences of "?" are replaced.

Now the server is listening on both applied addresses and my aim was reached fully.
Thank you for your help.

I will follow the function with much care and report bugs, if I find any.

Actions #7

Updated by tronox@hotmail.com over 10 years ago

Attached is the source code and a compiles .so file for the mod_mysql_vhost. This one allows for multiple '?' in the SQL query. And if I knew more about c I could even get it to escape the URI just to be safe (left the code in there that I was working on).

Actions #8

Updated by stbuehler over 10 years ago

  • File deleted (mod_mysql_vhost.so)
Actions #9

Updated by tronox@hotmail.com over 10 years ago

Further Edited the mod_mysql_vhost.c to allow for user directories to be listed through mysql.
SQL Table & Sample Data:

CREATE TABLE IF NOT EXISTS `vhosts` (
  `Uid` int(10) unsigned NOT NULL,
  `vhost` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
  `rootdir` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
  `admin` varchar(255) COLLATE utf8_bin DEFAULT '',
  `extra_php_config` text COLLATE utf8_bin,
  UNIQUE KEY `vhostname` (`vhost`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='vhosts';

INSERT INTO `vhosts` (`Uid`, `vhost`, `rootdir`, `admin`, `extra_php_config`) VALUES
    (5000, 'example.com', '/var/www/vhosts/example.com/subdomains/test', 'admin@example.com', ''),
    (5000, '~shinrai', '/var/www/vhosts/example.com/subdomains/test', 'admin@example.com', '');

http://localhost/~shinrai/ or http://example.com/ Will serve up the directory '/var/www/vhosts/example.com/subdomains/test'

Actions #10

Updated by tronox@hotmail.com over 10 years ago

Forgot to give the sample SQL for the config:

SELECT rootdir FROM (SELECT IF((SELECT rootdir FROM vhosts WHERE vhost='~@@') IS NOT NULL,(SELECT rootdir FROM vhosts WHERE vhost='~@@'),IF((SELECT rootdir FROM vhosts WHERE vhost='?') IS NOT NULL,(SELECT rootdir FROM vhosts WHERE vhost='?'),(SELECT rootdir FROM vhosts WHERE '?' like vhost))) as rootdir) as a WHERE rootdir IS NOT NULL

Actions #11

Updated by gstrauss over 7 years ago

  • Target version changed from 1.4.x to 1.4.42
  • % Done changed from 10 to 0

PSA: anyone using tronox (shinrai) patches above, the patches have serious memory leaks upon every request to URI beginning "/~username"

I re-implemented much simplified support for replacing multiple '?' with escaped URI authority in the MySQL query string.

However, the userdir feature (part of some of the contributed patches above) is not included. If it is desirable to add mod_userdir features into mod_mysql_vhost, giving the option to replace use of mod_userdir with mod_mysql_vhost queries, then there should be a new directive in mod_mysql_vhost to enable this feature (and the memory leaks in the contributed patches must be removed).

Actions #12

Updated by gstrauss over 7 years ago

  • Status changed from Patch Pending to Fixed
  • % Done changed from 0 to 100
Actions

Also available in: Atom