{"id":22309128,"url":"https://github.com/csnewman/libnss-rs","last_synced_at":"2025-04-13T05:07:20.097Z","repository":{"id":34922383,"uuid":"190997085","full_name":"csnewman/libnss-rs","owner":"csnewman","description":"Rust bindings for creating libnss modules","archived":false,"fork":false,"pushed_at":"2025-02-09T09:32:56.000Z","size":95,"stargazers_count":25,"open_issues_count":1,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T05:07:12.229Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csnewman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["csnewman"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-06-09T11:16:49.000Z","updated_at":"2025-02-09T09:32:59.000Z","dependencies_parsed_at":"2024-04-13T10:31:07.923Z","dependency_job_id":"29ab670e-c6e9-4d65-bba6-2a0f4a17c600","html_url":"https://github.com/csnewman/libnss-rs","commit_stats":{"total_commits":39,"total_committers":5,"mean_commits":7.8,"dds":0.5641025641025641,"last_synced_commit":"5e37bca311c7b29118a9a5c4d144b481681715bf"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csnewman%2Flibnss-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csnewman%2Flibnss-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csnewman%2Flibnss-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csnewman%2Flibnss-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csnewman","download_url":"https://codeload.github.com/csnewman/libnss-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T20:16:58.116Z","updated_at":"2025-04-13T05:07:20.072Z","avatar_url":"https://github.com/csnewman.png","language":"Rust","funding_links":["https://github.com/sponsors/csnewman"],"categories":[],"sub_categories":[],"readme":"# libnss-rs\nRust bindings for creating libnss modules.\n\nCurrently supports the following databases:\n- passwd\n- shadow\n- group\n- hosts\n\n## Getting started\n- Create a new library\n  ```bash\n  cargo new nss_example --lib\n  ```\n- Change library type to ```cdylib``` in your ```Cargo.toml```\n  ```yaml\n  [lib]\n  name = \"nss_example\"\n  crate-type = [ \"cdylib\" ]\n  ```\n  *** NOTE *** The name of the crate itself is not important, however the library itself must follow the ```nss_xxx``` pattern.\n\n- Add ```libnss``` to your ```Cargo.toml```\n  ```yaml\n  [dependencies]\n  libc = \"0.2.0\"\n  libnss = \"0.8.0\"\n  ```\n\n- Implement a ```passwd``` database\n  ```rust\n  use libnss::passwd::{PasswdHooks, Passwd};\n  use libnss::libnss_passwd_hooks;\n  \n  struct ExamplePasswd;\n  libnss_passwd_hooks!(example, ExamplePasswd);\n  ```\n  It is important that the first param of ```libnss_passwd_hooks``` is the name of your final library ```libnss_example.so.2```\n  ````rust\n  impl PasswdHooks for HardcodedPasswd {\n      fn get_all_entries() -\u003e Vec\u003cPasswd\u003e {\n          vec![\n              Passwd {\n                  name: \"test\".to_string(),\n                  passwd: \"x\".to_string(),\n                  uid: 1005,\n                  gid: 1005,\n                  gecos: \"Test Account\".to_string(),\n                  dir: \"/home/test\".to_string(),\n                  shell: \"/bin/bash\".to_string(),\n              }\n          ]\n      }\n  \n      fn get_entry_by_uid(uid: libc::uid_t) -\u003e Option\u003cPasswd\u003e {\n          if uid == 1005 {\n              return Some(Passwd {\n                  name: \"test\".to_string(),\n                  passwd: \"x\".to_string(),\n                  uid: 1005,\n                  gid: 1005,\n                  gecos: \"Test Account\".to_string(),\n                  dir: \"/home/test\".to_string(),\n                  shell: \"/bin/bash\".to_string(),\n              });\n          }\n  \n          None\n      }\n  \n      fn get_entry_by_name(name: String) -\u003e Option\u003cPasswd\u003e {\n          if name == \"test\" {\n              return Some(Passwd {\n                  name: \"test\".to_string(),\n                  passwd: \"x\".to_string(),\n                  uid: 1005,\n                  gid: 1005,\n                  gecos: \"Test Account\".to_string(),\n                  dir: \"/home/test\".to_string(),\n                  shell: \"/bin/bash\".to_string(),\n              });\n          }\n  \n          None\n      }\n  }\n  ````\n- Build\n  ```\n  cargo build --release\n  ```\n- Install the library\n  ```bash\n  cd target/release\n  cp libnss_example.so libnss_example.so.2\n  sudo install -m 0644 libnss_example.so.2 /lib\n  sudo /sbin/ldconfig -n /lib /usr/lib\n  ```\n- Enable your nss module in ```/etc/nsswitch.conf```\n  eg:\n  ```\n  passwd:         example files systemd\n  ```\n  The name in here must follow the final library name ```libnss_example.so.2```\n- Look at the examples for more information\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsnewman%2Flibnss-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsnewman%2Flibnss-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsnewman%2Flibnss-rs/lists"}