diff --git a/Cargo.lock b/Cargo.lock index 61a7268..c4bbf3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,50 +4,28 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "base64" -version = "0.13.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "bindgen" -version = "0.59.2" +version = "0.63.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" +checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885" dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", - "env_logger", "lazy_static", "lazycell", "log", @@ -57,6 +35,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn", "which", ] @@ -68,9 +47,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cexpr" @@ -89,9 +68,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" +checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", @@ -99,31 +78,19 @@ dependencies = [ ] [[package]] -name = "clap" -version = "2.34.0" +name = "convert_case" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", + "unicode-segmentation", ] -[[package]] -name = "convert_case" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" - [[package]] name = "ctor" -version = "0.1.21" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", "syn", @@ -131,43 +98,15 @@ dependencies = [ [[package]] name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "env_logger" -version = "0.9.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "krb5-js" @@ -188,7 +127,6 @@ name = "krb5-rs" version = "0.1.0" dependencies = [ "krb5-sys", - "lazy_static", "thiserror", ] @@ -216,15 +154,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.117" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", "winapi", @@ -232,18 +170,18 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "minimal-lexical" @@ -253,14 +191,15 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "napi" -version = "2.1.0" +version = "2.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ec66e60f000c78dd7c6215b6fa260e0591e09805024332bc5b3f55acc12244" +checksum = "b60e2bc632f89dad5d47da61591bd468f87f5dbfc85af27aa876772c89d8c4e4" dependencies = [ + "bitflags", "ctor", - "lazy_static", "napi-sys", - "windows", + "once_cell", + "thread_local", ] [[package]] @@ -271,9 +210,9 @@ checksum = "ebd4419172727423cf30351406c54f6cc1b354a2cfb4f1dba3e6cd07f6d5522b" [[package]] name = "napi-derive" -version = "2.1.0" +version = "2.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ac5287a5e94a8728fc82d16c5127acc5eb5b8ad6404ef5f82d6a4ce8d5bdd2" +checksum = "47bff5a8ed70117bce55053a74ff8f423f90c48c704030609272e6e3bde1c5a4" dependencies = [ "convert_case", "napi-derive-backend", @@ -284,9 +223,9 @@ dependencies = [ [[package]] name = "napi-derive-backend" -version = "1.0.25" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427f4f04525635cdf22005d1be62d6d671bcb5550d694a1efb480a315422b4af" +checksum = "e13b412301aeebee17724fff6d73536e9ecb8387f10bbbf317a9f7a006cc1c5b" dependencies = [ "convert_case", "once_cell", @@ -298,26 +237,28 @@ dependencies = [ [[package]] name = "napi-sys" -version = "2.1.0" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a385494dac3c52cbcacb393bb3b42669e7db8ab240c7ad5115f549eb061f2cc" +checksum = "166b5ef52a3ab5575047a9fe8d4a030cdd0f63c96f071cd6907674453b07bae3" +dependencies = [ + "libloading", +] [[package]] name = "nom" -version = "7.1.0" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", - "version_check", ] [[package]] name = "once_cell" -version = "1.9.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "peeking_take_while" @@ -327,33 +268,33 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "pkg-config" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.15" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.5.4" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -362,9 +303,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "rustc-hash" @@ -378,55 +319,31 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "syn" -version = "1.0.86" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", - "unicode-xid", -] - -[[package]] -name = "termcolor" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", + "unicode-ident", ] [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -434,38 +351,35 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.9" +name = "thread_local" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] [[package]] -name = "vec_map" -version = "0.8.2" +name = "unicode-ident" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] -name = "version_check" -version = "0.9.4" +name = "unicode-segmentation" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "which" -version = "4.2.4" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5a7e487e921cf220206864a94a89b6c6905bfc19f1057fa26a4cb360e5c1d2" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] @@ -484,64 +398,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b749ebd2304aa012c5992d11a25d07b406bdbe5f79d371cb7a918ce501a19eb0" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29277a4435d642f775f63c7d1faeb927adba532886ce0287bd985bffb16b6bca" - -[[package]] -name = "windows_i686_gnu" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145e1989da93956c68d1864f32fb97c8f561a8f89a5125f6a2b7ea75524e4b8" - -[[package]] -name = "windows_i686_msvc" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a09e3a0d4753b73019db171c1339cd4362c8c44baf1bcea336235e955954a6" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca64fcb0220d58db4c119e050e7af03c69e6f4f415ef69ec1773d9aab422d5a" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08cabc9f0066848fef4bc6a1c1668e6efce38b661d2aeec75d18d8617eebb5f1" - [[package]] name = "winreg" version = "0.10.1" diff --git a/crates/krb5_js/Cargo.toml b/crates/krb5_js/Cargo.toml index b1625df..12c3c86 100644 --- a/crates/krb5_js/Cargo.toml +++ b/crates/krb5_js/Cargo.toml @@ -16,6 +16,6 @@ krb5-rs = { path = "../krb5_rs" } thiserror = "1" napi = { version = "2", default-features = false, features = ["napi6"] } napi-derive = "2" -base64 = "0.13" +base64 = "0.21" regex = "1" lazy_static = "1.4" diff --git a/crates/krb5_js/src/kinit.rs b/crates/krb5_js/src/kinit.rs index cfc5979..b5f6a81 100644 --- a/crates/krb5_js/src/kinit.rs +++ b/crates/krb5_js/src/kinit.rs @@ -42,7 +42,7 @@ pub fn kinit_function( (principal.as_str(), None) }; let context = Context::new()?; - let realm = match realm_from_split.or_else(|| realm.as_deref()) { + let realm = match realm_from_split.or(realm.as_deref()) { Some(realm) => realm.to_owned(), None => context.get_default_realm()?, }; diff --git a/crates/krb5_js/src/spnego.rs b/crates/krb5_js/src/spnego.rs index 300a8c9..83e1c82 100644 --- a/crates/krb5_js/src/spnego.rs +++ b/crates/krb5_js/src/spnego.rs @@ -1,3 +1,4 @@ +use base64::{engine, Engine}; use krb5_rs::gssapi; use napi::{Env, JsString, Task}; use napi_derive::napi; @@ -52,7 +53,7 @@ pub fn generate_spnego_token_function( gssapi::krb5_ccache_name(ccname.as_ref().unwrap())?; } let token = gssapi::get_token(target_name)?; - Ok(base64::encode(token)) + Ok(engine::general_purpose::STANDARD.encode(token)) } pub struct Spnego { diff --git a/crates/krb5_rs/Cargo.toml b/crates/krb5_rs/Cargo.toml index e08f7a4..0bc4550 100644 --- a/crates/krb5_rs/Cargo.toml +++ b/crates/krb5_rs/Cargo.toml @@ -6,6 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -lazy_static = "1.4" thiserror = "1" krb5-sys = {path = "../krb5_sys"} diff --git a/crates/krb5_rs/src/ccache.rs b/crates/krb5_rs/src/ccache.rs index 9aaa37c..f1e873b 100644 --- a/crates/krb5_rs/src/ccache.rs +++ b/crates/krb5_rs/src/ccache.rs @@ -10,13 +10,13 @@ use krb5_sys::{ use super::{Context, Credentials, Krb5Error, Principal, Result}; -pub struct CCache<'a> { - pub(crate) context: &'a Context, +pub struct CCache<'context> { + pub(crate) context: &'context Context, pub(crate) inner: krb5_ccache, } -impl<'a> CCache<'a> { - pub fn default(context: &'a Context) -> Result { +impl<'context> CCache<'context> { + pub fn default(context: &'context Context) -> Result { let mut ccache: MaybeUninit = MaybeUninit::uninit(); let error_code = unsafe { krb5_cc_default(context.inner, ccache.as_mut_ptr()) }; Krb5Error::exit_if_library_error(context, error_code)?; @@ -27,7 +27,7 @@ impl<'a> CCache<'a> { }) } - pub fn resolve(context: &'a Context, cc_name: &str) -> Result> { + pub fn resolve(context: &'context Context, cc_name: &str) -> Result> { let mut ccache: MaybeUninit = MaybeUninit::uninit(); let cc_name = CString::new(cc_name).map_err(|_| Krb5Error::StringConversionError)?; @@ -77,7 +77,7 @@ impl<'a> CCache<'a> { } } -impl<'a> Drop for CCache<'a> { +impl<'context> Drop for CCache<'context> { fn drop(&mut self) { if !self.context.inner.is_null() && !self.inner.is_null() { unsafe { krb5_cc_close(self.context.inner, self.inner) }; diff --git a/crates/krb5_rs/src/context.rs b/crates/krb5_rs/src/context.rs index 75d5126..830fd10 100644 --- a/crates/krb5_rs/src/context.rs +++ b/crates/krb5_rs/src/context.rs @@ -1,4 +1,3 @@ -// use std::ops::{Deref, DerefMut}; use std::{ffi::CStr, mem::MaybeUninit, os::raw::c_char, sync::Mutex}; use crate::Result; @@ -7,32 +6,14 @@ use krb5_sys::{ krb5_free_error_message, krb5_get_default_realm, krb5_get_error_message, krb5_init_context, }; -use lazy_static::lazy_static; - use super::Krb5Error; -lazy_static! { - static ref CONTEXT_LOCK: Mutex<()> = Mutex::new(()); -} +static CONTEXT_LOCK: Mutex<()> = Mutex::new(()); pub struct Context { pub(crate) inner: krb5_context, } -// impl Deref for Context { -// type Target = krb5_context; - -// fn deref(&self) -> &Self::Target { -// &self.inner -// } -// } - -// impl DerefMut for Context { -// fn deref_mut(&mut self) -> &mut Self::Target { -// &mut self.inner -// } -// } - impl Context { pub fn get_default_realm(&self) -> Result { let mut default_realm: MaybeUninit<*mut c_char> = MaybeUninit::zeroed(); @@ -73,7 +54,7 @@ impl Context { } pub fn new() -> Result { - let _guard = CONTEXT_LOCK.lock().expect("Failed to lock context"); + let _guard = &CONTEXT_LOCK.lock().expect("Failed to lock context"); let mut krb5_context: MaybeUninit = MaybeUninit::uninit(); let error_code = unsafe { krb5_init_context(krb5_context.as_mut_ptr()) }; if error_code != 0 { @@ -89,7 +70,7 @@ impl Context { impl Drop for Context { fn drop(&mut self) { - let _guard = CONTEXT_LOCK.lock().expect("Failed to lock context"); + let _guard = &CONTEXT_LOCK.lock().expect("Failed to lock context"); if !self.inner.is_null() { unsafe { krb5_free_context(self.inner) } } diff --git a/crates/krb5_rs/src/credentials.rs b/crates/krb5_rs/src/credentials.rs index f5d90d0..6e1f274 100644 --- a/crates/krb5_rs/src/credentials.rs +++ b/crates/krb5_rs/src/credentials.rs @@ -6,17 +6,17 @@ use krb5_sys::{ use crate::{Context, Keytab, Krb5Error, Principal, Result}; -pub struct Credentials<'a> { - pub(crate) context: &'a Context, +pub struct Credentials<'context> { + pub(crate) context: &'context Context, pub(crate) inner: krb5_creds, } -impl<'a> Credentials<'a> { +impl<'context> Credentials<'context> { pub fn get_init_credentials_password( - context: &'a Context, + context: &'context Context, principal: &Principal, password: &str, - ) -> Result> { + ) -> Result> { let mut credentials: MaybeUninit = MaybeUninit::uninit(); let password = CString::new(password).map_err(|_| Krb5Error::StringConversionError)?; let error_code = unsafe { @@ -41,10 +41,10 @@ impl<'a> Credentials<'a> { } pub fn get_init_credentials_keytab( - context: &'a Context, + context: &'context Context, principal: &Principal, keytab: &Keytab, - ) -> Result> { + ) -> Result> { let mut credentials: MaybeUninit = MaybeUninit::uninit(); let error_code = unsafe { krb5_get_init_creds_keytab( @@ -66,7 +66,7 @@ impl<'a> Credentials<'a> { } } -impl<'a> Drop for Credentials<'a> { +impl<'context> Drop for Credentials<'context> { fn drop(&mut self) { if !self.context.inner.is_null() { unsafe { krb5_free_cred_contents(self.context.inner, &mut self.inner) } diff --git a/crates/krb5_rs/src/gssapi.rs b/crates/krb5_rs/src/gssapi.rs index aa5cd9f..b776aab 100644 --- a/crates/krb5_rs/src/gssapi.rs +++ b/crates/krb5_rs/src/gssapi.rs @@ -11,7 +11,7 @@ use krb5_sys::{ gss_release_name, OM_uint32, GSS_C_NO_CHANNEL_BINDINGS, GSS_C_NO_CONTEXT, GSS_C_NO_CREDENTIAL, }; -const MAX_AD_TOKEN_SIZE_BEFORE_B64: u64 = 48000; +const MAX_AD_TOKEN_SIZE_BEFORE_B64: usize = 48000; const GSS_C_REPLAY_FLAG: OM_uint32 = 4; const GSS_C_SEQUENCE_FLAG: OM_uint32 = 8; @@ -33,7 +33,7 @@ impl Drop for Name { pub fn import_name(principal: &str, input_name_type: &str) -> Result { let mut minor = 0; let mut service = gss_buffer_desc { - length: principal.len() as u64, + length: principal.len(), value: principal.as_ptr() as *mut _, }; let gss_oid = unsafe { @@ -103,8 +103,7 @@ pub fn get_token(target_name: Name) -> Result, String> { "The token returned by GSS is greater than the size allowed by Windows AD", )) } else { - // try_into().unwrap() won't fail, because output_token.length cannot be higher than MAX_AD_TOKEN_SIZE_BEFORE_B64 - let size = output_token.length.try_into().unwrap(); + let size = output_token.length; let mut vec: Vec = Vec::with_capacity(size); unsafe { std::ptr::copy(output_token.value, vec.as_mut_ptr() as *mut _, size); @@ -148,15 +147,8 @@ fn convert_gss_error(error_code: OM_uint32, minor: OM_uint32) -> String { &mut status_string, ) }; - let slice_from_data: &[u8] = unsafe { - slice::from_raw_parts( - status_string.value as *mut _, - status_string - .length - .try_into() - .expect("Failed to convert status_string.length to usize"), - ) - }; + let slice_from_data: &[u8] = + unsafe { slice::from_raw_parts(status_string.value as *mut _, status_string.length) }; error_msg.extend_from_slice(slice_from_data); unsafe { gss_release_buffer(&mut min_status, &mut status_string) }; diff --git a/crates/krb5_rs/src/keytab.rs b/crates/krb5_rs/src/keytab.rs index 041fd79..d29dedb 100644 --- a/crates/krb5_rs/src/keytab.rs +++ b/crates/krb5_rs/src/keytab.rs @@ -6,13 +6,13 @@ use krb5_sys::{krb5_keytab, krb5_kt_close, krb5_kt_resolve}; use super::Krb5Error; -pub struct Keytab<'a> { - pub(crate) context: &'a Context, +pub struct Keytab<'context> { + pub(crate) context: &'context Context, pub(crate) inner: krb5_keytab, } -impl<'a> Keytab<'a> { - pub fn resolve(context: &'a Context, name: &str) -> Result> { +impl<'context> Keytab<'context> { + pub fn resolve(context: &'context Context, name: &str) -> Result> { let mut keytab: MaybeUninit = MaybeUninit::uninit(); let name = CString::new(name).map_err(|_| Krb5Error::StringConversionError)?; let error_code = @@ -25,7 +25,7 @@ impl<'a> Keytab<'a> { } } -impl<'a> Drop for Keytab<'a> { +impl<'context> Drop for Keytab<'context> { fn drop(&mut self) { if !self.context.inner.is_null() && !self.inner.is_null() { unsafe { krb5_kt_close(self.context.inner, self.inner) }; diff --git a/crates/krb5_rs/src/principal.rs b/crates/krb5_rs/src/principal.rs index 6ddc506..7d3fdb9 100644 --- a/crates/krb5_rs/src/principal.rs +++ b/crates/krb5_rs/src/principal.rs @@ -3,13 +3,17 @@ use std::{mem::MaybeUninit, os::raw::c_uint}; use crate::{Context, Krb5Error, Result}; use krb5_sys::{krb5_build_principal_ext, krb5_free_principal, krb5_principal}; -pub struct Principal<'a> { - pub(crate) context: &'a Context, +pub struct Principal<'context> { + pub(crate) context: &'context Context, pub(crate) inner: krb5_principal, } -impl<'a> Principal<'a> { - pub fn build_principal(context: &'a Context, realm: &str, user: &str) -> Result> { +impl<'context> Principal<'context> { + pub fn build_principal( + context: &'context Context, + realm: &str, + user: &str, + ) -> Result> { let mut krb5_principal: MaybeUninit = MaybeUninit::uninit(); let sp: Vec<&str> = user.split('/').collect(); let error_code = match sp.len() { @@ -52,7 +56,7 @@ impl<'a> Principal<'a> { } } -impl<'a> Drop for Principal<'a> { +impl<'context> Drop for Principal<'context> { fn drop(&mut self) { if !self.context.inner.is_null() && !self.inner.is_null() { unsafe { krb5_free_principal(self.context.inner, self.inner) } diff --git a/crates/krb5_sys/Cargo.toml b/crates/krb5_sys/Cargo.toml index 2bc7c05..a246e4a 100644 --- a/crates/krb5_sys/Cargo.toml +++ b/crates/krb5_sys/Cargo.toml @@ -8,11 +8,11 @@ links = "krb5" [build-dependencies] -bindgen = "0.59.2" +bindgen = "0.63.0" cc = "1.0" [target.'cfg(not(windows))'.build-dependencies] -pkg-config = "0.3.24" +pkg-config = "0.3" [target.'cfg(any(windows))'.build-dependencies] winreg = { version = "0.10" } diff --git a/crates/krb5_sys/src/wrapper.c b/crates/krb5_sys/src/wrapper.c index 01532ef..21a77ef 100644 --- a/crates/krb5_sys/src/wrapper.c +++ b/crates/krb5_sys/src/wrapper.c @@ -1 +1,7 @@ #include "wrapper.h" + +OM_uint32 gss_error(OM_uint32 x) { return GSS_ERROR(x); } + +gss_OID gss_c_nt_hostbased_service() { return GSS_C_NT_HOSTBASED_SERVICE; } + +gss_OID gss_c_nt_user_name() { return GSS_C_NT_USER_NAME; } diff --git a/crates/krb5_sys/src/wrapper.h b/crates/krb5_sys/src/wrapper.h index 0f3b825..95d7d13 100644 --- a/crates/krb5_sys/src/wrapper.h +++ b/crates/krb5_sys/src/wrapper.h @@ -1,24 +1,19 @@ -#include #include #include +#include #undef GSS_C_NO_CREDENTIAL -const gss_cred_id_t GSS_C_NO_CREDENTIAL = ((gss_cred_id_t) 0); +const gss_cred_id_t GSS_C_NO_CREDENTIAL = ((gss_cred_id_t)0); #undef GSS_C_NO_CHANNEL_BINDINGS -const gss_channel_bindings_t GSS_C_NO_CHANNEL_BINDINGS = ((gss_channel_bindings_t) 0); +const gss_channel_bindings_t GSS_C_NO_CHANNEL_BINDINGS = + ((gss_channel_bindings_t)0); #undef GSS_C_NO_CONTEXT -const gss_ctx_id_t GSS_C_NO_CONTEXT = ((gss_ctx_id_t) 0); +const gss_ctx_id_t GSS_C_NO_CONTEXT = ((gss_ctx_id_t)0); -OM_uint32 gss_error(OM_uint32 x) { - return GSS_ERROR(x); -} +OM_uint32 gss_error(OM_uint32 x); -gss_OID gss_c_nt_hostbased_service() { - return GSS_C_NT_HOSTBASED_SERVICE; -} +gss_OID gss_c_nt_hostbased_service(); -gss_OID gss_c_nt_user_name() { - return GSS_C_NT_USER_NAME; -} +gss_OID gss_c_nt_user_name(); diff --git a/lib/index.d.ts b/lib/index.d.ts index c685283..279ee7c 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -4,20 +4,20 @@ /* auto-generated by NAPI-RS */ export interface KdestroyParameters { - ccname?: string | undefined | null + ccname?: string } export interface KinitParameters { principal: string - password?: string | undefined | null - keytab?: string | undefined | null - realm?: string | undefined | null - ccname?: string | undefined | null + password?: string + keytab?: string + realm?: string + ccname?: string } export interface GenerateSpnegoTokenParameters { - service_principal?: string | undefined | null - service_fqdn?: string | undefined | null - hostbased_service?: string | undefined | null - ccname?: string | undefined | null + service_principal?: string + service_fqdn?: string + hostbased_service?: string + ccname?: string } export function kinit(input: KinitParameters): Promise export function kdestroy(input: KdestroyParameters): Promise diff --git a/src/index.coffee b/src/index.coffee index 6a2ab6a..d7c468b 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -8,7 +8,6 @@ module.exports = .catch (err) -> callback err return - spnego: (options, callback) -> return krb5.spnego options unless callback krb5.spnego options @@ -22,9 +21,8 @@ module.exports = if typeof options is 'function' callback = options options = {} - + krb5.kdestroy options .then () -> callback() .catch (err) -> callback err return -