[systemd-commits] 2 commits - TODO src/login src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Feb 14 12:54:17 PST 2012
TODO | 2 --
src/login/libsystemd-login.sym | 6 ++++++
src/login/loginctl.c | 14 +++++++++++++-
src/login/logind-dbus.c | 16 +++++++++++++++-
src/login/logind-session-dbus.c | 3 +++
src/login/logind-session.c | 25 ++++++++++++++++++++++++-
src/login/logind-session.h | 12 ++++++++++++
src/login/pam-module.c | 11 +++++++++--
src/login/sd-login.c | 40 +++++++++++++++-------------------------
src/login/test-login.c | 14 +++++++++++---
src/systemd/sd-login.h | 6 ++++++
11 files changed, 114 insertions(+), 35 deletions(-)
New commits:
commit 51f58f083a9454599080dc01d7740cf097f48920
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 14 21:54:00 2012 +0100
login: add new sd_session_get_type() and sd_session_get_class API calls
diff --git a/TODO b/TODO
index 7693067..b6f7f00 100644
--- a/TODO
+++ b/TODO
@@ -28,8 +28,6 @@ Features:
* Possibly, detect whether SysV init scripts can do reloading by looking for "echo Usage:" lines
-* Add XDG_SESSION_CLASS
-
* figure out whether we should leave dbus around during shutdown
* support closing all fds via RLIMIT_NOFILE instead of /proc, in order to make chroot stuff work.
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
index 3100c17..2ae376d 100644
--- a/src/login/libsystemd-login.sym
+++ b/src/login/libsystemd-login.sym
@@ -39,3 +39,9 @@ global:
sd_pid_get_unit;
sd_session_get_service;
} LIBSYSTEMD_LOGIN_31;
+
+LIBSYSTEMD_LOGIN_43 {
+global:
+ sd_session_get_type;
+ sd_session_get_class;
+} LIBSYSTEMD_LOGIN_38;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 5a03d61..c100a7b 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -433,18 +433,18 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
return r;
}
-_public_ int sd_session_get_seat(const char *session, char **seat) {
+static int session_get_string(const char *session, const char *field, char **value) {
char *p, *s = NULL;
int r;
- if (!seat)
+ if (!value)
return -EINVAL;
r = file_of_session(session, &p);
if (r < 0)
return r;
- r = parse_env_file(p, NEWLINE, "SEAT", &s, NULL);
+ r = parse_env_file(p, NEWLINE, field, &s, NULL);
free(p);
if (r < 0) {
@@ -455,34 +455,24 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
if (isempty(s))
return -ENOENT;
- *seat = s;
+ *value = s;
return 0;
}
-_public_ int sd_session_get_service(const char *session, char **service) {
- char *p, *s = NULL;
- int r;
-
- if (!service)
- return -EINVAL;
-
- r = file_of_session(session, &p);
- if (r < 0)
- return r;
-
- r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
- free(p);
+_public_ int sd_session_get_seat(const char *session, char **seat) {
+ return session_get_string(session, "SEAT", seat);
+}
- if (r < 0) {
- free(s);
- return r;
- }
+_public_ int sd_session_get_service(const char *session, char **service) {
+ return session_get_string(session, "SERVICE", service);
+}
- if (isempty(s))
- return -ENOENT;
+_public_ int sd_session_get_type(const char *session, char **type) {
+ return session_get_string(session, "TYPE", type);
+}
- *service = s;
- return 0;
+_public_ int sd_session_get_class(const char *session, char **class) {
+ return session_get_string(session, "CLASS", class);
}
static int file_of_seat(const char *seat, char **_p) {
diff --git a/src/login/test-login.c b/src/login/test-login.c
index 4596721..2aaa31f 100644
--- a/src/login/test-login.c
+++ b/src/login/test-login.c
@@ -30,7 +30,7 @@
int main(int argc, char* argv[]) {
int r, k;
uid_t u, u2;
- char *seat;
+ char *seat, *type, *class;
char *session;
char *state;
char *session2;
@@ -75,6 +75,14 @@ int main(int argc, char* argv[]) {
printf("uid = %lu\n", (unsigned long) u);
assert_se(u == u2);
+ assert_se(sd_session_get_type(session, &type) >= 0);
+ printf("type = %s\n", type);
+ free(type);
+
+ assert_se(sd_session_get_class(session, &class) >= 0);
+ printf("class = %s\n", class);
+ free(class);
+
assert_se(sd_session_get_seat(session, &seat) >= 0);
printf("seat = %s\n", seat);
@@ -125,13 +133,13 @@ int main(int argc, char* argv[]) {
printf("seats = %s\n", t);
free(t);
+ assert_se(sd_get_seats(NULL) == r);
+
r = sd_seat_get_active(NULL, &t, NULL);
assert_se(r >= 0);
printf("active session on current seat = %s\n", t);
free(t);
- assert_se(sd_get_seats(NULL) == r);
-
r = sd_get_sessions(&sessions);
assert_se(r >= 0);
assert_se(r == (int) strv_length(sessions));
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 7746c74..879e074 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -90,6 +90,12 @@ int sd_session_get_seat(const char *session, char **seat);
/* Determine the (PAM) service name this session was registered by. */
int sd_session_get_service(const char *session, char **service);
+/* Determine the type of this session, i.e. one of "tty", "x11" or "unspecified". */
+int sd_session_get_type(const char *session, char **type);
+
+/* Determine the class of this session, i.e. one of "user", "greeter" or "lock-screen". */
+int sd_session_get_class(const char *session, char **class);
+
/* Return active session and user of seat */
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);
commit 55efac6cbcea0d8edda9c6820620ceb390009e7a
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 14 21:33:51 2012 +0100
login: track login class (i.e. one of "user", "greeter", "lock-screen") for each session
This introduces the new PAM environment variable XDG_SESSION_CLASS. If
not set, defaults to "user".
This is useful for apps that want to distuingish real user logins from
"fake" ones which just exist to show a gdm login screen or a lock
screen.
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 7e0056c..30e97e3 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -349,6 +349,7 @@ typedef struct SessionStatusInfo {
const char *service;
pid_t leader;
const char *type;
+ const char *class;
bool active;
} SessionStatusInfo;
@@ -431,10 +432,19 @@ static void print_session_status_info(SessionStatusInfo *i) {
if (i->type)
printf("; type %s", i->type);
+ if (i->class)
+ printf("; class %s", i->class);
+
printf("\n");
- } else if (i->type)
+ } else if (i->type) {
printf("\t Type: %s\n", i->type);
+ if (i->class)
+ printf("; class %s", i->class);
+ } else if (i->class)
+ printf("\t Class: %s\n", i->class);
+
+
printf("\t Active: %s\n", yes_no(i->active));
if (i->control_group) {
@@ -571,6 +581,8 @@ static int status_property_session(const char *name, DBusMessageIter *iter, Sess
i->service = s;
else if (streq(name, "Type"))
i->type = s;
+ else if (streq(name, "Class"))
+ i->class = s;
}
break;
}
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 7794ab9..d8f4d89 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -62,6 +62,7 @@
" <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"sevice\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"type\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"class\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"vtnr\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"tty\" type=\"s\" direction=\"in\"/>\n" \
@@ -222,11 +223,12 @@ static int bus_manager_append_idle_hint_since(DBusMessageIter *i, const char *pr
static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {
Session *session = NULL;
User *user = NULL;
- const char *type, *seat, *tty, *display, *remote_user, *remote_host, *service;
+ const char *type, *class, *seat, *tty, *display, *remote_user, *remote_host, *service;
uint32_t uid, leader, audit_id = 0;
dbus_bool_t remote, kill_processes;
char **controllers = NULL, **reset_controllers = NULL;
SessionType t;
+ SessionClass c;
Seat *s;
DBusMessageIter iter;
int r;
@@ -271,6 +273,17 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
return -EINVAL;
+ dbus_message_iter_get_basic(&iter, &class);
+ if (isempty(class))
+ c = SESSION_USER;
+ else
+ c = session_class_from_string(class);
+
+ if (c < 0 ||
+ !dbus_message_iter_next(&iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
dbus_message_iter_get_basic(&iter, &seat);
if (isempty(seat))
@@ -467,6 +480,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
session->leader = leader;
session->audit_id = audit_id;
session->type = t;
+ session->class = c;
session->remote = remote;
session->controllers = controllers;
session->reset_controllers = reset_controllers;
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index 9767f7d..102f8ac 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -57,6 +57,7 @@
" <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Audit\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"Class\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Active\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
@@ -196,6 +197,7 @@ static int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *pr
}
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_type, session_type, SessionType);
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_class, session_class, SessionClass);
static int get_session_for_path(Manager *m, const char *path, Session **_s) {
Session *s;
@@ -238,6 +240,7 @@ static const BusProperty bus_login_session_properties[] = {
{ "Leader", bus_property_append_pid, "u", offsetof(Session, leader) },
{ "Audit", bus_property_append_uint32, "u", offsetof(Session, audit_id) },
{ "Type", bus_session_append_type, "s", offsetof(Session, type) },
+ { "Class", bus_session_append_class, "s", offsetof(Session, class) },
{ "Active", bus_session_append_active, "b", 0 },
{ "Controllers", bus_property_append_strv, "as", offsetof(Session, controllers), true },
{ "ResetControllers", bus_property_append_strv, "as", offsetof(Session, reset_controllers), true },
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index c0d9532..af9c12d 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -145,6 +145,11 @@ int session_save(Session *s) {
"TYPE=%s\n",
session_type_to_string(s->type));
+ if (s->class >= 0)
+ fprintf(f,
+ "CLASS=%s\n",
+ session_class_to_string(s->class));
+
if (s->cgroup_path)
fprintf(f,
"CGROUP=%s\n",
@@ -225,7 +230,8 @@ int session_load(Session *s) {
*vtnr = NULL,
*leader = NULL,
*audit_id = NULL,
- *type = NULL;
+ *type = NULL,
+ *class = NULL;
int k, r;
@@ -245,6 +251,7 @@ int session_load(Session *s) {
"VTNR", &vtnr,
"LEADER", &leader,
"TYPE", &type,
+ "CLASS", &class,
NULL);
if (r < 0)
@@ -297,6 +304,14 @@ int session_load(Session *s) {
s->type = t;
}
+ if (class) {
+ SessionClass c;
+
+ c = session_class_from_string(class);
+ if (c >= 0)
+ s->class = c;
+ }
+
if (s->fifo_path) {
int fd;
@@ -947,6 +962,14 @@ static const char* const session_type_table[_SESSION_TYPE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType);
+static const char* const session_class_table[_SESSION_CLASS_MAX] = {
+ [SESSION_USER] = "user",
+ [SESSION_GREETER] = "greeter",
+ [SESSION_LOCK_SCREEN] = "lock-screen"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass);
+
static const char* const kill_who_table[_KILL_WHO_MAX] = {
[KILL_LEADER] = "leader",
[KILL_ALL] = "all"
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index 8e394ac..d0b8c87 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -38,6 +38,14 @@ typedef enum SessionType {
_SESSION_TYPE_INVALID = -1
} SessionType;
+typedef enum SessionClass {
+ SESSION_USER,
+ SESSION_GREETER,
+ SESSION_LOCK_SCREEN,
+ _SESSION_CLASS_MAX,
+ _SESSION_CLASS_INVALID = -1
+} SessionClass;
+
typedef enum KillWho {
KILL_LEADER,
KILL_ALL,
@@ -50,6 +58,7 @@ struct Session {
char *id;
SessionType type;
+ SessionClass class;
char *state_file;
@@ -118,6 +127,9 @@ int session_send_lock(Session *s, bool lock);
const char* session_type_to_string(SessionType t);
SessionType session_type_from_string(const char *s);
+const char* session_class_to_string(SessionClass t);
+SessionClass session_class_from_string(const char *s);
+
const char *kill_who_to_string(KillWho k);
KillWho kill_who_from_string(const char *s);
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 4650924..8544413 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -321,7 +321,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
struct passwd *pw;
bool kill_processes = false, debug = false;
- const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type, *cvtnr = NULL;
+ const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type, *class, *cvtnr = NULL;
char **controllers = NULL, **reset_controllers = NULL, **kill_only_users = NULL, **kill_exclude_users = NULL;
DBusError error;
uint32_t uid, pid;
@@ -465,13 +465,20 @@ _public_ PAM_EXTERN int pam_sm_open_session(
type = !isempty(display) ? "x11" :
!isempty(tty) ? "tty" : "unspecified";
- remote = !isempty(remote_host) && !streq(remote_host, "localhost") && !streq(remote_host, "localhost.localdomain");
+ class = pam_getenv(handle, "XDG_SESSION_CLASS");
+ if (isempty(class))
+ class = "user";
+
+ remote = !isempty(remote_host) &&
+ !streq(remote_host, "localhost") &&
+ !streq(remote_host, "localhost.localdomain");
if (!dbus_message_append_args(m,
DBUS_TYPE_UINT32, &uid,
DBUS_TYPE_UINT32, &pid,
DBUS_TYPE_STRING, &service,
DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_STRING, &class,
DBUS_TYPE_STRING, &seat,
DBUS_TYPE_UINT32, &vtnr,
DBUS_TYPE_STRING, &tty,
More information about the systemd-commits
mailing list