-
Notifications
You must be signed in to change notification settings - Fork 41
Basic AuthPlugin support #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sundy-li
wants to merge
21
commits into
jonhoo:main
Choose a base branch
from
datafuse-extras:auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0ba7f46
Bump deps, WIP
PsiACE c5f3f9b
try bump some dev-deps, drop de/encode tests
PsiACE 918b954
Remove time
PsiACE 6f6dbeb
Fix decode test
PsiACE 677fff8
Fix encode test
PsiACE 78b6901
Try to make clippy happy
PsiACE aacfa27
Set up CI with Azure Pipelines (#2)
4b32c95
Try to bump postgres
PsiACE bec0ad8
Merge pull request #1 from PsiACE/bump-deps
sundy-li ed40333
Minrust 1.51
884eaed
[bump] nom into 7.0.0-alpha2
sundy-li 77da474
Merge branch 'master' into bump-nom
sundy-li cc53408
Merge pull request #3 from datafuse-extras/bump-nom
sundy-li 49c9d5d
Merge upstream
sundy-li 45b5b8a
Merge pull request #5 from datafuse-extras/merge-upstream
sundy-li e614b26
add mysql_native_password auth support
sundy-li 1b9bcc2
Merge branch 'master' of github.com:jonhoo/msql-srv
sundy-li eed337c
Merge upstream
sundy-li 9a9651c
Merge branch 'master' into auth
sundy-li bb7ba7b
Update
sundy-li 2387bc8
Apply suggestions
sundy-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| //! After running this, you should be able to run: | ||
| //! | ||
| //! ```console | ||
| //! $ echo "SELECT * FROM foo" | mysql -h 127.0.0.1 --table | ||
| //! $ | ||
| //! ``` | ||
|
|
||
| extern crate msql_srv; | ||
| extern crate mysql; | ||
| extern crate mysql_common as myc; | ||
|
|
||
| use msql_srv::*; | ||
| use std::io; | ||
| use std::net; | ||
| use std::thread; | ||
|
|
||
| struct Backend; | ||
| impl<W: io::Write> MysqlShim<W> for Backend { | ||
| type Error = io::Error; | ||
|
|
||
| fn on_prepare(&mut self, _: &str, info: StatementMetaWriter<W>) -> io::Result<()> { | ||
| info.reply(42, &[], &[]) | ||
| } | ||
| fn on_execute( | ||
| &mut self, | ||
| _: u32, | ||
| _: msql_srv::ParamParser, | ||
| results: QueryResultWriter<W>, | ||
| ) -> io::Result<()> { | ||
| results.completed(0, 0) | ||
| } | ||
| fn on_close(&mut self, _: u32) {} | ||
|
|
||
| fn on_query(&mut self, sql: &str, results: QueryResultWriter<W>) -> io::Result<()> { | ||
| println!("execute sql {:?}", sql); | ||
| results.start(&[])?.finish() | ||
| } | ||
|
|
||
| /// authenticate method for the specified plugin | ||
| fn authenticate( | ||
| &self, | ||
| auth_plugin: &str, | ||
| username: &[u8], | ||
| salt: &[u8], | ||
| auth_data: &[u8], | ||
| ) -> bool { | ||
| println!( | ||
| "auth_plugin, {:?}, user: {:?} , salt: {:?}, auth_data:{:?}", | ||
| auth_plugin, username, salt, auth_data | ||
| ); | ||
|
|
||
| username == "default".as_bytes() | ||
| } | ||
|
|
||
| fn on_init(&mut self, _: &str, _: InitWriter<'_, W>) -> Result<(), Self::Error> { | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn version(&self) -> &str { | ||
| // 5.1.10 because that's what Ruby's ActiveRecord requires | ||
| "5.1.10-alpha-msql-proxy" | ||
| } | ||
|
|
||
| fn connect_id(&self) -> u32 { | ||
| u32::from_le_bytes([0x08, 0x00, 0x00, 0x00]) | ||
| } | ||
|
|
||
| fn default_auth_plugin(&self) -> &str { | ||
| "mysql_native_password" | ||
| } | ||
|
|
||
| fn auth_plugin_for_username(&self, _user: &[u8]) -> &str { | ||
| "mysql_native_password" | ||
| } | ||
|
|
||
| fn salt(&self) -> [u8; 20] { | ||
| let bs = ";X,po_k}>o6^Wz!/kM}N".as_bytes(); | ||
| let mut scramble: [u8; 20] = [0; 20]; | ||
| for i in 0..20 { | ||
| scramble[i] = bs[i]; | ||
| if scramble[i] == b'\0' || scramble[i] == b'$' { | ||
| scramble[i] = scramble[i] + 1; | ||
| } | ||
| } | ||
| scramble | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| let mut threads = Vec::new(); | ||
| let listener = net::TcpListener::bind("127.0.0.1:3306").unwrap(); | ||
|
|
||
| while let Ok((s, _)) = listener.accept() { | ||
| println!("{:?}", "got one socket"); | ||
| threads.push(thread::spawn(move || { | ||
| MysqlIntermediary::run_on_tcp(Backend, s).unwrap(); | ||
| })); | ||
| } | ||
|
|
||
| for t in threads { | ||
| t.join().unwrap(); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn it_works() { | ||
| let c: u8 = b'\0'; | ||
| let d: u8 = 0 as u8; | ||
| let e: u8 = 0x00; | ||
|
|
||
| assert_eq!(c, d); | ||
| assert_eq!(e, d); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.