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

Wtmp #1077

Closed
wants to merge 16 commits into from
Closed

Wtmp #1077

wants to merge 16 commits into from

Conversation

moobyfr
Copy link
Contributor

@moobyfr moobyfr commented Mar 23, 2018

Add the utmp/wtmp support.

@metalefty
Copy link
Member

I'll rebase the wtmp branch to current devel head after March release.

@speidy
Copy link
Member

speidy commented Mar 27, 2018

can you squash some commits?
there's a WIP commits too.

Copy link
Member

@speidy speidy left a comment

Choose a reason for hiding this comment

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

  • what about other pam files like archlinux pam file ?

@@ -5,6 +5,7 @@ AC_INIT([xrdp], [0.9.6], [[email protected]])
AC_CONFIG_HEADERS(config_ac.h:config_ac-h.in)
AM_INIT_AUTOMAKE([1.7.2 foreign])
AC_CONFIG_MACRO_DIR([m4])
AC_GNU_SOURCE
Copy link
Member

Choose a reason for hiding this comment

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

Why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to get UTMPX_FILE and other variables on linux, because of __USE_GNU in utmpx.h

Copy link
Member

Choose a reason for hiding this comment

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

ok

@@ -61,6 +61,8 @@ xrdp_sesman_SOURCES = \
sesman.h \
session.c \
session.h \
sessionrecord.c \
Copy link
Member

@speidy speidy Mar 27, 2018

Choose a reason for hiding this comment

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

I don't like the name sessionrecord.c , its misleading.
one might think of graphical session recording.
can you think of a better name? maybe logontrack.c or just utmp.c?

Copy link
Contributor Author

@moobyfr moobyfr Mar 27, 2018

Choose a reason for hiding this comment

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

First work used utmp.c and utmp.h but the #include directive was not able to get utmp.h from the sources and from /usr/include (with <> or "")

* this can handle login and logout at once with the 'state' parameter
*/

int
Copy link
Member

Choose a reason for hiding this comment

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

make it static


#define XRDP_LINE_FORMAT "xrdp:%d"

int add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostname, short state);
Copy link
Member

Choose a reason for hiding this comment

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

why you export this function?
I dont see its used outside of sessionrecord.c.

typedef struct utmp _utmp;
#endif

#define XRDP_LINE_FORMAT "xrdp:%d"
Copy link
Member

Choose a reason for hiding this comment

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

put it in the .c file, its used only there.

*/

int
add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostname, short state)
Copy link
Member

Choose a reason for hiding this comment

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

you never pass state argument when calling this function.
also, its unused here.

consider removing it.

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 are used in utmp_login and utmp_logout, state is set to USER_PROCESS or DEAD_PROCESS

Copy link
Member

@speidy speidy Mar 28, 2018

Choose a reason for hiding this comment

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

oh, right. my fault.
so just make it const short state

g_strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));

/* utmp */
setutxent();
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment explaining those calls ?


ut.ut_type=state;
ut.ut_pid = pid;
gettimeofday(&tv, NULL);
Copy link
Member

@speidy speidy Mar 27, 2018

Choose a reason for hiding this comment

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

can we use g_time1 , g_time2 or g_time3 from os_calls.c ?
otherwise, consider adding another wrapper there (or add support to the current wrappers)

endutxent();

/* wtmp : update on linux, FreeBSD uses utx */
#ifdef HAVE_UTMPX_H
Copy link
Member

@speidy speidy Mar 27, 2018

Choose a reason for hiding this comment

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

i prefer to avoid ifdefs inside the function body.
lets add some wrapper to this call outside the function and call it here.
for example:

#if defined(__FreeBSD__)
static inline void
updwtmp(...)
{
...
}
#elif defined(HAVE_UTMP_H)
static inline void
updwtmp(...)
{
...
}
#endif

* this can handle login and logout at once with the 'state' parameter
*/

int
Copy link
Member

Choose a reason for hiding this comment

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

either add error checks and return error in such cases or make this function return void


g_memset(&ut, 0, sizeof(ut));

ut.ut_type=state;
Copy link
Member

Choose a reason for hiding this comment

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

space between operators (=)

* So the IP is the string up the two last colons
*/
int i = g_strlen(rhostname) - 1;
while ((i>0) && (rhostname[i] != ':'))
Copy link
Member

@speidy speidy Mar 28, 2018

Choose a reason for hiding this comment

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

This logic is very specific to the way the given string is built right now.
The string might be changed at the future.
I'm not sure what is the best way to get the IP, but maybe we can fetch it from other, more reliable, source?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is very ad-hoc workaround right now and not the best.

@moobyfr
Copy link
Contributor Author

moobyfr commented Mar 29, 2018

I've made the changes requested (minus the gettimeofday and the pam file because he doesn't exist in this branch), but I'm unable to push it in the current branch. the change can be chery-picked on moobyfr@9b915fc

@metalefty
Copy link
Member

I'll cherry-pick.

@metalefty
Copy link
Member

and squash some commits.

@boppbo
Copy link
Contributor

boppbo commented Apr 18, 2018

Regarding the arch pam file, system-login already contains pam_loginuid.so (system-remote-login includes system-login). But it is added as optional not as required, will this cause issues?

moobyfr and others added 16 commits August 2, 2018 09:02
- renamed the two files, including the header was conflicting with official headers
- configure look for utmp/utmpx headers, wo we know which struct to use
- reworked the usage for linux, works mostly (last still showing 'gone' for loggued users)
So /proc/<uid>/loginuid will be filled by the uid of the user.
This will fix entries in 'last' with "gone - no logout" instead of
'still logged in'
Follow coding standard
@NZJourneyMan
Copy link

This branch now looks to be good to go? I'm interested in when it is likely to be merged as my organisation needs the wtmp changes before we can onboard xrdp in to production. We have been using a patch from this branch for testing and the results have been good.

@shaneforsythe
Copy link

What is the status of this Pull request?

@NZJourneyMan
Copy link

I see JonesB has copied this PR and added the missing reconnect functionality. The new PR can be found here: #1408. Is it possible to get this reviewed?

@NZJourneyMan NZJourneyMan mentioned this pull request Sep 10, 2019
@PaulJohnson
Copy link

Can we get this accepted please.

@metalefty
Copy link
Member

This should be redone after #1961. There's very few chance to get merged with current authentication architecture.

@metalefty metalefty closed this Sep 22, 2021
@matt335672
Copy link
Member

Anyone following this may find this comment useful, particularly on Red Hat and derivatives.

@matt335672
Copy link
Member

Can anyone following this thread please comment on #2745?

@matt335672 matt335672 deleted the wtmp branch February 21, 2024 14:27
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.

8 participants