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

Implement utmp/wtmp support #5491

Merged
merged 1 commit into from
Feb 15, 2021
Merged

Implement utmp/wtmp support #5491

merged 1 commit into from
Feb 15, 2021

Conversation

xacrimon
Copy link
Contributor

@xacrimon xacrimon commented Feb 5, 2021

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

@xacrimon xacrimon self-assigned this Feb 5, 2021
@xacrimon xacrimon added c-ju Internal Customer Reference c-q7j Internal Customer Reference R3 sales-onboarding Issues related to prospects labels Feb 5, 2021
Copy link
Contributor

@webvictim webvictim left a 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!

lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/utils/ttyname.go Outdated Show resolved Hide resolved
lib/utils/uacc.go Outdated Show resolved Hide resolved
lib/utils/uacc.h Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/utils/uacc.h Outdated Show resolved Hide resolved
@xacrimon xacrimon removed the sales-onboarding Issues related to prospects label Feb 5, 2021
Copy link
Contributor

@a-palchikov a-palchikov left a comment

Choose a reason for hiding this comment

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

lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/utils/ttyname.go Outdated Show resolved Hide resolved
lib/utils/ttyname.go Outdated Show resolved Hide resolved
lib/utils/uacc.go Outdated Show resolved Hide resolved
lib/utils/uacc.go Outdated Show resolved Hide resolved
lib/utils/uacc.go Outdated Show resolved Hide resolved
lib/utils/uacc.go Outdated Show resolved Hide resolved
lib/utils/uacc.h Outdated Show resolved Hide resolved
lib/utils/uacc.h Outdated Show resolved Hide resolved
lib/utils/ttyname.go Outdated Show resolved Hide resolved
lib/utils/uacc.h Outdated Show resolved Hide resolved
lib/srv/termhandlers.go Outdated Show resolved Hide resolved
@russjones
Copy link
Contributor

russjones commented Feb 6, 2021

@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.

lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/termhandlers.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_fallback.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_stub.go Show resolved Hide resolved
@xacrimon xacrimon force-pushed the joel/utmp-wtmp branch 2 times, most recently from f8f2413 to 58e9887 Compare February 11, 2021 17:30
@xacrimon xacrimon requested a review from russjones February 11, 2021 17:49
Comment on lines 104 to 108
// The path of the system utmp database.
UtmpPath *string `json:"utmp_path"`

// The path of the system wtmp log.
WtmpPath *string `json:"wtmp_path"`
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted comments

lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc_linux.go Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/exec_test.go Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
integration/db_integration_test.go Outdated Show resolved Hide resolved
"gopkg.in/check.v1"
)

func TestIntegrationsRoot(t *testing.T) { check.TestingT(t) }
Copy link
Contributor

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

integration/utmp_integration_test.go Outdated Show resolved Hide resolved
integration/utmp_integration_test.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Show resolved Hide resolved
lib/srv/reexec.go Show resolved Hide resolved
integration/integration_test.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
@xacrimon xacrimon force-pushed the joel/utmp-wtmp branch 2 times, most recently from cc6b5d9 to 79189e8 Compare February 12, 2021 17:48
@xacrimon xacrimon requested a review from awly February 12, 2021 18:14
integration/utmp_integration_test.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/ctx.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc.h Outdated Show resolved Hide resolved
@xacrimon xacrimon requested a review from a-palchikov February 12, 2021 20:01
integration/utmp_integration_test.go Show resolved Hide resolved
@xacrimon xacrimon force-pushed the joel/utmp-wtmp branch 3 times, most recently from ed27e23 to f49662d Compare February 15, 2021 18:40
lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/uacc/uacc.h Show resolved Hide resolved
@russjones
Copy link
Contributor

Also, what does e point to? It leads to invalid commit for me.

@xacrimon xacrimon merged commit 324ccda into master Feb 15, 2021
@xacrimon xacrimon deleted the joel/utmp-wtmp branch February 26, 2021 22:25
@xacrimon xacrimon restored the joel/utmp-wtmp branch February 26, 2021 22:25
}
struct utmp *entry = getutent();
while (entry != NULL) {
if (entry->ut_type == USER_PROCESS && strcmp(user, entry->ut_user) == 0) {

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

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 strncpys should truncate anything that's too long, but it would be good to return helpful errors instead.

@xacrimon
Copy link
Contributor Author

xacrimon commented Aug 3, 2021

@ben-latacora Thanks! I've posted a new PR addressing your feedback. Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-ju Internal Customer Reference c-q7j Internal Customer Reference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write to utmp/wtmp when an interactive session is opened by Teleport
6 participants