@@ -1569,79 +1569,64 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1569
1569
}
1570
1570
break ;
1571
1571
}
1572
+
1573
+ /*
1574
+ * Normal production daemon. Fork, and have
1575
+ * the child process the connection. The
1576
+ * parent continues listening.
1577
+ */
1578
+ platform_pre_fork ();
1572
1579
#ifdef WIN32_FIXME
1573
-
1574
- /*
1575
- * Win32 code.
1576
- */
1580
+ {
1581
+ PROCESS_INFORMATION pi ;
1582
+ STARTUPINFO si ;
1583
+ BOOL b ;
1584
+ char path [MAX_PATH ];
1577
1585
1578
- {
1579
- PROCESS_INFORMATION pi ;
1580
-
1581
- STARTUPINFO si ;
1582
-
1583
- BOOL b ;
1586
+ memset (& si , 0 , sizeof (STARTUPINFO ));
1584
1587
1588
+ char remotesoc [64 ];
1589
+ snprintf (remotesoc , sizeof (remotesoc ), "%d" , sfd_to_handle (* newsock ));
1590
+ SetEnvironmentVariable ("SSHD_REMSOC" , remotesoc );
1585
1591
1586
- /*
1587
- * Assign sockets to StartupInfo.
1588
- */
1589
-
1590
- memset (& si , 0 , sizeof (STARTUPINFO ));
1591
-
1592
- char remotesoc [64 ];
1593
- snprintf ( remotesoc , sizeof (remotesoc ), "%d" , sfd_to_handle (* newsock ));
1594
- SetEnvironmentVariable ("SSHD_REMSOC" , remotesoc );
1595
-
1596
- si .cb = sizeof (STARTUPINFO );
1597
- si .hStdInput = GetStdHandle (STD_INPUT_HANDLE ); //(HANDLE) sfd_to_handle(*newsock);
1598
- si .hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE );
1599
- si .hStdError = GetStdHandle (STD_ERROR_HANDLE );
1600
- si .wShowWindow = SW_HIDE ;
1601
- si .dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES ;
1602
-
1603
- /*
1604
- * Create the child process
1605
- */
1606
-
1607
- b = CreateProcess (NULL , fake_fork_args , NULL , NULL , TRUE,
1608
- CREATE_NEW_PROCESS_GROUP , NULL , NULL ,
1609
- & si , & pi );
1610
- if (!b )
1611
- {
1612
- debug ("CreateProcess failure: %d" , GetLastError ());
1613
-
1614
- exit (1 );
1615
- }
1592
+ si .cb = sizeof (STARTUPINFO );
1593
+ si .hStdInput = GetStdHandle (STD_INPUT_HANDLE );
1594
+ si .hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE );
1595
+ si .hStdError = GetStdHandle (STD_ERROR_HANDLE );
1596
+ si .wShowWindow = SW_HIDE ;
1597
+ si .dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES ;
1616
1598
1617
- /*
1618
- * Close child thread and process handles so it can go away
1619
- */
1599
+ /*
1600
+ * Create the child process
1601
+ */
1602
+ strncpy (path , GetCommandLineA (), MAX_PATH );
1603
+ if (CreateProcess (NULL , path , NULL , NULL , TRUE,
1604
+ CREATE_NEW_PROCESS_GROUP , NULL , NULL ,
1605
+ & si , & pi ) == FALSE) {
1606
+ debug ("CreateProcess failure: %d" , GetLastError ());
1607
+ exit (1 );
1608
+ }
1620
1609
1621
- CloseHandle (pi .hThread );
1622
- CloseHandle (pi .hProcess );
1623
-
1624
- close (* newsock );
1610
+ /*
1611
+ * Close child thread and process handles so it can go away
1612
+ */
1625
1613
1626
- /*
1627
- * FIXME pipes are not used so instead of
1628
- * cleaning we can disable creation.
1629
- */
1630
-
1631
- close (startup_pipes [i ]);
1632
- startup_pipes [i ] = -1 ;
1633
- startups -- ;
1634
- }
1614
+ CloseHandle (pi .hThread );
1615
+ CloseHandle (pi .hProcess );
1635
1616
1636
- #else
1617
+ close (* newsock );
1618
+ close (startup_pipes [i ]);
1619
+ startup_pipes [i ] = -1 ;
1620
+ startups -- ;
1621
+
1622
+ pid = pi .dwProcessId ;
1623
+ }
1624
+
1625
+ if (pid == 0 ) {
1626
+ #else
1637
1627
1638
- /*
1639
- * Normal production daemon. Fork, and have
1640
- * the child process the connection. The
1641
- * parent continues listening.
1642
- */
1643
- platform_pre_fork ();
1644
1628
if ((pid = fork ()) == 0 ) {
1629
+ #endif /* else WIN32_FIXME */
1645
1630
/*
1646
1631
* Child. Close the listening and
1647
1632
* max_startup sockets. Start using
@@ -1704,7 +1689,6 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1704
1689
RAND_seed (rnd , sizeof (rnd ));
1705
1690
#endif
1706
1691
explicit_bzero (rnd , sizeof (rnd ));
1707
- #endif /* else WIN32_FIXME */
1708
1692
}
1709
1693
1710
1694
/* child process check (or debug mode) */
@@ -1719,21 +1703,6 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1719
1703
* Win32 only.
1720
1704
*/
1721
1705
1722
- char * create_fake_fork_args (int ac , char * * av )
1723
- {
1724
- char * orig_cmd_line = GetCommandLine ();
1725
-
1726
- char fake_fork_param [] = " -~" ;
1727
-
1728
- int orig_cmd_line_len = strlen (orig_cmd_line );
1729
-
1730
- char * new_cmd_line = xmalloc (orig_cmd_line_len + 1 + sizeof (fake_fork_param ));
1731
-
1732
- strcpy (new_cmd_line , orig_cmd_line );
1733
- strcpy (new_cmd_line + orig_cmd_line_len , fake_fork_param );
1734
-
1735
- return new_cmd_line ;
1736
- }
1737
1706
1738
1707
/*
1739
1708
* This function handles exit signal from parent process.
@@ -1826,16 +1795,7 @@ main(int ac, char **av)
1826
1795
saved_argv [i ] = xstrdup (av [i ]);
1827
1796
saved_argv [i ] = NULL ;
1828
1797
1829
- #ifdef WIN32_FIXME
1830
-
1831
- /*
1832
- * Create arguments for starting fake forked sshd.exe instances.
1833
- */
1834
-
1835
- fake_fork_args = create_fake_fork_args (ac , av );
1836
-
1837
- #endif /* WIN32_FIXME */
1838
-
1798
+
1839
1799
#ifndef HAVE_SETPROCTITLE
1840
1800
/* Prepare for later setproctitle emulation */
1841
1801
compat_init_setproctitle (ac , av );
@@ -1852,35 +1812,11 @@ main(int ac, char **av)
1852
1812
1853
1813
/* Initialize configuration options to their default values. */
1854
1814
initialize_server_options (& options );
1855
-
1856
-
1857
- #ifdef WIN32_FIXME
1858
-
1859
- //debug_flag = 1;
1860
-
1861
- #define FAKE_FORK_ARG "~"
1862
-
1863
- #else
1864
-
1865
- #define FAKE_FORK_ARG
1866
-
1867
- #endif
1868
1815
1869
1816
/* Parse command-line arguments. */
1870
1817
while ((opt = getopt (ac , av ,
1871
- "C:E:b:c:f:g:h:k:o:p:u:46DQRTdeiqrt" FAKE_FORK_ARG )) != -1 ) {
1818
+ "C:E:b:c:f:g:h:k:o:p:u:46DQRTdeiqrt" )) != -1 ) {
1872
1819
switch (opt ) {
1873
-
1874
- #ifdef WIN32_FIXME
1875
- case '~' :
1876
- {
1877
- debug ("fake fork child" );
1878
-
1879
- options .i_am_a_fake_fork = 1 ;
1880
-
1881
- break ;
1882
- }
1883
- #endif
1884
1820
1885
1821
case '4' :
1886
1822
options .address_family = AF_INET ;
@@ -2000,37 +1936,7 @@ main(int ac, char **av)
2000
1936
}
2001
1937
2002
1938
#ifdef WIN32_FIXME
2003
-
2004
- /*
2005
- * Win32 only.
2006
- */
2007
-
2008
- /*
2009
- * Handle install and uninstall service options
2010
- */
2011
-
2012
- if (ac > 1 && strcmp ("install" , av [1 ]) == 0 )
2013
- {
2014
- /*
2015
- * Install the service
2016
- */
2017
-
2018
- SvcInstall ();
2019
-
2020
- return 0 ;
2021
- }
2022
- else if (ac > 1 && strcmp ("uninstall" , av [1 ]) == 0 )
2023
- {
2024
- /*
2025
- * Remove the service
2026
- */
2027
-
2028
- SvcUninstall ();
2029
-
2030
- return 0 ;
2031
- }
2032
-
2033
- if (!options .i_am_a_fake_fork )
1939
+ if (getenv ("SSHD_REMSOC" ) == NULL )
2034
1940
{
2035
1941
if (!ranServiceMain )
2036
1942
{
@@ -2575,7 +2481,7 @@ main(int ac, char **av)
2575
2481
} else {
2576
2482
platform_pre_listen ();
2577
2483
#ifdef WIN32_FIXME
2578
- if (! options . i_am_a_fake_fork )
2484
+ if (getenv ( "SSHD_REMSOC" ) == NULL )
2579
2485
#endif
2580
2486
server_listen ();
2581
2487
@@ -2604,7 +2510,7 @@ main(int ac, char **av)
2604
2510
}
2605
2511
#ifdef WIN32_FIXME
2606
2512
2607
- if (! options . i_am_a_fake_fork )
2513
+ if (getenv ( "SSHD_REMSOC" ) == NULL )
2608
2514
{
2609
2515
/*
2610
2516
* Accept a connection and return in a forked child
@@ -2613,23 +2519,11 @@ main(int ac, char **av)
2613
2519
server_accept_loop (& sock_in , & sock_out , & newsock , config_s );
2614
2520
}
2615
2521
else
2616
- {
2617
- //STARTUPINFO si;
2618
-
2619
- //memset(&si, 0 , sizeof(STARTUPINFO));
2620
-
2621
- //si.cb = sizeof(STARTUPINFO);
2622
-
2623
- /*
2624
- * Get the stdin handle from process info to use for client
2625
- */
2626
-
2627
- //GetStartupInfo(&si);
2628
-
2522
+ {
2629
2523
int remotesochandle ;
2630
2524
remotesochandle = atoi ( getenv ("SSHD_REMSOC" ) );
2631
2525
2632
- sock_in = sock_out = newsock = w32_allocate_fd_for_handle (remotesochandle , TRUE) ; //si.hStdInput);
2526
+ sock_in = sock_out = newsock = w32_allocate_fd_for_handle (remotesochandle , TRUE) ;
2633
2527
2634
2528
// we have the socket handle, delete it for child processes we create like shell
2635
2529
SetEnvironmentVariable ("SSHD_REMSOC" , NULL );
@@ -3249,7 +3143,7 @@ cleanup_exit(int i)
3249
3143
audit_event (SSH_CONNECTION_ABANDON );
3250
3144
#endif
3251
3145
#ifdef WIN32_FIXME
3252
- if (!iAmAService || options . i_am_a_fake_fork )
3146
+ if (!iAmAService || ( getenv ( "SSHD_REMSOC" )) )
3253
3147
#endif
3254
3148
_exit (i );
3255
3149
}
0 commit comments