#include "i18n.h"
#include "sysutils.h"
#include "gc-opt-flags.h"
+#include "asshelp.h"
#include "keyblob.h"
#include "server.h"
#include "runner.h"
aNull = 0,
oQuiet = 'q',
oVerbose = 'v',
+ oRecipient = 'r',
aGPGConfList = 500,
aGPGConfTest,
oDryRun,
oNoDetach,
- oRecipient,
-
oNoRandomSeedFile,
oFakedSystemTime
};
/* Hidden options. */
ARGPARSE_s_n (oNoVerbose, "no-verbose", "@"),
- ARGPARSE_s_n (oNoSecmemWarn, "no-secmem-warning", "@"),
+ ARGPARSE_s_n (oNoSecmemWarn, "no-secmem-warning", "@"),
ARGPARSE_s_n (oNoGreeting, "no-greeting", "@"),
ARGPARSE_s_n (oNoOptions, "no-options", "@"),
- ARGPARSE_s_s (oHomedir, "homedir", "@"),
+ ARGPARSE_s_s (oHomedir, "homedir", "@"),
ARGPARSE_s_s (oAgentProgram, "agent-program", "@"),
ARGPARSE_s_s (oGpgProgram, "gpg-program", "@"),
ARGPARSE_s_s (oDisplay, "display", "@"),
case 31: p = "\nHome: "; break;
case 32: p = opt.homedir; break;
-
+
default: p = NULL; break;
}
return p;
static void
set_debug (void)
{
+ int numok = (debug_level && digitp (debug_level));
+ int numlvl = numok? atoi (debug_level) : 0;
+
if (!debug_level)
;
- else if (!strcmp (debug_level, "none"))
+ else if (!strcmp (debug_level, "none") || (numok && numlvl < 1))
opt.debug = 0;
- else if (!strcmp (debug_level, "basic"))
+ else if (!strcmp (debug_level, "basic") || (numok && numlvl <= 2))
opt.debug = DBG_ASSUAN_VALUE|DBG_MOUNT_VALUE;
- else if (!strcmp (debug_level, "advanced"))
+ else if (!strcmp (debug_level, "advanced") || (numok && numlvl <= 5))
opt.debug = DBG_ASSUAN_VALUE|DBG_MOUNT_VALUE;
- else if (!strcmp (debug_level, "expert"))
+ else if (!strcmp (debug_level, "expert") || (numok && numlvl <= 8))
opt.debug = (DBG_ASSUAN_VALUE|DBG_MOUNT_VALUE|DBG_CRYPTO_VALUE);
- else if (!strcmp (debug_level, "guru"))
- opt.debug = ~0;
+ else if (!strcmp (debug_level, "guru") || numok)
+ {
+ opt.debug = ~0;
+ /* if (numok) */
+ /* opt.debug &= ~(DBG_HASHING_VALUE); */
+ }
else
{
log_error (_("invalid debug-level `%s' given\n"), debug_level);
if (opt.debug & DBG_CRYPTO_VALUE )
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1);
gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
+
+ if (opt.debug)
+ log_info ("enabled debug flags:%s%s%s%s%s\n",
+ (opt.debug & DBG_MOUNT_VALUE )? " mount":"",
+ (opt.debug & DBG_CRYPTO_VALUE )? " crypto":"",
+ (opt.debug & DBG_MEMORY_VALUE )? " memory":"",
+ (opt.debug & DBG_MEMSTAT_VALUE)? " memstat":"",
+ (opt.debug & DBG_ASSUAN_VALUE )? " assuan":"");
}
-
+
static void
if (!cmd || cmd == new_cmd)
cmd = new_cmd;
- else
+ else
{
log_error (_("conflicting commands\n"));
g13_exit (2);
}
-/* Helper to add recipients to a list. */
-static int
-add_encryption_key (ctrl_t ctrl, const char *name,
- void /*FIXME*/ *keylist, int is_cms)
-{
- /* FIXME: Decide whether to add a CMS or OpenPGP key and then add
- the key to a list. */
- /* int rc = foo_add_to_certlist (ctrl, name, 0, recplist, is_encrypt_to); */
- /* if (rc) */
- /* { */
- /* if (recp_required) */
- /* { */
- /* log_error ("can't encrypt to `%s': %s\n", name, gpg_strerror (rc)); */
- /* gpgsm_status2 (ctrl, STATUS_INV_RECP, */
- /* get_inv_recpsgnr_code (rc), name, NULL); */
- /* } */
- /* else */
- /* log_info (_("NOTE: won't be able to encrypt to `%s': %s\n"), */
- /* name, gpg_strerror (rc)); */
- /* } */
- return 0; /* Key is good. */
-}
-
-
int
main ( int argc, char **argv)
{
/* Make sure that our subsystems are ready. */
i18n_init ();
- init_common_subsystems ();
+ init_common_subsystems (&argc, &argv);
/* Libgcrypt requires us to register the threading model first.
Note that this will also do the pth_init. */
/* Check that the Libgcrypt is suitable. */
if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
- log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
+ log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
/* Take extra care of the random pool. */
gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
may_coredump = disable_core_dumps ();
-
+
gnupg_init_signals (0, emergency_cleanup);
-
+
create_dotlock (NULL); /* Register locking cleanup. */
+ opt.session_env = session_env_new ();
+ if (!opt.session_env)
+ log_fatal ("error allocating session environment block: %s\n",
+ strerror (errno));
+
opt.homedir = default_homedir ();
/* First check whether we have a config file on the commandline. */
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
maybe_setuid = 0;
- /*
- Now we are now working under our real uid
+ /*
+ Now we are now working under our real uid
*/
/* Setup malloc hooks. */
malloc_hooks.free = gcry_free;
assuan_set_malloc_hooks (&malloc_hooks);
}
-
+
/* Prepare libassuan. */
- assuan_set_assuan_log_prefix (log_get_prefix (NULL));
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
assuan_set_system_hooks (ASSUAN_SYSTEM_PTH);
-
+ setup_libassuan_logging (&opt.debug);
/* Setup a default control structure for command line mode. */
memset (&ctrl, 0, sizeof ctrl);
g13_init_default_ctrl (&ctrl);
+ ctrl.no_server = 1;
+ ctrl.status_fd = -1; /* No status output. */
/* Set the default option file */
if (default_config )
configname = make_filename (opt.homedir, "g13.conf", NULL);
-
+
argc = orig_argc;
argv = orig_argv;
pargs.argc = &argc;
if (parse_debug)
log_info (_("NOTE: no default option file `%s'\n"), configname);
}
- else
+ else
{
- log_error (_("option file `%s': %s\n"),
+ log_error (_("option file `%s': %s\n"),
configname, strerror(errno));
g13_exit(2);
}
log_info (_("reading options from `%s'\n"), configname);
default_config = 0;
}
-
- while (!no_more_options
+
+ while (!no_more_options
&& optfile_parse (configfp, configname, &configlineno, &pargs, opts))
{
switch (pargs.r_opt)
{
- case aGPGConfList:
- case aGPGConfTest:
+ case aGPGConfList:
+ case aGPGConfTest:
set_cmd (&cmd, pargs.r_opt);
nogreeting = 1;
nokeysetup = 1;
break;
case oLogFile: logfile = pargs.r.ret_str; break;
- case oNoLogFile: logfile = NULL; break;
+ case oNoLogFile: logfile = NULL; break;
case oNoDetach: nodetach = 1; break;
case oLCctype: opt.lc_ctype = xstrdup (pargs.r.ret_str); break;
case oLCmessages: opt.lc_messages = xstrdup (pargs.r.ret_str); break;
case oXauthority: opt.xauthority = xstrdup (pargs.r.ret_str); break;
-
+
case oFakedSystemTime:
{
- time_t faked_time = isotime2epoch (pargs.r.ret_str);
+ time_t faked_time = isotime2epoch (pargs.r.ret_str);
if (faked_time == (time_t)(-1))
faked_time = (time_t)strtoul (pargs.r.ret_str, NULL, 10);
gnupg_set_time (faked_time, 0);
break;
- default:
- pargs.err = configfp? ARGPARSE_PRINT_WARNING:ARGPARSE_PRINT_ERROR;
+ default:
+ pargs.err = configfp? ARGPARSE_PRINT_WARNING:ARGPARSE_PRINT_ERROR;
break;
}
}
if (nogreeting)
greeting = 0;
-
+
if (greeting)
{
fprintf (stderr, "%s %s; %s\n",
/* Terminate if we found any error until now. */
if (log_get_errorcount(0))
g13_exit (2);
-
+
/* Set the standard GnuPG random seed file. */
- if (use_random_seed)
+ if (use_random_seed)
{
char *p = make_filename (opt.homedir, "random_seed", NULL);
gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, p);
xfree(p);
}
-
+
/* Store given filename into FNAME. */
fname = argc? *argv : NULL;
/* Parse all given encryption keys. This does a lookup of the keys
and stops if any of the given keys was not found. */
+#if 0 /* Currently not implemented. */
if (!nokeysetup)
{
strlist_t sl;
int failed = 0;
-
+
for (sl = recipients; sl; sl = sl->next)
- if (add_encryption_key (&ctrl, sl->d, NULL /* FIXME*/, 0))
+ if (check_encryption_key ())
failed = 1;
if (failed)
g13_exit (1);
}
-
+#endif /*0*/
+
/* Dispatch command. */
switch (cmd)
{
- case aGPGConfList:
+ case aGPGConfList:
{ /* List options and default values in the GPG Conf format. */
char *config_filename_esc = percent_escape (opt.config_filename, NULL);
case aServer:
{
start_idle_task ();
+ ctrl.no_server = 0;
err = g13_server (&ctrl);
if (err)
log_error ("server exited with error: %s <%s>\n",
case aCreate: /* Create a new container. */
{
- if (argc != 1)
+ if (argc != 1)
wrong_args ("--create filename");
start_idle_task ();
- err = g13_create_container (&ctrl, argv[0]);
+ err = g13_create_container (&ctrl, argv[0], recipients);
if (err)
log_error ("error creating a new container: %s <%s>\n",
gpg_strerror (err), gpg_strsource (err));
case aMount: /* Mount a container. */
{
- if (argc != 1 && argc != 2 )
+ if (argc != 1 && argc != 2 )
wrong_args ("--mount filename [mountpoint]");
start_idle_task ();
err = g13_mount_container (&ctrl, argv[0], argc == 2?argv[1]:NULL);
log_info ("SIGHUP received - re-reading configuration\n");
/* Fixme: Not yet implemented. */
break;
-
+
case SIGUSR1:
log_info ("SIGUSR1 received - printing internal information:\n");
- pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ());
+ /* Fixme: We need to see how to integrate pth dumping into our
+ logging system. */
+ /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */
mountinfo_dump_all ();
break;
g13_exit (0);
}
break;
-
+
case SIGINT:
log_info ("SIGINT received - immediate shutdown\n");
log_info( "%s %s stopped\n", strusage(11), strusage(13));
g13_exit (0);
break;
#endif /*!HAVE_W32_SYSTEM*/
-
+
default:
log_info ("signal %d received - no action defined\n", signo);
}
{
pth_attr_t tattr;
pth_t tid;
-
+
tattr = pth_attr_new ();
pth_attr_set (tattr, PTH_ATTR_JOINABLE, 1);
pth_attr_set (tattr, PTH_ATTR_STACK_SIZE, 64*1024);
pth_attr_set (tattr, PTH_ATTR_NAME, "idle-task");
-
+
tid = pth_spawn (tattr, idle_task, NULL);
if (!tid)
{
- log_fatal ("error starting idle task: %s\n",
+ log_fatal ("error starting idle task: %s\n",
gpg_strerror (gpg_error_from_syserror ()));
return; /*NOTREACHED*/
}
gpg_strerror (gpg_error_from_syserror ()));
}
}
-