Module: wine Branch: master Commit: 9979725211ecd3c6cdcb53b9c2501dca95978f86 URL: http://source.winehq.org/git/wine.git/?a=commit;h=9979725211ecd3c6cdcb53b9c2...
Author: Ken Thomases ken@codeweavers.com Date: Wed Nov 30 16:49:20 2011 -0600
netapi32: Wait for and reap smbpasswd child process.
---
dlls/netapi32/access.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/dlls/netapi32/access.c b/dlls/netapi32/access.c index 7cd05fc..d3b9063 100644 --- a/dlls/netapi32/access.c +++ b/dlls/netapi32/access.c @@ -21,6 +21,12 @@ #include "config.h" #include <stdarg.h> #include <fcntl.h> +#ifdef HAVE_SYS_ERRNO_H +#include <sys/errno.h> +#endif +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -872,7 +878,7 @@ NET_API_STATUS WINAPI NetUserModalsGet( return NERR_Success; }
-static int fork_smbpasswd( char * const argv[] ) +static int fork_smbpasswd( char * const argv[], pid_t *pid ) { #ifdef HAVE_FORK int pipe_out[2]; @@ -881,7 +887,7 @@ static int fork_smbpasswd( char * const argv[] ) fcntl( pipe_out[0], F_SETFD, FD_CLOEXEC ); fcntl( pipe_out[1], F_SETFD, FD_CLOEXEC );
- switch (fork()) + switch ((*pid = fork())) { case -1: close( pipe_out[0] ); @@ -893,7 +899,7 @@ static int fork_smbpasswd( char * const argv[] ) close( pipe_out[1] ); execvp( "smbpasswd", argv ); ERR( "can't execute smbpasswd, is it installed?\n" ); - return -1; + _exit(1); default: close( pipe_out[0] ); break; @@ -917,12 +923,14 @@ static char *strdup_unixcp( const WCHAR *str ) static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username, LPCWSTR oldpassword, LPCWSTR newpassword ) { + NET_API_STATUS ret = NERR_Success; static char option_silent[] = "-s"; static char option_user[] = "-U"; static char option_remote[] = "-r"; static char smbpasswd[] = "smbpasswd"; int pipe_out; - char *server = NULL, *user, *argv[7], *old, *new; + pid_t pid; + char *server = NULL, *user, *argv[7], *old, *new = NULL;
if (domainname && !(server = strdup_unixcp( domainname ))) return ERROR_OUTOFMEMORY; if (!(user = strdup_unixcp( username ))) @@ -942,21 +950,20 @@ static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username, } else argv[4] = NULL;
- pipe_out = fork_smbpasswd( argv ); + pipe_out = fork_smbpasswd( argv, &pid ); HeapFree( GetProcessHeap(), 0, server ); HeapFree( GetProcessHeap(), 0, user ); if (pipe_out == -1) return NERR_InternalError;
if (!(old = strdup_unixcp( oldpassword ))) { - close( pipe_out ); - return ERROR_OUTOFMEMORY; + ret = ERROR_OUTOFMEMORY; + goto end; } if (!(new = strdup_unixcp( newpassword ))) { - close( pipe_out ); - HeapFree( GetProcessHeap(), 0, old ); - return ERROR_OUTOFMEMORY; + ret = ERROR_OUTOFMEMORY; + goto end; } write( pipe_out, old, strlen( old ) ); write( pipe_out, "\n", 1 ); @@ -965,10 +972,26 @@ static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username, write( pipe_out, new, strlen( new ) ); write( pipe_out, "\n", 1 );
+end: close( pipe_out ); + +#ifdef HAVE_FORK + { + pid_t wret; + int status; + + do { + wret = waitpid(pid, &status, 0); + } while (wret < 0 && errno == EINTR); + if (ret == NERR_Success && + (wret < 0 || !WIFEXITED(status) || WEXITSTATUS(status))) + ret = NERR_InternalError; + } +#endif + HeapFree( GetProcessHeap(), 0, old ); HeapFree( GetProcessHeap(), 0, new ); - return NERR_Success; + return ret; }
/******************************************************************************