1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

man: introduce new "Desktop" property for sessions

This is initialized from XDG_SESSION_DESKTOP and is useful for GNOME
to recognize its own sessions. It's supposed to be set to a short string
identifying the session, such as "kde" or "gnome".
This commit is contained in:
Lennart Poettering 2014-02-05 20:34:11 +01:00
parent 49ebd11fb0
commit a4cd87e9dc
7 changed files with 111 additions and 20 deletions

View File

@ -222,6 +222,66 @@
operating system operating system
provides.</para></listitem> provides.</para></listitem>
</varlistentry> </varlistentry>
</variablelist>
<para>The following environment variables are read by
the module and may be used by the PAM service to pass
meta data to the module:</para>
<variablelist class='environment-variables'>
<varlistentry>
<term><varname>$XDG_SESSION_TYPE</varname></term>
<listitem><para>The session type. This
may be used instead of
<option>session=</option> on the
module parameter line, and is usually
preferred.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$XDG_SESSION_CLASS</varname></term>
<listitem><para>The session class. This
may be used instead of
<option>class=</option> on the
module parameter line, and is usually
preferred.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$XDG_SESSION_DESKTOP</varname></term>
<listitem><para>The session
deskop. This may be used to indicate
the session desktop used, where this
applies. This should be a short,
lowercase string identifying the
desktop environment used if this
information is available. For example:
<literal>gnome</literal>, or
<literal>kde</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$XDG_SEAT</varname></term>
<listitem><para>The seat name the session
shall be registered for, if
any.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$XDG_VTNR</varname></term>
<listitem><para>The VT number the
session shall be registered for, if
any. (Only applies to seats with a VT
available, such as
<literal>seat0</literal>)</para></listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -271,6 +271,7 @@ typedef struct SessionStatusInfo {
const char *class; const char *class;
const char *state; const char *state;
const char *scope; const char *scope;
const char *desktop;
} SessionStatusInfo; } SessionStatusInfo;
typedef struct UserStatusInfo { typedef struct UserStatusInfo {
@ -363,6 +364,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
{ "RemoteHost", "s", NULL, offsetof(SessionStatusInfo, remote_host) }, { "RemoteHost", "s", NULL, offsetof(SessionStatusInfo, remote_host) },
{ "RemoteUser", "s", NULL, offsetof(SessionStatusInfo, remote_user) }, { "RemoteUser", "s", NULL, offsetof(SessionStatusInfo, remote_user) },
{ "Service", "s", NULL, offsetof(SessionStatusInfo, service) }, { "Service", "s", NULL, offsetof(SessionStatusInfo, service) },
{ "Desktop", "s", NULL, offsetof(SessionStatusInfo, desktop) },
{ "Type", "s", NULL, offsetof(SessionStatusInfo, type) }, { "Type", "s", NULL, offsetof(SessionStatusInfo, type) },
{ "Class", "s", NULL, offsetof(SessionStatusInfo, class) }, { "Class", "s", NULL, offsetof(SessionStatusInfo, class) },
{ "Scope", "s", NULL, offsetof(SessionStatusInfo, scope) }, { "Scope", "s", NULL, offsetof(SessionStatusInfo, scope) },
@ -462,6 +464,9 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
} else if (i.class) } else if (i.class)
printf("\t Class: %s\n", i.class); printf("\t Class: %s\n", i.class);
if (!isempty(i.desktop))
printf("\t Desktop: %s\n", i.desktop);
if (i.state) if (i.state)
printf("\t State: %s\n", i.state); printf("\t State: %s\n", i.state);

View File

