Commit 99797252 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

netapi32: Wait for and reap smbpasswd child process.

parent 6df7adff
......@@ -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;
}
/******************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment