svn rev #25257: trunk/src/ include/ windows/kfwlogon/ windows/leashdll/ windows/leashdll/include/ ...

hartmans@MIT.EDU hartmans at MIT.EDU
Wed Sep 28 16:55:18 EDT 2011


http://src.mit.edu/fisheye/changelog/krb5/?cs=25257
Commit By: hartmans
Log Message:
Moved LoadFuncs/UnloadFuncs() to windows/lib

Signed-off-by: Alexey Melnikov <aamelnikov at gmail.com>


Changed Files:
A   trunk/src/include/loadfuncs.h
U   trunk/src/windows/kfwlogon/Makefile.in
U   trunk/src/windows/kfwlogon/kfwcommon.c
U   trunk/src/windows/kfwlogon/kfwlogon.h
U   trunk/src/windows/leashdll/Makefile.in
D   trunk/src/windows/leashdll/include/loadfuncs.h
D   trunk/src/windows/leashdll/loadfuncs.c
U   trunk/src/windows/lib/Makefile.in
A   trunk/src/windows/lib/loadfuncs.c
Copied: trunk/src/include/loadfuncs.h (from rev 25256, trunk/src/windows/leashdll/include/loadfuncs.h)
===================================================================
--- trunk/src/include/loadfuncs.h	                        (rev 0)
+++ trunk/src/include/loadfuncs.h	2011-09-28 20:55:18 UTC (rev 25257)
@@ -0,0 +1,41 @@
+#ifndef __LOADFUNCS_H__
+#define __LOADFUNCS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <windows.h>
+
+typedef struct _FUNC_INFO {
+    void** func_ptr_var;
+    char* func_name;
+} FUNC_INFO;
+
+#define DECL_FUNC_PTR(x) FP_##x p##x
+#define MAKE_FUNC_INFO(x) { (void**) &p##x, #x }
+#define END_FUNC_INFO { 0, 0 }
+#define TYPEDEF_FUNC(ret, call, name, args) typedef ret (call *FP_##name) args
+
+void
+UnloadFuncs(
+    FUNC_INFO fi[],
+    HINSTANCE h
+    );
+
+int
+LoadFuncs(
+    const char* dll_name,
+    FUNC_INFO fi[],
+    HINSTANCE* ph,  // [out, optional] - DLL handle
+    int* pindex,    // [out, optional] - index of last func loaded (-1 if none)
+    int cleanup,    // cleanup function pointers and unload on error
+    int go_on,      // continue loading even if some functions cannot be loaded
+    int silent      // do not pop-up a system dialog if DLL cannot be loaded
+    );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOADFUNCS_H__ */

Modified: trunk/src/windows/kfwlogon/Makefile.in
===================================================================
--- trunk/src/windows/kfwlogon/Makefile.in	2011-09-28 20:55:14 UTC (rev 25256)
+++ trunk/src/windows/kfwlogon/Makefile.in	2011-09-28 20:55:18 UTC (rev 25257)
@@ -29,11 +29,11 @@
 all-windows:: $(OUTPRE)kfwlogon.dll $(OUTPRE)kfwcpcc.exe
 
 $(KFWLOGON): $(OUTPRE)kfwlogon.obj $(OUTPRE)kfwcommon.obj $(LIBRES)
-    link $(DLL_LINKOPTS) -out:$@ $(OUTPRE)kfwlogon.obj $(OUTPRE)kfwcommon.obj -entry:DllEntryPoint -def:kfwlogon.def $(SYSLIBS) $(KLIB) $(CLIB) $(SCLIB) $(LIBRES)
+    link $(DLL_LINKOPTS) -out:$@ $(OUTPRE)kfwlogon.obj $(OUTPRE)kfwcommon.obj -entry:DllEntryPoint -def:kfwlogon.def $(SYSLIBS) $(KLIB) $(CLIB) $(SCLIB) ../lib/$(OUTPRE)libwin.lib $(LIBRES)
     $(_VC_MANIFEST_EMBED_DLL)
 
 $(KFWCPCC): $(OUTPRE)kfwcpcc.obj $(OUTPRE)kfwcommon.obj $(EXERES)
-    link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)kfwcpcc.obj $(OUTPRE)kfwcommon.obj $(SYSLIBS) $(KLIB) $(CLIB) $(SCLIB) $(EXERES)
+    link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)kfwcpcc.obj $(OUTPRE)kfwcommon.obj $(SYSLIBS) $(KLIB) $(CLIB) $(SCLIB) ../lib/$(OUTPRE)libwin.lib $(EXERES)
     $(_VC_MANIFEST_EMBED_EXE)
 
 install::

