File: logind.c

package info (click to toggle)
shadow 1%3A4.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 66,808 kB
  • sloc: sh: 44,185; ansic: 34,184; xml: 12,350; exp: 3,691; makefile: 1,655; python: 1,409; perl: 120; sed: 16
file content (52 lines) | stat: -rw-r--r-- 829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * SPDX-FileCopyrightText:  2023, Iker Pedrosa <ipedrosa@redhat.com>
 *
 * SPDX-License-Identifier:  BSD-3-Clause
 */

#include "config.h"

#ident "$Id$"

#include "attr.h"
#include "defines.h"
#include "prototypes.h"

#include <systemd/sd-login.h>

int get_session_host (char **out, pid_t main_pid)
{
	char *host = NULL;
	char *session = NULL;
	int ret;

	ret = sd_pid_get_session(main_pid, &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)
{
	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;
}