chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / debian / patches / 0055-common-Implicitly-do-a-gpgconf-create-socketdir.patch
1 From: Werner Koch <wk@gnupg.org>
2 Date: Thu, 23 Mar 2017 09:38:19 +0100
3 Subject: common: Implicitly do a gpgconf --create-socketdir.
4
5 * common/homedir.c (_gnupg_socketdir_internal): Create the
6 sub-directory.
7 --
8
9 Although there is no auto cleanup (yet) this should be helpful.  Let's
10 see whether possibly leaving stale directories around is better than
11 running into trouble when --create-socketdir was not used.
12
13 Signed-off-by: Werner Koch <wk@gnupg.org>
14 (cherry picked from commit 26086b362ff47d21b1abefaf674a6464bf0a8921)
15 ---
16  common/homedir.c | 25 ++++++++++++++++++-------
17  1 file changed, 18 insertions(+), 7 deletions(-)
18
19 diff --git a/common/homedir.c b/common/homedir.c
20 index 6b40bb6..c41cbdc 100644
21 --- a/common/homedir.c
22 +++ b/common/homedir.c
23 @@ -542,7 +542,7 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
24  
25    /* If a non default homedir is used, we check whether an
26     * corresponding sub directory below the socket dir is available
27 -   * and use that.  We has the non default homedir to keep the new
28 +   * and use that.  We hash the non default homedir to keep the new
29     * subdir short enough.  */
30    if (non_default_homedir)
31      {
32 @@ -566,16 +566,27 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
33            goto leave;
34          }
35  
36 -      /* Stat that directory and check constraints.  Note that we
37 -       * do not auto create such a directory because we would not
38 -       * have a way to remove it.  Thus the directory needs to be
39 -       * pre-created.  The command
40 -       *    gpgconf --create-socketdir
41 -       * can be used tocreate that directory.  */
42 +      /* Stat that directory and check constraints.
43 +       * The command
44 +       *    gpgconf --remove-socketdir
45 +       * can be used to remove that directory.  */
46        if (stat (name, &sb))
47          {
48            if (errno != ENOENT)
49              *r_info |= 1; /* stat failed. */
50 +          else if (!skip_checks)
51 +            {
52 +              /* Try to create the directory and check again.  */
53 +              if (gnupg_mkdir (name, "-rwx"))
54 +                *r_info |= 16; /* mkdir failed.  */
55 +              else if (stat (prefix, &sb))
56 +                {
57 +                  if (errno != ENOENT)
58 +                    *r_info |= 1; /* stat failed. */
59 +                  else
60 +                    *r_info |= 64; /* Subdir does not exist.  */
61 +                }
62 +            }
63            else
64              *r_info |= 64; /* Subdir does not exist.  */
65            if (!skip_checks)