# HG changeset patch # User J. Ali Harlow # Date 1463739622 -3600 # Node ID 30dd8888a27158fdf5fba5b6eef3b8887d1b32a1 # Parent a3325f4388819693c8bb6f51f14ac73a3b7c55f4 catalog subsystem should cope with being called with different lua states whelk 0.3.2 was assuming that lua state would always be the same. If it wasn't then there would be no cat admin metatable registered in the second lua state but whelk would just assume that there was causing things to go wrong. We now use luaL_newmetatable() to test for whether a metatable was already registered and take the appropriate actions if it wasn't. diff -r a3325f438881 -r 30dd8888a271 .hgtags --- a/.hgtags Thu Aug 25 20:41:08 2011 +0100 +++ b/.hgtags Fri May 20 11:20:22 2016 +0100 @@ -1,1 +1,2 @@ 579831f324c72818382f1eeacfe54b5b9dace0e1 0.3.2 +36ce85e5c7c0fe2fb7b140656021b5ef28ab5b7f 0.3.2.50 diff -r a3325f438881 -r 30dd8888a271 configure.ac --- a/configure.ac Thu Aug 25 20:41:08 2011 +0100 +++ b/configure.ac Fri May 20 11:20:22 2016 +0100 @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([whelk],[0.3.2],[ali@juiblex.co.uk]) +AC_INIT([whelk],[0.3.3],[ali@juiblex.co.uk]) AC_PREREQ(2.59) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_SRCDIR([whelk/whelk.c]) @@ -27,7 +27,7 @@ # See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details # LT_CURRENT=2 -LT_REVISION=0 +LT_REVISION=1 LT_AGE=2 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) diff -r a3325f438881 -r 30dd8888a271 whelk/_whelk.h --- a/whelk/_whelk.h Thu Aug 25 20:41:08 2011 +0100 +++ b/whelk/_whelk.h Fri May 20 11:20:22 2016 +0100 @@ -56,6 +56,7 @@ int whelk_crypt_cat_admin_new(lua_State *L); +int whelk_win32_error(lua_State *L,DWORD err); int whelk_setup_copy_oem_inf(lua_State *L); int whelk_setup_uninstall_oem_inf(lua_State *L); void whelk_open_setup(lua_State *L); diff -r a3325f438881 -r 30dd8888a271 whelk/catalog.c --- a/whelk/catalog.c Thu Aug 25 20:41:08 2011 +0100 +++ b/whelk/catalog.c Fri May 20 11:20:22 2016 +0100 @@ -132,26 +132,39 @@ { NULL } }; -static struct whelk_cat_admin_class *whelk_cat_admin_class_new(lua_State *L) +static struct whelk_cat_admin_class *whelk_cat_admin_class_new(lua_State *L, + DWORD *err) { struct whelk_cat_admin_class *klass; klass=calloc(sizeof(struct whelk_cat_admin_class),1); - klass->wintrust=LoadLibrary("wintrust.dll"); + klass->wintrust=LoadLibraryA("wintrust.dll"); if (!klass->wintrust) { + if (err) + *err=GetLastError(); free(klass); return NULL; } - klass->acquire_context= + klass->acquire_context=(BOOL (WINAPI *)()) GetProcAddress(klass->wintrust,"CryptCATAdminAcquireContext"); + if (err && !klass->acquire_context) + *err=GetLastError(); klass->add_catalog=(HCATINFO (WINAPI *)()) GetProcAddress(klass->wintrust,"CryptCATAdminAddCatalog"); - klass->remove_catalog= + if (err && !klass->add_catalog) + *err=GetLastError(); + klass->remove_catalog=(BOOL (WINAPI *)()) GetProcAddress(klass->wintrust,"CryptCATAdminRemoveCatalog"); - klass->release_catalog_context= + if (err && !klass->remove_catalog) + *err=GetLastError(); + klass->release_catalog_context=(BOOL (WINAPI *)()) GetProcAddress(klass->wintrust,"CryptCATAdminReleaseCatalogContext"); - klass->release_context= + if (err && !klass->release_catalog_context) + *err=GetLastError(); + klass->release_context=(BOOL (WINAPI *)()) GetProcAddress(klass->wintrust,"CryptCATAdminReleaseContext"); + if (err && !klass->release_context) + *err=GetLastError(); if (!klass->acquire_context || !klass->add_catalog || !klass->release_catalog_context || !klass->release_context) { @@ -159,33 +172,39 @@ free(klass); return NULL; } - luaL_newmetatable(L,WHELK_TYPE_CAT_ADMIN); - lua_pushvalue(L,-1); - lua_setfield(L,-2,"__index"); - luaL_register(L,NULL,whelk_cat_admin_methods); return klass; } -static struct whelk_cat_admin *newcatadmin(lua_State *L) +static struct whelk_cat_admin *newcatadmin(lua_State *L,DWORD *err) { struct whelk_cat_admin *ca; static struct whelk_cat_admin_class *klass=NULL; if (!klass) - klass=whelk_cat_admin_class_new(L); + klass=whelk_cat_admin_class_new(L,err); + if (!klass) + return NULL; ca=lua_newuserdata(L,sizeof(struct whelk_cat_admin)); ca->klass=klass; ca->handle=INVALID_HANDLE_VALUE; - luaL_getmetatable(L,WHELK_TYPE_CAT_ADMIN); + if (luaL_newmetatable(L,WHELK_TYPE_CAT_ADMIN)) + { + lua_pushvalue(L,-1); + lua_setfield(L,-2,"__index"); + luaL_register(L,NULL,whelk_cat_admin_methods); + } lua_setmetatable(L,-2); return ca; } int whelk_crypt_cat_admin_new(lua_State *L) { + DWORD err=0; struct whelk_cat_admin *ca; static GUID subsystem=DRIVER_ACTION_VERIFY; - ca=newcatadmin(L); + ca=newcatadmin(L,&err); + if (!ca) + return whelk_win32_error(L,err); if (!ca->klass->acquire_context(&ca->handle,&subsystem,0)) - lua_pushnil(L); + return whelk_win32_error(L,GetLastError()); return 1; }