chiark
/
gitweb
/
~ian
/
secnet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
changelog: tidy up changes since 0.5.1
[secnet.git]
/
pubkeys.fl.pl
diff --git
a/pubkeys.fl.pl
b/pubkeys.fl.pl
index b89d191f51ed04eafe89a567dff9a97a94802a57..da1e4d40ce396e255ff685c181710b531c23f8b8 100755
(executable)
--- a/
pubkeys.fl.pl
+++ b/
pubkeys.fl.pl
@@
-73,10
+73,15
@@
sub inst ($) {
while (<DATA>) {
s#\{!2(\w+)\}# '{'.(2 * ($subst{$1}//die "$1 ?")).'}' #ge;
while (<DATA>) {
s#\{!2(\w+)\}# '{'.(2 * ($subst{$1}//die "$1 ?")).'}' #ge;
- if (m/^!
KEYWORD
([-0-9a-z]+)(\s*\{.*\})?$/) {
+ if (m/^!
(KEYWORD|KWALIAS)
([-0-9a-z]+)(\s*\{.*\})?$/) {
my $kwt=$2;
my $kwt=$2;
- die if $kw;
- $kw = $1;
+ if ($1 eq 'KEYWORD') {
+ die if $kw;
+ $kw = $kwt;
+ } else {
+ die if @next_kw;
+ die unless $kw;
+ }
my $xact = $3 // '';
$kwid = $kw; $kwid =~ y/-/_/;
$in_s = "HK_${kwid}";
my $xact = $3 // '';
$kwid = $kw; $kwid =~ y/-/_/;
$in_s = "HK_${kwid}";
@@
-104,7
+109,7
@@
while (<DATA>) {
if (m/^!FINAL \{\s*$/) {
die unless $kw;
die if @next_kw;
if (m/^!FINAL \{\s*$/) {
die unless $kw;
die if @next_kw;
- $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->l
no
++; }\n";
+ $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->l
oc.line
++; }\n";
$co .= inst("$in_s")."{L}/\\n {\n";
$co .= "\tBEGIN(FIN_$kwid);\n";
$co .= lineno(1,1);
$co .= inst("$in_s")."{L}/\\n {\n";
$co .= "\tBEGIN(FIN_$kwid);\n";
$co .= lineno(1,1);
@@
-129,6
+134,7
@@
L [ \t]*
S [ \t]+
BASE91S []-~!#-&(-[]+
%x SKIPNL
S [ \t]+
BASE91S []-~!#-&(-[]+
%x SKIPNL
+%x SYNTAXERR
%option yylineno
%option noyywrap
%option yylineno
%option noyywrap
@@
-153,12
+159,13
@@
BASE91S []-~!#-&(-[]+
struct pubkeyset_context {
/* filled in during setup: */
struct pubkeyset_context {
/* filled in during setup: */
+ struct cloc loc; /* line is runtime */
struct log_if *log;
struct buffer_if *data_buf;
struct peer_keyset *building;
/* runtime: */
bool_t had_serial;
struct log_if *log;
struct buffer_if *data_buf;
struct peer_keyset *building;
/* runtime: */
bool_t had_serial;
-
int lno
;
+
bool_t fallback_skip
;
const struct sigscheme_info *scheme;
uint8_t grpid[GRPIDSZ];
serialt serial;
const struct sigscheme_info *scheme;
uint8_t grpid[GRPIDSZ];
serialt serial;
@@
-179,11
+186,11
@@
static struct pubkeyset_context c[1];
break; \
})
#define DOSKIP(m) ({ \
break; \
})
#define DOSKIP(m) ({ \
- slilog(LI,M_INFO,"
l.%d: " m, c->lno);
\
+ slilog(LI,M_INFO,"
%s:%d: " m, c->loc.file, c->loc.line);
\
DOSKIPQ; \
})
#define FAIL(m) do{ \
DOSKIPQ; \
})
#define FAIL(m) do{ \
- slilog(LI,M_ERR,"
l.%d: " m, c->lno);
\
+ slilog(LI,M_ERR,"
%s:%d: " m, c->loc.file, c->loc.line);
\
return -1; \
}while(0)
return -1; \
}while(0)
@@
-191,7
+198,8
@@
static struct pubkeyset_context c[1];
%%
%%
-!KEYWORD pkg
+!KEYWORD pkg { c->fallback_skip=0; }
+!KWALIAS pkgf { c->fallback_skip=!!c->building->nkeys; }
!ARG id [0-9a-f]{!2GRPIDSZ} {
HEX2BIN_ARRAY(c->grpid);
!}
!ARG id [0-9a-f]{!2GRPIDSZ} {
HEX2BIN_ARRAY(c->grpid);
!}
@@
-199,6
+207,7
@@
static struct pubkeyset_context c[1];
!}
!KEYWORD pub
!ARG algo [-0-9a-z]+ {
!}
!KEYWORD pub
!ARG algo [-0-9a-z]+ {
+ if (c->fallback_skip) DOSKIP("fallback not needed");
c->scheme = sigscheme_lookup(yytext);
if (!c->scheme) DOSKIP("unknown pk algorithm");
!}
c->scheme = sigscheme_lookup(yytext);
if (!c->scheme) DOSKIP("unknown pk algorithm");
!}
@@
-218,16
+227,16
@@
static struct pubkeyset_context c[1];
!FINAL {
if (c->building->nkeys >= MAX_SIG_KEYS) DOSKIP("too many public keys");
struct sigpubkey_if *pubkey;
!FINAL {
if (c->building->nkeys >= MAX_SIG_KEYS) DOSKIP("too many public keys");
struct sigpubkey_if *pubkey;
+ closure_t *cl;
bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
- &pubkey,
c->log
);
+ &pubkey,
&cl,c->log,c->loc
);
if (!ok) break;
if (!ok) break;
- memcpy(c->building->keys[c->building->nkeys].id.b,
- c->grpid,
- GRPIDSZ);
+ struct peer_pubkey *fill=&c->building->keys[c->building->nkeys];
+ memcpy(fill->id.b,c->grpid,GRPIDSZ);
assert(ALGIDSZ==1); /* otherwise need htons or htonl or something */
assert(ALGIDSZ==1); /* otherwise need htons or htonl or something */
- c->building->keys[c->building->nkeys].id.b[GRPIDSZ]=
-
c->scheme->algid
;
- c->building->
keys[c->building->nkeys++].pubkey=pubkey
;
+ fill->id.b[GRPIDSZ]=c->scheme->algid;
+
fill->pubkey=pubkey
;
+ c->building->
nkeys++
;
!}
!KEYWORD serial
!}
!KEYWORD serial
@@
-249,17
+258,24
@@
static struct pubkeyset_context c[1];
BEGIN(SKIPNL);
}
{L}\n {
BEGIN(SKIPNL);
}
{L}\n {
- c->l
no
++;
+ c->l
oc.line
++;
}
<SKIPNL>.*\n {
}
<SKIPNL>.*\n {
- c->l
no
++;
+ c->l
oc.line
++;
BEGIN(0);
}
<INITIAL><<EOF>> { return 0; }
BEGIN(0);
}
<INITIAL><<EOF>> { return 0; }
-<*>. { FAIL("syntax error"); }
+<*>. {
+ yymore();
+ BEGIN(SYNTAXERR);
+}
+<SYNTAXERR>.* {
+ slilog(LI,M_DEBUG,"pubkeys syntax error at `%s'", yytext);
+ FAIL("syntax error");
+}
<*>\n { FAIL("syntax error - unexpected newline"); }
<<EOF>> { FAIL("syntax error - unexpected eof"); }
<*>\n { FAIL("syntax error - unexpected newline"); }
<<EOF>> { FAIL("syntax error - unexpected eof"); }
@@
-270,11
+286,13
@@
keyset_load(const char *path, struct buffer_if *data_buf,
struct log_if *log, int logcl_enoent) {
assert(!c->building);
c->log=log;
struct log_if *log, int logcl_enoent) {
assert(!c->building);
c->log=log;
+ c->loc.file=path;
pkyyin = fopen(path, "r");
if (!pkyyin) {
slilog(LI,
errno==ENOENT ? logcl_enoent : M_ERR,
pkyyin = fopen(path, "r");
if (!pkyyin) {
slilog(LI,
errno==ENOENT ? logcl_enoent : M_ERR,
- "could not open keyset file %s: %s",
+ "%scould not open keyset file %s: %s",
+ logcl_enoent==M_DEBUG && errno==ENOENT ? "expectedly " : "",
path,strerror(errno));
goto err;
}
path,strerror(errno));
goto err;
}
@@
-285,17
+303,14
@@
keyset_load(const char *path, struct buffer_if *data_buf,
NEW(c->building);
c->building->nkeys=0;
c->building->refcount=1;
NEW(c->building);
c->building->nkeys=0;
c->building->refcount=1;
+ c->fallback_skip=0;
c->had_serial=0;
c->had_serial=0;
- c->l
no
=1;
+ c->l
oc.line
=1;
FILLZERO(c->grpid);
FILLZERO(c->serial);
int r=pkyylex();
if (r) goto err_bad;
FILLZERO(c->grpid);
FILLZERO(c->serial);
int r=pkyylex();
if (r) goto err_bad;
- if (!c->had_serial) {
- slilog(LI,M_ERR,"missing serial number in %s",path);
- goto err_bad;
- }
if (!c->building->nkeys) {
slilog(LI,M_ERR,"no useable keys in %s",path);
goto err_bad;
if (!c->building->nkeys) {
slilog(LI,M_ERR,"no useable keys in %s",path);
goto err_bad;