LCOV - code coverage report
Current view: top level - dirmngr - ks-engine-finger.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 47 0.0 %
Date: 2016-09-12 13:01:59 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* ks-engine-finger.c - Finger OpenPGP key access
       2             :  * Copyright (C) 2011 Free Software Foundation, Inc.
       3             :  *
       4             :  * This file is part of GnuPG.
       5             :  *
       6             :  * GnuPG is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * GnuPG is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : 
      22             : #include <stdio.h>
      23             : #include <stdlib.h>
      24             : #include <string.h>
      25             : #include <assert.h>
      26             : 
      27             : #include "dirmngr.h"
      28             : #include "misc.h"
      29             : #include "userids.h"
      30             : #include "ks-engine.h"
      31             : 
      32             : /* Print a help output for the schemata supported by this module. */
      33             : gpg_error_t
      34           0 : ks_finger_help (ctrl_t ctrl, parsed_uri_t uri)
      35             : {
      36           0 :   char const data[] =
      37             :     "Handler for FINGER:\n"
      38             :     "  finger:<user>@<host>\n"
      39             :     "Supported methods: fetch\n"
      40             :     "Example:\n"
      41             :     "  finger:joe@example.org\n";
      42             :   gpg_error_t err;
      43             : 
      44           0 :   if (!uri)
      45           0 :     err = ks_print_help (ctrl, "  finger");
      46           0 :   else if (!strcmp (uri->scheme, "finger"))
      47           0 :     err = ks_print_help (ctrl, data);
      48             :   else
      49           0 :     err = 0;
      50             : 
      51           0 :   return err;
      52             : }
      53             : 
      54             : 
      55             : /* Get the key from URI which is expected to specify a finger scheme.
      56             :    On success R_FP has an open stream to read the data.  */
      57             : gpg_error_t
      58           0 : ks_finger_fetch (ctrl_t ctrl, parsed_uri_t uri, estream_t *r_fp)
      59             : {
      60             :   gpg_error_t err;
      61             :   estream_t fp;
      62             :   char *server;
      63             :   char *name;
      64             :   http_t http;
      65             : 
      66             :   (void)ctrl;
      67           0 :   *r_fp = NULL;
      68             : 
      69           0 :   if (strcmp (uri->scheme, "finger") || !uri->opaque || !uri->path)
      70           0 :     return gpg_error (GPG_ERR_INV_ARG);
      71             : 
      72           0 :   name = xtrystrdup (uri->path);
      73           0 :   if (!name)
      74           0 :     return gpg_error_from_syserror ();
      75             : 
      76           0 :   server = strchr (name, '@');
      77           0 :   if (!server)
      78             :     {
      79           0 :       err = gpg_error (GPG_ERR_INV_URI);
      80           0 :       xfree (name);
      81           0 :       return err;
      82             :     }
      83           0 :   *server++ = 0;
      84             : 
      85           0 :   err = http_raw_connect (&http, server, 79,
      86           0 :                           (opt.use_tor? HTTP_FLAG_FORCE_TOR : 0), NULL);
      87           0 :   if (err)
      88             :     {
      89           0 :       xfree (name);
      90           0 :       return err;
      91             :     }
      92             : 
      93           0 :   fp = http_get_write_ptr (http);
      94           0 :   if (!fp)
      95             :     {
      96           0 :       err = gpg_error (GPG_ERR_INTERNAL);
      97           0 :       http_close (http, 0);
      98           0 :       xfree (name);
      99           0 :       return err;
     100             :     }
     101             : 
     102           0 :   if (es_fputs (name, fp) || es_fputs ("\r\n", fp) || es_fflush (fp))
     103             :     {
     104           0 :       err = gpg_error_from_syserror ();
     105           0 :       http_close (http, 0);
     106           0 :       xfree (name);
     107           0 :       return err;
     108             :     }
     109           0 :   xfree (name);
     110           0 :   es_fclose (fp);
     111             : 
     112           0 :   fp = http_get_read_ptr (http);
     113           0 :   if (!fp)
     114             :     {
     115           0 :       err = gpg_error (GPG_ERR_INTERNAL);
     116           0 :       http_close (http, 0);
     117           0 :       return err;
     118             :     }
     119             : 
     120           0 :   http_close (http, 1 /* Keep read ptr.  */);
     121             : 
     122           0 :   *r_fp = fp;
     123           0 :   return 0;
     124             : }

Generated by: LCOV version 1.11