LCOV - code coverage report
Current view: top level - src - posix-util.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 45 37.8 %
Date: 2018-11-14 16:53:58 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /* posix-util.c - Utility functions for Posix
       2             :    Copyright (C) 2001 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2002, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             : 
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             : 
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : #include <stdio.h>
      26             : #include <stdlib.h>
      27             : #include <string.h>
      28             : #include <assert.h>
      29             : 
      30             : #include "util.h"
      31             : #include "sys-util.h"
      32             : #include "debug.h"
      33             : 
      34             : /* These variables store the malloced name of alternative default
      35             :    binaries.  The are set only once by gpgme_set_global_flag.  */
      36             : static char *default_gpg_name;
      37             : static char *default_gpgconf_name;
      38             : 
      39             : /* Set the default name for the gpg binary.  This function may only be
      40             :    called by gpgme_set_global_flag.  Returns 0 on success.  Leading
      41             :    directories are removed from NAME.  */
      42             : int
      43           0 : _gpgme_set_default_gpg_name (const char *name)
      44             : {
      45             :   const char *s;
      46             : 
      47           0 :   s = strrchr (name, '/');
      48           0 :   if (s)
      49           0 :     name = s + 1;
      50             : 
      51           0 :   if (!default_gpg_name)
      52           0 :     default_gpg_name = strdup (name);
      53           0 :   return !default_gpg_name;
      54             : }
      55             : 
      56             : /* Set the default name for the gpgconf binary.  This function may
      57             :    only be called by gpgme_set_global_flag.  Returns 0 on success.
      58             :    Leading directories are removed from NAME.  */
      59             : int
      60           0 : _gpgme_set_default_gpgconf_name (const char *name)
      61             : {
      62             :   const char *s;
      63             : 
      64           0 :   s = strrchr (name, '/');
      65           0 :   if (s)
      66           0 :     name = s + 1;
      67             : 
      68           0 :   if (!default_gpgconf_name)
      69           0 :     default_gpgconf_name = strdup (name);
      70           0 :   return !default_gpgconf_name;
      71             : }
      72             : 
      73             : 
      74             : /* Dummy function - see w32-util.c for the actual code.  */
      75             : int
      76           0 : _gpgme_set_override_inst_dir (const char *dir)
      77             : {
      78             :   (void)dir;
      79           0 :   return 0;
      80             : }
      81             : 
      82             : 
      83             : /* Find an executable program PGM along the envvar PATH.  */
      84             : static char *
      85          98 : walk_path (const char *pgm)
      86             : {
      87             :   const char *orig_path, *path, *s;
      88             :   char *fname, *p;
      89             : 
      90             : #ifdef FIXED_SEARCH_PATH
      91             :   orig_path = FIXED_SEARCH_PATH;
      92             : #else
      93          98 :   orig_path = getenv ("PATH");
      94          98 :   if (!orig_path)
      95           0 :     orig_path = "/bin:/usr/bin";
      96             : #endif
      97             : 
      98          98 :   fname = malloc (strlen (orig_path) + 1 + strlen (pgm) + 1);
      99          98 :   if (!fname)
     100           0 :     return NULL;
     101             : 
     102          98 :   path = orig_path;
     103             :   for (;;)
     104             :     {
     105       11368 :       for (s=path, p=fname; *s && *s != ':'; s++, p++)
     106       10486 :         *p = *s;
     107         490 :       if (p != fname && p[-1] != '/')
     108         490 :         *p++ = '/';
     109         490 :       strcpy (p, pgm);
     110         490 :       if (!access (fname, X_OK))
     111          98 :         return fname;
     112         392 :       if (!*s)
     113           0 :         break;
     114         392 :       path = s + 1;
     115             :     }
     116             : 
     117           0 :   _gpgme_debug (DEBUG_ENGINE, "gpgme-walk_path: '%s' not found in '%s'",
     118             :                 pgm, orig_path);
     119             : 
     120           0 :   free (fname);
     121           0 :   return NULL;
     122             : }
     123             : 
     124             : 
     125             : /* Return the full file name of the GPG binary.  This function is used
     126             :    if gpgconf was not found and thus it can be assumed that gpg2 is
     127             :    not installed.  This function is only called by get_gpgconf_item
     128             :    and may not be called concurrently.  */
     129             : char *
     130           0 : _gpgme_get_gpg_path (void)
     131             : {
     132           0 :   return walk_path (default_gpg_name? default_gpg_name : "gpg");
     133             : }
     134             : 
     135             : 
     136             : /* This function is only called by get_gpgconf_item and may not be
     137             :    called concurrently.  */
     138             : char *
     139          98 : _gpgme_get_gpgconf_path (void)
     140             : {
     141          98 :   return walk_path (default_gpgconf_name? default_gpgconf_name : "gpgconf");
     142             : }
     143             : 
     144             : /* See w32-util.c */
     145             : int
     146           0 : _gpgme_get_conf_int (const char *key, int *value)
     147             : {
     148             :   (void)key;
     149             :   (void)value;
     150           0 :   return 0;
     151             : }
     152             : 
     153             : void
     154           0 : _gpgme_allow_set_foreground_window (pid_t pid)
     155             : {
     156             :   (void)pid;
     157             :   /* Not needed.  */
     158           0 : }

Generated by: LCOV version 1.13