chiark / gitweb /
changelog: start 0.6.8
[secnet.git] / pubkeys.fl.pl
index da22a251e45a6e3427c0195a67546455e5afc7e2..da1e4d40ce396e255ff685c181710b531c23f8b8 100755 (executable)
@@ -73,10 +73,15 @@ sub inst ($) {
 
 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;
-       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}";
@@ -104,7 +109,7 @@ while (<DATA>) {
     if (m/^!FINAL \{\s*$/) {
        die unless $kw;
        die if @next_kw;
-       $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->lno++; }\n";
+       $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->loc.line++; }\n";
        $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
+%x SYNTAXERR
 
 %option yylineno
 %option noyywrap
@@ -153,12 +159,12 @@ BASE91S   []-~!#-&(-[]+
 
 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;
-    int lno;
     bool_t fallback_skip;
     const struct sigscheme_info *scheme;
     uint8_t grpid[GRPIDSZ];
@@ -180,11 +186,11 @@ static struct pubkeyset_context c[1];
         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{                                    \
-       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)
 
@@ -193,6 +199,7 @@ static struct pubkeyset_context c[1];
 %%
 
 !KEYWORD pkg  { c->fallback_skip=0; }
+!KWALIAS pkgf { c->fallback_skip=!!c->building->nkeys; }
 !ARG id [0-9a-f]{!2GRPIDSZ} {
     HEX2BIN_ARRAY(c->grpid);
 !}
@@ -220,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;
+    closure_t *cl;
     bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
-                                &pubkey,c->log);
+                                &pubkey,&cl,c->log,c->loc);
     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 */
-    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
@@ -251,17 +258,24 @@ static struct pubkeyset_context c[1];
     BEGIN(SKIPNL);
 }
 {L}\n {
-    c->lno++;
+    c->loc.line++;
 }
 
 <SKIPNL>.*\n {
-    c->lno++;
+    c->loc.line++;
     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"); }
 
@@ -272,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;
+    c->loc.file=path;
     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;
     }
@@ -289,16 +305,12 @@ keyset_load(const char *path, struct buffer_if *data_buf,
     c->building->refcount=1;
     c->fallback_skip=0;
     c->had_serial=0;
-    c->lno=1;
+    c->loc.line=1;
     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;