chiark / gitweb /
gpg: Fix searching for mail addresses in keyrings.
[gnupg2.git] / tools / gpgconf.c
1 /* gpgconf.c - Configuration utility for GnuPG
2  * Copyright (C) 2003, 2007, 2009, 2011 Free Software Foundation, Inc.
3  * Copyright (C) 2016 g10 Code GmbH.
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 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #include "gpgconf.h"
29 #include "i18n.h"
30 #include "sysutils.h"
31 #include "../common/init.h"
32
33
34 /* Constants to identify the commands and options. */
35 enum cmd_and_opt_values
36   {
37     aNull = 0,
38     oDryRun     = 'n',
39     oOutput     = 'o',
40     oQuiet      = 'q',
41     oVerbose    = 'v',
42     oRuntime    = 'r',
43     oComponent  = 'c',
44     oNull       = '0',
45     oNoVerbose  = 500,
46     oHomedir,
47     oBuilddir,
48
49     aListComponents,
50     aCheckPrograms,
51     aListOptions,
52     aChangeOptions,
53     aCheckOptions,
54     aApplyDefaults,
55     aListConfig,
56     aCheckConfig,
57     aQuerySWDB,
58     aListDirs,
59     aLaunch,
60     aKill,
61     aCreateSocketDir,
62     aRemoveSocketDir,
63     aApplyProfile,
64     aReload
65   };
66
67
68 /* The list of commands and options. */
69 static ARGPARSE_OPTS opts[] =
70   {
71     { 300, NULL, 0, N_("@Commands:\n ") },
72
73     { aListComponents, "list-components", 256, N_("list all components") },
74     { aCheckPrograms, "check-programs", 256, N_("check all programs") },
75     { aListOptions, "list-options", 256, N_("|COMPONENT|list options") },
76     { aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") },
77     { aCheckOptions, "check-options", 256, N_("|COMPONENT|check options") },
78     { aApplyDefaults, "apply-defaults", 256,
79       N_("apply global default values") },
80     { aApplyProfile, "apply-profile", 256,
81       N_("|FILE|update configuration files using FILE") },
82     { aListDirs, "list-dirs", 256,
83       N_("get the configuration directories for @GPGCONF@") },
84     { aListConfig,   "list-config", 256,
85       N_("list global configuration file") },
86     { aCheckConfig,   "check-config", 256,
87       N_("check global configuration file") },
88     { aQuerySWDB,     "query-swdb", 256,
89       N_("query the software version database") },
90     { aReload,        "reload", 256, N_("reload all or a given component")},
91     { aLaunch,        "launch", 256, N_("launch a given component")},
92     { aKill,          "kill", 256,   N_("kill a given component")},
93     { aCreateSocketDir, "create-socketdir", 256, "@"},
94     { aRemoveSocketDir, "remove-socketdir", 256, "@"},
95
96     { 301, NULL, 0, N_("@\nOptions:\n ") },
97
98     { oOutput, "output",    2, N_("use as output file") },
99     { oVerbose, "verbose",  0, N_("verbose") },
100     { oQuiet, "quiet",      0, N_("quiet") },
101     { oDryRun, "dry-run",   0, N_("do not make any changes") },
102     { oRuntime, "runtime",  0, N_("activate changes at runtime, if possible") },
103     /* hidden options */
104     { oHomedir, "homedir", 2, "@" },
105     { oBuilddir, "build-prefix", 2, "@" },
106     { oNull, "null", 0, "@" },
107     { oNoVerbose, "no-verbose",  0, "@"},
108     {0}
109   };
110
111
112 /* Print usage information and and provide strings for help. */
113 static const char *
114 my_strusage( int level )
115 {
116   const char *p;
117
118   switch (level)
119     {
120     case 11: p = "@GPGCONF@ (@GNUPG@)";
121       break;
122     case 13: p = VERSION; break;
123     case 17: p = PRINTABLE_OS_NAME; break;
124     case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
125
126     case 1:
127     case 40: p = _("Usage: @GPGCONF@ [options] (-h for help)");
128       break;
129     case 41:
130       p = _("Syntax: @GPGCONF@ [options]\n"
131             "Manage configuration options for tools of the @GNUPG@ system\n");
132       break;
133
134     default: p = NULL; break;
135     }
136   return p;
137 }
138
139
140 /* Return the fp for the output.  This is usually stdout unless
141    --output has been used.  In the latter case this function opens
142    that file.  */
143 static estream_t
144 get_outfp (estream_t *fp)
145 {
146   if (!*fp)
147     {
148       if (opt.outfile)
149         {
150           *fp = es_fopen (opt.outfile, "w");
151           if (!*fp)
152             gc_error (1, errno, "can not open '%s'", opt.outfile);
153         }
154       else
155         *fp = es_stdout;
156     }
157   return *fp;
158 }
159
160
161 static void
162 list_dirs (estream_t fp, char **names)
163 {
164   static struct {
165     const char *name;
166     const char *(*fnc)(void);
167     const char *extra;
168   } list[] = {
169     { "sysconfdir",         gnupg_sysconfdir, NULL },
170     { "bindir",             gnupg_bindir,     NULL },
171     { "libexecdir",         gnupg_libexecdir, NULL },
172     { "libdir",             gnupg_libdir,     NULL },
173     { "datadir",            gnupg_datadir,    NULL },
174     { "localedir",          gnupg_localedir,  NULL },
175     { "socketdir",          gnupg_socketdir,  NULL },
176     { "dirmngr-socket",     dirmngr_socket_name, NULL,},
177     { "agent-ssh-socket",   gnupg_socketdir,  GPG_AGENT_SSH_SOCK_NAME },
178     { "agent-extra-socket", gnupg_socketdir,  GPG_AGENT_EXTRA_SOCK_NAME },
179     { "agent-browser-socket",gnupg_socketdir, GPG_AGENT_BROWSER_SOCK_NAME },
180     { "agent-socket",       gnupg_socketdir,  GPG_AGENT_SOCK_NAME },
181     { "homedir",            gnupg_homedir,    NULL }
182   };
183   int idx, j;
184   char *tmp;
185   const char *s;
186
187
188   for (idx = 0; idx < DIM (list); idx++)
189     {
190       s = list[idx].fnc ();
191       if (list[idx].extra)
192         {
193           tmp = make_filename (s, list[idx].extra, NULL);
194           s = tmp;
195         }
196       else
197         tmp = NULL;
198       if (!names)
199         es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s));
200       else
201         {
202           for (j=0; names[j]; j++)
203             if (!strcmp (names[j], list[idx].name))
204               {
205                 es_fputs (s, fp);
206                 es_putc (opt.null? '\0':'\n', fp);
207               }
208         }
209
210       xfree (tmp);
211     }
212 }
213
214
215
216 /* Check whether NAME is valid argument for query_swdb().  Valid names
217  * start with a letter and contain only alphanumeric characters or an
218  * underscore.  */
219 static int
220 valid_swdb_name_p (const char *name)
221 {
222   if (!name || !*name || !alphap (name))
223     return 0;
224
225   for (name++; *name; name++)
226     if (!alnump (name) && *name != '_')
227       return 0;
228
229   return 1;
230 }
231
232
233 /* Query the SWDB file.  If necessary and possible this functions asks
234  * the dirmngr to load an updated version of that file.  The caller
235  * needs to provide the NAME to query (e.g. "gnupg", "libgcrypt") and
236  * optional the currently installed version in CURRENT_VERSION.  The
237  * output written to OUT is a colon delimited line with these fields:
238  *
239  * name   :: The name of the package
240  * curvers:: The installed version if given.
241  * status :: This value tells the status of the software package
242  *           '-' :: No information available
243  *                  (error or CURRENT_VERSION not given)
244  *           '?' :: Unknown NAME
245  *           'u' :: Update available
246  *           'c' :: The version is Current
247  *           'n' :: The current version is already Newer than the
248  *                  available one.
249  * urgency :: If the value is greater than zero an urgent update is required.
250  * error   :: 0 on success or an gpg_err_code_t
251  *            Common codes seen:
252  *            GPG_ERR_TOO_OLD :: The SWDB file is to old to be used.
253  *            GPG_ERR_ENOENT  :: The SWDB file is not available.
254  *            GPG_ERR_BAD_SIGNATURE :: Currupted SWDB file.
255  * filedate:: Date of the swdb file (yyyymmddThhmmss)
256  * verified:: Date we checked the validity of the file (yyyyymmddThhmmss)
257  * version :: The version string from the swdb.
258  * reldate :: Release date of that version (yyyymmddThhmmss)
259  * size    :: Size of the package in bytes.
260  * hash    :: SHA-2 hash of the package.
261  *
262  */
263 static void
264 query_swdb (estream_t out, const char *name, const char *current_version)
265 {
266   gpg_error_t err;
267   const char *search_name;
268   char *fname = NULL;
269   estream_t fp = NULL;
270   char *line = NULL;
271   char *self_version = NULL;
272   size_t length_of_line = 0;
273   size_t  maxlen;
274   ssize_t len;
275   char *fields[2];
276   char *p;
277   gnupg_isotime_t filedate = {0};
278   gnupg_isotime_t verified = {0};
279   char *value_ver = NULL;
280   gnupg_isotime_t value_date = {0};
281   char *value_size = NULL;
282   char *value_sha2 = NULL;
283   unsigned long value_size_ul = 0;
284   int status, i;
285
286
287   if (!valid_swdb_name_p (name))
288     {
289       log_error ("error in package name '%s': %s\n",
290                  name, gpg_strerror (GPG_ERR_INV_NAME));
291       goto leave;
292     }
293   if (!strcmp (name, "gnupg"))
294     search_name = "gnupg21";
295   else if (!strcmp (name, "gnupg1"))
296     search_name = "gnupg1";
297   else
298     search_name = name;
299
300   if (!current_version && !strcmp (name, "gnupg"))
301     {
302       /* Use our own version but string a possible beta string.  */
303       self_version = xstrdup (PACKAGE_VERSION);
304       p = strchr (self_version, '-');
305       if (p)
306         *p = 0;
307       current_version = self_version;
308     }
309
310   if (current_version && (strchr (current_version, ':')
311                           || compare_version_strings (current_version, NULL)))
312     {
313       log_error ("error in version string '%s': %s\n",
314                  current_version, gpg_strerror (GPG_ERR_INV_ARG));
315       goto leave;
316     }
317
318   fname = make_filename (gnupg_homedir (), "swdb.lst", NULL);
319   fp = es_fopen (fname, "r");
320   if (!fp)
321     {
322       err = gpg_error_from_syserror ();
323       es_fprintf (out, "%s:%s:-::%u:::::::\n",
324                   name,
325                   current_version? current_version : "",
326                   gpg_err_code (err));
327       if (gpg_err_code (err) != GPG_ERR_ENOENT)
328         log_error (_("error opening '%s': %s\n"), fname, gpg_strerror (err));
329       goto leave;
330     }
331
332   /* Note that the parser uses the first occurance of a matching
333    * values and ignores possible duplicated values.  */
334
335   maxlen = 2048; /* Set limit.  */
336   while ((len = es_read_line (fp, &line, &length_of_line, &maxlen)) > 0)
337     {
338       if (!maxlen)
339         {
340           err = gpg_error (GPG_ERR_LINE_TOO_LONG);
341           log_error (_("error reading '%s': %s\n"), fname, gpg_strerror (err));
342           goto leave;
343         }
344       /* Strip newline and carriage return, if present.  */
345       while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
346         line[--len] = '\0';
347
348       if (split_fields (line, fields, DIM (fields)) < DIM(fields))
349         continue; /* Skip empty lines and names w/o a value.  */
350       if (*fields[0] == '#')
351         continue; /* Skip comments.  */
352
353       /* Record the meta data.  */
354       if (!*filedate && !strcmp (fields[0], ".filedate"))
355         {
356           string2isotime (filedate, fields[1]);
357           continue;
358         }
359       if (!*verified && !strcmp (fields[0], ".verified"))
360         {
361           string2isotime (verified, fields[1]);
362           continue;
363         }
364
365       /* Tokenize the name.  */
366       p = strrchr (fields[0], '_');
367       if (!p)
368         continue; /* Name w/o an underscore.  */
369       *p++ = 0;
370
371       /* Wait for the requested name.  */
372       if (!strcmp (fields[0], search_name))
373         {
374           if (!strcmp (p, "ver") && !value_ver)
375             value_ver = xstrdup (fields[1]);
376           else if (!strcmp (p, "date") && !*value_date)
377             string2isotime (value_date, fields[1]);
378           else if (!strcmp (p, "size") && !value_size)
379             value_size = xstrdup (fields[1]);
380           else if (!strcmp (p, "sha2") && !value_sha2)
381             value_sha2 = xstrdup (fields[1]);
382         }
383     }
384   if (len < 0 || es_ferror (fp))
385     {
386       err = gpg_error_from_syserror ();
387       log_error (_("error reading '%s': %s\n"), fname, gpg_strerror (err));
388       goto leave;
389     }
390
391   if (!*filedate || !*verified)
392     {
393       err = gpg_error (GPG_ERR_INV_TIME);
394       es_fprintf (out, "%s:%s:-::%u:::::::\n",
395                   name,
396                   current_version? current_version : "",
397                   gpg_err_code (err));
398       goto leave;
399     }
400
401   if (!value_ver)
402     {
403       es_fprintf (out, "%s:%s:?:::::::::\n",
404                   name,
405                   current_version? current_version : "");
406       goto leave;
407     }
408
409   if (value_size)
410     {
411       gpg_err_set_errno (0);
412       value_size_ul = strtoul (value_size, &p, 10);
413       if (errno)
414         value_size_ul = 0;
415       else if (*p == 'k')
416         value_size_ul *= 1024;
417     }
418
419   err = 0;
420   status = '-';
421   if (compare_version_strings (value_ver, NULL))
422     err = gpg_error (GPG_ERR_INV_VALUE);
423   else if (!current_version)
424     ;
425   else if (!(i = compare_version_strings (value_ver, current_version)))
426     status = 'c';
427   else if (i > 0)
428     status = 'u';
429   else
430     status = 'n';
431
432   es_fprintf (out, "%s:%s:%c::%d:%s:%s:%s:%s:%lu:%s:\n",
433               name,
434               current_version? current_version : "",
435               status,
436               err,
437               filedate,
438               verified,
439               value_ver,
440               value_date,
441               value_size_ul,
442               value_sha2? value_sha2 : "");
443
444  leave:
445   xfree (value_ver);
446   xfree (value_size);
447   xfree (value_sha2);
448   xfree (line);
449   es_fclose (fp);
450   xfree (fname);
451   xfree (self_version);
452 }
453
454
455 /* gpgconf main. */
456 int
457 main (int argc, char **argv)
458 {
459   ARGPARSE_ARGS pargs;
460   const char *fname;
461   int no_more_options = 0;
462   enum cmd_and_opt_values cmd = 0;
463   estream_t outfp = NULL;
464
465   early_system_init ();
466   gnupg_reopen_std (GPGCONF_NAME);
467   set_strusage (my_strusage);
468   log_set_prefix (GPGCONF_NAME, GPGRT_LOG_WITH_PREFIX);
469
470   /* Make sure that our subsystems are ready.  */
471   i18n_init();
472   init_common_subsystems (&argc, &argv);
473   gc_components_init ();
474
475   /* Parse the command line. */
476   pargs.argc  = &argc;
477   pargs.argv  = &argv;
478   pargs.flags =  1;  /* Do not remove the args.  */
479   while (!no_more_options && optfile_parse (NULL, NULL, NULL, &pargs, opts))
480     {
481       switch (pargs.r_opt)
482         {
483         case oOutput:    opt.outfile = pargs.r.ret_str; break;
484         case oQuiet:     opt.quiet = 1; break;
485         case oDryRun:    opt.dry_run = 1; break;
486         case oRuntime:
487           opt.runtime = 1;
488           break;
489         case oVerbose:   opt.verbose++; break;
490         case oNoVerbose: opt.verbose = 0; break;
491         case oHomedir:   gnupg_set_homedir (pargs.r.ret_str); break;
492         case oBuilddir:  gnupg_set_builddir (pargs.r.ret_str); break;
493         case oNull:      opt.null = 1; break;
494
495         case aListDirs:
496         case aListComponents:
497         case aCheckPrograms:
498         case aListOptions:
499         case aChangeOptions:
500         case aCheckOptions:
501         case aApplyDefaults:
502         case aApplyProfile:
503         case aListConfig:
504         case aCheckConfig:
505         case aQuerySWDB:
506         case aReload:
507         case aLaunch:
508         case aKill:
509         case aCreateSocketDir:
510         case aRemoveSocketDir:
511           cmd = pargs.r_opt;
512           break;
513
514         default: pargs.err = 2; break;
515         }
516     }
517
518   if (log_get_errorcount (0))
519     exit (2);
520
521   /* Print a warning if an argument looks like an option.  */
522   if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
523     {
524       int i;
525
526       for (i=0; i < argc; i++)
527         if (argv[i][0] == '-' && argv[i][1] == '-')
528           log_info (_("Note: '%s' is not considered an option\n"), argv[i]);
529     }
530
531   fname = argc ? *argv : NULL;
532
533   switch (cmd)
534     {
535     case aListComponents:
536     default:
537       /* List all components. */
538       gc_component_list_components (get_outfp (&outfp));
539       break;
540
541     case aCheckPrograms:
542       /* Check all programs. */
543       gc_check_programs (get_outfp (&outfp));
544       break;
545
546     case aListOptions:
547     case aChangeOptions:
548     case aCheckOptions:
549       if (!fname)
550         {
551           es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
552           es_putc ('\n', es_stderr);
553           es_fputs (_("Need one component argument"), es_stderr);
554           es_putc ('\n', es_stderr);
555           exit (2);
556         }
557       else
558         {
559           int idx = gc_component_find (fname);
560           if (idx < 0)
561             {
562               es_fputs (_("Component not found"), es_stderr);
563               es_putc ('\n', es_stderr);
564               exit (1);
565             }
566           if (cmd == aCheckOptions)
567             gc_component_check_options (idx, get_outfp (&outfp), NULL);
568           else
569             {
570               gc_component_retrieve_options (idx);
571               if (gc_process_gpgconf_conf (NULL, 1, 0, NULL))
572                 exit (1);
573               if (cmd == aListOptions)
574                 gc_component_list_options (idx, get_outfp (&outfp));
575               else if (cmd == aChangeOptions)
576                 gc_component_change_options (idx, es_stdin,
577                                              get_outfp (&outfp), 0);
578             }
579         }
580       break;
581
582     case aLaunch:
583     case aKill:
584       if (!fname)
585         {
586           es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
587           es_putc ('\n', es_stderr);
588           es_fputs (_("Need one component argument"), es_stderr);
589           es_putc ('\n', es_stderr);
590           exit (2);
591         }
592       else if (!strcmp (fname, "all"))
593         {
594           if (cmd == aLaunch)
595             {
596               if (gc_component_launch (-1))
597                 exit (1);
598             }
599           else
600             {
601               gc_component_kill (-1);
602             }
603         }
604       else
605         {
606           /* Launch/Kill a given component.  */
607           int idx;
608
609           idx = gc_component_find (fname);
610           if (idx < 0)
611             {
612               es_fputs (_("Component not found"), es_stderr);
613               es_putc ('\n', es_stderr);
614               exit (1);
615             }
616           else if (cmd == aLaunch)
617             {
618               if (gc_component_launch (idx))
619                 exit (1);
620             }
621           else
622             {
623               /* We don't error out if the kill failed because this
624                  command should do nothing if the component is not
625                  running.  */
626               gc_component_kill (idx);
627             }
628         }
629       break;
630
631     case aReload:
632       if (!fname || !strcmp (fname, "all"))
633         {
634           /* Reload all.  */
635           gc_component_reload (-1);
636         }
637       else
638         {
639           /* Reload given component.  */
640           int idx;
641
642           idx = gc_component_find (fname);
643           if (idx < 0)
644             {
645               es_fputs (_("Component not found"), es_stderr);
646               es_putc ('\n', es_stderr);
647               exit (1);
648             }
649           else
650             {
651               gc_component_reload (idx);
652             }
653         }
654       break;
655
656     case aListConfig:
657       if (gc_process_gpgconf_conf (fname, 0, 0, get_outfp (&outfp)))
658         exit (1);
659       break;
660
661     case aCheckConfig:
662       if (gc_process_gpgconf_conf (fname, 0, 0, NULL))
663         exit (1);
664       break;
665
666     case aApplyDefaults:
667       if (fname)
668         {
669           es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
670           es_putc ('\n', es_stderr);
671           es_fputs (_("No argument allowed"), es_stderr);
672           es_putc ('\n', es_stderr);
673           exit (2);
674         }
675       gc_component_retrieve_options (-1);
676       if (gc_process_gpgconf_conf (NULL, 1, 1, NULL))
677         exit (1);
678       break;
679
680     case aApplyProfile:
681       gc_component_retrieve_options (-1);
682       if (gc_apply_profile (fname))
683         exit (1);
684       break;
685
686     case aListDirs:
687       /* Show the system configuration directories for gpgconf.  */
688       get_outfp (&outfp);
689       list_dirs (outfp, argc? argv : NULL);
690       break;
691
692     case aQuerySWDB:
693       /* Query the software version database.  */
694       if (!fname || argc > 2)
695         {
696           es_fprintf (es_stderr, "usage: %s --query-swdb NAME [VERSION]\n",
697                       GPGCONF_NAME);
698           exit (2);
699         }
700       get_outfp (&outfp);
701       query_swdb (outfp, fname, argc > 1? argv[1] : NULL);
702       break;
703
704     case aCreateSocketDir:
705       {
706         char *socketdir;
707         unsigned int flags;
708
709         /* Make sure that the top /run/user/UID/gnupg dir has been
710          * created.  */
711         gnupg_socketdir ();
712
713         /* Check the /var/run dir.  */
714         socketdir = _gnupg_socketdir_internal (1, &flags);
715         if ((flags & 64) && !opt.dry_run)
716           {
717             /* No sub dir - create it. */
718             if (gnupg_mkdir (socketdir, "-rwx"))
719               gc_error (1, errno, "error creating '%s'", socketdir);
720             /* Try again.  */
721             xfree (socketdir);
722             socketdir = _gnupg_socketdir_internal (1, &flags);
723           }
724
725         /* Give some info.  */
726         if ( (flags & ~32) || opt.verbose || opt.dry_run)
727           {
728             log_info ("socketdir is '%s'\n", socketdir);
729             if ((flags &   1)) log_info ("\tgeneral error\n");
730             if ((flags &   2)) log_info ("\tno /run/user dir\n");
731             if ((flags &   4)) log_info ("\tbad permissions\n");
732             if ((flags &   8)) log_info ("\tbad permissions (subdir)\n");
733             if ((flags &  16)) log_info ("\tmkdir failed\n");
734             if ((flags &  32)) log_info ("\tnon-default homedir\n");
735             if ((flags &  64)) log_info ("\tno such subdir\n");
736             if ((flags & 128)) log_info ("\tusing homedir as fallback\n");
737           }
738
739         if ((flags & ~32) && !opt.dry_run)
740           gc_error (1, 0, "error creating socket directory");
741
742         xfree (socketdir);
743       }
744       break;
745
746     case aRemoveSocketDir:
747       {
748         char *socketdir;
749         unsigned int flags;
750
751         /* Check the /var/run dir.  */
752         socketdir = _gnupg_socketdir_internal (1, &flags);
753         if ((flags & 128))
754           log_info ("ignoring request to remove non /run/user socket dir\n");
755         else if (opt.dry_run)
756           ;
757         else if (rmdir (socketdir))
758           gc_error (1, errno, "error removing '%s'", socketdir);
759
760         xfree (socketdir);
761       }
762       break;
763
764     }
765
766   if (outfp != es_stdout)
767     if (es_fclose (outfp))
768       gc_error (1, errno, "error closing '%s'", opt.outfile);
769
770   return 0;
771 }