| diff -Naur libsecret-0.19.1.orig/configure.ac libsecret-0.19.1/configure.ac |
| --- libsecret-0.19.1.orig/configure.ac 2019-09-08 22:13:01.644668900 -0400 |
| +++ libsecret-0.19.1/configure.ac 2019-09-08 22:14:13.969779900 -0400 |
| @@ -96,7 +96,7 @@ |
| PKG_CHECK_MODULES(GLIB, |
| glib-2.0 >= $GLIB_REQ |
| gio-2.0 |
| - gio-unix-2.0) |
| + gio-windows-2.0) |
| LIBS="$LIBS $GLIB_LIBS" |
| CFLAGS="$CFLAGS $GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=$GLIB_MIN -DGLIB_VERSION_MAX_ALLOWED=$GLIB_MAX" |
| |
| diff -Naur libsecret-0.19.1.orig/egg/egg-secure-memory.c libsecret-0.19.1/egg/egg-secure-memory.c |
| --- libsecret-0.19.1.orig/egg/egg-secure-memory.c 2019-09-08 22:13:01.660294400 -0400 |
| +++ libsecret-0.19.1/egg/egg-secure-memory.c 2019-09-08 22:18:08.797436800 -0400 |
| @@ -31,7 +31,11 @@ |
| #include "egg-secure-memory.h" |
| |
| #include <sys/types.h> |
| +#ifndef _WIN32 |
| #include <sys/mman.h> |
| +#else |
| +#include <windows.h> |
| +#endif |
| #include <stddef.h> |
| #include <string.h> |
| #include <stdio.h> |
| @@ -139,6 +143,218 @@ |
| return *stack; |
| } |
| |
| +#ifdef _WIN32 |
| +# ifndef _SC_PAGE_SIZE |
| +# define _SC_PAGE_SIZE 30 |
| +# endif |
| +# define PROT_READ 0x1 |
| +# define PROT_WRITE 0x2 |
| +# define MAP_SHARED 0x1 |
| +# define MAP_PRIVATE 0x2 |
| +# define MAP_FIXED 0x10 |
| +# define MAP_ANONYMOUS 0x20 |
| +# define MAP_ANON MAP_ANONYMOUS |
| +# define MAP_FAILED ((void *) -1) |
| + |
| +long sysconf(int name); |
| +int getpagesize(void); |
| +void *mmap(void *start, size_t len, int access, int flags, int fd, unsigned long long off); |
| +void *mmap_impl(void *start, size_t len, int access, int flags, int fd, unsigned long long off, int inherited); |
| +int munmap (void *start, size_t length); |
| +int munmap_impl (void *start, size_t length, int anonymous); |
| +# define HAVE_MLOCK 1 |
| +int mlock(const void *addr, size_t len); |
| +int munlock(const void *addr, size_t len); |
| + |
| + |
| +/** |
| + * @brief get configurable system variables |
| + * @param system variable to be queried |
| + * @return -1 on error, current variable value on the system otherwise |
| + */ |
| +long |
| +sysconf (int name) |
| +{ |
| + switch(name) |
| + { |
| + case _SC_PAGE_SIZE: |
| + { |
| + SYSTEM_INFO sys_info; |
| + GetSystemInfo(&sys_info); |
| + return sys_info.dwAllocationGranularity; |
| + } |
| + default: |
| + errno = EINVAL; |
| + return -1; |
| + } |
| +} |
| + |
| +int |
| +getpagesize (void) |
| +{ |
| + return sysconf (_SC_PAGE_SIZE); |
| +} |
| + |
| +void * |
| +mmap_impl (void *start, size_t len, int access, int flags, int fd, |
| + unsigned long long off, int inheritable) |
| +{ |
| + DWORD protect; |
| + DWORD access_param; |
| + DWORD high, low; |
| + HANDLE h, hFile; |
| + SECURITY_ATTRIBUTES sec_none; |
| + void *base; |
| + errno = 0; |
| + |
| + switch(access) |
| + { |
| + case PROT_WRITE: |
| + protect = PAGE_READWRITE; |
| + access_param = FILE_MAP_WRITE; |
| + break; |
| + case PROT_READ: |
| + protect = PAGE_READONLY; |
| + access_param = FILE_MAP_READ; |
| + break; |
| + default: |
| + protect = PAGE_WRITECOPY; |
| + access_param = FILE_MAP_COPY; |
| + break; |
| + } |
| + |
| + h = NULL; |
| + base = NULL; |
| + if (fd >= 0) |
| + { |
| + |
| + sec_none.nLength = sizeof(SECURITY_ATTRIBUTES); |
| + sec_none.bInheritHandle = inheritable ? TRUE : FALSE; |
| + sec_none.lpSecurityDescriptor = NULL; |
| + |
| + hFile = (HANDLE) _get_osfhandle(fd); |
| + |
| + h = CreateFileMapping(hFile, &sec_none, protect, 0, 0, NULL); |
| + |
| + if (! h) |
| + { |
| + errno = EINVAL; |
| + return MAP_FAILED; |
| + } |
| + |
| + high = off >> 32; |
| + low = off & ULONG_MAX; |
| + |
| + /* If a non-zero start is given, try mapping using the given address first. |
| + If it fails and flags is not MAP_FIXED, try again with NULL address. */ |
| + if (start) |
| + base = MapViewOfFileEx(h, access_param, high, low, len, start); |
| + if (!base && !(flags & MAP_FIXED)) |
| + base = MapViewOfFileEx(h, access_param, high, low, len, NULL); |
| + } |
| + else if ((flags & MAP_PRIVATE) && (flags & MAP_ANONYMOUS)) |
| + { |
| + if (start) |
| + base = VirtualAlloc (start, len, MEM_COMMIT | MEM_RESERVE, |
| + protect); |
| + if (!base && !(flags & MAP_FIXED)) |
| + base = VirtualAlloc (NULL, len, MEM_COMMIT | MEM_RESERVE, |
| + protect); |
| + } |
| + else |
| + { |
| + errno = ENOSYS; |
| + return MAP_FAILED; |
| + } |
| + |
| + if (!base || ((flags & MAP_FIXED) && base != start)) |
| + { |
| + if (!base) |
| + { |
| + errno = EINVAL; |
| + } |
| + else |
| + errno = EINVAL; |
| + |
| + if (h) |
| + CloseHandle(h); |
| + return MAP_FAILED; |
| + } |
| + |
| + return base; |
| +} |
| + |
| +void * |
| +mmap(void *start, size_t len, int access, int flags, int fd, unsigned long long off) |
| +{ |
| + return mmap_impl (start, len, access, flags, fd, off, TRUE); |
| +} |
| + |
| +/** |
| + * @brief Unmap files from memory |
| + * @author Cygwin team |
| + * @author Nils Durner |
| + */ |
| +int |
| +munmap_impl (void *start, size_t length, int anonymous) |
| +{ |
| + if (anonymous) |
| + { |
| + if (VirtualFree (start, 0, MEM_RELEASE)) |
| + { |
| + errno = 0; |
| + return 0; |
| + } |
| + else |
| + { |
| + errno = EINVAL; |
| + return (int) MAP_FAILED; |
| + } |
| + } |
| + else |
| + { |
| + if (UnmapViewOfFile(start)) |
| + { |
| + errno = 0; |
| + return 0; |
| + } |
| + else |
| + { |
| + errno = EINVAL; |
| + return (int) MAP_FAILED; |
| + } |
| + } |
| +} |
| + |
| +int |
| +munmap (void *start, size_t length) |
| +{ |
| + return munmap_impl (start, length, TRUE); |
| +} |
| + |
| + |
| +int |
| +mlock (const void *addr, size_t len) |
| +{ |
| + BOOL b; |
| + b = VirtualLock ((LPVOID) addr, len); |
| + if (0 == b) |
| + return EINVAL; |
| + return 0; |
| +} |
| + |
| +int |
| +munlock (const void *addr, size_t len) |
| +{ |
| + BOOL b; |
| + b = VirtualUnlock ((LPVOID) addr, len); |
| + if (0 == b) |
| + return EINVAL; |
| + return 0; |
| +} |
| +#endif |
| + |
| + |
| /* ----------------------------------------------------------------------------- |
| * POOL META DATA ALLOCATION |
| * |
| diff -Naur libsecret-0.19.1.orig/libsecret/mock-service.c libsecret-0.19.1/libsecret/mock-service.c |
| --- libsecret-0.19.1.orig/libsecret/mock-service.c 2019-09-08 22:13:01.722864500 -0400 |
| +++ libsecret-0.19.1/libsecret/mock-service.c 2019-09-08 22:20:09.668492100 -0400 |
| @@ -22,6 +22,9 @@ |
| #include <errno.h> |
| #include <stdio.h> |
| #include <string.h> |
| +#ifdef G_OS_WIN32 |
| +#include <windows.h> |
| +#endif |
| |
| #ifdef __linux |
| #include <sys/prctl.h> |
| @@ -135,10 +138,16 @@ |
| while (g_main_context_iteration (NULL, FALSE)); |
| |
| if (pid) { |
| +#ifndef G_OS_WIN32 |
| if (kill (pid, SIGTERM) < 0) { |
| if (errno != ESRCH) |
| g_warning ("kill() failed: %s", g_strerror (errno)); |
| } |
| +#else |
| + if (!TerminateProcess ((HANDLE) pid, 0)) { |
| + g_warning ("TerminateProcess() failed: %lu", GetLastError ()); |
| + } |
| +#endif |
| |
| g_spawn_close_pid (pid); |
| pid = 0; |
| diff -Naur libsecret-0.19.1.orig/tool/secret-tool.c libsecret-0.19.1/tool/secret-tool.c |
| --- libsecret-0.19.1.orig/tool/secret-tool.c 2019-09-08 22:13:01.660294400 -0400 |
| +++ libsecret-0.19.1/tool/secret-tool.c 2019-09-08 22:23:56.154326600 -0400 |
| @@ -20,12 +20,17 @@ |
| #include "libsecret/secret-value.h" |
| |
| #include <glib/gi18n.h> |
| +#include <glib/gprintf.h> |
| |
| #include <errno.h> |
| #include <locale.h> |
| #include <limits.h> |
| #include <stdlib.h> |
| #include <string.h> |
| +#ifdef _WIN32 |
| +#include <io.h> |
| +#include <conio.h> |
| +#endif |
| |
| #define SECRET_ALIAS_PREFIX "/org/freedesktop/secrets/aliases/" |
| |
| @@ -262,6 +267,39 @@ |
| (GDestroyNotify)secret_password_free); |
| } |
| |
| +#if defined(G_OS_WIN32) || defined(__BIONIC__) |
| +/* win32 doesn't have getpass() */ |
| +#include <stdio.h> |
| +#ifndef BUFSIZ |
| +#define BUFSIZ 8192 |
| +#endif |
| +static gchar * |
| +getpass (const gchar *prompt) |
| +{ |
| + static gchar buf[BUFSIZ]; |
| + gint i; |
| + |
| + g_printf ("%s", prompt); |
| + fflush (stdout); |
| + |
| + for (i = 0; i < BUFSIZ - 1; ++i) |
| + { |
| +#ifdef __BIONIC__ |
| + buf[i] = getc (stdin); |
| +#else |
| + buf[i] = _getch (); |
| +#endif |
| + if (buf[i] == '\r') |
| + break; |
| + } |
| + buf[i] = '\0'; |
| + |
| + g_printf ("\n"); |
| + |
| + return &buf[0]; |
| +} |
| +#endif |
| + |
| static SecretValue * |
| read_password_tty (void) |
| { |