Modified: trunk/src/windows/kfwlogon/kfwcommon.c
===================================================================
--- trunk/src/windows/kfwlogon/kfwcommon.c	2011-09-28 20:55:14 UTC (rev 25256)
+++ trunk/src/windows/kfwlogon/kfwcommon.c	2011-09-28 20:55:18 UTC (rev 25257)
@@ -350,75 +350,6 @@
     }
 }
 
-void
-UnloadFuncs(
-    FUNC_INFO fi[],
-    HINSTANCE h
-    )
-{
-    int n;
-    if (fi)
-        for (n = 0; fi[n].func_ptr_var; n++)
-            *(fi[n].func_ptr_var) = 0;
-    if (h) FreeLibrary(h);
-}
-
-int
-LoadFuncs(
-    const char* dll_name,
-    FUNC_INFO fi[],
-    HINSTANCE* ph,  // [out, optional] - DLL handle
-    int* pindex,    // [out, optional] - index of last func loaded (-1 if none)
-    int cleanup,    // cleanup function pointers and unload on error
-    int go_on,      // continue loading even if some functions cannot be loaded
-    int silent      // do not pop-up a system dialog if DLL cannot be loaded
-    )
-{
-    HINSTANCE h;
-    int i, n, last_i;
-    int error = 0;
-    UINT em;
-
-    if (ph) *ph = 0;
-    if (pindex) *pindex = -1;
-
-    for (n = 0; fi[n].func_ptr_var; n++)
-	*(fi[n].func_ptr_var) = 0;
-
-    if (silent)
-	em = SetErrorMode(SEM_FAILCRITICALERRORS);
-    h = LoadLibrary(dll_name);
-    if (silent)
-        SetErrorMode(em);
-
-    if (!h)
-        return 0;
-
-    last_i = -1;
-    for (i = 0; (go_on || !error) && (i < n); i++)
-    {
-	void* p = (void*)GetProcAddress(h, fi[i].func_name);
-	if (!p)
-	    error = 1;
-        else
-        {
-            last_i = i;
-	    *(fi[i].func_ptr_var) = p;
-        }
-    }
-    if (pindex) *pindex = last_i;
-    if (error && cleanup && !go_on) {
-	for (i = 0; i < n; i++) {
-	    *(fi[i].func_ptr_var) = 0;
-	}
-	FreeLibrary(h);
-	return 0;
-    }
-    if (ph) *ph = h;
-    if (error) return 0;
-    return 1;
-}
-
 static HANDLE hInitMutex = NULL;
 static BOOL bInit = FALSE;
 

