Skip to content

Commit d9e7488

Browse files
committed
Use the keyboxd for a fresh install
* common/homedir.c (gnupg_maybe_make_homedir): Also create a common.conf. * g10/keydb.c: Include comopt.h. (maybe_create_keyring_or_box): Detect the creation of a common.conf. * g10/gpg.c (main): Avoid adding more resources in this case. * sm/keydb.c: Include comopt.h. (maybe_create_keybox): Detect the creation of a common.conf. * common/comopt.h (comopt): Remove the conditional "extern".
1 parent db6ae6f commit d9e7488

File tree

8 files changed

+110
-18
lines changed

8 files changed

+110
-18
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Noteworthy changes in version 2.4.1 (unreleased)
22
------------------------------------------------
33

4+
* If the ~/.gnupg home directory does not exist, the keyboxd is now
5+
automagically enabled.
6+
47
* gpg: New option --add-desig-revoker. [rG3d094e2bcf]
58

69
* gpg: New list-option "show-unusable-sigs". Also show

README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
Only public keys and X.509 certificates are managed by the keyboxd;
129129
private keys are still stored as separate files.
130130

131+
Since version 2.4.1 the keyboxd will be used by default for a fresh
132+
install; i.e. if a ~/.gnupg directory did not yet exist.
133+
131134
Note that there is no automatic migration; if the use-keyboxd option
132135
is enabled keys are not taken from pubring.kbx. To migrate existing
133136
keys to the keyboxd do this:

common/comopt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636

3737
/* Common options for all GnuPG components. */
38-
EXTERN_UNLESS_MAIN_MODULE
3938
struct
4039
{
4140
char *logfile; /* Socket used by daemons for logging. */

common/homedir.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,42 @@ gnupg_maybe_make_homedir (const char *fname, int quiet)
789789
if (gnupg_mkdir (fname, "-rwx"))
790790
log_fatal ( _("can't create directory '%s': %s\n"),
791791
fname, strerror(errno) );
792-
else if (!quiet )
793-
log_info ( _("directory '%s' created\n"), fname );
792+
else
793+
{
794+
estream_t fp;
795+
char *fcommon;
796+
797+
if (!quiet )
798+
log_info ( _("directory '%s' created\n"), fname );
799+
800+
#ifdef BUILD_WITH_KEYBOXD
801+
/* A new default homedir has been created. Now create a
802+
* common.conf. */
803+
fcommon = make_filename (fname, "common.conf", NULL);
804+
fp = es_fopen (fcommon, "wx,mode=-rw-r");
805+
if (!fp)
806+
{
807+
log_info (_("error creating '%s': %s\n"), fcommon,
808+
gpg_strerror (gpg_error_from_syserror ()));
809+
}
810+
else
811+
{
812+
if (es_fputs ("use-keyboxd\n", fp) == EOF)
813+
{
814+
log_info (_("error writing to '%s': %s\n"), fcommon,
815+
gpg_strerror (es_ferror (fp)
816+
? gpg_error_from_syserror ()
817+
: gpg_error (GPG_ERR_EOF)));
818+
es_fclose (fp);
819+
}
820+
else if (es_fclose (fp))
821+
{
822+
log_info (_("error closing '%s': %s\n"), fcommon,
823+
gpg_strerror (gpg_error_from_syserror ()));
824+
}
825+
}
826+
#endif /* BUILD_WITH_KEYBOXD */
827+
}
794828
}
795829
}
796830

doc/gpg.texi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,9 @@ current home directory (@pxref{option --homedir}).
39153915
@efindex common.conf
39163916
This is an optional configuration file read by @command{@gpgname} on
39173917
startup. It may contain options pertaining to all components of
3918-
GnuPG. Its current main use is for the "use-keyboxd" option.
3918+
GnuPG. Its current main use is for the "use-keyboxd" option. If
3919+
the default home directory @file{~/.gnupg} does not exist, GnuPG creates
3920+
this directory and a @file{common.conf} file with "use_keyboxd".
39193921

39203922
@end table
39213923

g10/gpg.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,17 +4187,27 @@ main (int argc, char **argv)
41874187
* need to add the keyrings if we are running under SELinux, this
41884188
* is so that the rings are added to the list of secured files.
41894189
* We do not add any keyring if --no-keyring or --use-keyboxd has
4190-
* been used. */
4190+
* been used. Note that keydb_add_resource may create a new
4191+
* homedir and also tries to write a common.conf to enable the use
4192+
* of the keyboxd - in this case a special error code is returned
4193+
* and use_keyboxd is then also set. */
41914194
if (!opt.use_keyboxd
41924195
&& default_keyring >= 0
41934196
&& (ALWAYS_ADD_KEYRINGS
41944197
|| (cmd != aDeArmor && cmd != aEnArmor && cmd != aGPGConfTest)))
41954198
{
4199+
gpg_error_t tmperr = 0;
4200+
41964201
if (!nrings || default_keyring > 0) /* Add default ring. */
4197-
keydb_add_resource ("pubring" EXTSEP_S GPGEXT_GPG,
4198-
KEYDB_RESOURCE_FLAG_DEFAULT);
4199-
for (sl = nrings; sl; sl = sl->next )
4200-
keydb_add_resource (sl->d, sl->flags);
4202+
tmperr = keydb_add_resource ("pubring" EXTSEP_S GPGEXT_GPG,
4203+
KEYDB_RESOURCE_FLAG_DEFAULT);
4204+
if (gpg_err_code (tmperr) == GPG_ERR_TRUE && opt.use_keyboxd)
4205+
; /* The keyboxd has been enabled. */
4206+
else
4207+
{
4208+
for (sl = nrings; sl; sl = sl->next )
4209+
keydb_add_resource (sl->d, sl->flags);
4210+
}
42014211
}
42024212
FREE_STRLIST(nrings);
42034213

