Skip to content

Commit

Permalink
Merge pull request #1652 from zowe/fix/daemon/username-casing
Browse files Browse the repository at this point in the history
daemon (Windows): coerce username to lowercase
  • Loading branch information
traeok authored Mar 14, 2023
2 parents 1a7893f + 0993e3e commit cb98eab
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 194 deletions.
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- BugFix: Solved daemon issue where Windows usernames were treated as case-sensitive when checking the daemon process owner during Zowe commands.

## `7.11.0`
- Enhancement: Added support for a CLI specific environment variable file. [#1484](https://github.com/zowe/zowe-cli/issues/1484)
- BugFix: Enabled option to download output from a submitted job with the -d flag. The -e flag now enables changes to file extension as originally intended. [#729](https://github.com/zowe/zowe-cli/issues/729)
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/daemon/DaemonDecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export class DaemonDecider {
this.initialParse();
if (this.startServer) {
this.mUser = os.userInfo().username;
if (process.platform === "win32") {
this.mUser = this.mUser.toLowerCase();
}
this.mServer = net.createServer((c) => {
new DaemonClient(c, this.mServer, this.mUser).run();
});
Expand Down
2 changes: 1 addition & 1 deletion zowex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zowex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zowe"
version = "1.0.2"
version = "1.0.3"
authors = ["Zowe Project"]
edition = "2018"
license = "EPL-2.0"
Expand Down
68 changes: 37 additions & 31 deletions zowex/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
// Functions related to daemon cummunication.

use std::io;
use std::io::BufReader;
use std::io::prelude::*;
use std::io::BufReader;
use std::str;
use std::thread;
use std::time::Duration;

#[cfg(target_family = "unix")]
use {
std::net::Shutdown,
std::os::unix::net::UnixStream
};
use {std::net::Shutdown, std::os::unix::net::UnixStream};

extern crate atty;
use atty::Stream;
Expand All @@ -31,25 +28,23 @@ extern crate base64;
use base64::encode;

#[cfg(target_family = "windows")]
extern crate named_pipe;
extern crate named_pipe;
#[cfg(target_family = "windows")]
use named_pipe::PipeClient;
use named_pipe::PipeClient;

extern crate rpassword;
use rpassword::read_password;

extern crate whoami;
use whoami::username;

// Zowe daemon executable modules
use crate::defs::*;
use crate::proc::*;
use crate::util::util_get_username;

#[cfg(target_family = "unix")]
type DaemonClient = UnixStream;
type DaemonClient = UnixStream;

#[cfg(target_family = "windows")]
type DaemonClient = PipeClient;
type DaemonClient = PipeClient;

/**
* Attempt to make a TCP connection to the daemon.
Expand All @@ -65,7 +60,10 @@ use crate::proc::*;
* A Result containing a stream upon success.
* This function exits the process upon error.
*/
pub fn comm_establish_connection(njs_zowe_path: &str, daemon_socket: &str) -> io::Result<DaemonClient> {
pub fn comm_establish_connection(
njs_zowe_path: &str,
daemon_socket: &str,
) -> io::Result<DaemonClient> {
const RETRY_TO_SHOW_DIAG: i32 = 5;

let mut conn_retries = 0;
Expand All @@ -89,7 +87,8 @@ pub fn comm_establish_connection(njs_zowe_path: &str, daemon_socket: &str) -> io
we_started_daemon = true;
cmd_to_show = proc_start_daemon(njs_zowe_path);
} else if we_started_daemon && conn_retries > THREE_MIN_OF_RETRIES {
println!("The Zowe daemon that we started is not running on socket: {}.",
println!(
"The Zowe daemon that we started is not running on socket: {}.",
daemon_socket
);
println!(
Expand All @@ -101,7 +100,10 @@ pub fn comm_establish_connection(njs_zowe_path: &str, daemon_socket: &str) -> io
}

if conn_retries > THREE_MIN_OF_RETRIES {
println!("Terminating after {} connection retries.", THREE_MIN_OF_RETRIES);
println!(
"Terminating after {} connection retries.",
THREE_MIN_OF_RETRIES
);
std::process::exit(EXIT_CODE_CANNOT_CONNECT_TO_RUNNING_DAEMON);
}

Expand All @@ -116,7 +118,8 @@ pub fn comm_establish_connection(njs_zowe_path: &str, daemon_socket: &str) -> io
} else {
println!("Command = {}", daemon_proc_info.cmd);
}
println!("Process name = {} pid = {} socket = {}\n",
println!(
"Process name = {} pid = {} socket = {}\n",
daemon_proc_info.name, daemon_proc_info.pid, daemon_socket
);
}
Expand All @@ -127,7 +130,10 @@ pub fn comm_establish_connection(njs_zowe_path: &str, daemon_socket: &str) -> io
"Attempting to connect to the Zowe daemon"
};
if conn_retries > 0 {
println!("{} ({} of {})", retry_msg, conn_retries, THREE_MIN_OF_RETRIES);
println!(
"{} ({} of {})",
retry_msg, conn_retries, THREE_MIN_OF_RETRIES
);
}
conn_retries += 1;
};
Expand Down Expand Up @@ -187,18 +193,16 @@ pub fn comm_talk(message: &[u8], stream: &mut DaemonClient) -> io::Result<i32> {
io::stderr().flush().unwrap();
}
continue;
},
result => {
match result {
Ok(ok_val) => {
p = ok_val;
},
Err(err_val) => {
eprintln!("You may be running mismatched versions of Zowe executable and Zowe daemon.");
return Err(std::io::Error::new(std::io::ErrorKind::Other, err_val))
}
}
}
result => match result {
Ok(ok_val) => {
p = ok_val;
}
Err(err_val) => {
eprintln!("You may be running mismatched versions of Zowe executable and Zowe daemon.");
return Err(std::io::Error::new(std::io::ErrorKind::Other, err_val));
}
},
};

if let Some(s) = p.stdout {
Expand All @@ -225,14 +229,16 @@ pub fn comm_talk(message: &[u8], stream: &mut DaemonClient) -> io::Result<i32> {
reply = Some(read_password().unwrap());
}

let executor = util_get_username();

if let Some(s) = reply {
let response: DaemonResponse = DaemonResponse {
argv: None,
cwd: None,
env: None,
stdinLength: None,
stdin: Some(s),
user: Some(encode(username())),
user: Some(encode(executor)),
};
let v = serde_json::to_string(&response)?;
#[cfg(target_family = "unix")]
Expand All @@ -254,8 +260,8 @@ pub fn comm_talk(message: &[u8], stream: &mut DaemonClient) -> io::Result<i32> {
// end of reading
break;
}
},
Err(err_val) => { return Err(err_val) }
}
Err(err_val) => return Err(err_val),
} // end match on read
} // end loop