@ -450,7 +450,7 @@ static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *us
} }
static int method_create_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { static int method_create_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host; const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop;
uint32_t uid, leader, audit_id = 0; uint32_t uid, leader, audit_id = 0;
_cleanup_free_ char *id = NULL; _cleanup_free_ char *id = NULL;
Session *session = NULL; Session *session = NULL;
@ -467,7 +467,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
assert(message); assert(message);
assert(m); assert(m);
r = sd_bus_message_read(message, "uussssussbss", &uid, &leader, &service, &type, &class, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host); r = sd_bus_message_read(message, "uusssssussbss", &uid, &leader, &service, &type, &class, &desktop, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host);
if (r < 0) if (r < 0)
return r; return r;
@ -490,6 +490,13 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid session class %s", class); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid session class %s", class);
} }
if (isempty(desktop))
desktop = NULL;
else {
if (!string_is_safe(desktop))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid desktop string %s", desktop);
}
if (isempty(cseat)) if (isempty(cseat))
seat = NULL; seat = NULL;
else { else {
@ -550,10 +557,10 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
} }
if (c == _SESSION_CLASS_INVALID) { if (c == _SESSION_CLASS_INVALID) {
if (!isempty(display) || !isempty(tty)) if (t == SESSION_UNSPECIFIED)
c = SESSION_USER;
else
c = SESSION_BACKGROUND; c = SESSION_BACKGROUND;
else
c = SESSION_USER;
} }
if (leader <= 0) { if (leader <= 0) {
@ -687,6 +694,14 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
} }
} }
if (!isempty(desktop)) {
session->desktop = strdup(desktop);
if (!session->desktop) {
r = -ENOMEM;
goto fail;
}
}
if (seat) { if (seat) {
r = seat_attach_session(seat, session); r = seat_attach_session(seat, session);
if (r < 0) if (r < 0)
@ -1864,7 +1879,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_METHOD("ListUsers", NULL, "a(uso)", method_list_users, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("ListUsers", NULL, "a(uso)", method_list_users, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("ListSeats", NULL, "a(so)", method_list_seats, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("ListSeats", NULL, "a(so)", method_list_seats, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("ListInhibitors", NULL, "a(ssssuu)", method_list_inhibitors, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("ListInhibitors", NULL, "a(ssssuu)", method_list_inhibitors, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("CreateSession", "uussssussbssa(sv)", "soshusub", method_create_session, 0), SD_BUS_METHOD("CreateSession", "uusssssussbssa(sv)", "soshusub", method_create_session, 0),
SD_BUS_METHOD("ReleaseSession", "s", NULL, method_release_session, 0), SD_BUS_METHOD("ReleaseSession", "s", NULL, method_release_session, 0),
SD_BUS_METHOD("ActivateSession", "s", NULL, method_activate_session, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("ActivateSession", "s", NULL, method_activate_session, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("ActivateSessionOnSeat", "ss", NULL, method_activate_session_on_seat, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("ActivateSessionOnSeat", "ss", NULL, method_activate_session_on_seat, SD_BUS_VTABLE_UNPRIVILEGED),

View File

@ -444,6 +444,7 @@ const sd_bus_vtable session_vtable[] = {
SD_BUS_PROPERTY("RemoteHost", "s", NULL, offsetof(Session, remote_host), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RemoteHost", "s", NULL, offsetof(Session, remote_host), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RemoteUser", "s", NULL, offsetof(Session, remote_user), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RemoteUser", "s", NULL, offsetof(Session, remote_user), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Service", "s", NULL, offsetof(Session, service), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Service", "s", NULL, offsetof(Session, service), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Desktop", "s", NULL, offsetof(Session, desktop), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Scope", "s", NULL, offsetof(Session, scope), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Scope", "s", NULL, offsetof(Session, scope), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Leader", "u", bus_property_get_pid, offsetof(Session, leader), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Leader", "u", bus_property_get_pid, offsetof(Session, leader), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Audit", "u", NULL, offsetof(Session, audit_id), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Audit", "u", NULL, offsetof(Session, audit_id), SD_BUS_VTABLE_PROPERTY_CONST),

View File

@ -143,6 +143,7 @@ void session_free(Session *s) {
free(s->remote_host); free(s->remote_host);
free(s->remote_user); free(s->remote_user);
free(s->service); free(s->service);
free(s->desktop);
hashmap_remove(s->manager->sessions, s->id); hashmap_remove(s->manager->sessions, s->id);
@ -229,6 +230,9 @@ int session_save(Session *s) {
if (s->service) if (s->service)
fprintf(f, "SERVICE=%s\n", s->service); fprintf(f, "SERVICE=%s\n", s->service);
if (s->desktop)
fprintf(f, "DESKTOP=%s\n", s->desktop);
if (s->seat && seat_has_vts(s->seat)) if (s->seat && seat_has_vts(s->seat))
fprintf(f, "VTNR=%u\n", s->vtnr); fprintf(f, "VTNR=%u\n", s->vtnr);
@ -294,6 +298,7 @@ int session_load(Session *s) {
"REMOTE_HOST", &s->remote_host, "REMOTE_HOST", &s->remote_host,
"REMOTE_USER", &s->remote_user, "REMOTE_USER", &s->remote_user,
"SERVICE", &s->service, "SERVICE", &s->service,
"DESKTOP", &s->desktop,
"VTNR", &vtnr, "VTNR", &vtnr,
"POS", &pos, "POS", &pos,
"LEADER", &leader, "LEADER", &leader,

View File

@ -87,6 +87,7 @@ struct Session {
char *remote_user; char *remote_user;
char *remote_host; char *remote_host;
char *service; char *service;
char *desktop;
char *scope; char *scope;
char *scope_job; char *scope_job;

View File

@ -212,7 +212,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
*remote_user = NULL, *remote_host = NULL, *remote_user = NULL, *remote_host = NULL,
*seat = NULL, *seat = NULL,
*type = NULL, *class = NULL, *type = NULL, *class = NULL,
*class_pam = NULL, *type_pam = NULL, *cvtnr = NULL; *class_pam = NULL, *type_pam = NULL, *cvtnr = NULL, *desktop = NULL;
_cleanup_bus_unref_ sd_bus *bus = NULL; _cleanup_bus_unref_ sd_bus *bus = NULL;
int session_fd = -1, existing, r; int session_fd = -1, existing, r;
bool debug = false, remote; bool debug = false, remote;
@ -303,8 +303,11 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (isempty(class)) if (isempty(class))
class = class_pam; class = class_pam;
desktop = pam_getenv(handle, "XDG_SESSION_DESKTOP");
if (isempty(desktop))
desktop = getenv("XDG_SESSION_DESKTOP");
tty = strempty(tty); tty = strempty(tty);
display = strempty(display);
if (strchr(tty, ':')) { if (strchr(tty, ':')) {
/* A tty with a colon is usually an X11 display, /* A tty with a colon is usually an X11 display,
@ -314,21 +317,21 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (isempty(display)) if (isempty(display))
display = tty; display = tty;
tty = ""; tty = NULL;
} else if (streq(tty, "cron")) { } else if (streq(tty, "cron")) {
/* cron has been setting PAM_TTY to "cron" for a very /* cron has been setting PAM_TTY to "cron" for a very
* long time and it probably shouldn't stop doing that * long time and it probably shouldn't stop doing that
* for compatibility reasons. */ * for compatibility reasons. */
type = "unspecified"; type = "unspecified";
class = "background"; class = "background";
tty = ""; tty = NULL;
} else if (streq(tty, "ssh")) { } else if (streq(tty, "ssh")) {
/* ssh has been setting PAM_TTY to "ssh" for a very /* ssh has been setting PAM_TTY to "ssh" for a very
* long time and probably shouldn't stop doing that * long time and probably shouldn't stop doing that
* for compatibility reasons. */ * for compatibility reasons. */
type ="tty"; type ="tty";
class = "user"; class = "user";
tty = ""; tty = NULL;
} }
/* If this fails vtnr will be 0, that's intended */ /* If this fails vtnr will be 0, that's intended */
@ -368,11 +371,11 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (debug) if (debug)
pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: " pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: "
"uid=%u pid=%u service=%s type=%s class=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s", "uid=%u pid=%u service=%s type=%s class=%s desktop=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s",
pw->pw_uid, getpid(), pw->pw_uid, getpid(),
strempty(service), strempty(service),
type, class, type, class, desktop,
strempty(seat), vtnr, tty, strempty(display), strempty(seat), vtnr, strempty(tty), strempty(display),
yes_no(remote), strempty(remote_user), strempty(remote_host)); yes_no(remote), strempty(remote_user), strempty(remote_host));
r = sd_bus_call_method(bus, r = sd_bus_call_method(bus,
@ -382,19 +385,20 @@ _public_ PAM_EXTERN int pam_sm_open_session(
"CreateSession", "CreateSession",
&error, &error,
&reply, &reply,
"uussssussbssa(sv)", "uusssssussbssa(sv)",
(uint32_t) pw->pw_uid, (uint32_t) pw->pw_uid,
(uint32_t) getpid(), (uint32_t) getpid(),
strempty(service), service,
type, type,
class, class,
strempty(seat), desktop,
seat,
vtnr, vtnr,
tty, tty,
strempty(display), display,
remote, remote,
strempty(remote_user), remote_user,
strempty(remote_host), remote_host,
0); 0);
if (r < 0) { if (r < 0) {
pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r));