From 0acdd92bc0b1fec24474c66eb9536bc282c6483f Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 9 Mar 2013 18:24:31 -0500 Subject: [PATCH] Use gpg_error_from_errno() and not gpg_error_from_syserror(). Fixes OpenSolaris problems. May be do to multithreading. --- src/agent.c | 8 ++++---- src/cache.c | 3 ++- src/commands.c | 6 +++--- src/convert.c | 9 +++++---- src/crypto.c | 46 +++++++++++++++++++++++----------------------- src/pinentry.c | 2 +- src/pwmd.c | 45 +++++++++++++++++++++++---------------------- src/rcfile.c | 2 +- src/status.c | 13 +++++++------ src/tls.c | 2 ++ src/util-misc.c | 4 ++-- 11 files changed, 73 insertions(+), 67 deletions(-) diff --git a/src/agent.c b/src/agent.c index 89a565f8..6ff520d2 100644 --- a/src/agent.c +++ b/src/agent.c @@ -165,7 +165,7 @@ launch_agent (struct agent_s *agent) fclose (fp); } else - log_write ("%s: %s", s, pwmd_strerror (gpg_error_from_syserror ())); + log_write ("%s: %s", s, pwmd_strerror (gpg_error_from_errno (errno))); xfree (s); } @@ -1009,7 +1009,7 @@ inquire_keyfile (void *user, const char *keyword) return gpg_error (GPG_ERR_ASS_UNKNOWN_INQUIRE); if (stat (filename, &st) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); if (crypto->agent->inquire_maxlen && st.st_size > crypto->agent->inquire_maxlen) @@ -1025,7 +1025,7 @@ inquire_keyfile (void *user, const char *keyword) fd = open (filename, O_RDONLY); if (fd == -1) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); else { len = read (fd, buf, st.st_size); @@ -1036,7 +1036,7 @@ inquire_keyfile (void *user, const char *keyword) assuan_end_confidential (crypto->agent->ctx); } else if (len == -1) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); else rc = GPG_ERR_BUFFER_TOO_SHORT; } diff --git a/src/cache.c b/src/cache.c index 3802930c..4575f42c 100644 --- a/src/cache.c +++ b/src/cache.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "pwmd-error.h" #include @@ -497,7 +498,7 @@ cache_iscached (const char *filename, int *defer) unsigned char md5file[16]; if (access (filename, R_OK) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); MUTEX_LOCK (&cache_mutex); pthread_cleanup_push (cleanup_mutex_cb, &cache_mutex); diff --git a/src/commands.c b/src/commands.c index b483f881..82104b74 100644 --- a/src/commands.c +++ b/src/commands.c @@ -788,7 +788,7 @@ parse_save_opt_iterations (void *data, void *value) errno = 0; n = strtoull (v, &p, 10); if (n == UINT64_MAX && errno) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); else if (p && *p) return GPG_ERR_INV_VALUE; @@ -964,7 +964,7 @@ save_command (assuan_context_t ctx, char *line) return send_error (ctx, GPG_ERR_WRONG_KEY_USAGE); if (lstat (client->filename, &st) == -1 && errno != ENOENT) - return send_error (ctx, gpg_error_from_syserror ()); + return send_error (ctx, gpg_error_from_errno (errno)); if (errno != ENOENT && !S_ISREG (st.st_mode)) { @@ -3769,7 +3769,7 @@ ls_command (assuan_context_t ctx, char *line) char *dir = expand_homedir (tmp); DIR *d = opendir (dir); - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); xfree (tmp); if (!d) diff --git a/src/convert.c b/src/convert.c index 1272733e..6b64ee89 100644 --- a/src/convert.c +++ b/src/convert.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "pwmd-error.h" #include @@ -317,11 +318,11 @@ read_v2_datafile (const char *filename, const char *keyfile, FILE *fp; if (stat (filename, &st) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); fd = open (filename, O_RDONLY); if (fd == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); len = read (fd, &fh, sizeof (fh) - 8); if (len != sizeof (fh) - 8) @@ -383,13 +384,13 @@ read_v2_datafile (const char *filename, const char *keyfile, if (pfd == -1) { - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); goto fail; } if (stat (keyfile, &pst) == -1) { - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); close (pfd); goto fail; } diff --git a/src/crypto.c b/src/crypto.c index 0e4325bd..08b6fe9f 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -137,7 +137,7 @@ read_header (file_header_t *hdr, int fd) #endif done: - return len == -1 ? gpg_error_from_syserror () : 0; + return len == -1 ? gpg_error_from_errno (errno) : 0; } /* Read the header of a data file to determine cipher and other. The @@ -153,14 +153,14 @@ read_data_header (const char *filename, file_header_t * rhdr, int fd; if (lstat (filename, &st) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); if (!S_ISREG (st.st_mode)) return gpg_error (GPG_ERR_ENOANO); fd = open (filename, O_RDONLY); if (fd == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); rc = read_header (&hdr, fd); if (!rc && memcmp (hdr.magic, pwmd_magic, sizeof (hdr.magic))) @@ -214,14 +214,14 @@ read_data_file (const char *filename, struct crypto_s * crypto) rlen = read (fd, crypto->grip, 20); if (rlen != 20) { - rc = rc == -1 ? gpg_error_from_syserror () : GPG_ERR_BAD_DATA; + rc = rc == -1 ? gpg_error_from_errno (errno) : GPG_ERR_BAD_DATA; goto done; } rlen = read (fd, crypto->sign_grip, 20); if (rlen != 20) { - rc = rc == -1 ? gpg_error_from_syserror () : GPG_ERR_BAD_DATA; + rc = rc == -1 ? gpg_error_from_errno (errno) : GPG_ERR_BAD_DATA; goto done; } } @@ -229,7 +229,7 @@ read_data_file (const char *filename, struct crypto_s * crypto) len = read (fd, crypto->ciphertext, crypto->hdr.datalen); if (len != crypto->hdr.datalen) { - rc = rc == -1 ? gpg_error_from_syserror () : GPG_ERR_BAD_DATA; + rc = rc == -1 ? gpg_error_from_errno (errno) : GPG_ERR_BAD_DATA; goto done; } @@ -255,7 +255,7 @@ read_data_file (const char *filename, struct crypto_s * crypto) rlen = read (fd, buf, len); if (rlen != len) { - rc = rc == -1 ? gpg_error_from_syserror () : GPG_ERR_BAD_DATA; + rc = rc == -1 ? gpg_error_from_errno (errno) : GPG_ERR_BAD_DATA; goto done; } @@ -853,7 +853,7 @@ export_common (assuan_context_t ctx, int inquire, struct crypto_s * crypto, struct stat st; if (stat (keyfile, &st) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); buf = gcry_malloc (st.st_size); if (!buf) @@ -861,7 +861,7 @@ export_common (assuan_context_t ctx, int inquire, struct crypto_s * crypto, fd = open (keyfile, O_RDONLY); if (fd == -1) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); else { len = read (fd, buf, st.st_size); @@ -1081,7 +1081,7 @@ write_header (struct crypto_s *crypto, int fd) #endif done: - return len == -1 ? gpg_error_from_syserror () : 0; + return len == -1 ? gpg_error_from_errno (errno) : 0; } /* Write the data structures to disk. */ @@ -1110,13 +1110,13 @@ write_file (struct crypto_s *crypto, const char *filename, return GPG_ERR_EACCES; } else if (errno != ENOENT) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); snprintf (tmp, sizeof (tmp), "%s.XXXXXX", filename); fd = mkstemp (tmp); if (fd == -1) { - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); log_write ("%s: %s", tmp, pwmd_strerror (rc)); return rc; } @@ -1149,20 +1149,20 @@ write_file (struct crypto_s *crypto, const char *filename, { len = write (fd, sexp, sexp_len); if (len != sexp_len) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } else - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } } else - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } else { len = write (fd, data, data_len); if (len != data_len) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } } @@ -1181,7 +1181,7 @@ write_file (struct crypto_s *crypto, const char *filename, acl = acl_get_file (".", ACL_TYPE_DEFAULT); if (!acl) log_write ("ACL: %s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); #endif if (mode && config_get_boolean (filename, "backup")) @@ -1190,14 +1190,14 @@ write_file (struct crypto_s *crypto, const char *filename, snprintf (tmp2, sizeof (tmp2), "%s.backup", filename); if (rename (filename, tmp2) == -1) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } } else if (filename) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } else - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } if (!rc) @@ -1211,11 +1211,11 @@ write_file (struct crypto_s *crypto, const char *filename, #ifdef WITH_LIBACL if (acl && acl_set_file (filename, ACL_TYPE_ACCESS, acl)) log_write ("ACL: %s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); #endif } else - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); } #ifdef WITH_LIBACL @@ -1461,7 +1461,7 @@ decrypt_common (assuan_context_t ctx, int inquire, struct crypto_s *crypto, fd = open (key, O_RDONLY); if (fd == -1) { - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); log_write ("%s: %s", key, pwmd_strerror (rc)); xfree (key); return rc; diff --git a/src/pinentry.c b/src/pinentry.c index 021e4e99..a98fcfbe 100644 --- a/src/pinentry.c +++ b/src/pinentry.c @@ -162,7 +162,7 @@ set_pinentry_options (struct pinentry_s *pin) tty = pin->pinentry_opts.ttyname ? pin->pinentry_opts.ttyname : ttyname (STDOUT_FILENO); if (!tty) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); } if (!have_display && !tty) diff --git a/src/pwmd.c b/src/pwmd.c index 0bc5f42b..0e6969cd 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -47,6 +47,7 @@ #include #include #include +#include #ifdef TM_IN_SYS_TIME #include @@ -1122,7 +1123,7 @@ xml_import (const char *filename, const char *outfile, if (stat (filename, &st) == -1) { log_write ("%s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); return 0; } @@ -1138,7 +1139,7 @@ xml_import (const char *filename, const char *outfile, if ((fd = open (filename, O_RDONLY)) == -1) { log_write ("%s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); goto fail; } @@ -1152,7 +1153,7 @@ xml_import (const char *filename, const char *outfile, if (read (fd, xmlbuf, st.st_size) == -1) { - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); close (fd); log_write ("%s: %s", filename, pwmd_strerror (rc)); goto fail; @@ -1330,7 +1331,7 @@ init_client (int fd, const char *addr) pthread_cleanup_push (cleanup_mutex_cb, &cn_mutex); if (pipe (new->status_msg_pipe) == -1) - rc = gpg_error_from_syserror (); + rc = gpg_error_from_errno (errno); if (!rc) { @@ -1469,7 +1470,7 @@ tcp_accept_thread (void *arg) { if (errno == EMFILE || errno == ENFILE) log_write ("accept(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); else if (errno != EAGAIN) { if (!quit) // probably EBADF @@ -1589,7 +1590,7 @@ start_stop_tls_with_protocol (int ipv6, int term) if (setsockopt (*fd, SOL_SOCKET, SO_REUSEADDR, &r, sizeof (int)) == -1) { log_write ("setsockopt(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); freeaddrinfo (servinfo); goto fail; } @@ -1598,7 +1599,7 @@ start_stop_tls_with_protocol (int ipv6, int term) { close (*fd); log_write ("bind(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); continue; } @@ -1617,7 +1618,7 @@ start_stop_tls_with_protocol (int ipv6, int term) strlen (tmp)) == -1) { log_write ("setsockopt(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); xfree (tmp); goto fail; } @@ -1733,12 +1734,12 @@ accept_thread (void *arg) { if (errno == EMFILE || errno == ENFILE) log_write ("accept(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); else if (errno != EAGAIN) { if (!quit) // probably EBADF log_write ("accept(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); break; } @@ -2209,7 +2210,7 @@ convert_v2_datafile (const char *filename, const char *cipher, if (access (filename, R_OK) == -1) { log_write ("%s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); return 0; } @@ -2220,7 +2221,7 @@ convert_v2_datafile (const char *filename, const char *cipher, if (access (keyfile, R_OK) == -1) { log_write ("%s: %s", keyfile, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); return 0; } } @@ -2661,7 +2662,7 @@ main (int argc, char *argv[]) if (setpriority (PRIO_PROCESS, 0, x) == -1) { log_write ("setpriority(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; } } @@ -2669,7 +2670,7 @@ main (int argc, char *argv[]) if (disable_mlock == 0 && mlockall (MCL_CURRENT | MCL_FUTURE) == -1) { log_write ("mlockall(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; } #endif @@ -2755,7 +2756,7 @@ main (int argc, char *argv[]) if (chdir (datadir)) { log_write ("%s: %s", datadir, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); unlink (socketpath); goto do_exit; } @@ -2821,7 +2822,7 @@ main (int argc, char *argv[]) if (chdir (socketdir)) { log_write ("%s: %s", socketdir, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; } @@ -2829,7 +2830,7 @@ main (int argc, char *argv[]) if ((sockfd = socket (PF_UNIX, SOCK_STREAM, 0)) == -1) { - log_write ("socket(): %s", pwmd_strerror (gpg_error_from_syserror ())); + log_write ("socket(): %s", pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; } @@ -2839,7 +2840,7 @@ main (int argc, char *argv[]) if (bind (sockfd, (struct sockaddr *) &addr, sizeof (struct sockaddr)) == -1) { - log_write ("bind(): %s", pwmd_strerror (gpg_error_from_syserror ())); + log_write ("bind(): %s", pwmd_strerror (gpg_error_from_errno (errno))); if (errno == EADDRINUSE) { @@ -2865,7 +2866,7 @@ main (int argc, char *argv[]) if (chmod (socketname, mode) == -1) { log_write ("%s: %s", socketname, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); close (sockfd); umask (mask); goto do_exit; @@ -2880,7 +2881,7 @@ main (int argc, char *argv[]) if (chdir (datadir)) { log_write ("%s: %s", datadir, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); close (sockfd); goto do_exit; } @@ -2889,7 +2890,7 @@ main (int argc, char *argv[]) if (listen (sockfd, 0) == -1) { - log_write ("listen(): %s", pwmd_strerror (gpg_error_from_syserror ())); + log_write ("listen(): %s", pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; } @@ -2901,7 +2902,7 @@ main (int argc, char *argv[]) { case -1: log_write ("fork(): %s", - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); goto do_exit; case 0: close (0); diff --git a/src/rcfile.c b/src/rcfile.c index 6cc3b5d5..ac7bf12d 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -907,7 +907,7 @@ config_parse (const char *filename) if (!fp) { log_write ("%s: %s", filename, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); if (errno != ENOENT) return NULL; diff --git a/src/status.c b/src/status.c index e5a7853a..0dc11bca 100644 --- a/src/status.c +++ b/src/status.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef HAVE_LINUX_SOCKIOS_H #include @@ -130,11 +131,11 @@ send_status (assuan_context_t ctx, status_msg_t which, const char *fmt, ...) #ifdef HAVE_DECL_SIOCOUTQ if (ioctl (client->thd->fd, SIOCOUTQ, &buffered) == -1) log_write ("%s(%i): ioctl: %s", __FUNCTION__, __LINE__, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); #elif defined (HAVE_DECL_FIONWRITE) if (ioctl (client->thd->fd, FIONWRITE, &buffered) == -1) log_write ("%s(%i): ioctl: %s", __FUNCTION__, __LINE__, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); #else if (1) { @@ -144,7 +145,7 @@ send_status (assuan_context_t ctx, status_msg_t which, const char *fmt, ...) if (getsockopt (client->thd->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, &len) == -1) log_write ("%s(%i): getsockopt: %s", __FUNCTION__, __LINE__, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); else { int lowat; @@ -153,7 +154,7 @@ send_status (assuan_context_t ctx, status_msg_t which, const char *fmt, ...) if (getsockopt (client->thd->fd, SOL_SOCKET, SO_SNDLOWAT, &lowat, &len) == -1) log_write ("%s(%i): getsockopt: %s", __FUNCTION__, - __LINE__, pwmd_strerror (gpg_error_from_syserror ())); + __LINE__, pwmd_strerror (gpg_error_from_errno (errno))); else { len = sizeof(int); @@ -161,7 +162,7 @@ send_status (assuan_context_t ctx, status_msg_t which, const char *fmt, ...) &sndbuf, len) == -1) log_write ("%s(%i): setsockopt: %s", __FUNCTION__, __LINE__, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); else { struct timeval tv = { 0, 0 }; @@ -177,7 +178,7 @@ send_status (assuan_context_t ctx, status_msg_t which, const char *fmt, ...) &lowat, len) == -1) log_write ("%s(%i): setsockopt: %s", __FUNCTION__, __LINE__, - pwmd_strerror (gpg_error_from_syserror ())); + pwmd_strerror (gpg_error_from_errno (errno))); if (n > 0 && FD_ISSET (client->thd->fd, &wfds)) buffered = 0; } diff --git a/src/tls.c b/src/tls.c index 68679625..117ff323 100644 --- a/src/tls.c +++ b/src/tls.c @@ -23,6 +23,8 @@ #include #endif +#include + #include "pwmd-error.h" #include "mem.h" #include "util-misc.h" diff --git a/src/util-misc.c b/src/util-misc.c index 496a3462..4aedf6ce 100644 --- a/src/util-misc.c +++ b/src/util-misc.c @@ -490,11 +490,11 @@ get_checksum (const char *filename, unsigned char **r_crc, size_t * r_crclen) struct stat st; if (stat (filename, &st) == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); fd = open (filename, O_RDONLY); if (fd == -1) - return gpg_error_from_syserror (); + return gpg_error_from_errno (errno); pthread_cleanup_push (cleanup_fd_cb, &fd); buf = xmalloc (st.st_size); -- 2.11.4.GIT