g10/keydb.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "../kbx/keybox.h"
3838
#include "keydb.h"
3939
#include "../common/i18n.h"
40+
#include "../common/comopt.h"
4041

4142
#include "keydb-private.h" /* For struct keydb_handle_s */
4243

@@ -265,8 +266,24 @@ maybe_create_keyring_or_box (char *filename, int is_box, int force_create)
265266
*last_slash_in_filename = save_slash;
266267
goto leave;
267268
}
269+
270+
*last_slash_in_filename = save_slash;
271+
272+
if (!opt.use_keyboxd
273+
&& !parse_comopt (GNUPG_MODULE_NAME_GPG, 0)
274+
&& comopt.use_keyboxd)
275+
{
276+
/* The above try_make_homedir created a new default hoemdir
277+
* and also wrote a new common.conf. Thus we now see that
278+
* use-keyboxd has been set. Let's set this option and
279+
* return a dedicated error code. */
280+
opt.use_keyboxd = comopt.use_keyboxd;
281+
rc = gpg_error (GPG_ERR_TRUE);
282+
goto leave;
283+
}
268284
}
269-
*last_slash_in_filename = save_slash;
285+
else
286+
*last_slash_in_filename = save_slash;
270287

271288
/* To avoid races with other instances of gpg trying to create or
272289
update the keyring (it is removed during an update for a short
@@ -555,7 +572,8 @@ keydb_search_desc_dump (struct keydb_search_desc *desc)
555572
* If KEYDB_RESOURCE_FLAG_READONLY is set and the resource is a
556573
* keyring (not a keybox), then the keyring is marked as read only and
557574
* operations just as keyring_insert_keyblock will return
558-
* GPG_ERR_ACCESS. */
575+
* GPG_ERR_ACCESS.
576+
*/
559577
gpg_error_t
560578
keydb_add_resource (const char *url, unsigned int flags)
561579
{
@@ -774,9 +792,12 @@ keydb_add_resource (const char *url, unsigned int flags)
774792
leave:
775793
if (err)
776794
{
777-
log_error (_("keyblock resource '%s': %s\n"),
778-
filename, gpg_strerror (err));
779-
write_status_error ("add_keyblock_resource", err);
795+
if (gpg_err_code (err) != GPG_ERR_TRUE)
796+
{
797+
log_error (_("keyblock resource '%s': %s\n"),
798+
filename, gpg_strerror (err));
799+
write_status_error ("add_keyblock_resource", err);
800+
}
780801
}
781802
else
782803
any_registered = 1;

sm/keydb.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "keydb.h"
3434
#include "../common/i18n.h"
3535
#include "../common/asshelp.h"
36+
#include "../common/comopt.h"
3637
#include "../kbx/kbx-client-util.h"
3738

3839

@@ -242,8 +243,23 @@ maybe_create_keybox (char *filename, int force, int *r_created)
242243
*last_slash_in_filename = save_slash;
243244
goto leave;
244245
}
246+
*last_slash_in_filename = save_slash;
247+
248+
if (!opt.use_keyboxd
249+
&& !parse_comopt (GNUPG_MODULE_NAME_GPG, 0)
250+
&& comopt.use_keyboxd)
251+
{
252+
/* The above try_make_homedir created a new default hoemdir
253+
* and also wrote a new common.conf. Thus we now see that
254+
* use-keyboxd has been set. Let's set this option and
255+
* return a dedicated error code. */
256+
opt.use_keyboxd = comopt.use_keyboxd;
257+
rc = gpg_error (GPG_ERR_TRUE);
258+
goto leave;
259+
}
245260
}
246-
*last_slash_in_filename = save_slash;
261+
else
262+
*last_slash_in_filename = save_slash;
247263

248264
/* To avoid races with other instances of gpg trying to create or
249265
update the keybox (it is removed during an update for a short
@@ -459,9 +475,13 @@ keydb_add_resource (ctrl_t ctrl, const char *url, int force, int *auto_created)
459475
leave:
460476
if (err)
461477
{
462-
log_error ("keyblock resource '%s': %s\n", filename, gpg_strerror (err));
463-
gpgsm_status_with_error (ctrl, STATUS_ERROR,
464-
"add_keyblock_resource", err);
478+
if (gpg_err_code (err) != GPG_ERR_TRUE)
479+
{
480+
log_error ("keyblock resource '%s': %s\n",
481+
filename, gpg_strerror (err));
482+
gpgsm_status_with_error (ctrl, STATUS_ERROR,
483+
"add_keyblock_resource", err);
484+
}
465485
}
466486
else
467487
any_registered = 1;

0 commit comments

Comments
 (0)