Modified: trunk/src/windows/kfwlogon/kfwlogon.h
===================================================================
--- trunk/src/windows/kfwlogon/kfwlogon.h	2011-09-28 20:55:14 UTC (rev 25256)
+++ trunk/src/windows/kfwlogon/kfwlogon.h	2011-09-28 20:55:18 UTC (rev 25257)
@@ -188,10 +188,6 @@
 extern "C" {
 #endif
 
-void UnloadFuncs(FUNC_INFO [], HINSTANCE);
-
-int  LoadFuncs(const char*, FUNC_INFO [], HINSTANCE*, int*, int, int, int);
-
 void DebugEvent0(char *a);
 void DebugEvent(char *b,...);
 

Modified: trunk/src/windows/leashdll/Makefile.in
===================================================================
--- trunk/src/windows/leashdll/Makefile.in	2011-09-28 20:55:14 UTC (rev 25256)
+++ trunk/src/windows/leashdll/Makefile.in	2011-09-28 20:55:18 UTC (rev 25257)
@@ -32,8 +32,7 @@
 	$(OUTPRE)timesync.$(OBJEXT) \
 	$(OUTPRE)winerr.$(OBJEXT) \
 	$(OUTPRE)winutil.$(OBJEXT) \
-	$(OUTPRE)registry.$(OBJEXT) \
-	$(OUTPRE)loadfuncs.$(OBJEXT)
+	$(OUTPRE)registry.$(OBJEXT)
 
 #TODO: Fix resource compilation
 RESFILE = $(OUTPRE)lsh_pwd.res
@@ -75,7 +74,7 @@
 
 $(OUTPRE)$(DLL_NAME).dll: $(DEF_FILE) $(OBJS) $(XOBJS)
 	link $(WINDLLFLAGS) -def:$(DEF_FILE) -out:$*.dll \
-	$(OBJS) $(XOBJS) $(WINLIBS) $(SCLIB)
+	$(OBJS) $(XOBJS) $(WINLIBS) ../lib/$(OUTPRE)libwin.lib $(SCLIB)
 	$(_VC_MANIFEST_EMBED_DLL)
 
 #TODO: Add dependencies on include files here

Modified: trunk/src/windows/lib/Makefile.in
===================================================================
--- trunk/src/windows/lib/Makefile.in	2011-09-28 20:55:14 UTC (rev 25256)
+++ trunk/src/windows/lib/Makefile.in	2011-09-28 20:55:18 UTC (rev 25257)
@@ -2,10 +2,13 @@
 
 lib-windows: $(OUTPRE)libwin.lib
 
-SRCS=	vardlg.c gic.c registry.c
+SRCS=	vardlg.c gic.c registry.c loadfuncs.c
 
-OBJS=	$(OUTPRE)vardlg.obj $(OUTPRE)gic.obj $(OUTPRE)registry.obj
 
+OBJS=	$(OUTPRE)vardlg.obj $(OUTPRE)gic.obj $(OUTPRE)registry.obj \
+	$(OUTPRE)loadfuncs.obj
+
+
 $(OUTPRE)libwin.lib: $(OBJS)
        lib /nologo /out:$*.lib $(OBJS)
 

Copied: trunk/src/windows/lib/loadfuncs.c (from rev 25256, trunk/src/windows/leashdll/loadfuncs.c)
===================================================================
--- trunk/src/windows/lib/loadfuncs.c	                        (rev 0)
+++ trunk/src/windows/lib/loadfuncs.c	2011-09-28 20:55:18 UTC (rev 25257)
@@ -0,0 +1,88 @@
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include "loadfuncs.h"
+
+//
+// UnloadFuncs:
+//
+// This function will reset all the function pointers of a function loaded
+// by LaodFuncs and will free the DLL instance provided.
+//
+
+void
+UnloadFuncs(
+    FUNC_INFO fi[],
+    HINSTANCE h
+    )
+{
+    int n;
+    if (fi)
+        for (n = 0; fi[n].func_ptr_var; n++)
+            *(fi[n].func_ptr_var) = NULL;
+    if (h) FreeLibrary(h);
+}
+
+
+//
+// LoadFuncs:
+//
+// This function try to load the functions for a DLL.  It returns 0 on failure
+// and non-zero on success.  The parameters are descibed below.
+//
+
+int
+LoadFuncs(
+    const char* dll_name,
+    FUNC_INFO fi[],
+    HINSTANCE* ph,  // [out, optional] - DLL handle
+    int* pindex,    // [out, optional] - index of last func loaded (-1 if none)
+    int cleanup,    // cleanup function pointers and unload on error
+    int go_on,      // continue loading even if some functions cannot be loaded
+    int silent      // do not pop-up a system dialog if DLL cannot be loaded
+
+    )
+{
+    HINSTANCE h;
+    int i, n, last_i;
+    int error = 0;
+    UINT em;
+
+    if (ph) *ph = 0;
+    if (pindex) *pindex = -1;
+
+    for (n = 0; fi[n].func_ptr_var; n++)
+	*(fi[n].func_ptr_var) = NULL;
+
+    if (silent)
+	em = SetErrorMode(SEM_FAILCRITICALERRORS);
+    h = LoadLibrary(dll_name);
+    if (silent)
+        SetErrorMode(em);
+
+    if (!h)
+        return 0;
+
+    last_i = -1;
+    for (i = 0; (go_on || !error) && (i < n); i++)
+    {
+	void* p = (void*)GetProcAddress(h, fi[i].func_name);
+	if (!p)
+	    error = 1;
+        else
+        {
+            last_i = i;
+	    *(fi[i].func_ptr_var) = p;
+        }
+    }
+    if (pindex) *pindex = last_i;
+    if (error && cleanup && !go_on) {
+	for (i = 0; i < n; i++) {
+	    *(fi[i].func_ptr_var) = NULL;
+	}
+	FreeLibrary(h);
+	return 0;
+    }
+    if (ph) *ph = h;
+    if (error) return 0;
+    return 1;
+}




More information about the cvs-krb5 mailing list