Skip to content

Commit e421a4d

Browse files
committed
opendkim.c: Use dkim_table_canonicalizations and dkim_table_algorithms in
libopendkim instead of dkimf_canon and dkimf_sign.
1 parent 2471d3e commit e421a4d

File tree

1 file changed

+60
-33
lines changed

1 file changed

+60
-33
lines changed

opendkim/opendkim.c

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,6 @@ struct lookup dkimf_values[] =
622622
{ NULL, -1 },
623623
};
624624

625-
struct lookup dkimf_canon[] =
626-
{
627-
{ "relaxed", DKIM_CANON_RELAXED },
628-
{ "simple", DKIM_CANON_SIMPLE },
629-
{ NULL, -1 },
630-
};
631-
632-
struct lookup dkimf_sign[] =
633-
{
634-
{ "rsa-sha1", DKIM_SIGN_RSASHA1 },
635-
{ "rsa-sha256", DKIM_SIGN_RSASHA256 },
636-
{ "ed25519-sha256", DKIM_SIGN_ED25519SHA256 },
637-
{ NULL, -1 },
638-
};
639-
640625
struct lookup dkimf_atpshash[] =
641626
{
642627
#ifdef HAVE_SHA256
@@ -7697,8 +7682,8 @@ dkimf_config_load(struct config *data, struct dkimf_config *conf,
76977682

76987683
if (conf->conf_signalgstr != NULL)
76997684
{
7700-
conf->conf_signalg = dkimf_lookup_strtoint(conf->conf_signalgstr,
7701-
dkimf_sign);
7685+
conf->conf_signalg = dkim_name_to_code(dkim_table_algorithms,
7686+
conf->conf_signalgstr);
77027687
if (conf->conf_signalg == -1)
77037688
{
77047689
snprintf(err, errlen,
@@ -7719,8 +7704,8 @@ dkimf_config_load(struct config *data, struct dkimf_config *conf,
77197704
p = strchr(conf->conf_canonstr, '/');
77207705
if (p == NULL)
77217706
{
7722-
conf->conf_hdrcanon = dkimf_lookup_strtoint(conf->conf_canonstr,
7723-
dkimf_canon);
7707+
conf->conf_hdrcanon = dkim_name_to_code(dkim_table_canonicalizations,
7708+
conf->conf_canonstr);
77247709
if (conf->conf_hdrcanon == -1)
77257710
{
77267711
snprintf(err, errlen,
@@ -7735,8 +7720,8 @@ dkimf_config_load(struct config *data, struct dkimf_config *conf,
77357720
{
77367721
*p = '\0';
77377722

7738-
conf->conf_hdrcanon = dkimf_lookup_strtoint(conf->conf_canonstr,
7739-
dkimf_canon);
7723+
conf->conf_hdrcanon = dkim_name_to_code(dkim_table_canonicalizations,
7724+
conf->conf_canonstr);
77407725
if (conf->conf_hdrcanon == -1)
77417726
{
77427727
snprintf(err, errlen,
@@ -7745,8 +7730,8 @@ dkimf_config_load(struct config *data, struct dkimf_config *conf,
77457730
return -1;
77467731
}
77477732

7748-
conf->conf_bodycanon = dkimf_lookup_strtoint(p + 1,
7749-
dkimf_canon);
7733+
conf->conf_bodycanon = dkim_name_to_code(dkim_table_canonicalizations,
7734+
p + 1);
77507735
if (conf->conf_bodycanon == -1)
77517736
{
77527737
snprintf(err, errlen,
@@ -11718,18 +11703,18 @@ mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
1171811703
{
1171911704
*slash = '\0';
1172011705

11721-
c = dkimf_lookup_strtoint(headerv, dkimf_canon);
11706+
c = dkim_name_to_code(dkim_table_canonicalizations, headerv);
1172211707
if (c != -1)
1172311708
dfc->mctx_hdrcanon = (dkim_canon_t) c;
11724-
c = dkimf_lookup_strtoint(slash + 1, dkimf_canon);
11709+
c = dkim_name_to_code(dkim_table_canonicalizations, slash + 1);
1172511710
if (c != -1)
1172611711
dfc->mctx_bodycanon = (dkim_canon_t) c;
1172711712

1172811713
*slash = '/';
1172911714
}
1173011715
else
1173111716
{
11732-
c = dkimf_lookup_strtoint(headerv, dkimf_canon);
11717+
c = dkim_name_to_code(dkim_table_canonicalizations, headerv);
1173311718
if (c != -1)
1173411719
dfc->mctx_hdrcanon = (dkim_canon_t) c;
1173511720
}
@@ -15544,6 +15529,10 @@ main(int argc, char **argv)
1554415529
char *end;
1554515530
char argstr[MAXARGV];
1554615531
char err[BUFRSZ + 1];
15532+
DKIM_STAT dkim_stat;
15533+
DKIM_ITER_CTX *iter_ctx;
15534+
int entry_code;
15535+
char *entry_name;
1554715536

1554815537
/* initialize */
1554915538
reload = FALSE;
@@ -15771,17 +15760,55 @@ main(int argc, char **argv)
1577115760
printf("\tlibmilter version %d.%d.%d\n",
1577215761
mvmajor, mvminor, mvrelease);
1577315762
#endif /* HAVE_SMFI_VERSION */
15763+
dkim_stat = dkim_nametable_first(dkim_table_algorithms,
15764+
&iter_ctx, &entry_name,
15765+
&entry_code);
1577415766
printf("\tSupported signing algorithms:\n");
15775-
for (c = 0; dkimf_sign[c].str != NULL; c++)
15767+
if (dkim_stat == DKIM_STAT_NORESOURCE)
15768+
{
15769+
printf("\twarn: list of algorithms is not "
15770+
"available\n");
15771+
}
15772+
else
1577615773
{
15777-
if (dkimf_sign[c].code != DKIM_SIGN_RSASHA256 ||
15778-
dkim_libfeature(curconf->conf_libopendkim,
15779-
DKIM_FEATURE_SHA256))
15780-
printf("\t\t%s\n", dkimf_sign[c].str);
15774+
while(dkim_stat == DKIM_STAT_OK)
15775+
{
15776+
if (entry_code != DKIM_SIGN_RSASHA256 ||
15777+
dkim_libfeature(curconf->conf_libopendkim,
15778+
DKIM_FEATURE_SHA256))
15779+
{
15780+
printf("\t\t%s\n", entry_name);
15781+
}
15782+
dkim_stat = dkim_nametable_next(iter_ctx,
15783+
&entry_name,
15784+
&entry_code);
15785+
}
15786+
dkim_stat = dkim_iter_ctx_free(iter_ctx);
15787+
/* we can do nothing eveif dkim_stat is not
15788+
DKIM_STAT_OK ... */
1578115789
}
1578215790
printf("\tSupported canonicalization algorithms:\n");
15783-
for (c = 0; dkimf_canon[c].str != NULL; c++)
15784-
printf("\t\t%s\n", dkimf_canon[c].str);
15791+
dkim_stat = dkim_nametable_first(dkim_table_canonicalizations,
15792+
&iter_ctx, &entry_name,
15793+
&entry_code);
15794+
if (dkim_stat == DKIM_STAT_NORESOURCE)
15795+
{
15796+
printf("\twarn: list of canonicalizations "
15797+
"is not available\n");
15798+
}
15799+
else
15800+
{
15801+
while(dkim_stat == DKIM_STAT_OK)
15802+
{
15803+
printf("\t\t%s\n", entry_name);
15804+
dkim_stat = dkim_nametable_next(iter_ctx,
15805+
&entry_name,
15806+
&entry_code);
15807+
}
15808+
dkim_stat = dkim_iter_ctx_free(iter_ctx);
15809+
/* we can do nothing eveif dkim_stat is not
15810+
DKIM_STAT_OK ... */
15811+
}
1578515812
dkimf_optlist(stdout);
1578615813
return EX_OK;
1578715814

0 commit comments

Comments
 (0)