1 --- lightdm-1.19.3/config.h.in.1 2016-08-11 16:37:18.327488055 +0300
2 +++ lightdm-1.19.3/config.h.in 2016-08-11 16:37:49.333955249 +0300
7 +/* libcontract support */
8 +#undef HAVE_SMF_CONTRACTS
10 /* Define to 1 if you have the <memory.h> header file. */
13 --- lightdm-1.19.3/configure.ac.1 2016-08-11 16:35:29.359045915 +0300
14 +++ lightdm-1.19.3/configure.ac 2016-08-11 16:37:03.732983253 +0300
17 AM_CONDITIONAL(COMPILE_LIBLIGHTDM_QT5, test x"$compile_liblightdm_qt5" != "xno")
19 +dnl ---------------------------------------------------------------------------
20 +dnl check for Solaris SMF contract support
21 +dnl ---------------------------------------------------------------------------
23 +AC_MSG_CHECKING(for Solaris SMF contract support)
24 +AC_CHECK_LIB(contract, ct_tmpl_activate, [
25 + AC_DEFINE(HAVE_SMF_CONTRACTS,1,[lcontract support])
26 + LIGHTDM_LIBS="${LIGHTDM_LIBS} -lcontract" ])
28 AC_ARG_ENABLE([libaudit],
29 AS_HELP_STRING([--enable-libaudit],
30 [Enable libaudit logging of login and logout events [[default=auto]]]),
31 --- lightdm-1.28.0/src/session.c 2018-08-30 02:28:55.000000000 +0000
32 +++ lightdm-1.28.0/src/session.c 2018-12-22 12:13:04.194567557 +0000
37 +#ifdef HAVE_SMF_CONTRACTS
38 +#include <sys/ctfs.h>
39 +#include <sys/contract.h>
40 +#include <sys/contract/process.h>
41 +#include <libcontract.h>
45 #include "configuration.h"
46 #include "console-kit.h"
47 @@ -131,6 +138,141 @@ G_DEFINE_TYPE_WITH_CODE (Session, sessio
48 G_IMPLEMENT_INTERFACE (
49 LOGGER_TYPE, session_logger_iface_init))
51 +#ifdef HAVE_SMF_CONTRACTS
52 +static int contracts_fd = -1;
54 +void contracts_pre_fork ();
55 +void contracts_post_fork_child ();
56 +void contracts_post_fork_parent (int fork_succeeded);
59 +contracts_pre_fork ()
61 + const char *errmsg = "opening process contract template";
64 + * On failure, just continue since it is better to start with
65 + * children in the same contract than to not start them at all.
67 + if (contracts_fd == -1) {
68 + if ((contracts_fd = open64 (CTFS_ROOT "/process/template",
72 + errmsg = "setting contract terms";
73 + if ((errno = ct_pr_tmpl_set_param (contracts_fd, CT_PR_PGRPONLY)))
76 + if ((errno = ct_tmpl_set_informative (contracts_fd, CT_PR_EV_HWERR)))
79 + if ((errno = ct_pr_tmpl_set_fatal (contracts_fd, CT_PR_EV_HWERR)))
82 + if ((errno = ct_tmpl_set_critical (contracts_fd, 0)))
86 + errmsg = "setting active template";
87 + if ((errno = ct_tmpl_activate (contracts_fd)))
90 + g_debug ("Set active contract");
94 + if (contracts_fd != -1)
95 + (void) close (contracts_fd);
101 + "Error setting up active contract template: %s while %s",
102 + strerror (errno), errmsg);
107 +contracts_post_fork_child ()
109 + /* Clear active template so no new contracts are created on fork */
110 + if (contracts_fd == -1)
113 + if ((errno = (ct_tmpl_clear (contracts_fd)))) {
115 + "Error clearing active contract template (child): %s",
118 + g_debug ("Cleared active contract template (child)");
121 + (void) close (contracts_fd);
127 +contracts_post_fork_parent (int fork_succeeded)
129 + char path[PATH_MAX];
131 + ct_stathdl_t status;
134 + /* Clear active template, abandon latest contract. */
135 + if (contracts_fd == -1)
138 + if ((errno = ct_tmpl_clear (contracts_fd)))
139 + g_debug ("Error while clearing active contract template: %s",
142 + g_debug ("Cleared active contract template (parent)");
144 + if (!fork_succeeded)
147 + if ((cfd = open64 (CTFS_ROOT "/process/latest", O_RDONLY)) == -1) {
148 + g_debug ("Error getting latest contract: %s",
153 + if ((errno = ct_status_read (cfd, CTD_COMMON, &status)) != 0) {
154 + g_debug ("Error getting latest contract ID: %s",
156 + (void) close (cfd);
160 + latest = ct_status_get_id (status);
161 + ct_status_free (status);
162 + (void) close (cfd);
164 + if ((snprintf (path, PATH_MAX, CTFS_ROOT "/all/%ld/ctl", latest)) >=
166 + g_debug ("Error opening the latest contract ctl file: %s",
167 + strerror (ENAMETOOLONG));
171 + cfd = open64 (path, O_WRONLY);
173 + g_debug ("Error opening the latest contract ctl file: %s",
178 + if ((errno = ct_ctl_abandon (cfd)))
179 + g_debug ("Error abandoning latest contract: %s",
182 + g_debug ("Abandoned latest contract");
189 @@ -612,10 +754,16 @@ session_real_start (Session *session)
192 g_autofree gchar *arg0 = g_strdup_printf ("%d", to_child_output);
193 +#ifdef HAVE_SMF_CONTRACTS
194 + contracts_pre_fork ();
196 g_autofree gchar *arg1 = g_strdup_printf ("%d", from_child_input);
200 +#ifdef HAVE_SMF_CONTRACTS
201 + contracts_post_fork_child ();
203 /* Run us again in session child mode */
206 @@ -623,6 +771,10 @@ session_real_start (Session *session)
208 _exit (EXIT_FAILURE);
210 +#ifdef HAVE_SMF_CONTRACTS
211 + /* Child would have already exited */
212 + contracts_post_fork_parent ((priv->pid > 0));