Files
shadow/lib/logind.c
Alejandro Colomar 0004cc46dd lib: Merge libmisc into libshadow
The separation was unnecessary, and caused build problems.  Let's go
wild and obliterate the library.  The files are moved to libshadow.

Scripted change:

$ find libmisc/ -type f \
| grep '\.[chy]$' \
| xargs mv -t lib;

Plus updating the Makefile and other references.  While at it, I've
sorted the sources lists.

Link: <https://github.com/shadow-maint/shadow/pull/792>
Reported-by: David Seifert <soap@gentoo.org>
Cc: Sam James <sam@gentoo.org>
Cc: Christian Bricart <christian@bricart.de>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Robert Förster <Dessa@gmake.de>
[ soap tested the Gentoo package ]
Tested-by: David Seifert <soap@gentoo.org>
Acked-by: David Seifert <soap@gentoo.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-10 14:13:01 +02:00

52 lines
878 B
C

/*
* SPDX-FileCopyrightText: 2023, Iker Pedrosa <ipedrosa@redhat.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
#ident "$Id$"
#include "defines.h"
#include "prototypes.h"
#include <systemd/sd-login.h>
int get_session_host (char **out)
{
char *host = NULL;
char *session = NULL;
int ret;
ret = sd_pid_get_session (getpid(), &session);
if (ret < 0) {
return ret;
}
ret = sd_session_get_remote_host (session, &host);
if (ret < 0) {
goto done;
}
*out = host;
done:
free (session);
return ret;
}
unsigned long active_sessions_count(const char *name, unsigned long unused)
{
struct passwd *pw;
unsigned long count = 0;
pw = prefix_getpwnam(name);
if (pw == NULL) {
return 0;
}
count = sd_uid_get_sessions(pw->pw_uid, 0, NULL);
return count;
}