chiark / gitweb /
privcache: uncached_get: Introduce `databuf' local
[secnet.git] / privcache.c
index 790281df61fa4e48608fceb7f9335f135a7116db..f95ee37a6600e0d2b280dc614652b7c31300ad93 100644 (file)
@@ -45,29 +45,33 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
 
     sprintf(st->path.write_here, SIGKEYID_PR_FMT, SIGKEYID_PR_VAL(id));
 
-    f = fopen(st->path.buffer,"rb");
+    const char *path=st->path.buffer;
+    struct hash_if *defhash=st->defhash;
+    struct buffer_if *databuf=&st->databuf;
+
+    f = fopen(path,"rb");
     if (!f) {
        if (errno == ENOENT) {
            slilog(log,M_DEBUG,"private key %s not found",
-                  st->path.buffer);
+                  path);
        } else {
            slilog(log,M_ERR,"failed to open private key file %s",
-                  st->path.buffer);
+                  path);
        }
        goto out;
     }
 
     setbuf(f,0);
-    buffer_init(&st->databuf,0);
-    ssize_t got=fread(st->databuf.base,1,st->databuf.alloclen,f);
+    buffer_init(databuf,0);
+    ssize_t got=fread(databuf->base,1,databuf->alloclen,f);
     if (ferror(f)) {
        slilog(log,M_ERR,"failed to read private-key file %s",
-              st->path.buffer);
+              path);
        goto out;
     }
     if (!feof(f)) {
        slilog(log,M_ERR,"private key file %s longer than max %d",
-              st->path.buffer, (int)st->databuf.alloclen);
+              path, (int)databuf->alloclen);
        goto out;
     }
     fclose(f); f=0;
@@ -81,26 +85,26 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
            goto found;
 
     slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
-          st->path.buffer);
+          path);
     goto out;
 
  found:
-    st->databuf.start=st->databuf.base;
-    st->databuf.size=got;
-    struct cloc loc = { .file=st->path.buffer, .line=0 };
-    ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc);
+    databuf->start=databuf->base;
+    databuf->size=got;
+    struct cloc loc = { .file=path, .line=0 };
+    ok=scheme->loadpriv(scheme, databuf, &sigpriv, log, loc);
     if (!ok) goto out; /* loadpriv will have logged */
 
     if (sigpriv->sethash) {
-       if (!st->defhash) {
+       if (!defhash) {
            slilog(log,M_ERR,
  "private key %s requires `hash' config key for privcache to load",
-                  st->path.buffer);
+                  path);
            sigpriv->dispose(sigpriv->st);
            sigpriv=0;
            goto out;
        }
-       sigpriv->sethash(sigpriv->st,st->defhash);
+       sigpriv->sethash(sigpriv->st,defhash);
     }
 
   out: