libsecret: WIP.

This commit is contained in:
Alexpux
2014-09-05 00:51:26 +04:00
parent 311113cd00
commit 5171a4ac41
2 changed files with 529 additions and 0 deletions

View File

@@ -0,0 +1,470 @@
diff -ru libsecret-0.16.orig/configure.ac libsecret-0.16/configure.ac
--- libsecret-0.16.orig/configure.ac 2013-06-21 13:11:14.000000000 +0000
+++ libsecret-0.16/configure.ac 2014-02-20 12:30:29.842487200 +0000
@@ -62,7 +62,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"
diff -ru libsecret-0.16.orig/egg/egg-secure-memory.c libsecret-0.16/egg/egg-secure-memory.c
--- libsecret-0.16.orig/egg/egg-secure-memory.c 2012-10-27 10:23:32.000000000 +0000
+++ libsecret-0.16/egg/egg-secure-memory.c 2014-02-20 13:38:49.275549000 +0000
@@ -32,7 +32,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>
@@ -140,6 +144,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 -ru libsecret-0.16.orig/libsecret/tests/mock/service.py libsecret-0.16/libsecret/tests/mock/service.py
--- libsecret-0.16.orig/libsecret/mock/service.py 2013-04-30 16:28:15.000000000 +0000
+++ libsecret-0.16/libsecret/mock/service.py 2014-02-20 14:10:46.344485900 +0000
@@ -29,7 +29,12 @@
COLLECTION_PREFIX = "/org/freedesktop/secrets/collection/"
bus_name = 'org.freedesktop.Secret.MockService'
-ready_pipe = -1
+if os.name != 'nt':
+ ready_pipe = -1
+else:
+ import win32event
+ import pywintypes
+ ready_event = None
objects = { }
class NotSupported(dbus.exceptions.DBusException):
@@ -532,12 +537,19 @@
self.set_alias('session', collection)
def listen(self):
- global ready_pipe
loop = gobject.MainLoop()
- if ready_pipe >= 0:
- os.write(ready_pipe, "GO")
- os.close(ready_pipe)
- ready_pipe = -1
+ if os.name != 'nt':
+ global ready_pipe
+ if ready_pipe >= 0:
+ os.write(ready_pipe, "GO")
+ os.close(ready_pipe)
+ ready_pipe = -1
+ else:
+ global ready_event
+ if ready_event is not None:
+ win32event.SetEvent (ready_event)
+ ready_event.close ()
+ ready_event = None
loop.run()
def add_session(self, session):
@@ -696,7 +708,11 @@
def parse_options(args):
- global bus_name, ready_pipe
+ if os.name != 'nt':
+ global ready_pipe
+ else:
+ global ready_event
+ global bus_name
try:
opts, args = getopt.getopt(args, "nr", ["name=", "ready="])
except getopt.GetoptError, err:
@@ -706,7 +722,10 @@
if o in ("-n", "--name"):
bus_name = a
elif o in ("-r", "--ready"):
- ready_pipe = int(a)
+ if os.name != 'nt':
+ ready_pipe = int(a)
+ else:
+ ready_event = pywintypes.HANDLE (int (a))
else:
assert False, "unhandled option"
return args
diff -ru libsecret-0.16.orig/libsecret/tests/mock-service.c libsecret-0.16/libsecret/tests/mock-service.c
--- libsecret-0.16.orig/libsecret/mock-service.c 2013-04-30 16:28:15.000000000 +0000
+++ libsecret-0.16/libsecret/mock-service.c 2014-02-20 14:01:20.525136000 +0000
@@ -21,6 +21,9 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
static GTestDBus *test_bus = NULL;
static GPid pid = 0;
@@ -30,10 +33,16 @@
{
gchar ready[8] = { 0, };
GSpawnFlags flags;
+#ifndef G_OS_WIN32
int wait_pipe[2];
GPollFD poll_fd;
- gboolean ret;
gint polled;
+#else
+ SECURITY_ATTRIBUTES sa;
+ HANDLE event;
+ DWORD dw;
+#endif
+ gboolean ret;
gchar *argv[] = {
"python", (gchar *)mock_script,
@@ -46,7 +55,7 @@
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_setenv ("SECRET_SERVICE_BUS_NAME", MOCK_SERVICE_NAME, TRUE);
-
+#ifndef G_OS_WIN32
if (pipe (wait_pipe) < 0) {
g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errno),
"Couldn't create pipe for mock service");
@@ -54,10 +63,21 @@
}
snprintf (ready, sizeof (ready), "%d", wait_pipe[1]);
-
+#else
+ sa.nLength = sizeof (sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+ event = CreateEvent (&sa, TRUE, FALSE, NULL);
+ if (NULL == event) {
+ g_set_error_literal (error, G_IO_ERROR, g_io_error_from_win32_error (GetLastError ()),
+ "Couldn't create event for mock service");
+ return FALSE;
+ }
+#endif
flags = G_SPAWN_SEARCH_PATH | G_SPAWN_LEAVE_DESCRIPTORS_OPEN;
ret = g_spawn_async (SRCDIR, argv, NULL, flags, NULL, NULL, &pid, error);
+#ifndef G_OS_WIN32
close (wait_pipe[1]);
if (ret) {
@@ -73,6 +93,17 @@
}
close (wait_pipe[0]);
+#else
+ if (ret) {
+ dw = WaitForSingleObject (event, 2000);
+ if (dw == WAIT_FAILED)
+ g_warning ("couldn't poll file descirptor: %lu", GetLastError ());
+ if (dw == WAIT_TIMEOUT)
+ g_warning ("couldn't wait for mock service");
+ }
+
+ CloseHandle (event);
+#endif
return ret;
}
@@ -82,10 +113,16 @@
if (!pid)
return;
+#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 -ru libsecret-0.16.orig/tool/secret-tool.c libsecret-0.16/tool/secret-tool.c
--- libsecret-0.16.orig/tool/secret-tool.c 2013-03-25 12:10:12.000000000 +0000
+++ libsecret-0.16/tool/secret-tool.c 2014-02-20 14:16:41.690109100 +0000
@@ -20,12 +20,15 @@
#include "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>
+#include <io.h>
+#include <conio.h>
#define SECRET_ALIAS_PREFIX "/org/freedesktop/secrets/aliases/"
@@ -269,6 +272,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)
{

View File

@@ -0,0 +1,59 @@
# Maintainer: Alexey Pavlov <alexpux@gmail.com>
_realname=libsecret
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.18
pkgrel=1
pkgdesc="Library for storing and retrieving passwords and other secrets (mingw-w64)"
arch=('any')
url="https://wiki.gnome.org/Projects/Libsecret"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
"${MINGW_PACKAGE_PREFIX}-pkg-config"
"${MINGW_PACKAGE_PREFIX}-gobject-introspection"
"${MINGW_PACKAGE_PREFIX}-vala"
"intltool")
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
${MINGW_PACKAGE_PREFIX}-glib2
${MINGW_PACKAGE_PREFIX}-libgcrypt)
options=('!libtool' 'strip')
source=(http://ftp.gnome.org/pub/gnome/sources/${_realname}/$pkgver/${_realname}-$pkgver.tar.xz
0001-port-to.mingw.patch)
md5sums=('279d723cd005e80d1d304f74a3488acc'
'32d12d84dc3ae5b108e67f12a512bd3c')
prepare() {
cd "$srcdir/${_realname}-${pkgver}"
patch -p1 -i ${srcdir}/0001-port-to.mingw.patch
autoreconf -fi
}
build() {
[[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
mkdir -p build-${MINGW_CHOST}
cd "${srcdir}/build-${MINGW_CHOST}"
export MSYS2_ARG_CONV_EXCL="-//OASIS//DTD"
../${_realname}-${pkgver}/configure \
--prefix=${MINGW_PREFIX} \
--build=${MINGW_CHOST} \
--host=${MINGW_CHOST} \
--target=${MINGW_CHOST} \
--enable-shared \
--enable-static \
--enable-introspection \
--enable-vala
make
}
check() {
cd "${srcdir}/build-${MINGW_CHOST}"
make -j1 check
}
package() {
cd "${srcdir}/build-${MINGW_CHOST}"
make DESTDIR=${pkgdir} install
}