Skip to content

Commit 200a3f1

Browse files
authored
chan_dahdi: Fix broken hidecallerid setting. (asterisk#101)
The hidecallerid setting in chan_dahdi.conf currently is broken for a couple reasons. First, the actual code in sig_analog to "allow" or "block" Caller ID depending on this setting improperly used ast_set_callerid instead of updating the presentation. This issue was mostly fixed in ASTERISK_29991, and that fix is carried forward to this code as well. Secondly, the hidecallerid setting is set on the DAHDI pvt but not carried forward to the analog pvt properly. This is because the chan_dahdi config loading code improperly set permhidecallerid to permhidecallerid from the config file, even though hidecallerid is what is actually set from the config file. (This is done correctly for call waiting, a few lines above.) This is fixed to read the proper value. Thirdly, in sig_analog, hidecallerid is set to permhidecallerid only on hangup. This can lead to potential security vulnerabilities as an allowed Caller ID from an initial call can "leak" into subsequent calls if no hangup occurs between them. This is fixed by setting hidecallerid to permcallerid when calls begin, rather than when they end. This also means we don't need to also set hidecallerid in chan_dahdi.c when copying from the config, as we would have to otherwise. Fourthly, sig_analog currently only allows dialing *67 or *82 if that would actually toggle the presentation. A comment is added clarifying that this behavior is okay. Finally, a couple log messages are updated to be more accurate. Resolves: asterisk#100 ASTERISK-30349 #close
1 parent 869cb0c commit 200a3f1

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

channels/chan_dahdi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13178,7 +13178,8 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf,
1317813178
analog_p->canpark = conf->chan.canpark;
1317913179
analog_p->dahditrcallerid = conf->chan.dahditrcallerid;
1318013180
analog_p->immediate = conf->chan.immediate;
13181-
analog_p->permhidecallerid = conf->chan.permhidecallerid;
13181+
analog_p->permhidecallerid = conf->chan.hidecallerid; /* hidecallerid is the config setting, not permhidecallerid (~permcallwaiting above) */
13182+
/* It's not necessary to set analog_p->hidecallerid here, sig_analog will set hidecallerid=permhidecaller before each call */
1318213183
analog_p->pulse = conf->chan.pulse;
1318313184
analog_p->threewaycalling = conf->chan.threewaycalling;
1318413185
analog_p->transfer = conf->chan.transfer;

channels/sig_analog.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,8 @@ int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
14511451
ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
14521452
p->callwaitcas = 0;
14531453
analog_set_callwaiting(p, p->permcallwaiting);
1454+
/* In theory, the below is not necessary since we set hidecallerid = permhidecaller when calls start,
1455+
* but this ensures the setting is defaulted properly when channels are idle, too. */
14541456
p->hidecallerid = p->permhidecallerid;
14551457
analog_set_dialing(p, 0);
14561458
analog_update_conf(p);
@@ -2133,6 +2135,19 @@ static void *__analog_ss_thread(void *data)
21332135
case ANALOG_SIG_FXOLS:
21342136
case ANALOG_SIG_FXOGS:
21352137
case ANALOG_SIG_FXOKS:
2138+
/* Set our default presentation.
2139+
* This is necessary because the presentation for each call is independent
2140+
* (though the default may be the same).
2141+
* For example, if hidecallerid=yes and somebody makes a call with *82,
2142+
* then makes a 3-way call, the presentation for the 2nd call should still
2143+
* be blocked, unless that also had a *82.
2144+
* For this reason, setting hidecallerid = permhidecallerid on hangup
2145+
* is NOT sufficient, as the *82 from the first call could "leak" into
2146+
* subsequent ones made before a hangup, improperly leaking a number
2147+
* that should have been hidden.
2148+
*/
2149+
p->hidecallerid = p->permhidecallerid;
2150+
21362151
/* Read the first digit */
21372152
timeout = analog_get_firstdigit_timeout(p);
21382153
/* If starting a threeway call, never timeout on the first digit so someone
@@ -2190,18 +2205,18 @@ static void *__analog_ss_thread(void *data)
21902205
res = analog_play_tone(p, idx, -1);
21912206
ast_channel_lock(chan);
21922207
ast_channel_exten_set(chan, exten);
2193-
if (!ast_strlen_zero(p->cid_num)) {
2194-
if (!p->hidecallerid) {
2195-
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2196-
} else {
2197-
ast_set_callerid(chan, NULL, NULL, p->cid_num);
2198-
}
2199-
}
2200-
if (!ast_strlen_zero(p->cid_name)) {
2201-
if (!p->hidecallerid) {
2202-
ast_set_callerid(chan, NULL, p->cid_name, NULL);
2203-
}
2208+
2209+
/* Properly set the presentation.
2210+
* We need to do this here as well, because p->hidecallerid might be set
2211+
* due to permanent blocking, not star-67/star-82 usage. */
2212+
if (p->hidecallerid) {
2213+
ast_channel_caller(chan)->id.number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
2214+
ast_channel_caller(chan)->id.name.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
2215+
} else {
2216+
ast_channel_caller(chan)->id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
2217+
ast_channel_caller(chan)->id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
22042218
}
2219+
22052220
ast_setstate(chan, AST_STATE_RING);
22062221
ast_channel_unlock(chan);
22072222
analog_set_echocanceller(p, 1);
@@ -2263,9 +2278,11 @@ static void *__analog_ss_thread(void *data)
22632278
ast_hangup(chan);
22642279
goto quit;
22652280
}
2266-
2281+
/* While the DMS-100 allows dialing as many *67s and *82s in succession as one's heart may desire,
2282+
* the 5ESS does not, it only allows pure toggling (and only once!). So, it's not incorrect
2283+
* to prevent people from dialing *67 if that won't actually do anything. */
22672284
} else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2268-
ast_verb(3, "Disabling Caller*ID on %s\n", ast_channel_name(chan));
2285+
ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan));
22692286
/* Disable Caller*ID if enabled */
22702287
p->hidecallerid = 1;
22712288
ast_channel_caller(chan)->id.number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
@@ -2352,7 +2369,7 @@ static void *__analog_ss_thread(void *data)
23522369
len = 0;
23532370
}
23542371
} else if (p->hidecallerid && !strcmp(exten, "*82")) {
2355-
ast_verb(3, "Enabling Caller*ID on %s\n", ast_channel_name(chan));
2372+
ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan));
23562373
/* Enable Caller*ID if enabled */
23572374
p->hidecallerid = 0;
23582375
ast_channel_caller(chan)->id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;

0 commit comments

Comments
 (0)