chiark / gitweb /
c7d0c6bc1e52c4373e710f874dc745d8b69a9eca
[tripe] / server / keymgmt.c
1 /* -*-c-*-
2  *
3  * Key loading and storing
4  *
5  * (c) 2001 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of Trivial IP Encryption (TrIPE).
11  *
12  * TrIPE is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * TrIPE is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with TrIPE; if not, write to the Free Software Foundation,
24  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 /*----- Header files ------------------------------------------------------*/
28
29 #include "tripe.h"
30
31 /*----- Global variables --------------------------------------------------*/
32
33 group *gg;
34 mp *kpriv;
35 ge *kpub;
36 algswitch algs;
37 size_t indexsz;
38
39 /*----- Static variables --------------------------------------------------*/
40
41 static key_file *kf_pub;
42 static const char *kr_priv, *kr_pub, *tag_priv;
43 static fwatch w_priv, w_pub;
44
45 /*----- Key groups --------------------------------------------------------*/
46
47 typedef struct kgops {
48   const char *ty;
49   int (*loadpriv)(key_data *, group **, mp **, dstr *, dstr *);
50   int (*loadpub)(key_data *, group **, ge **, dstr *, dstr *);
51 } kgops;
52
53 /* --- Diffie-Hellman --- */
54
55 static int kgdh_priv(key_data *kd, group **g, mp **x, dstr *t, dstr *e)
56 {
57   key_packstruct kps[DH_PRIVFETCHSZ];
58   key_packdef *kp;
59   dh_priv dp;
60   int rc;
61
62   kp = key_fetchinit(dh_privfetch, kps, &dp);
63   if ((rc = key_unpack(kp, kd, t)) != 0) {
64     a_format(e, "unpack-failed", "%s", key_strerror(rc), A_END);
65     goto fail_0;
66   }
67   *g = group_prime(&dp.dp);
68   *x = MP_COPY(dp.x);
69   rc = 0;
70   goto done;
71 fail_0:
72   rc = -1;
73 done:
74   key_fetchdone(kp);
75   return (rc);
76 }
77
78 static int kgdh_pub(key_data *kd, group **g, ge **p, dstr *t, dstr *e)
79 {
80   key_packstruct kps[DH_PUBFETCHSZ];
81   key_packdef *kp;
82   dh_pub dp;
83   int rc;
84
85   kp = key_fetchinit(dh_pubfetch, kps, &dp);
86   if ((rc = key_unpack(kp, kd, t)) != 0) {
87     a_format(e, "unpack-failed", "%s", key_strerror(rc), A_END);
88     goto fail_0;
89   }
90   *g = group_prime(&dp.dp);
91   *p = G_CREATE(*g);
92   if (G_FROMINT(*g, *p, dp.y)) {
93     a_format(e, "bad-public-vector", A_END);
94     goto fail_1;
95   }
96   rc = 0;
97   goto done;
98 fail_1:
99   G_DESTROY(*g, *p);
100   G_DESTROYGROUP(*g);
101 fail_0:
102   rc = -1;
103 done:
104   key_fetchdone(kp);
105   return (rc);
106 }
107
108 static const kgops kgdh_ops = { "dh", kgdh_priv, kgdh_pub };
109
110 /* --- Elliptic curve --- */
111
112 static int kgec_priv(key_data *kd, group **g, mp **x, dstr *t, dstr *e)
113 {
114   key_packstruct kps[EC_PRIVFETCHSZ];
115   key_packdef *kp;
116   ec_priv ep;
117   ec_info ei;
118   const char *err;
119   int rc;
120
121   kp = key_fetchinit(ec_privfetch, kps, &ep);
122   if ((rc = key_unpack(kp, kd, t)) != 0) {
123     a_format(e, "unpack-failed", "%s", key_strerror(rc), A_END);
124     goto fail_0;
125   }
126   if ((err = ec_getinfo(&ei, ep.cstr)) != 0) {
127     a_format(e, "decode-failed", "%s", err, A_END);
128     goto fail_0;
129   }
130   *g = group_ec(&ei);
131   *x = MP_COPY(ep.x);
132   rc = 0;
133   goto done;
134 fail_0:
135   rc = -1;
136 done:
137   key_fetchdone(kp);
138   return (rc);
139 }
140
141 static int kgec_pub(key_data *kd, group **g, ge **p, dstr *t, dstr *e)
142 {
143   key_packstruct kps[EC_PUBFETCHSZ];
144   key_packdef *kp;
145   ec_pub ep;
146   ec_info ei;
147   const char *err;
148   int rc;
149
150   kp = key_fetchinit(ec_pubfetch, kps, &ep);
151   if ((rc = key_unpack(kp, kd, t)) != 0) {
152     a_format(e, "unpack-failed", "%s", key_strerror(rc), A_END);
153     goto fail_0;
154   }
155   if ((err = ec_getinfo(&ei, ep.cstr)) != 0) {
156     a_format(e, "decode-failed", "%s", err, A_END);
157     goto fail_0;
158   }
159   *g = group_ec(&ei);
160   *p = G_CREATE(*g);
161   if (G_FROMEC(*g, *p, &ep.p)) {
162     a_format(e, "bad-public-vector", A_END);
163     goto fail_1;
164   }
165   rc = 0;
166   goto done;
167 fail_1:
168   G_DESTROY(*g, *p);
169   G_DESTROYGROUP(*g);
170 fail_0:
171   rc = -1;
172 done:
173   key_fetchdone(kp);
174   return (rc);
175 }
176
177 static const kgops kgec_ops = { "ec", kgec_priv, kgec_pub };
178
179 /* --- Table of supported key types --- */
180
181 static const kgops *kgtab[] = { &kgdh_ops, &kgec_ops, 0 };
182
183 /*----- Algswitch stuff ---------------------------------------------------*/
184
185 /* --- @algs_get@ --- *
186  *
187  * Arguments:   @algswitch *a@ = where to put the algorithms
188  *              @dstr *e@ = where to write errror tokens
189  *              @key_file *kf@ = key file
190  *              @key *k@ = key to inspect
191  *
192  * Returns:     Zero if OK; nonzero on error.
193  *
194  * Use:         Extracts an algorithm choice from a key.
195  */
196
197 static int algs_get(algswitch *a, dstr *e, key_file *kf, key *k)
198 {
199   const char *p;
200   char *q, *qq;
201   dstr d = DSTR_INIT;
202   int rc = -1;
203
204   /* --- Symmetric encryption for bulk data --- */
205
206   if ((p = key_getattr(kf, k, "cipher")) == 0) p = "blowfish-cbc";
207   if ((a->c = gcipher_byname(p)) == 0) {
208     a_format(e, "unknown-cipher", "%s", p, A_END);
209     goto done;
210   }
211
212   /* --- Hash function --- */
213
214   if ((p = key_getattr(kf, k, "hash")) == 0) p = "rmd160";
215   if ((a->h = ghash_byname(p)) == 0) {
216     a_format(e, "unknown-hash", "%s", p, A_END);
217     goto done;
218   }
219
220   /* --- Symmetric encryption for key derivation --- */
221
222   if ((p = key_getattr(kf, k, "mgf")) == 0) {
223     dstr_reset(&d);
224     dstr_putf(&d, "%s-mgf", a->h->name);
225     p = d.buf;
226   }
227   if ((a->mgf = gcipher_byname(p)) == 0) {
228     a_format(e, "unknown-mgf-cipher", "%s", p, A_END);
229     goto done;
230   }
231
232   /* --- Message authentication for bulk data --- */
233
234   if ((p = key_getattr(kf, k, "mac")) != 0) {
235     dstr_reset(&d);
236     dstr_puts(&d, p);
237     if ((q = strchr(d.buf, '/')) != 0)
238       *q++ = 0;
239     if ((a->m = gmac_byname(d.buf)) == 0) {
240       a_format(e, "unknown-mac", "%s", d.buf, A_END);
241       goto done;
242     }
243     if (!q)
244       a->tagsz = a->m->hashsz;
245     else {
246       unsigned long n = strtoul(q, &qq, 0);
247       if (*qq)  {
248         a_format(e, "bad-tag-length-string", "%s", q, A_END);
249         goto done;
250       }
251       if (n%8 || n/8 > a->m->hashsz) {
252         a_format(e, "bad-tag-length", "%lu", n, A_END);
253         goto done;
254       }
255       a->tagsz = n/8;
256     }
257   } else {
258     dstr_reset(&d);
259     dstr_putf(&d, "%s-hmac", a->h->name);
260     if ((a->m = gmac_byname(d.buf)) == 0) {
261       a_format(e, "no-hmac-for-hash", "%s", a->h->name, A_END);
262       goto done;
263     }
264     a->tagsz = a->h->hashsz/2;
265   }
266
267   rc = 0;
268 done:
269   dstr_destroy(&d);
270   return (rc);
271 }
272
273 /* --- @algs_check@ --- *
274  *
275  * Arguments:   @algswitch *a@ = a choice of algorithms
276  *              @dstr *e@ = where to write error tokens
277  *              @const group *g@ = the group we're working in
278  *
279  * Returns:     Zero if OK; nonzero on error.
280  *
281  * Use:         Checks an algorithm choice for sensibleness.  This also
282  *              derives some useful information from the choices, and you
283  *              must call this before committing the algorithm selection
284  *              for use by @keyset@ functions.
285  */
286
287 static int algs_check(algswitch *a, dstr *e, const group *g)
288 {
289   /* --- Derive the key sizes --- *
290    *
291    * Must ensure that we have non-empty keys.  This isn't ideal, but it
292    * provides a handy sanity check.  Also must be based on a 64- or 128-bit
293    * block cipher or we can't do the data expiry properly.
294    */
295
296   a->hashsz = a->h->hashsz;
297   if ((a->cksz = keysz(a->hashsz, a->c->keysz)) == 0) {
298     a_format(e, "cipher", "%s", a->c->name,
299              "no-key-size", "%lu", (unsigned long)a->hashsz,
300              A_END);
301     return (-1);
302   }
303   if ((a->mksz = keysz(a->hashsz, a->m->keysz)) == 0) {
304     a_format(e, "mac", "%s", a->m->name,
305              "no-key-size", "%lu", (unsigned long)a->hashsz,
306              A_END);
307     return (-1);
308   }
309
310   /* --- Derive the data limit --- */
311
312   if (a->c->blksz < 16) a->expsz = MEG(64);
313   else a->expsz = MEG(2048);
314
315   /* --- Ensure the MGF accepts hashes as keys --- */
316
317   if (keysz(a->hashsz, a->mgf->keysz) != a->hashsz) {
318     a_format(e, "mgf", "%s", a->mgf->name,
319              "restrictive-key-schedule",
320              A_END);
321     return (-1);
322   }
323
324   /* --- All ship-shape and Bristol-fashion --- */
325
326   return (0);
327 }
328
329 /* --- @algs_samep@ --- *
330  *
331  * Arguments:   @const algswitch *a, *aa@ = two algorithm selections
332  *
333  * Returns:     Nonzero if the two selections are the same.
334  *
335  * Use:         Checks sameness of algorithm selections: used to ensure that
336  *              peers are using sensible algorithms.
337  */
338
339 static int algs_samep(const algswitch *a, const algswitch *aa)
340 {
341   return (a->c == aa->c && a->mgf == aa->mgf && a->h == aa->h &&
342           a->m == aa->m && a->tagsz == aa->tagsz);
343 }
344
345 /*----- Main code ---------------------------------------------------------*/
346
347 /* --- @keymoan@ --- *
348  *
349  * Arguments:   @const char *file@ = name of the file
350  *              @int line@ = line number in file
351  *              @const char *msg@ = error message
352  *              @void *p@ = argument pointer (indicates which keyring)
353  *
354  * Returns:     ---
355  *
356  * Use:         Reports an error message about loading a key file.
357  */
358
359 static void keymoan(const char *file, int line, const char *msg, void *p)
360 {
361   const char *kind = p;
362
363   if (!line) {
364     a_warn("KEYMGMT", "%s-keyring", kind, "%s", file,
365            "io-error", "?ERRNO", A_END);
366   } else {
367     a_warn("KEYMGMT", "%s-keyring", kind, "%s", file, "line", "%d", line,
368            "%s", msg, A_END);
369   }
370 }
371
372 /* --- @keykg@ --- *
373  *
374  * Arguments:   @key_file *kf@ = pointer to key file
375  *              @key *k@ = pointer to key
376  *              @const char **tyr@ = where to put the type string
377  *
378  * Returns:     Pointer to indicated key-group options, or null.
379  *
380  * Use:         Looks up a key's group indicator and tries to find a matching
381  *              table entry.
382  */
383
384 static const kgops *keykg(key_file *kf, key *k, const char **tyr)
385 {
386   const char *ty;
387   const kgops **ko;
388
389   /* --- Look up the key type in the table --- *
390    *
391    * There are several places to look for this.  The most obvious is the
392    * `kx-group' key attribute.  But there's also the key type itself.
393    */
394
395   ty = key_getattr(kf, k, "kx-group");
396   if (!ty && strncmp(k->type, "tripe-", 6) == 0) ty = k->type + 6;
397   if (!ty) ty = "dh";
398   if (tyr) *tyr = ty;
399
400   for (ko = kgtab; *ko; ko++) {
401     if (strcmp((*ko)->ty, ty) == 0)
402       return (*ko);
403   }
404   return (0);
405 }
406
407 /* --- @loadpriv@ --- *
408  *
409  * Arguments:   @dstr *d@ = string to write errors in
410  *
411  * Returns:     Zero if OK, nonzero on error.
412  *
413  * Use:         Loads the private key from its keyfile.
414  */
415
416 static int loadpriv(void)
417 {
418   key_file kf;
419   key *k;
420   key_data **kd;
421   dstr t = DSTR_INIT;
422   dstr e = DSTR_INIT;
423   group *g = 0;
424   mp *x = 0;
425   int rc = -1;
426   const kgops *ko;
427   const char *err, *tag, *ty;
428   algswitch a;
429
430   /* --- Open the private key file --- */
431
432   if (key_open(&kf, kr_priv, KOPEN_READ, keymoan, "private"))
433     goto done_0;
434
435   /* --- Find the private key --- */
436
437   if (tag_priv ?
438       key_qtag(&kf, tag = tag_priv, &t, &k, &kd) :
439       key_qtag(&kf, tag = "tripe", &t, &k, &kd) &&
440         key_qtag(&kf, tag = "tripe-dh", &t, &k, &kd)) {
441     a_warn("KEYMGMT", "private-keyring", "%s", kr_priv,
442            "key-not-found", "%s", tag, A_END);
443     goto done_1;
444   }
445
446   /* --- Look up the key type in the table --- */
447
448   if ((ko = keykg(&kf, k, &ty)) == 0) {
449     a_warn("KEYMGMT", "private-keyring",
450            "%s", kr_priv, "key", "%s", t.buf,
451            "unknown-group-type", "%s", ty, A_END);
452     goto done_1;
453   }
454
455   /* --- Load the key --- */
456
457   if (ko->loadpriv(*kd, &g, &x, &t, &e)) {
458     a_warn("KEYMGMT", "private-keyring",
459            "%s", kr_priv, "key", "%s", t.buf,
460            "*%s", e.buf, A_END);
461     goto done_1;
462   }
463
464   /* --- Check that the key is sensible --- */
465
466   if ((err = G_CHECK(g, &rand_global)) != 0) {
467     a_warn("KEYMGMT", "private-keyring",
468            "%s", kr_priv, "key", "%s", t.buf,
469            "bad-group", "%s", err, A_END);
470     goto done_1;
471   }
472
473   /* --- Collect the algorithms --- */
474
475   if (algs_get(&a, &e, &kf, k) ||
476       algs_check(&a, &e, g)) {
477     a_warn("KEYMGMT", "private-keyring",
478            "%s", kr_priv, "key", "%s", t.buf,
479            "*%s", e.buf, A_END);
480     goto done_1;
481   }
482
483   /* --- Good, we're happy --- *
484    *
485    * Dodginess!  We change the group over here, but don't free any old group
486    * elements.  This assumes that the new group is basically the same as the
487    * old one, and will happily adopt the existing elements.  If it isn't,
488    * then we lose badly.  Check this, then.
489    */
490
491   if (gg) {
492     if (!group_samep(g, gg)) {
493       a_warn("KEYMGMT", "private-keyring",
494              "%s", kr_priv, "key", "%s", t.buf,
495              "changed-group", A_END);
496       goto done_1;
497     }
498     G_DESTROYGROUP(gg);
499   }
500   if (kpriv)
501     mp_drop(kpriv);
502
503   if (kpub)
504     G_DESTROY(g, kpub);
505   kpub = G_CREATE(g);
506   G_EXP(g, kpub, g->g, x);
507   indexsz = mp_octets(g->r);
508
509   /* --- Dump out the group --- */
510
511   IF_TRACING(T_KEYMGMT, {
512     trace(T_KEYMGMT, "keymgmt: extracted private key `%s'", t.buf);
513     IF_TRACING(T_CRYPTO, {
514       trace(T_CRYPTO, "crypto: r = %s", mpstr(g->r));
515       trace(T_CRYPTO, "crypto: h = %s", mpstr(g->h));
516       trace(T_CRYPTO, "crypto: x = %s", mpstr(x));
517       trace(T_CRYPTO, "crypto: cipher = %s", a.c->name);
518       trace(T_CRYPTO, "crypto: mgf = %s", a.mgf->name);
519       trace(T_CRYPTO, "crypto: hash = %s", a.h->name);
520       trace(T_CRYPTO, "crypto: mac = %s/%lu",
521             a.m->name, (unsigned long)a.tagsz * 8);
522     })
523   })
524
525   /* --- Success! --- */
526
527   gg = g; g = 0;
528   algs = a;
529   kpriv = x; x = 0;
530   rc = 0;
531
532   /* --- Tidy up --- */
533
534 done_1:
535   key_close(&kf);
536 done_0:
537   dstr_destroy(&t);
538   dstr_destroy(&e);
539   if (x) mp_drop(x);
540   if (g) G_DESTROYGROUP(g);
541   return (rc);
542 }
543
544 /* --- @loadpub@ --- *
545  *
546  * Arguments:   @dstr *d@ = string to write errors to
547  *
548  * Returns:     Zero if OK, nonzero on error.
549  *
550  * Use:         Reloads the public keyring.
551  */
552
553 static int loadpub(void)
554 {
555   key_file *kf = CREATE(key_file);
556
557   if (key_open(kf, kr_pub, KOPEN_READ, keymoan, "public")) {
558     DESTROY(kf);
559     return (-1);
560   }
561   kf_pub = kf;
562   T( trace(T_KEYMGMT, "keymgmt: loaded public keyring `%s'", kr_pub); )
563   return (0);
564 }
565
566 /* --- @km_reload@ --- *
567  *
568  * Arguments:   ---
569  *
570  * Returns:     Zero if OK, nonzero to force reloading of keys.
571  *
572  * Use:         Checks the keyrings to see if they need reloading.
573  */
574
575 int km_reload(void)
576 {
577   key_file *kf;
578   int reload = 0;
579
580   /* --- Check the private key first --- */
581
582   if (fwatch_update(&w_priv, kr_priv)) {
583     T( trace(T_KEYMGMT, "keymgmt: private keyring updated: reloading..."); )
584     if (!loadpriv())
585       reload = 1;
586   }
587
588   /* --- Now check the public keys --- */
589
590   if (fwatch_update(&w_pub, kr_pub)) {
591     T( trace(T_KEYMGMT, "keymgmt: public keyring updated: reloading..."); )
592     kf = kf_pub;
593     if (!loadpub()) {
594       reload = 1;
595       key_close(kf);
596       DESTROY(kf);
597     }
598   }
599
600   /* --- Done --- */
601
602   return (reload);
603 }
604
605 /* --- @km_init@ --- *
606  *
607  * Arguments:   @const char *priv@ = private keyring file
608  *              @const char *pub@ = public keyring file
609  *              @const char *tag@ = tag to load
610  *
611  * Returns:     ---
612  *
613  * Use:         Initializes, and loads the private key.
614  */
615
616 void km_init(const char *priv, const char *pub, const char *tag)
617 {
618   const gchash *const *hh;
619
620   kr_priv = priv;
621   kr_pub = pub;
622   tag_priv = tag;
623   fwatch_init(&w_priv, kr_priv);
624   fwatch_init(&w_pub, kr_pub);
625
626   for (hh = ghashtab; *hh; hh++) {
627     if ((*hh)->hashsz > MAXHASHSZ) {
628       die(EXIT_FAILURE, "INTERNAL ERROR: %s hash length %lu > MAXHASHSZ %d",
629           (*hh)->name, (unsigned long)(*hh)->hashsz, MAXHASHSZ);
630     }
631   }
632
633   if (loadpriv() || loadpub())
634     exit(EXIT_FAILURE);
635 }
636
637 /* --- @km_getpubkey@ --- *
638  *
639  * Arguments:   @const char *tag@ = public key tag to load
640  *              @ge *kpub@ = where to put the public key
641  *              @time_t *t_exp@ = where to put the expiry time
642  *
643  * Returns:     Zero if OK, nonzero if it failed.
644  *
645  * Use:         Fetches a public key from the keyring.
646  */
647
648 int km_getpubkey(const char *tag, ge *kpub, time_t *t_exp)
649 {
650   key *k;
651   key_data **kd;
652   dstr t = DSTR_INIT;
653   dstr e = DSTR_INIT;
654   const kgops *ko;
655   const char *ty;
656   group *g = 0;
657   ge *p = 0;
658   algswitch a;
659   int rc = -1;
660
661   /* --- Find the key --- */
662
663   if (key_qtag(kf_pub, tag, &t, &k, &kd)) {
664     a_warn("KEYMGMT", "public-keyring", "%s", kr_pub,
665            "key-not-found", "%s", tag, A_END);
666     goto done;
667   }
668
669   /* --- Look up the key type in the table --- */
670
671   if ((ko = keykg(kf_pub, k, &ty)) == 0) {
672     a_warn("KEYMGMT", "public-keyring",
673            "%s", kr_pub, "key", "%s", t.buf,
674            "unknown-group-type", "%s", ty, A_END);
675     goto done;
676   }
677
678   /* --- Load the key --- */
679
680   if (ko->loadpub(*kd, &g, &p, &t, &e)) {
681     a_warn("KEYMGMT", "public-keyring",
682            "%s", kr_pub, "key", "%s", t.buf,
683            "*%s", e.buf, A_END);
684     goto done;
685   }
686
687   /* --- Ensure that the group is correct --- *
688    *
689    * Dodginess!  We assume that if this works, our global group is willing to
690    * adopt this public element.  Probably reasonable.
691    */
692
693   if (!group_samep(gg, g)) {
694     a_warn("KEYMGMT", "public-keyring",
695            "%s", kr_pub, "key", "%s", t.buf,
696            "*%s", e.buf, A_END);
697     goto done;
698   }
699
700   /* --- Check the public group element --- */
701
702   if (group_check(gg, p)) {
703     a_warn("KEYMGMT", "public-keyring",
704            "%s", kr_pub, "key", "%s", t.buf,
705            "bad-public-group-element",
706            A_END);
707     goto done;
708   }
709
710   /* --- Check the algorithms --- */
711
712   if (algs_get(&a, &e, kf_pub, k)) {
713     a_warn("KEYMGMT", "public-keyring",
714            "%s", kr_pub, "key", "%s", t.buf,
715            "*%s", e.buf, A_END);
716     goto done;
717   }
718   if (!algs_samep(&a, &algs)) {
719     a_warn("KEYMGMT", "public-keyring",
720            "%s", kr_pub, "key", "%s", t.buf,
721            "algorithm-mismatch", A_END);
722     goto done;
723   }
724
725   /* --- Dump the public key --- */
726
727   IF_TRACING(T_KEYMGMT, {
728     trace(T_KEYMGMT, "keymgmt: extracted public key `%s'", t.buf);
729     trace(T_CRYPTO, "crypto: p = %s", gestr(gg, p));
730   })
731
732   /* --- OK, accept the public key --- */
733
734   *t_exp = k->exp;
735   G_COPY(gg, kpub, p);
736   rc = 0;
737
738   /* --- Tidy up --- */
739
740 done:
741   if (p) G_DESTROY(g, p);
742   if (g) G_DESTROYGROUP(g);
743   dstr_destroy(&t);
744   dstr_destroy(&e);
745   return (rc);
746 }
747
748 /*----- That's all, folks -------------------------------------------------*/