mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Replace all calls to stat by gnupg_stat.
* common/sysutils.c (gnupg_stat): New. * common/sysutils.h: Include sys/stat.h. -- Yet another wrapper for Unicode support on Windows. GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <wk@gnupg.org> Backported-from-master: 18e5dd7b03ced51611c9ba1345cf498a0aaf14a6)
This commit is contained in:
parent
86e52e3c33
commit
157030271f
@ -2307,7 +2307,7 @@ create_private_keys_directory (const char *home)
|
||||
struct stat statbuf;
|
||||
|
||||
fname = make_filename (home, GNUPG_PRIVATE_KEYS_DIR, NULL);
|
||||
if (stat (fname, &statbuf) && errno == ENOENT)
|
||||
if (gnupg_stat (fname, &statbuf) && errno == ENOENT)
|
||||
{
|
||||
if (gnupg_mkdir (fname, "-rwx"))
|
||||
log_error (_("can't create directory '%s': %s\n"),
|
||||
@ -2346,7 +2346,7 @@ create_directories (void)
|
||||
char *home;
|
||||
|
||||
home = make_filename (gnupg_homedir (), NULL);
|
||||
if ( stat (home, &statbuf) )
|
||||
if (gnupg_stat (home, &statbuf))
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
@ -2434,7 +2434,7 @@ handle_tick (void)
|
||||
/* Check whether the homedir is still available. */
|
||||
if (!shutdown_pending
|
||||
&& (!have_homedir_inotify || !reliable_homedir_inotify)
|
||||
&& stat (gnupg_homedir (), &statbuf) && errno == ENOENT)
|
||||
&& gnupg_stat (gnupg_homedir (), &statbuf) && errno == ENOENT)
|
||||
{
|
||||
shutdown_pending = 1;
|
||||
log_info ("homedir has been removed - shutting down\n");
|
||||
|
@ -78,7 +78,7 @@ gnupg_amkdir_p (const char **directory_components)
|
||||
|
||||
/* log_debug ("%s: stat(%s)\n", __func__, dirs[i]); */
|
||||
|
||||
if (!stat (dirs[i], &s))
|
||||
if (!gnupg_stat (dirs[i], &s))
|
||||
{
|
||||
if ( ! S_ISDIR (s.st_mode))
|
||||
{
|
||||
|
@ -1107,6 +1107,49 @@ gnupg_access (const char *name, int mode)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* A wrapper around stat to handle Unicode file names under Windows. */
|
||||
#ifdef HAVE_STAT
|
||||
int
|
||||
gnupg_stat (const char *name, struct stat *statbuf)
|
||||
{
|
||||
# ifdef HAVE_W32_SYSTEM
|
||||
if (any8bitchar (name))
|
||||
{
|
||||
wchar_t *wname;
|
||||
struct _stat32 st32;
|
||||
int ret;
|
||||
|
||||
wname = utf8_to_wchar (name);
|
||||
if (!wname)
|
||||
return -1;
|
||||
ret = _wstat (wname, &st32);
|
||||
xfree (wname);
|
||||
if (!ret)
|
||||
{
|
||||
statbuf->st_dev = st32.st_dev;
|
||||
statbuf->st_ino = st32.st_ino;
|
||||
statbuf->st_mode = st32.st_mode;
|
||||
statbuf->st_nlink = st32.st_nlink;
|
||||
statbuf->st_uid = st32.st_uid;
|
||||
statbuf->st_gid = st32.st_gid;
|
||||
statbuf->st_rdev = st32.st_rdev;
|
||||
statbuf->st_size = st32.st_size;
|
||||
statbuf->st_atime = st32.st_atime;
|
||||
statbuf->st_mtime = st32.st_mtime;
|
||||
statbuf->st_ctime = st32.st_ctime;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return stat (name, statbuf);
|
||||
# else
|
||||
return stat (name, statbuf);
|
||||
# endif
|
||||
}
|
||||
#endif /*HAVE_STAT*/
|
||||
|
||||
|
||||
/* A wrapper around open to handle Unicode file names under Windows. */
|
||||
int
|
||||
gnupg_open (const char *name, int flags, unsigned int mode)
|
||||
|
@ -46,6 +46,9 @@ typedef int gnupg_fd_t;
|
||||
#define FD2INT(h) (h)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STAT
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
void trap_unaligned (void);
|
||||
int disable_core_dumps (void);
|
||||
@ -73,6 +76,9 @@ int gnupg_setenv (const char *name, const char *value, int overwrite);
|
||||
int gnupg_unsetenv (const char *name);
|
||||
char *gnupg_getcwd (void);
|
||||
gpg_err_code_t gnupg_access (const char *name, int mode);
|
||||
#ifdef HAVE_STAT
|
||||
int gnupg_stat (const char *name, struct stat *statbuf);
|
||||
#endif /*HAVE_STAT*/
|
||||
int gnupg_open (const char *name, int flags, unsigned int mode);
|
||||
char *gnupg_get_socket_name (int fd);
|
||||
int gnupg_fd_valid (int fd);
|
||||
|
@ -271,7 +271,7 @@ cleanup_cache_dir (int force)
|
||||
if (force)
|
||||
okay = 1;
|
||||
else
|
||||
okay = (!stat (cdbname, &sbuf) && S_ISREG (sbuf.st_mode));
|
||||
okay = (!gnupg_stat (cdbname, &sbuf) && S_ISREG (sbuf.st_mode));
|
||||
|
||||
if (okay)
|
||||
{
|
||||
|
@ -2044,7 +2044,7 @@ handle_tick (void)
|
||||
|
||||
/* Check whether the homedir is still available. */
|
||||
if (!shutdown_pending
|
||||
&& stat (gnupg_homedir (), &statbuf) && errno == ENOENT)
|
||||
&& gnupg_stat (gnupg_homedir (), &statbuf) && errno == ENOENT)
|
||||
{
|
||||
shutdown_pending = 1;
|
||||
log_info ("homedir has been removed - shutting down\n");
|
||||
|
@ -1501,7 +1501,7 @@ check_permissions (const char *path, int item)
|
||||
}
|
||||
|
||||
/* It's okay if the file or directory doesn't exist */
|
||||
if(stat(tmppath,&statbuf)!=0)
|
||||
if (gnupg_stat (tmppath,&statbuf))
|
||||
{
|
||||
ret=0;
|
||||
goto end;
|
||||
@ -1512,7 +1512,7 @@ check_permissions (const char *path, int item)
|
||||
I'm stopping at one level down. */
|
||||
dir=make_dirname(tmppath);
|
||||
|
||||
if(stat(dir,&dirbuf)!=0 || !S_ISDIR(dirbuf.st_mode))
|
||||
if (gnupg_stat (dir,&dirbuf) || !S_ISDIR (dirbuf.st_mode))
|
||||
{
|
||||
/* Weird error */
|
||||
ret=1;
|
||||
|
@ -1371,7 +1371,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname, const char *fname)
|
||||
|
||||
statbuf.st_mode=S_IRUSR | S_IWUSR;
|
||||
|
||||
if (!stat (bakfname, &statbuf) && !chmod (fname, statbuf.st_mode))
|
||||
if (!gnupg_stat (bakfname, &statbuf) && !chmod (fname, statbuf.st_mode))
|
||||
;
|
||||
else
|
||||
log_error ("WARNING: unable to restore permissions to '%s': %s",
|
||||
|
@ -102,7 +102,7 @@ register_secured_file (const char *fname)
|
||||
struct secured_file_item *sf;
|
||||
|
||||
/* Note that we stop immediately if something goes wrong here. */
|
||||
if (stat (fname, &buf))
|
||||
if (gnupg_stat (fname, &buf))
|
||||
log_fatal (_("fstat of '%s' failed in %s: %s\n"), fname,
|
||||
"register_secured_file", strerror (errno));
|
||||
/* log_debug ("registering '%s' i=%lu.%lu\n", fname, */
|
||||
@ -131,7 +131,7 @@ unregister_secured_file (const char *fname)
|
||||
struct stat buf;
|
||||
struct secured_file_item *sf, *sfprev;
|
||||
|
||||
if (stat (fname, &buf))
|
||||
if (gnupg_stat (fname, &buf))
|
||||
{
|
||||
log_error (_("fstat of '%s' failed in %s: %s\n"), fname,
|
||||
"unregister_secured_file", strerror (errno));
|
||||
@ -205,7 +205,7 @@ is_secured_filename (const char *fname)
|
||||
|
||||
/* Note that we print out a error here and claim that a file is
|
||||
secure if something went wrong. */
|
||||
if (stat (fname, &buf))
|
||||
if (gnupg_stat (fname, &buf))
|
||||
{
|
||||
if (errno == ENOENT || errno == EPERM || errno == EACCES)
|
||||
return 0;
|
||||
|
@ -409,7 +409,7 @@ get_openpgp_revocdir (const char *home)
|
||||
struct stat statbuf;
|
||||
|
||||
fname = make_filename (home, GNUPG_OPENPGP_REVOC_DIR, NULL);
|
||||
if (stat (fname, &statbuf) && errno == ENOENT)
|
||||
if (gnupg_stat (fname, &statbuf) && errno == ENOENT)
|
||||
{
|
||||
if (gnupg_mkdir (fname, "-rwx"))
|
||||
log_error (_("can't create directory '%s': %s\n"),
|
||||
|
@ -681,7 +681,7 @@ tdbio_set_dbname (ctrl_t ctrl, const char *new_dbname,
|
||||
* trustdb.gpg. This check is not required in theory, but it helps
|
||||
* in practice avoiding costly operations of preparing and taking
|
||||
* the lock. */
|
||||
if (!stat (fname, &statbuf) && statbuf.st_size > 0)
|
||||
if (!gnupg_stat (fname, &statbuf) && statbuf.st_size > 0)
|
||||
{
|
||||
/* OK, we have the valid trustdb.gpg already. */
|
||||
return 0;
|
||||
@ -722,7 +722,7 @@ tdbio_set_dbname (ctrl_t ctrl, const char *new_dbname,
|
||||
take_write_lock ();
|
||||
|
||||
if (gnupg_access (fname, R_OK)
|
||||
|| stat (fname, &statbuf)
|
||||
|| gnupg_stat (fname, &statbuf)
|
||||
|| statbuf.st_size == 0)
|
||||
{
|
||||
estream_t fp;
|
||||
|
@ -197,7 +197,7 @@ begin_transaction (ctrl_t ctrl, int only_batch)
|
||||
/* Check if another process wants to run. (We just ignore any
|
||||
* stat failure. A waiter might have to wait a bit longer, but
|
||||
* otherwise there should be no impact.) */
|
||||
if (stat (dbs->want_lock_file, &statbuf) == 0
|
||||
if (gnupg_stat (dbs->want_lock_file, &statbuf) == 0
|
||||
&& statbuf.st_ctime != dbs->want_lock_file_ctime)
|
||||
{
|
||||
end_transaction (ctrl, 2);
|
||||
@ -237,7 +237,7 @@ begin_transaction (ctrl_t ctrl, int only_batch)
|
||||
dbs->in_batch_transaction = 1;
|
||||
dbs->batch_update_started = gnupg_get_time ();
|
||||
|
||||
if (stat (dbs->want_lock_file, &statbuf) == 0)
|
||||
if (gnupg_stat (dbs->want_lock_file, &statbuf) == 0)
|
||||
dbs->want_lock_file_ctime = statbuf.st_ctime;
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ be_take_lock_for_create (ctrl_t ctrl, const char *fname, dotlock_t *r_lock)
|
||||
}
|
||||
|
||||
/* Check again that the file does not exist. */
|
||||
err = stat (fname, &sb)? 0 : gpg_error (GPG_ERR_EEXIST);
|
||||
err = gnupg_stat (fname, &sb)? 0 : gpg_error (GPG_ERR_EEXIST);
|
||||
|
||||
leave:
|
||||
if (!err)
|
||||
|
@ -250,7 +250,7 @@ g13_create_container (ctrl_t ctrl, const char *filename)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (!stat (detachedname, &sb))
|
||||
if (!gnupg_stat (detachedname, &sb))
|
||||
{
|
||||
err = gpg_error (GPG_ERR_EEXIST);
|
||||
goto leave;
|
||||
|
@ -121,7 +121,7 @@ g13_mount_container (ctrl_t ctrl, const char *filename, const char *mountpoint)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat (filename, &sb))
|
||||
if (gnupg_stat (filename, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
|
@ -94,7 +94,7 @@ check_blockdev (const char *devname, int expect_busy)
|
||||
char **fields = NULL;
|
||||
int lno, count;
|
||||
|
||||
if (stat (devname, &sb))
|
||||
if (gnupg_stat (devname, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error stating '%s': %s\n", devname, gpg_strerror (err));
|
||||
|
@ -307,7 +307,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat (opt.directory, &sb))
|
||||
if (gnupg_stat (opt.directory, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error accessing directory '%s': %s\n",
|
||||
|
@ -332,7 +332,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat (opt.directory, &sb))
|
||||
if (gnupg_stat (opt.directory, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error accessing directory '%s': %s\n",
|
||||
@ -1640,7 +1640,7 @@ get_domain_list (strlist_t *r_list)
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (stat (fname, &sb))
|
||||
if (gnupg_stat (fname, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error accessing '%s': %s\n", fname, gpg_strerror (err));
|
||||
@ -1718,7 +1718,7 @@ expire_one_domain (const char *top_dirname, const char *domain)
|
||||
log_info ("garbage file '%s' ignored\n", fname);
|
||||
continue;
|
||||
}
|
||||
if (stat (fname, &sb))
|
||||
if (gnupg_stat (fname, &sb))
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error accessing '%s': %s\n", fname, gpg_strerror (err));
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "gpgtar.h"
|
||||
|
||||
#ifndef HAVE_LSTAT
|
||||
#define lstat(a,b) stat ((a), (b))
|
||||
#define lstat(a,b) gnupg_stat ((a), (b))
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -843,13 +843,13 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
|
||||
|
||||
/* Try to create missing directories below opt.directory. */
|
||||
fname = make_filename_try (opt.directory, domain, NULL);
|
||||
if (fname && stat (fname, &sb)
|
||||
if (fname && gnupg_stat (fname, &sb)
|
||||
&& gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
|
||||
if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
|
||||
log_info ("directory '%s' created\n", fname);
|
||||
xfree (fname);
|
||||
fname = make_filename_try (opt.directory, domain, "hu", NULL);
|
||||
if (fname && stat (fname, &sb)
|
||||
if (fname && gnupg_stat (fname, &sb)
|
||||
&& gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
|
||||
if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
|
||||
log_info ("directory '%s' created\n", fname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user