Expand Down
22 changes: 11 additions & 11 deletions zowex/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ pub struct DaemonResponse {
#[derive(Deserialize)]
pub struct DaemonPidForUser {
pub user: String,
pub pid: i32
pub pid: i32,
}

pub enum CmdShell {
Bash, // Bourne Again SHell
Sh, // Standard Linux shell
Korn, // Korn shell
Zshell, // Z shell
Cshell, // C shell
Tenex, // TENEX C shell
PowerShellDotNet, // Newer cross-platform .NET Core PowerShell
PowerShellExe, // Legacy Windows executable PowerShell (version 5.x)
WindowsCmd, // Classic Windows CMD shell
Unknown // A command shell that we do not yet understand
Bash, // Bourne Again SHell
Sh, // Standard Linux shell
Korn, // Korn shell
Zshell, // Z shell
Cshell, // C shell
Tenex, // TENEX C shell
PowerShellDotNet, // Newer cross-platform .NET Core PowerShell
PowerShellExe, // Legacy Windows executable PowerShell (version 5.x)
WindowsCmd, // Classic Windows CMD shell
Unknown, // A command shell that we do not yet understand
}
6 changes: 3 additions & 3 deletions zowex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::env;
use std::io;

// other source modules that constitute this executable
mod defs;
mod comm;
mod defs;
mod proc;
mod run;
mod util;
Expand Down Expand Up @@ -49,11 +49,11 @@ fn main() -> io::Result<()> {
*/
let exit_code: i32 = match run_zowe_command(&mut cmd_line_args) {
Ok(ok_val) => ok_val,
Err(err_val) => err_val
Err(err_val) => err_val,
};

/* Rust does not enable main() to return an exit code.
* Thus, we explicitly exit the process with our desired exit code.
*/
std::process::exit(exit_code);
}
}
Loading

0 comments on commit cb98eab

Please sign in to comment.