]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/audit.c
man: document ARM root partition types
[thirdparty/systemd.git] / src / shared / audit.c
CommitLineData
d7832d2c
KS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
d7832d2c
KS
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
d7832d2c 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
d7832d2c
KS
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <assert.h>
23#include <string.h>
24#include <unistd.h>
25#include <errno.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <ctype.h>
d7832d2c
KS
29
30#include "macro.h"
31#include "audit.h"
32#include "util.h"
33#include "log.h"
a5c32cff 34#include "fileio.h"
9a3ef988 35#include "virt.h"
d7832d2c
KS
36
37int audit_session_from_pid(pid_t pid, uint32_t *id) {
5b12334d
LP
38 _cleanup_free_ char *s = NULL;
39 const char *p;
d7832d2c
KS
40 uint32_t u;
41 int r;
42
43 assert(id);
44
b68fa010 45 p = procfs_file_alloca(pid, "sessionid");
d7832d2c 46
5b12334d 47 r = read_one_line_file(p, &s);
d7832d2c
KS
48 if (r < 0)
49 return r;
50
51 r = safe_atou32(s, &u);
d7832d2c
KS
52 if (r < 0)
53 return r;
54
55 if (u == (uint32_t) -1 || u <= 0)
5b12334d 56 return -ENXIO;
d7832d2c
KS
57
58 *id = u;
59 return 0;
60}
61
62int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
5b12334d
LP
63 _cleanup_free_ char *s = NULL;
64 const char *p;
d7832d2c
KS
65 uid_t u;
66 int r;
67
68 assert(uid);
69
b68fa010 70 p = procfs_file_alloca(pid, "loginuid");
d7832d2c 71
5b12334d 72 r = read_one_line_file(p, &s);
d7832d2c
KS
73 if (r < 0)
74 return r;
75
76 r = parse_uid(s, &u);
d7832d2c
KS
77 if (r < 0)
78 return r;
79
80 if (u == (uid_t) -1)
5b12334d 81 return -ENXIO;
d7832d2c
KS
82
83 *uid = (uid_t) u;
84 return 0;
85}