[NFSD] [TELNET] Remove the hardcoded directory paths C:\ReactOS
[reactos.git] / base / services / telnetd / telnetd.c
index 920ddea..927d286 100644 (file)
@@ -367,12 +367,20 @@ static void RunShell(client_t *client)
    STARTUPINFO           si;
    PROCESS_INFORMATION   piProcInfo;
    SECURITY_ATTRIBUTES   saAttr;
+   char cmd_path[MAX_PATH];
+
+   if (!GetEnvironmentVariableA("COMSPEC", cmd_path, ARRAYSIZE(cmd_path)))
+   {
+      if (GetSystemDirectoryA(cmd_path, ARRAYSIZE(cmd_path)))
+      {
+         StringCchCatA(cmd_path, ARRAYSIZE(cmd_path), "\\cmd.exe");
+      }
+      else
+      {
+         StringCchCopyA(cmd_path, ARRAYSIZE(cmd_path), "C:\\ReactOS\\system32\\cmd.exe");
+      }
+   }
 
-   const char *name = "c:\\reactos\\system32\\cmd.exe";
-   const char *cmd = NULL;
-   //const char *name = "d:\\cygwin\\bin\\bash.exe";
-   //const char *cmd = "d:\\cygwin\\bin\\bash.exe --login -i";
-   
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
    saAttr.bInheritHandle = TRUE; 
    saAttr.lpSecurityDescriptor = NULL; 
@@ -406,8 +414,8 @@ static void RunShell(client_t *client)
    //si.dwFlags |= STARTF_USESHOWWINDOW;
    //si.wShowWindow = SW_SHOW;
 
-   if (!CreateProcess((LPSTR) name,              // executable module
-                      (LPSTR) cmd,               // command line 
+   if (!CreateProcess(cmd_path,                  // executable module
+                      NULL,                      // command line 
                       NULL,                      // process security attributes 
                       NULL,                      // primary thread security attributes 
                       TRUE,                      // handles are inherited