mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-25 23:14:54 +02:00
Refactored do_exec* calls
This commit is contained in:
parent
92ddf4f9e1
commit
122ed4bf4d
Binary file not shown.
123
session.c
123
session.c
@ -491,29 +491,12 @@ do_authenticated1(Authctxt *authctxt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRAGMA:TODO
|
#ifdef WINDOWS
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
#define USE_PIPES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
int do_exec_windows(Session *s, const char *command, int pty) {
|
||||||
extern int debug_flag;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is called to fork and execute a command when we have no tty. This
|
|
||||||
* will call do_child from the child, and server_loop from the parent after
|
|
||||||
* setting up file descriptors and such.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
do_exec_no_pty(Session *s, const char *command)
|
|
||||||
{
|
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
wchar_t* pw_dir_utf16 = utf8_to_utf16(s->pw->pw_dir);
|
wchar_t* pw_dir_utf16 = utf8_to_utf16(s->pw->pw_dir);
|
||||||
|
extern int debug_flag;
|
||||||
/*
|
|
||||||
* Win32 code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (s->is_subsystem == SUBSYSTEM_INT_SFTP_ERROR)
|
if (s->is_subsystem == SUBSYSTEM_INT_SFTP_ERROR)
|
||||||
{
|
{
|
||||||
@ -544,9 +527,6 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
|
|
||||||
HANDLE hToken = INVALID_HANDLE_VALUE;
|
HANDLE hToken = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
int do_xauth;
|
|
||||||
|
|
||||||
FILE *f = NULL;
|
|
||||||
|
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
char *exec_command;
|
char *exec_command;
|
||||||
@ -558,30 +538,13 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
|
|
||||||
if (!command)
|
if (!command)
|
||||||
{
|
{
|
||||||
#ifndef WIN32_PRAGMA_REMCON
|
|
||||||
exec_command = s->pw->pw_shell;
|
exec_command = s->pw->pw_shell;
|
||||||
#else
|
|
||||||
if ( PathFileExists("\\program files\\pragma\\shared files\\cmdserver.exe") )
|
|
||||||
snprintf(exec_command_str, sizeof(exec_command_str),
|
|
||||||
"\\program files\\pragma\\shared files\\cmdserver.exe SSHD %d %d", s->row, s->col );
|
|
||||||
else {
|
|
||||||
// find base path of our executable
|
|
||||||
char basepath[MAX_PATH];
|
|
||||||
strcpy_s(basepath, MAX_PATH, __progname);
|
|
||||||
PathRemoveFileSpec(basepath); // get the full dir part of the name
|
|
||||||
snprintf(exec_command_str, sizeof(exec_command_str),
|
|
||||||
"%s\\cmdserver.exe SSHD %d %d", basepath,s->row, s->col);
|
|
||||||
}
|
|
||||||
exec_command = exec_command_str;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exec_command = command;
|
exec_command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_xauth = s -> display != NULL && s -> auth_proto != NULL && s -> auth_data != NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create three socket pairs for stdin, stdout and stderr
|
* Create three socket pairs for stdin, stdout and stderr
|
||||||
*/
|
*/
|
||||||
@ -639,45 +602,6 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
SetEnvironmentVariable("USERNAME", s->pw->pw_name);
|
SetEnvironmentVariable("USERNAME", s->pw->pw_name);
|
||||||
SetEnvironmentVariable("LOGNAME", s->pw->pw_name);
|
SetEnvironmentVariable("LOGNAME", s->pw->pw_name);
|
||||||
|
|
||||||
/*
|
|
||||||
* Setup xauth if needed
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (do_xauth && options.xauth_location != NULL)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Add authority data to .Xauthority if appropriate.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (debug_flag)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Running %.500s remove %.100s\n",
|
|
||||||
options.xauth_location, s->auth_display);
|
|
||||||
|
|
||||||
fprintf(stderr, "%.500s add %.100s %.100s %.100s\n", options.xauth_location,
|
|
||||||
s -> auth_display, s -> auth_proto, s -> auth_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(cmd, sizeof cmd, "%s -q -", options.xauth_location);
|
|
||||||
|
|
||||||
f = _popen(cmd, "w");
|
|
||||||
|
|
||||||
if (f)
|
|
||||||
{
|
|
||||||
fprintf(f, "remove %s\n", s -> auth_display);
|
|
||||||
|
|
||||||
fprintf(f, "add %s %s %s\n", s -> auth_display, s -> auth_proto, s -> auth_data);
|
|
||||||
|
|
||||||
_pclose(f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Could not run %s\n", cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
|
||||||
set_nonblock(pipein[0]);
|
set_nonblock(pipein[0]);
|
||||||
set_nonblock(pipein[1]);
|
set_nonblock(pipein[1]);
|
||||||
set_nonblock(pipeout[0]);
|
set_nonblock(pipeout[0]);
|
||||||
@ -685,8 +609,6 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
set_nonblock(pipeerr[0]);
|
set_nonblock(pipeerr[0]);
|
||||||
set_nonblock(pipeerr[1]);
|
set_nonblock(pipeerr[1]);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we get this far, the user has already been authenticated
|
* If we get this far, the user has already been authenticated
|
||||||
* We should either have a user token in authctxt -> methoddata
|
* We should either have a user token in authctxt -> methoddata
|
||||||
@ -723,8 +645,6 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
SetEnvironmentVariableW(L"HOMEPATH", (wstr + 1));
|
SetEnvironmentVariableW(L"HOMEPATH", (wstr + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// find the server name of the domain controller which created this token
|
// find the server name of the domain controller which created this token
|
||||||
GetDomainFromToken(&hToken, buf, sizeof(buf));
|
GetDomainFromToken(&hToken, buf, sizeof(buf));
|
||||||
if (buf[0])
|
if (buf[0])
|
||||||
@ -905,11 +825,28 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
do_exec_no_pty(Session *s, const char *command) {
|
||||||
|
return do_exec_windows(s, command, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
do_exec_pty(Session *s, const char *command) {
|
||||||
|
return do_exec_windows(s, command, 1);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Original OpenSSH code.
|
* This is called to fork and execute a command when we have no tty. This
|
||||||
|
* will call do_child from the child, and server_loop from the parent after
|
||||||
|
* setting up file descriptors and such.
|
||||||
*/
|
*/
|
||||||
|
int
|
||||||
|
do_exec_no_pty(Session *s, const char *command)
|
||||||
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
#ifdef USE_PIPES
|
#ifdef USE_PIPES
|
||||||
@ -1094,7 +1031,7 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* else WIN32_FIXME */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1106,11 +1043,6 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
int
|
int
|
||||||
do_exec_pty(Session *s, const char *command)
|
do_exec_pty(Session *s, const char *command)
|
||||||
{
|
{
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Original OpenSSH code.
|
|
||||||
*/
|
|
||||||
int fdout, ptyfd, ttyfd, ptymaster;
|
int fdout, ptyfd, ttyfd, ptymaster;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
@ -1222,17 +1154,8 @@ do_exec_pty(Session *s, const char *command)
|
|||||||
/* server_loop _has_ closed ptyfd and fdout. */
|
/* server_loop _has_ closed ptyfd and fdout. */
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Win32 code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//return 0;
|
|
||||||
return do_exec_no_pty(s, command);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LOGIN_NEEDS_UTMPX
|
#ifdef LOGIN_NEEDS_UTMPX
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user