-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Implement utmp/wtmp support #5491
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome @xacrimon!
Just a few quick nits; I'm sure others will have more detailed analysis!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd draw some inspiration from https://github.com/ericlagergren/go-gnulib/tree/master/ttyname and https://github.com/ericlagergren/go-gnulib/tree/master/utmp as a way to avoid cgo.
@xacrimon Also a bookkeeping comment, when this PR has been approved by two reviewers make sure you rebase and merge so we get a single commit on master with no merge commit. |
4ce407d
to
fc28273
Compare
beb0586
to
08615f0
Compare
7fcd399
to
d76cc59
Compare
f8f2413
to
58e9887
Compare
986a037
to
35ebc89
Compare
lib/srv/reexec.go
Outdated
// The path of the system utmp database. | ||
UtmpPath *string `json:"utmp_path"` | ||
|
||
// The path of the system wtmp log. | ||
WtmpPath *string `json:"wtmp_path"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason these are pointers?
Also Go comments start with the name of the variable, so for this (and elsewhere):
// UtmpPath is the path to the system utmp database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're pointers because they're optional, if not provided, uacc will default to system defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted comments
9511a09
to
68904de
Compare
integration/root_integration_test.go
Outdated
"gopkg.in/check.v1" | ||
) | ||
|
||
func TestIntegrationsRoot(t *testing.T) { check.TestingT(t) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was marked as resolved but the function isn't removed
i think this whole file can be removed
cc6b5d9
to
79189e8
Compare
ed27e23
to
f49662d
Compare
Also, what does |
c234972
to
c575ce5
Compare
} | ||
struct utmp *entry = getutent(); | ||
while (entry != NULL) { | ||
if (entry->ut_type == USER_PROCESS && strcmp(user, entry->ut_user) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use strncmp
since the utmp fields aren't necessarily null terminated? Worst case, it seems like this would read into the hostname field.
var accountDb sync.Mutex | ||
|
||
// Max length of username and hostname as defined by glibc. | ||
const nameMaxLen = 255 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like usernames should be limited at 32 bytes. 256 is only for hostnames. The strncpy
s should truncate anything that's too long, but it would be good to return helpful errors instead.
@ben-latacora Thanks! I've posted a new PR addressing your feedback. Good catch. |
This PR introduces support for updating utmp and wtmp files on Linux with current and past interactive sessions.
This is a best-effort feature. It is only enabled on platforms where utmp/wtmp exists and will do nothing otherwise. If it lacks permissions to modify the user accounting database a warning will be logged instead of taking down the service as this is not a critical feature that needs to be enabled in all cases.
Fixes #3987