Coverage Report

Created: 2022-12-08 06:09

/src/gnupg/g10/expand-group.c
Line
Count
Source (jump to first uncovered line)
1
/* expand-group.c - expand GPG group definitions
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3
 *               2008, 2009, 2010 Free Software Foundation, Inc.
4
 *
5
 * This file is part of GnuPG.
6
 *
7
 * GnuPG is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * GnuPG is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
#include <config.h>
22
23
#include "gpg.h"
24
#include "options.h"
25
#include "keydb.h"
26
27
int
28
expand_id (const char *id, strlist_t *into, unsigned int flags)
29
0
{
30
0
  struct groupitem *groups;
31
0
  int count=0;
32
33
0
  for (groups = opt.grouplist; groups; groups=groups->next)
34
0
    {
35
      /* need strcasecmp() here, as this should be localized */
36
0
      if (strcasecmp (groups->name,id) == 0)
37
0
   {
38
0
     strlist_t each,sl;
39
40
     /* This maintains the current utf8-ness */
41
0
     for (each = groups->values; each; each=each->next)
42
0
       {
43
0
         sl = add_to_strlist (into, each->d);
44
0
         sl->flags = flags;
45
0
         count++;
46
0
       }
47
48
0
     break;
49
0
   }
50
0
    }
51
52
0
  return count;
53
0
}
54
55
/* For simplicity, and to avoid potential loops, we only expand once -
56
 * you can't make an alias that points to an alias.  If PREPEND_INPUT
57
 * is true each item from INPUT is prepended to the new list; if it is
58
 * false the original item from INPUT is only added if no group
59
 * existed for it. */
60
strlist_t
61
expand_group (strlist_t input, int prepend_input)
62
0
{
63
0
  strlist_t output = NULL;
64
0
  strlist_t sl, rover;
65
66
0
  for (rover = input; rover; rover = rover->next)
67
0
    {
68
0
      if ((rover->flags & PK_LIST_FROM_FILE))
69
0
        continue;
70
0
      if (!expand_id (rover->d, &output, rover->flags))
71
0
        {
72
          /* Didn't find any groups, so use the existing string unless
73
           * we will anyway add it due to the prepend flag.  */
74
0
          if (!prepend_input)
75
0
            {
76
0
              sl = add_to_strlist (&output, rover->d);
77
0
              sl->flags = rover->flags;
78
0
            }
79
0
        }
80
0
      if (prepend_input)
81
0
        {
82
0
          sl = add_to_strlist (&output, rover->d);
83
0
          sl->flags = rover->flags;
84
0
        }
85
0
    }
86
87
0
  return output;
88
0
}