Commit b7ceca13 authored by Alexandre Julliard's avatar Alexandre Julliard

netapi32: Simplify the smbpasswd invocation to avoid compiler warnings.

parent ca8e3c1c
...@@ -876,39 +876,6 @@ NET_API_STATUS WINAPI NetUserModalsGet( ...@@ -876,39 +876,6 @@ NET_API_STATUS WINAPI NetUserModalsGet(
return NERR_Success; return NERR_Success;
} }
static int fork_smbpasswd( char * const argv[], pid_t *pid )
{
#ifdef HAVE_FORK
int pipe_out[2];
if (pipe( pipe_out ) == -1) return -1;
fcntl( pipe_out[0], F_SETFD, FD_CLOEXEC );
fcntl( pipe_out[1], F_SETFD, FD_CLOEXEC );
switch ((*pid = fork()))
{
case -1:
close( pipe_out[0] );
close( pipe_out[1] );
return -1;
case 0:
dup2( pipe_out[0], 0 );
close( pipe_out[0] );
close( pipe_out[1] );
execvp( "smbpasswd", argv );
ERR( "can't execute smbpasswd, is it installed?\n" );
_exit(1);
default:
close( pipe_out[0] );
break;
}
return pipe_out[1];
#else
ERR( "no fork support on this platform\n" );
return -1;
#endif
}
static char *strdup_unixcp( const WCHAR *str ) static char *strdup_unixcp( const WCHAR *str )
{ {
char *ret; char *ret;
...@@ -921,20 +888,32 @@ static char *strdup_unixcp( const WCHAR *str ) ...@@ -921,20 +888,32 @@ static char *strdup_unixcp( const WCHAR *str )
static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username, static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username,
LPCWSTR oldpassword, LPCWSTR newpassword ) LPCWSTR oldpassword, LPCWSTR newpassword )
{ {
#ifdef HAVE_FORK
NET_API_STATUS ret = NERR_Success; NET_API_STATUS ret = NERR_Success;
static char option_silent[] = "-s"; static char option_silent[] = "-s";
static char option_user[] = "-U"; static char option_user[] = "-U";
static char option_remote[] = "-r"; static char option_remote[] = "-r";
static char smbpasswd[] = "smbpasswd"; static char smbpasswd[] = "smbpasswd";
int pipe_out; int pipe_out[2];
pid_t pid; pid_t pid, wret;
char *server = NULL, *user, *argv[7], *old, *new = NULL; int status;
char *server = NULL, *user, *argv[7], *old = NULL, *new = NULL;
if (domainname && !(server = strdup_unixcp( domainname ))) return ERROR_OUTOFMEMORY; if (domainname && !(server = strdup_unixcp( domainname ))) return ERROR_OUTOFMEMORY;
if (!(user = strdup_unixcp( username ))) if (!(user = strdup_unixcp( username )))
{ {
HeapFree( GetProcessHeap(), 0, server ); ret = ERROR_OUTOFMEMORY;
return ERROR_OUTOFMEMORY; goto end;
}
if (!(old = strdup_unixcp( oldpassword )))
{
ret = ERROR_OUTOFMEMORY;
goto end;
}
if (!(new = strdup_unixcp( newpassword )))
{
ret = ERROR_OUTOFMEMORY;
goto end;
} }
argv[0] = smbpasswd; argv[0] = smbpasswd;
argv[1] = option_silent; argv[1] = option_silent;
...@@ -948,48 +927,57 @@ static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username, ...@@ -948,48 +927,57 @@ static NET_API_STATUS change_password_smb( LPCWSTR domainname, LPCWSTR username,
} }
else argv[4] = NULL; else argv[4] = NULL;
pipe_out = fork_smbpasswd( argv, &pid ); if (pipe( pipe_out ) == -1)
HeapFree( GetProcessHeap(), 0, server );
HeapFree( GetProcessHeap(), 0, user );
if (pipe_out == -1) return NERR_InternalError;
if (!(old = strdup_unixcp( oldpassword )))
{ {
ret = ERROR_OUTOFMEMORY; ret = NERR_InternalError;
goto end; goto end;
} }
if (!(new = strdup_unixcp( newpassword ))) fcntl( pipe_out[0], F_SETFD, FD_CLOEXEC );
fcntl( pipe_out[1], F_SETFD, FD_CLOEXEC );
switch ((pid = fork()))
{ {
ret = ERROR_OUTOFMEMORY; case -1:
close( pipe_out[0] );
close( pipe_out[1] );
ret = NERR_InternalError;
goto end; goto end;
case 0:
dup2( pipe_out[0], 0 );
close( pipe_out[0] );
close( pipe_out[1] );
execvp( "smbpasswd", argv );
ERR( "can't execute smbpasswd, is it installed?\n" );
_exit(1);
default:
close( pipe_out[0] );
break;
} }
write( pipe_out, old, strlen( old ) ); write( pipe_out[1], old, strlen( old ) );
write( pipe_out, "\n", 1 ); write( pipe_out[1], "\n", 1 );
write( pipe_out, new, strlen( new ) ); write( pipe_out[1], new, strlen( new ) );
write( pipe_out, "\n", 1 ); write( pipe_out[1], "\n", 1 );
write( pipe_out, new, strlen( new ) ); write( pipe_out[1], new, strlen( new ) );
write( pipe_out, "\n", 1 ); write( pipe_out[1], "\n", 1 );
close( pipe_out[1] );
end: do {
close( pipe_out ); wret = waitpid(pid, &status, 0);
} while (wret < 0 && errno == EINTR);
#ifdef HAVE_FORK if (ret == NERR_Success && (wret < 0 || !WIFEXITED(status) || WEXITSTATUS(status)))
{ ret = NERR_InternalError;
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
end:
HeapFree( GetProcessHeap(), 0, server );
HeapFree( GetProcessHeap(), 0, user );
HeapFree( GetProcessHeap(), 0, old ); HeapFree( GetProcessHeap(), 0, old );
HeapFree( GetProcessHeap(), 0, new ); HeapFree( GetProcessHeap(), 0, new );
return ret; return ret;
#else
ERR( "no fork support on this platform\n" );
return NERR_InternalError;
#endif
} }
/****************************************************************************** /******************************************************************************
......
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