Skip to content
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

getpwnam is missing #862

Closed
ctrlcctrlv opened this issue Feb 21, 2018 · 9 comments
Closed

getpwnam is missing #862

ctrlcctrlv opened this issue Feb 21, 2018 · 9 comments

Comments

@ctrlcctrlv
Copy link

No description provided.

@Susurrus
Copy link
Contributor

Is this a request to add that functionality or are you planning on adding it?

@ctrlcctrlv ctrlcctrlv changed the title Implement getpwnam getpwnam is missing Feb 23, 2018
@ctrlcctrlv
Copy link
Author

ctrlcctrlv commented Feb 23, 2018

Hi,

I was planning on implementing it. There are a few related functions that are also missing, e.g. getgrnam.

I haven't implemented the others yet, but I have finished this one. (Tested only on FreeBSD, append to src/unistd.rs.)

use libc::time_t;
#[derive(Debug, Default)]
pub struct Passwd {
    pub name: CString,
    pub passwd: CString,
    pub uid: uid_t,
    pub gid: gid_t,
    pub change: time_t,
    pub class: CString,
    pub gecos: CString,
    pub dir: CString,
    pub shell: CString,
    pub expire: time_t
}

pub fn getpwnam<S: Into<Vec<u8>>>(name: S) -> Result<Option<Passwd>> {
    let pw = unsafe { libc::getpwnam(CString::new(name).unwrap().as_ptr()).as_ref() };

    unsafe {
        match pw {
            None => {return Ok(None)},
            Some(pw) =>
                Ok( Some( Passwd {
                    name: CString::new(CStr::from_ptr(pw.pw_name).to_bytes()).unwrap(),
                    passwd: CString::new(CStr::from_ptr(pw.pw_passwd).to_bytes()).unwrap(),
                    class: CString::new(CStr::from_ptr(pw.pw_class).to_bytes()).unwrap(),
                    gecos: CString::new(CStr::from_ptr(pw.pw_gecos).to_bytes()).unwrap(),
                    dir: CString::new(CStr::from_ptr(pw.pw_dir).to_bytes()).unwrap(),
                    shell: CString::new(CStr::from_ptr(pw.pw_shell).to_bytes()).unwrap(),
                    uid: pw.pw_uid,
                    gid: pw.pw_gid,
                    change: pw.pw_change,
                    expire: pw.pw_expire
                } ) )
        }
    }
}

@ctrlcctrlv
Copy link
Author

@Susurrus I notice my PR #864 has been ignored while later PR #865 has received many comments. Have I done something seriously wrong? Is my code that bad that there are so many errors no one wants to review it? :-(

@kristate
Copy link

@ctrlcctrlv Thanks for your hard work!
I did an informal review on your code.
I would appreciate if you could look over it.

@Susurrus
Copy link
Contributor

@ctrlcctrlv To address your question directed to me, there isn't a real order to how we triage PRs or even code. Sometimes older things come to the top of my queue because I'm more familiar with the API it's implementing or even because it was the most recent email. So pinging is definitely the right idea.

@kristate Thanks for reviewing their code! We heavily rely on the community to help us. I see myself more of a project manager than a coder when it comes to nix, so having people help doing the code reviews and writing code is essential and much appreciated!

@sanxiyn
Copy link

sanxiyn commented May 14, 2019

You can use pwd crate if you need this NOW.

@0xpr03
Copy link

0xpr03 commented Sep 2, 2019

Note that if you search for things like getgrnam, there is also users.

@pskopnik
Copy link

There is User::from_uid and User::from_name which perform getpwuid_r/getpwnam_r as introduced by #1139.

This issue may even be closed?

@ctrlcctrlv
Copy link
Author

Oh yeah, it sure can be. I had given up on this ever happening, but @otavio had far more patience than me. (Cf. #864.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants