summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-06-24 18:50:50 +0200
committerLennart Poettering <lennart@poettering.net>2011-06-24 18:50:50 +0200
commit98a28fef2618e54a644614c759f371f297381b70 (patch)
treeac0f1d97bce1a298706d367c0b788a956f700bda /src/util.c
parent77527da0a02029ce9c5ec86d5db5ea42147a658f (diff)
logind: hook up PAM module with logind
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 08529cc235..5d57d52dc8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -4040,8 +4040,31 @@ bool tty_is_vc(const char *tty) {
if (startswith(tty, "/dev/"))
tty += 5;
- return startswith(tty, "tty") &&
- tty[3] >= '0' && tty[3] <= '9';
+ return vtnr_from_tty(tty) >= 0;
+}
+
+int vtnr_from_tty(const char *tty) {
+ int i, r;
+
+ assert(tty);
+
+ if (startswith(tty, "/dev/"))
+ tty += 5;
+
+ if (!startswith(tty, "tty") )
+ return -EINVAL;
+
+ if (tty[3] < '0' || tty[3] > '9')
+ return -EINVAL;
+
+ r = safe_atoi(tty+3, &i);
+ if (r < 0)
+ return r;
+
+ if (i < 0 || i > 63)
+ return -EINVAL;
+
+ return i;
}
const char *default_term_for_tty(const char *tty) {
@@ -5068,6 +5091,38 @@ int symlink_or_copy_atomic(const char *from, const char *to) {
return r;
}
+int audit_session_from_pid(pid_t pid, uint32_t *id) {
+ char *p, *s;
+ uint32_t u;
+ int r;
+
+ assert(pid >= 1);
+ assert(id);
+
+ if (have_effective_cap(CAP_AUDIT_CONTROL) <= 0)
+ return -ENOENT;
+
+ if (asprintf(&p, "/proc/%lu/sessionid", (unsigned long) pid) < 0)
+ return -ENOMEM;
+
+ r = read_one_line_file(p, &s);
+ free(p);
+ if (r < 0)
+ return r;
+
+ r = safe_atou32(s, &u);
+ free(s);
+
+ if (r < 0)
+ return r;
+
+ if (u == (uint32_t) -1 || u <= 0)
+ return -ENOENT;
+
+ *id = u;
+ return 0;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",