From 499eed087ec36d0344b403ff9b5800fd2a4053fc Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 20 Nov 2013 10:30:01 +0100 Subject: [PATCH] netapi32: Add helpers to initialize and destroy a libnetapi context. --- dlls/netapi32/netapi32.c | 68 ++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/dlls/netapi32/netapi32.c b/dlls/netapi32/netapi32.c index 74635dc5971..e6f34590d29 100644 --- a/dlls/netapi32/netapi32.c +++ b/dlls/netapi32/netapi32.c @@ -85,10 +85,48 @@ static NET_API_STATUS (*pNetShareAdd)(const char *, unsigned int, unsigned char static NET_API_STATUS (*pNetShareDel)(const char *, const char *, unsigned int); static NET_API_STATUS (*pNetWkstaGetInfo)(const char *, unsigned int, unsigned char **); +static void destroy_context(void) +{ + TRACE( "destroying %p\n", libnetapi_ctx ); + plibnetapi_free( libnetapi_ctx ); + libnetapi_ctx = NULL; +} + +static BOOL init_context(void) +{ + DWORD status; + + if ((status = plibnetapi_init( &libnetapi_ctx ))) + { + ERR( "Failed to initialize context %u\n", status ); + return FALSE; + } + if (TRACE_ON( netapi32 ) && (status = plibnetapi_set_debuglevel( libnetapi_ctx, "10" ))) + { + ERR( "Failed to set debug level %u\n", status ); + destroy_context(); + return FALSE; + } + /* perform an anonymous login by default (avoids a password prompt) */ + if ((status = plibnetapi_set_username( libnetapi_ctx, "Guest" ))) + { + ERR( "Failed to set username %u\n", status ); + destroy_context(); + return FALSE; + } + if ((status = plibnetapi_set_password( libnetapi_ctx, "" ))) + { + ERR( "Failed to set password %u\n", status ); + destroy_context(); + return FALSE; + } + TRACE( "using %p\n", libnetapi_ctx ); + return TRUE; +} + static BOOL libnetapi_init(void) { char buf[200]; - DWORD status; if (libnetapi_handle) return TRUE; if (!(libnetapi_handle = wine_dlopen( SONAME_LIBNETAPI, RTLD_NOW, buf, sizeof(buf) ))) @@ -118,35 +156,9 @@ static BOOL libnetapi_init(void) LOAD_FUNCPTR(NetWkstaGetInfo) #undef LOAD_FUNCPTR - if ((status = plibnetapi_init( &libnetapi_ctx ))) - { - ERR( "Failed to initialize context %u\n", status ); - goto error; - } - if (TRACE_ON( netapi32 ) && (status = plibnetapi_set_debuglevel( libnetapi_ctx, "10" ))) - { - ERR( "Failed to set debug level %u\n", status ); - goto error; - } - /* perform an anonymous login by default (avoids a password prompt) */ - if ((status = plibnetapi_set_username( libnetapi_ctx, "Guest" ))) - { - ERR( "Failed to set username %u\n", status ); - goto error; - } - if ((status = plibnetapi_set_password( libnetapi_ctx, "" ))) - { - ERR( "Failed to set password %u\n", status ); - goto error; - } - return TRUE; + if (init_context()) return TRUE; error: - if (libnetapi_ctx) - { - plibnetapi_free( libnetapi_ctx ); - libnetapi_ctx = NULL; - } wine_dlclose( libnetapi_handle, NULL, 0 ); libnetapi_handle = NULL; return FALSE; -- 2.11.4.GIT