Skip to content

Commit b7d7cb6

Browse files
authored
Merge pull request #331 from jajik/issue-329
Fix handling of duplicite MCMP command parameters
2 parents 21ba117 + c86eda6 commit b7d7cb6

3 files changed

Lines changed: 164 additions & 73 deletions

File tree

native/mod_manager/mod_manager.c

Lines changed: 54 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,6 @@ static const struct domain_storage_method domain_storage = {
484484
};
485485
/* clang-format on */
486486

487-
/* helper for the handling of the Alias: host1,... Context: context1,... */
488-
struct cluster_host
489-
{
490-
char *host;
491-
char *context;
492-
struct cluster_host *next;
493-
};
494-
495487
/*
496488
* cleanup logic
497489
*/
@@ -1261,13 +1253,13 @@ static int check_context_alias_length(const char *str, int limit)
12611253
* 2) during APP command
12621254
* to differenciate between the two use the last argument (true -> CONFIG, false -> APP)
12631255
*/
1264-
static char *process_context_alias(char *key, char *val, apr_pool_t *p, struct cluster_host *phost, int *errtype,
1256+
static char *process_context_alias(char *key, char *val, apr_pool_t *p, char **contexts, char **aliases, int *errtype,
12651257
int in_config)
12661258
{
12671259
if (strcasecmp(key, "Alias") == 0) {
12681260
char *tmp;
12691261

1270-
if (phost->host && !in_config) {
1262+
if (*aliases && !in_config) {
12711263
*errtype = TYPESYNTAX;
12721264
return in_config ? SALIBAD : SMULALB;
12731265
}
@@ -1276,31 +1268,35 @@ static char *process_context_alias(char *key, char *val, apr_pool_t *p, struct c
12761268
return SALIBIG;
12771269
}
12781270

1279-
if (phost->host) {
1280-
phost->next = apr_palloc(p, sizeof(struct cluster_host));
1281-
phost = phost->next;
1282-
phost->next = NULL;
1283-
phost->context = NULL;
1284-
}
12851271
/* Aliases to lower case for further case-insensitive treatment, IETF RFC 1035 Section 2.3.3. */
12861272
tmp = val;
12871273
while (*tmp) {
12881274
*tmp = apr_tolower(*tmp);
12891275
tmp++;
12901276
}
1291-
phost->host = val;
1277+
1278+
if (*aliases) {
1279+
*aliases = apr_pstrcat(p, *aliases, ",", val, NULL);
1280+
} else {
1281+
*aliases = val;
1282+
}
12921283
}
12931284

12941285
if (strcasecmp(key, "Context") == 0) {
1295-
if (phost->context && !in_config) {
1286+
if (*contexts && !in_config) {
12961287
*errtype = TYPESYNTAX;
12971288
return SMULCTB;
12981289
}
12991290
if (check_context_alias_length(val, CONTEXTSZ)) {
13001291
*errtype = TYPESYNTAX;
13011292
return SCONBIG;
13021293
}
1303-
phost->context = val;
1294+
1295+
if (*contexts) {
1296+
*contexts = apr_pstrcat(p, *contexts, ",", val, NULL);
1297+
} else {
1298+
*contexts = val;
1299+
}
13041300
}
13051301

13061302
return NULL;
@@ -1332,8 +1328,8 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13321328
nodeinfo_t *node;
13331329
balancerinfo_t balancerinfo;
13341330

1335-
struct cluster_host *vhost;
1336-
struct cluster_host *phost;
1331+
char *contexts = NULL;
1332+
char *aliases = NULL;
13371333

13381334
int i = 0;
13391335
int id = -1;
@@ -1346,14 +1342,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13461342
const proxy_server_conf *the_conf = NULL;
13471343
apr_status_t rv;
13481344

1349-
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
1350-
1351-
/* Map nothing by default */
1352-
vhost->host = NULL;
1353-
vhost->context = NULL;
1354-
vhost->next = NULL;
1355-
phost = vhost;
1356-
13571345
/* Fill default node values */
13581346
process_config_node_defaults(r, &nodeinfo, mconf);
13591347
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_config: Start");
@@ -1363,7 +1351,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13631351

13641352
while (ptr[i]) {
13651353
char *err_msg = NULL;
1366-
if (ptr[i + 1] && *ptr[i + 1] == '\0') {
1354+
if (!ptr[i + 1] || *ptr[i + 1] == '\0') {
13671355
*errtype = TYPESYNTAX;
13681356
return SMESPAR;
13691357
}
@@ -1379,7 +1367,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13791367
return err_msg;
13801368
}
13811369
/* Optional parameters */
1382-
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, phost, errtype, 1);
1370+
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, &contexts, &aliases, errtype, 1);
13831371
if (err_msg != NULL) {
13841372
return err_msg;
13851373
}
@@ -1570,8 +1558,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
15701558
inc_version_node();
15711559

15721560
/* Insert the Alias and corresponding Context */
1573-
phost = vhost;
1574-
if (phost->host == NULL && phost->context == NULL) {
1561+
if (aliases == NULL && contexts == NULL) {
15751562
/* if using mod_balancer create or update the worker */
15761563
if (balancer_manage) {
15771564
apr_status_t rv = mod_manager_manage_worker(r, &nodeinfo, &balancerinfo);
@@ -1582,19 +1569,20 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
15821569
loc_unlock_nodes();
15831570
return NULL; /* Alias and Context missing */
15841571
}
1585-
while (phost) {
1586-
if (insert_update_hosts(r->server, hoststatsmem, phost->host, id, vid) != APR_SUCCESS) {
1587-
loc_unlock_nodes();
1588-
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
1589-
}
1590-
if (insert_update_contexts(r->server, contextstatsmem, phost->context, id, vid, STOPPED) != APR_SUCCESS) {
1591-
loc_unlock_nodes();
1592-
return apr_psprintf(r->pool, MCONTUI, nodeinfo.mess.JVMRoute);
1593-
}
1594-
phost = phost->next;
1595-
vid++;
1572+
1573+
1574+
if (insert_update_hosts(r->server, hoststatsmem, aliases, id, vid) != APR_SUCCESS) {
1575+
loc_unlock_nodes();
1576+
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
1577+
}
1578+
1579+
if (insert_update_contexts(r->server, contextstatsmem, contexts, id, vid, STOPPED) != APR_SUCCESS) {
1580+
loc_unlock_nodes();
1581+
return apr_psprintf(r->pool, MCONTUI, nodeinfo.mess.JVMRoute);
15961582
}
15971583

1584+
vid++;
1585+
15981586
/* if using mod_balancer create or update the worker */
15991587
if (balancer_manage) {
16001588
apr_status_t rv = mod_manager_manage_worker(r, &nodeinfo, &balancerinfo);
@@ -2088,19 +2076,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
20882076
{
20892077
nodeinfo_t nodeinfo;
20902078
nodeinfo_t *node;
2091-
struct cluster_host *vhost;
2079+
2080+
char *contexts = NULL;
2081+
char *aliases = NULL;
20922082

20932083
int i = 0;
20942084
hostinfo_t hostinfo;
20952085
hostinfo_t *host = NULL;
20962086
char *err_msg;
20972087

20982088
memset(&nodeinfo.mess, '\0', sizeof(nodeinfo.mess));
2099-
/* Map nothing by default */
2100-
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
2101-
vhost->host = NULL;
2102-
vhost->context = NULL;
2103-
vhost->next = NULL;
21042089

21052090
while (ptr[i]) {
21062091
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
@@ -2111,7 +2096,7 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21112096
strcpy(nodeinfo.mess.JVMRoute, ptr[i + 1]);
21122097
nodeinfo.mess.id = -1;
21132098
}
2114-
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, vhost, errtype, 0);
2099+
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, &contexts, &aliases, errtype, 0);
21152100
if (err_msg) {
21162101
return err_msg;
21172102
}
@@ -2126,16 +2111,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21262111
}
21272112

21282113
/* Note: This applies only for non-wildcarded requests for which Alias and Context are required */
2129-
if (vhost->context == NULL && vhost->host == NULL && strcmp(r->uri, "/*") != 0) {
2114+
if (contexts == NULL && aliases == NULL && strcmp(r->uri, "/*") != 0) {
21302115
*errtype = TYPESYNTAX;
21312116
return NOCONAL;
21322117
}
21332118

2134-
if (vhost->context == NULL && vhost->host != NULL) {
2119+
if (contexts == NULL && aliases != NULL) {
21352120
*errtype = TYPESYNTAX;
21362121
return SALIBAD;
21372122
}
2138-
if (vhost->host == NULL && vhost->context != NULL) {
2123+
if (aliases == NULL && contexts != NULL) {
21392124
*errtype = TYPESYNTAX;
21402125
return SCONBAD;
21412126
}
@@ -2178,15 +2163,15 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21782163
*/
21792164
hostinfo.node = node->mess.id;
21802165
hostinfo.id = 0;
2181-
if (vhost->host != NULL) {
2166+
if (aliases != NULL) {
21822167
int start = 0;
21832168
i = 0;
2184-
while (host == NULL && (unsigned)(i + start) < strlen(vhost->host)) {
2185-
while (vhost->host[start + i] != ',' && vhost->host[start + i] != '\0') {
2169+
while (host == NULL && (unsigned)(i + start) < strlen(aliases)) {
2170+
while (aliases[start + i] != ',' && aliases[start + i] != '\0') {
21862171
i++;
21872172
}
21882173

2189-
strncpy(hostinfo.host, vhost->host + start, i);
2174+
strncpy(hostinfo.host, aliases + start, i);
21902175
hostinfo.host[i] = '\0';
21912176
host = read_host(hoststatsmem, &hostinfo);
21922177
start = start + i + 1;
@@ -2223,16 +2208,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22232208
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_appl_cmd: adding vhost: %d node: %d route: %s",
22242209
vid, node->mess.id, nodeinfo.mess.JVMRoute);
22252210
/* If the Host doesn't exist yet create it */
2226-
if (insert_update_hosts(r->server, hoststatsmem, vhost->host, node->mess.id, vid) != APR_SUCCESS) {
2211+
if (insert_update_hosts(r->server, hoststatsmem, aliases, node->mess.id, vid) != APR_SUCCESS) {
22272212
loc_unlock_nodes();
22282213
*errtype = TYPEMEM;
22292214
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
22302215
}
22312216
hostinfo.id = 0;
22322217
hostinfo.node = node->mess.id;
22332218
hostinfo.host[0] = '\0';
2234-
if (vhost->host != NULL) {
2235-
strncpy(hostinfo.host, vhost->host, sizeof(hostinfo.host));
2219+
if (aliases != NULL) {
2220+
strncpy(hostinfo.host, aliases, sizeof(hostinfo.host));
22362221
hostinfo.host[sizeof(hostinfo.host) - 1] = '\0';
22372222
}
22382223

@@ -2254,7 +2239,7 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22542239
if (get_context(contextstatsmem, &ou, id[i]) != APR_SUCCESS) {
22552240
continue;
22562241
}
2257-
if (strcmp(ou->context, vhost->context) == 0) {
2242+
if (strcmp(ou->context, contexts) == 0) {
22582243
/* There is the same context somewhere else */
22592244
nodeinfo_t *hisnode;
22602245
if (get_node(nodestatsmem, &hisnode, ou->node) != APR_SUCCESS) {
@@ -2263,22 +2248,22 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22632248
if (strcmp(hisnode->mess.balancer, node->mess.balancer)) {
22642249
/* the same context would be on 2 different balancer */
22652250
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
2266-
"process_appl_cmd: ENABLE: context %s is in balancer %s and %s", vhost->context,
2251+
"process_appl_cmd: ENABLE: context %s is in balancer %s and %s", contexts,
22672252
node->mess.balancer, hisnode->mess.balancer);
22682253
}
22692254
}
22702255
}
22712256
}
22722257

22732258
/* Now update each context from Context: part */
2274-
if (insert_update_contexts(r->server, contextstatsmem, vhost->context, node->mess.id, host->vhost, status) !=
2259+
if (insert_update_contexts(r->server, contextstatsmem, contexts, node->mess.id, host->vhost, status) !=
22752260
APR_SUCCESS) {
22762261
loc_unlock_nodes();
22772262
*errtype = TYPEMEM;
22782263
return apr_psprintf(r->pool, MCONTUI, node->mess.JVMRoute);
22792264
}
22802265

2281-
if (insert_update_hosts(r->server, hoststatsmem, vhost->host, node->mess.id, host->vhost) != APR_SUCCESS) {
2266+
if (insert_update_hosts(r->server, hoststatsmem, aliases, node->mess.id, host->vhost) != APR_SUCCESS) {
22822267
loc_unlock_nodes();
22832268
*errtype = TYPEMEM;
22842269
return apr_psprintf(r->pool, MHOSTUI, node->mess.JVMRoute);
@@ -2314,11 +2299,11 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
23142299
}
23152300
}
23162301
} else if (status == STOPPED) {
2317-
/* insert_update_contexts in fact makes that vhost->context corresponds only to the first context... */
2302+
/* insert_update_contexts in fact makes that contexts corresponds only to the first context... */
23182303
contextinfo_t in;
23192304
contextinfo_t *ou;
23202305
in.id = 0;
2321-
strncpy(in.context, vhost->context, CONTEXTSZ);
2306+
strncpy(in.context, contexts, CONTEXTSZ);
23222307
in.context[CONTEXTSZ] = '\0';
23232308
in.vhost = host->vhost;
23242309
in.node = node->mess.id;
@@ -2329,8 +2314,8 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
23292314
if (fromnode) {
23302315
ap_set_content_type(r, PLAINTEXT_CONTENT_TYPE);
23312316
ap_rprintf(r, "Type=STOP-APP-RSP&JvmRoute=%.*s&Alias=%.*s&Context=%.*s&Requests=%d",
2332-
(int)sizeof(nodeinfo.mess.JVMRoute), nodeinfo.mess.JVMRoute, (int)sizeof(vhost->host),
2333-
vhost->host, (int)sizeof(vhost->context), vhost->context, ou->nbrequests);
2317+
(int)sizeof(nodeinfo.mess.JVMRoute), nodeinfo.mess.JVMRoute, (int)sizeof(aliases), aliases,
2318+
(int)sizeof(contexts), contexts, ou->nbrequests);
23342319
ap_rprintf(r, "\n");
23352320
}
23362321
} else {

0 commit comments

Comments
 (0)