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

libcontainer: user: always treat numeric ids numerically #708

Merged
merged 3 commits into from
Mar 30, 2016
Merged

libcontainer: user: always treat numeric ids numerically #708

merged 3 commits into from
Mar 30, 2016

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Mar 30, 2016

Most shadow-related tools don't treat numeric ids as potential
usernames, so change our behaviour to match that. Previously, using an
explicit specification like 111:222 could result in the UID and GID not
being 111 and 222 respectively (which is confusing).

Fixes #695

Signed-off-by: Aleksa Sarai asarai@suse.de

@cyphar
Copy link
Member Author

cyphar commented Mar 30, 2016

@tianon I know it's been a while, but I've refactored most of the code you wrote a few years ago. Want to take a look? :P

// panic, because this is a programming/logic error, not a runtime one
panic("parseLine expects only pointers! argument " + strconv.Itoa(i) + " is not a pointer!")
// Someone goof'd when writing code using this function. Scream so they can hear us.
panic(fmt.Sprintf("parseLine only accepts {*string, *int, *[]string} as arguments! %#v\n is not a pointer!", e))
Copy link
Contributor

Choose a reason for hiding this comment

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

lets not do a new line here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, typo. :P

@cyphar
Copy link
Member Author

cyphar commented Mar 30, 2016

@dqminh Nits addressed. 😸

return u.Uid == user.Uid
}
return u.Name == userArg || strconv.Itoa(u.Uid) == userArg

if uid, err := strconv.Atoi(userArg); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it'd be worthwhile or possible to do this test/conversion once instead of once per passwd entry like it's doing now, plus one more time outside this filter if we don't find the UID in the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I didn't consider the fact that it doesn't shortcircuit anymore. But since it's a constant for the entire function we can definitely refactor our essentially all calls to Atoi. I'm just not sure what to do about negative UIDs.

@tianon
Copy link
Member

tianon commented Mar 30, 2016

Other than the fact that we're hitting Atoi at least once per every line in both /etc/passwd and /etc/group unnecessarily, this LGTM (and I'm OK with the implementation if there isn't a clean way to switch that code) 👍

@crosbymichael
Copy link
Member

Thanks @cyphar !

Most shadow-related tools don't treat numeric ids as potential
usernames, so change our behaviour to match that. Previously, using an
explicit specification like 111:222 could result in the UID and GID not
being 111 and 222 respectively (which is confusing).

Signed-off-by: Aleksa Sarai <asarai@suse.de>
@cyphar
Copy link
Member Author

cyphar commented Mar 30, 2016

@tianon I've addressed your concern about calling Atoi too many times per line. Merging.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
Some of the code was quite confusing inside libcontainer/user, so
refactor and comment it so future maintainers can understand what's
going and what edge cases we have to deal with.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
@jordmoz
Copy link

jordmoz commented Mar 30, 2016

awesome, thanks all

@tianon
Copy link
Member

tianon commented Mar 30, 2016

🤘

runcom pushed a commit to runcom/docker that referenced this pull request Jun 8, 2016
… as uid numbers

Upstream reference: opencontainers/runc#708

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
crawford pushed a commit to crawford/docker that referenced this pull request Jun 14, 2016
… as uid numbers

Upstream reference: opencontainers/runc#708

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
config-solaris: Fix "VNIC`s" -> "VNIC's" typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants