Skip to content

Add shadow.h functions #1173

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add shadow.h functions #1173

wants to merge 1 commit into from

Conversation

ArniDagur
Copy link

@ArniDagur ArniDagur commented Dec 24, 2019

The code is adapted from the shadow crate, which is MIT licensed.

@asomers
Copy link
Member

asomers commented Dec 24, 2019

It looks like you need to set appropriate #[cfg()] guards around your new code. Also, any particular reason you want to merge the shadow crate into Nix?

@ArniDagur ArniDagur force-pushed the shadow branch 4 times, most recently from 289f189 to 72ed1f1 Compare December 26, 2019 01:21
@ArniDagur
Copy link
Author

Also, any particular reason you want to merge the shadow crate into Nix?

  1. I think nix would be incomplete without the shadow(3) suite of functions. It's nice having only one crate that fulfils all of my "safe(r) libc" needs.
  2. It doesn't look like the shadow crate is maintained; it hasn't been touched in 3 years. The nix crate is well maintained (e.g. Replace most instances of mem::uninitialized with mem::MaybeUninit #1114).

@ArniDagur
Copy link
Author

@asomers Some of the builds were failing on 32-bit systems because I assumed that long int was always 64 bits, which caused the implicit cast to fail. Are you happy with using i64 as the integer type? Another possible option could be usize, but are we sure that the size of usize is always equal to or larger than libc::c_long?

@asomers
Copy link
Member

asomers commented Feb 2, 2020

What's wrong with declaring the fields as c_long?

@ArniDagur
Copy link
Author

I thought we didn't want to use C types, but now that I think about it, this project does it all the time. I will change it to use c_long.

@ArniDagur
Copy link
Author

On another note, I tried GitHub's inbuilt "resolve merge conflict" functionality, and it seems to have merged master into this branch. Should I revert that change manually also?

@asomers
Copy link
Member

asomers commented Feb 3, 2020

Yeah, you should manually rebase rather than use the "resolve conflicts" button.

@ArniDagur
Copy link
Author

I've rebased and squashed.

@ArniDagur ArniDagur requested a review from asomers February 3, 2020 19:47
/// The minimum password age is the number of days the user will have to
/// wait before she will be allowed to change their password again.
/// An empty field and value 0 mean that there are no minimum password age.
pub min: libc::c_long,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mysterious flag values, how about making this field a NonZeroIsize?

Copy link
Author

@ArniDagur ArniDagur Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, do you mean Option<NonZeroIsize>, where zero corresponds to None?

///
/// An empty field and value 0 mean that there are no password warning
/// period.
pub warn: libc::c_long,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Option type would also be useful here.

///
/// The value 0 should not be used as it is interpreted as either an account
/// with no expiration, or as an expiration on Jan 1, 1970.
pub expire: libc::c_long,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this could be a NonZeroIsize.

///
/// A password field which starts with a exclamation mark means that the
/// password is locked.
pub password: CString,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use String for name, but CString for password?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of what I read from @ctrlcctrlv here: https://github.com/nix-rust/nix/pull/864/files

Because it's guaranteed that the fields I made String will conform to NAME_REGEX. gecos ("real name") has no such guarantee.

/// ([`getspent()`][1], and [`endspent()`][1]) are not thread safe.
///
/// [1]: http://man7.org/linux/man-pages/man3/shadow.3.html
#[derive(Debug, Default)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you call setspent during construction?

/// println!("There are {} shadow entries", shadows.len());
/// ```
///
/// # Safety
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the reentrant versions getspent_r etc to solve the thread-safety problem?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently blocked by rust-lang/libc#1653

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 this pull request may close these issues.

2 participants