mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Whole lot of changes to support CE.
This commit is contained in:
parent
aed838b750
commit
31d7bdfe77
28 changed files with 413 additions and 151 deletions
|
@ -1,3 +1,40 @@
|
|||
2010-04-14 Werner Koch <wk@g10code.com>
|
||||
|
||||
* trustlist.c (read_one_trustfile): Use estream.
|
||||
|
||||
2010-04-13 Werner Koch <wk@g10code.com>
|
||||
|
||||
* findkey.c (read_key_file): Use estream.
|
||||
(agent_write_private_key): Ditto.
|
||||
|
||||
2010-04-07 Werner Koch <wk@g10code.com>
|
||||
|
||||
* gpg-agent.c (handle_connections) [W32]: Assume that PTh support
|
||||
the handle event. Use a dummy event for W32CE.
|
||||
(get_agent_scd_notify_event) [W32CE]: Do not build.
|
||||
|
||||
* call-pinentry.c: Remove setenv.h. Include sysutils.h.
|
||||
(atfork_cb): s/setenv/gnupg_setenv/.
|
||||
|
||||
* gpg-agent.c: Do not include setenv.h.
|
||||
(main): s/unsetenv/gnupg_unsetenv/.
|
||||
|
||||
* protect.c (calibrate_get_time) [W32CE]: Use GetThreadTimes.
|
||||
|
||||
2010-04-06 Werner Koch <wk@g10code.com>
|
||||
|
||||
* call-scd.c [!HAVE_SIGNAL_H]: Do not include signal.h.
|
||||
|
||||
* findkey.c (agent_write_private_key): s/remove/gnupg_remove/.
|
||||
|
||||
* command-ssh.c (search_control_file): Replace rewind by fseek and
|
||||
clearerr.
|
||||
* genkey.c (check_passphrase_pattern): Ditto.
|
||||
|
||||
* gpg-agent.c [!HAVE_SIGNAL_H]: Do not include signal.h.
|
||||
(remove_socket): s/remove/gnupg_remove/.
|
||||
(create_private_keys_directory): Use gnupg_mkdir.
|
||||
|
||||
2010-03-11 Werner Koch <wk@g10code.com>
|
||||
|
||||
* gpg-agent.c: Include "asshelp.h".
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "agent.h"
|
||||
#include <assuan.h>
|
||||
#include "setenv.h"
|
||||
#include "sysutils.h"
|
||||
#include "i18n.h"
|
||||
|
||||
#ifdef _POSIX_OPEN_MAX
|
||||
|
@ -190,7 +190,7 @@ atfork_cb (void *opaque, int where)
|
|||
{
|
||||
value = session_env_getenv (ctrl->session_env, name);
|
||||
if (value)
|
||||
setenv (name, value, 1);
|
||||
gnupg_setenv (name, value, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ start_pinentry (ctrl_t ctrl)
|
|||
|
||||
if (!opt.pinentry_program || !*opt.pinentry_program)
|
||||
opt.pinentry_program = gnupg_module_name (GNUPG_MODULE_NAME_PINENTRY);
|
||||
pgmname = opt.pinentry_program;
|
||||
pgmname = opt.pinentry_program;
|
||||
if ( !(pgmname = strrchr (opt.pinentry_program, '/')))
|
||||
pgmname = opt.pinentry_program;
|
||||
else
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
|
@ -385,7 +387,9 @@ start_scd (ctrl_t ctrl)
|
|||
xfree (databuf);
|
||||
}
|
||||
|
||||
/* Tell the scdaemon we want him to send us an event signal. */
|
||||
/* Tell the scdaemon we want him to send us an event signal. We
|
||||
don't support this for W32CE. */
|
||||
#ifndef HAVE_W32CE_SYSTEM
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
|
@ -397,6 +401,7 @@ start_scd (ctrl_t ctrl)
|
|||
#endif
|
||||
assuan_transact (ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
#endif /*HAVE_W32CE_SYSTEM*/
|
||||
|
||||
primary_scd_ctx = ctx;
|
||||
primary_scd_ctx_reusable = 0;
|
||||
|
|
|
@ -721,7 +721,8 @@ search_control_file (FILE *fp, const char *hexgrip,
|
|||
|
||||
assert (strlen (hexgrip) == 40 );
|
||||
|
||||
rewind (fp);
|
||||
fseek (fp, 0, SEEK_SET);
|
||||
clearerr (fp);
|
||||
*r_disabled = 0;
|
||||
next_line:
|
||||
do
|
||||
|
|
|
@ -57,9 +57,8 @@ agent_write_private_key (const unsigned char *grip,
|
|||
const void *buffer, size_t length, int force)
|
||||
{
|
||||
char *fname;
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char hexgrip[40+4+1];
|
||||
int fd;
|
||||
|
||||
bin2hex (grip, 20, hexgrip);
|
||||
strcpy (hexgrip+40, ".key");
|
||||
|
@ -73,53 +72,30 @@ agent_write_private_key (const unsigned char *grip,
|
|||
return gpg_error (GPG_ERR_GENERAL);
|
||||
}
|
||||
|
||||
/* In FORCE mode we would like to create FNAME but only if it does
|
||||
not already exist. We cannot make this guarantee just using
|
||||
POSIX (GNU provides the "x" opentype for fopen, however, this is
|
||||
not portable). Thus, we use the more flexible open function and
|
||||
then use fdopen to obtain a stream. */
|
||||
fd = open (fname, force? (O_CREAT | O_TRUNC | O_WRONLY | O_BINARY)
|
||||
: (O_CREAT | O_EXCL | O_WRONLY | O_BINARY),
|
||||
S_IRUSR | S_IWUSR
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
| S_IRGRP
|
||||
#endif
|
||||
);
|
||||
if (fd < 0)
|
||||
fp = NULL;
|
||||
else
|
||||
{
|
||||
fp = fdopen (fd, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
int save_e = errno;
|
||||
close (fd);
|
||||
errno = save_e;
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: On POSIX systems we used include S_IRGRP as well. */
|
||||
fp = es_fopen (fname, force? "wb" : "wbx");
|
||||
if (!fp)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
log_error ("can't create `%s': %s\n", fname, strerror (errno));
|
||||
gpg_error_t tmperr = gpg_error_from_syserror ();
|
||||
log_error ("can't create `%s': %s\n", fname, gpg_strerror (tmperr));
|
||||
xfree (fname);
|
||||
return tmperr;
|
||||
}
|
||||
|
||||
if (fwrite (buffer, length, 1, fp) != 1)
|
||||
if (es_fwrite (buffer, length, 1, fp) != 1)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
log_error ("error writing `%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
remove (fname);
|
||||
gpg_error_t tmperr = gpg_error_from_syserror ();
|
||||
log_error ("error writing `%s': %s\n", fname, gpg_strerror (tmperr));
|
||||
es_fclose (fp);
|
||||
gnupg_remove (fname);
|
||||
xfree (fname);
|
||||
return tmperr;
|
||||
}
|
||||
if ( fclose (fp) )
|
||||
if (es_fclose (fp))
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
log_error ("error closing `%s': %s\n", fname, strerror (errno));
|
||||
remove (fname);
|
||||
gpg_error_t tmperr = gpg_error_from_syserror ();
|
||||
log_error ("error closing `%s': %s\n", fname, gpg_strerror (tmperr));
|
||||
gnupg_remove (fname);
|
||||
xfree (fname);
|
||||
return tmperr;
|
||||
}
|
||||
|
@ -425,7 +401,7 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
|
|||
{
|
||||
int rc;
|
||||
char *fname;
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
struct stat st;
|
||||
unsigned char *buf;
|
||||
size_t buflen, erroff;
|
||||
|
@ -438,7 +414,7 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
|
|||
strcpy (hexgrip+40, ".key");
|
||||
|
||||
fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
|
||||
fp = fopen (fname, "rb");
|
||||
fp = es_fopen (fname, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
rc = gpg_error_from_syserror ();
|
||||
|
@ -448,23 +424,36 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
|
|||
return rc;
|
||||
}
|
||||
|
||||
if (fstat (fileno(fp), &st))
|
||||
if (fstat (es_fileno (fp), &st))
|
||||
{
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("can't stat `%s': %s\n", fname, strerror (errno));
|
||||
xfree (fname);
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
return rc;
|
||||
}
|
||||
|
||||
buflen = st.st_size;
|
||||
buf = xtrymalloc (buflen+1);
|
||||
if (!buf || fread (buf, buflen, 1, fp) != 1)
|
||||
if (!buf)
|
||||
{
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("error reading `%s': %s\n", fname, strerror (errno));
|
||||
log_error ("error allocating %zu bytes for `%s': %s\n",
|
||||
buflen, fname, strerror (errno));
|
||||
xfree (fname);
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
if (es_fread (buf, buflen, 1, fp) != 1)
|
||||
{
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("error reading %zu bytes from `%s': %s\n",
|
||||
buflen, fname, strerror (errno));
|
||||
xfree (fname);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
return rc;
|
||||
}
|
||||
|
@ -472,7 +461,7 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
|
|||
/* Convert the file into a gcrypt S-expression object. */
|
||||
rc = gcry_sexp_sscan (&s_skey, &erroff, (char*)buf, buflen);
|
||||
xfree (fname);
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
if (rc)
|
||||
{
|
||||
|
|
|
@ -117,7 +117,8 @@ check_passphrase_pattern (ctrl_t ctrl, const char *pw)
|
|||
fclose (infp);
|
||||
return 1; /* Error - assume password should not be used. */
|
||||
}
|
||||
rewind (infp);
|
||||
fseek (infp, 0, SEEK_SET);
|
||||
clearerr (infp);
|
||||
|
||||
i = 0;
|
||||
argv[i++] = "--null";
|
||||
|
@ -134,7 +135,8 @@ check_passphrase_pattern (ctrl_t ctrl, const char *pw)
|
|||
result = 0; /* Success; i.e. no match. */
|
||||
|
||||
/* Overwrite our temporary file. */
|
||||
rewind (infp);
|
||||
fseek (infp, 0, SEEK_SET);
|
||||
clearerr (infp);
|
||||
for (i=((strlen (pw)+99)/100)*100; i > 0; i--)
|
||||
putc ('\xff', infp);
|
||||
fflush (infp);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* gpg-agent.c - The GnuPG Agent
|
||||
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
* 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009,
|
||||
* 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -35,7 +35,9 @@
|
|||
# include <sys/un.h>
|
||||
#endif /*!HAVE_W32_SYSTEM*/
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#include <pth.h>
|
||||
|
||||
#define JNLIB_NEED_LOG_LOGV
|
||||
|
@ -46,7 +48,6 @@
|
|||
#include "i18n.h"
|
||||
#include "mkdtemp.h" /* Gnulib replacement. */
|
||||
#include "sysutils.h"
|
||||
#include "setenv.h"
|
||||
#include "gc-opt-flags.h"
|
||||
#include "exechelp.h"
|
||||
#include "asshelp.h"
|
||||
|
@ -425,7 +426,7 @@ remove_socket (char *name)
|
|||
{
|
||||
char *p;
|
||||
|
||||
remove (name);
|
||||
gnupg_remove (name);
|
||||
p = strrchr (name, '/');
|
||||
if (p)
|
||||
{
|
||||
|
@ -615,7 +616,7 @@ main (int argc, char **argv )
|
|||
malloc_hooks.realloc = gcry_realloc;
|
||||
malloc_hooks.free = gcry_free;
|
||||
assuan_set_malloc_hooks (&malloc_hooks);
|
||||
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
|
||||
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
|
||||
assuan_set_system_hooks (ASSUAN_SYSTEM_PTH);
|
||||
assuan_sock_init ();
|
||||
setup_libassuan_logging (&opt.debug);
|
||||
|
@ -994,7 +995,7 @@ main (int argc, char **argv )
|
|||
exec the program given as arguments). */
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
if (!opt.keep_display && !argc)
|
||||
unsetenv ("DISPLAY");
|
||||
gnupg_unsetenv ("DISPLAY");
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1374,7 +1375,7 @@ get_agent_ssh_socket_name (void)
|
|||
/* Under W32, this function returns the handle of the scdaemon
|
||||
notification event. Calling it the first time creates that
|
||||
event. */
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
|
||||
void *
|
||||
get_agent_scd_notify_event (void)
|
||||
{
|
||||
|
@ -1412,7 +1413,7 @@ get_agent_scd_notify_event (void)
|
|||
log_debug ("returning notify handle %p\n", the_event);
|
||||
return the_event;
|
||||
}
|
||||
#endif /*HAVE_W32_SYSTEM*/
|
||||
#endif /*HAVE_W32_SYSTEM && !HAVE_W32CE_SYSTEM*/
|
||||
|
||||
|
||||
|
||||
|
@ -1510,7 +1511,7 @@ create_server_socket (char *name, int is_ssh, assuan_sock_nonce_t *nonce)
|
|||
assuan_sock_close (fd);
|
||||
agent_exit (2);
|
||||
}
|
||||
remove (name);
|
||||
gnupg_remove (name);
|
||||
rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
|
||||
}
|
||||
if (rc != -1
|
||||
|
@ -1556,15 +1557,9 @@ create_private_keys_directory (const char *home)
|
|||
fname = make_filename (home, GNUPG_PRIVATE_KEYS_DIR, NULL);
|
||||
if (stat (fname, &statbuf) && errno == ENOENT)
|
||||
{
|
||||
#ifdef HAVE_W32_SYSTEM /*FIXME: Setup proper permissions. */
|
||||
if (!CreateDirectory (fname, NULL))
|
||||
log_error (_("can't create directory `%s': %s\n"),
|
||||
fname, w32_strerror (-1) );
|
||||
#else
|
||||
if (mkdir (fname, S_IRUSR|S_IWUSR|S_IXUSR ))
|
||||
if (gnupg_mkdir (fname, "-rwx"))
|
||||
log_error (_("can't create directory `%s': %s\n"),
|
||||
fname, strerror (errno) );
|
||||
#endif
|
||||
else if (!opt.quiet)
|
||||
log_info (_("directory `%s' created\n"), fname);
|
||||
}
|
||||
|
@ -1601,15 +1596,9 @@ create_directories (void)
|
|||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
if (!CreateDirectory (home, NULL))
|
||||
log_error (_("can't create directory `%s': %s\n"),
|
||||
home, w32_strerror (-1) );
|
||||
#else
|
||||
if (mkdir (home, S_IRUSR|S_IWUSR|S_IXUSR ))
|
||||
if (gnupg_mkdir (home, "-rwx"))
|
||||
log_error (_("can't create directory `%s': %s\n"),
|
||||
home, strerror (errno) );
|
||||
#endif
|
||||
else
|
||||
{
|
||||
if (!opt.quiet)
|
||||
|
@ -1863,14 +1852,14 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
|||
pth_sigmask (SIG_UNBLOCK, &sigs, NULL);
|
||||
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
|
||||
#else
|
||||
# ifdef PTH_EVENT_HANDLE
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
|
||||
signo = 0;
|
||||
# else
|
||||
# ifdef HAVE_W32CE_SYSTEM
|
||||
/* Use a dummy event. */
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
|
||||
# else
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
|
||||
signo = 0;
|
||||
# endif
|
||||
#endif
|
||||
time_ev = NULL;
|
||||
|
|
|
@ -1249,14 +1249,14 @@ store_private_key (const unsigned char *grip,
|
|||
{
|
||||
log_error ("error writing `%s': %s\n", fname, strerror (errno));
|
||||
es_fclose (fp);
|
||||
remove (fname);
|
||||
gnupg_remove (fname);
|
||||
xfree (fname);
|
||||
return -1;
|
||||
}
|
||||
if (es_fclose (fp))
|
||||
{
|
||||
log_error ("error closing `%s': %s\n", fname, strerror (errno));
|
||||
remove (fname);
|
||||
gnupg_remove (fname);
|
||||
xfree (fname);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,11 @@ static void
|
|||
calibrate_get_time (struct calibrate_time_s *data)
|
||||
{
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
# ifdef HAVE_W32CE_SYSTEM
|
||||
GetThreadTimes (GetCurrentThread (),
|
||||
# else
|
||||
GetProcessTimes (GetCurrentProcess (),
|
||||
# endif
|
||||
&data->creation_time, &data->exit_time,
|
||||
&data->kernel_time, &data->user_time);
|
||||
#else
|
||||
|
|
|
@ -116,7 +116,7 @@ read_one_trustfile (const char *fname, int allow_include,
|
|||
int *addr_of_tableidx)
|
||||
{
|
||||
gpg_error_t err = 0;
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
int n, c;
|
||||
char *p, line[256];
|
||||
trustitem_t *table, *ti;
|
||||
|
@ -128,7 +128,7 @@ read_one_trustfile (const char *fname, int allow_include,
|
|||
tablesize = *addr_of_tablesize;
|
||||
tableidx = *addr_of_tableidx;
|
||||
|
||||
fp = fopen (fname, "r");
|
||||
fp = es_fopen (fname, "r");
|
||||
if (!fp)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
|
@ -136,14 +136,14 @@ read_one_trustfile (const char *fname, int allow_include,
|
|||
goto leave;
|
||||
}
|
||||
|
||||
while (fgets (line, DIM(line)-1, fp))
|
||||
while (es_fgets (line, DIM(line)-1, fp))
|
||||
{
|
||||
lnr++;
|
||||
|
||||
if (!*line || line[strlen(line)-1] != '\n')
|
||||
{
|
||||
/* Eat until end of line. */
|
||||
while ( (c=getc (fp)) != EOF && c != '\n')
|
||||
while ( (c=es_getc (fp)) != EOF && c != '\n')
|
||||
;
|
||||
err = gpg_error (*line? GPG_ERR_LINE_TOO_LONG
|
||||
: GPG_ERR_INCOMPLETE_LINE);
|
||||
|
@ -288,7 +288,7 @@ read_one_trustfile (const char *fname, int allow_include,
|
|||
}
|
||||
tableidx++;
|
||||
}
|
||||
if ( !err && !feof (fp) )
|
||||
if ( !err && !es_feof (fp) )
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error (_("error reading `%s', line %d: %s\n"),
|
||||
|
@ -296,8 +296,7 @@ read_one_trustfile (const char *fname, int allow_include,
|
|||
}
|
||||
|
||||
leave:
|
||||
if (fp)
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
*addr_of_table = table;
|
||||
*addr_of_tablesize = tablesize;
|
||||
*addr_of_tableidx = tableidx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue