--- gdm-2.29.5/acconfig.h-orig 2010-01-20 12:25:31.161980534 -0600 +++ gdm-2.29.5/acconfig.h 2010-01-20 12:25:49.994672342 -0600 @@ -30,6 +30,7 @@ #undef HAVE_SETENV #undef HAVE_SETRESUID #undef HAVE_SHADOW +#undef HAVE_SMF_CONTRACTS #undef HAVE_SOLARIS_XINERAMA #undef HAVE_STPCPY #undef HAVE_SYS_SOCKIO_H --- gdm-2.29.5/configure.ac-orig 2010-01-20 12:24:46.259973144 -0600 +++ gdm-2.29.5/configure.ac 2010-01-20 12:25:25.298947638 -0600 @@ -951,6 +951,14 @@ if test "x$enable_rbac_shutdown" != "xno fi AC_SUBST(RBAC_LIBS) +dnl --------------------------------------------------------------------------- +dnl check for Solaris SMF contract support +dnl --------------------------------------------------------------------------- + +AC_MSG_CHECKING(for Solaris SMF contract support) +AC_CHECK_LIB(contract, ct_tmpl_activate, [ + AC_DEFINE(HAVE_SMF_CONTRACTS) + EXTRA_DAEMON_LIBS="$EXTRA_DAEMON_LIBS -lcontract" ]) dnl --------------------------------------------------------------------------- dnl check for backtrace support --- gdm-2.29.5/daemon/gdm-slave-proxy.c-orig 2010-01-20 12:26:18.196290065 -0600 +++ gdm-2.29.5/daemon/gdm-slave-proxy.c 2010-01-20 12:30:40.753432413 -0600 @@ -30,6 +30,13 @@ #include #include +#ifdef HAVE_SMF_CONTRACTS +#include +#include +#include +#include +#endif + #include #include #include @@ -129,9 +136,145 @@ typedef struct { const char *log_file; } SpawnChildData; +#ifdef HAVE_SMF_CONTRACTS +static int contracts_fd = -1; + +void +contracts_pre_fork () +{ + const char *errmsg = "opening process contract template"; + + /* + * On failure, just continue since it is better to start with + * children in the same contract than to not start them at all. + */ + if (contracts_fd == -1) { + if ((contracts_fd = open64 (CTFS_ROOT "/process/template", + O_RDWR)) == -1) + goto exit; + + errmsg = "setting contract terms"; + if ((errno = ct_pr_tmpl_set_param (contracts_fd, CT_PR_PGRPONLY))) + goto exit; + + if ((errno = ct_tmpl_set_informative (contracts_fd, CT_PR_EV_HWERR))) + goto exit; + + if ((errno = ct_pr_tmpl_set_fatal (contracts_fd, CT_PR_EV_HWERR))) + goto exit; + + if ((errno = ct_tmpl_set_critical (contracts_fd, 0))) + goto exit; + } + + errmsg = "setting active template"; + if ((errno = ct_tmpl_activate (contracts_fd))) + goto exit; + + g_debug ("Set active contract"); + return; + +exit: + if (contracts_fd != -1) + (void) close (contracts_fd); + + contracts_fd = -1; + + if (errno) { + g_debug ( + "Error setting up active contract template: %s while %s", + strerror (errno), errmsg); + } +} + +void +contracts_post_fork_child () +{ + /* Clear active template so no new contracts are created on fork */ + if (contracts_fd == -1) + return; + + if ((errno = (ct_tmpl_clear (contracts_fd)))) { + g_debug ( + "Error clearing active contract template (child): %s", + strerror (errno)); + } else { + g_debug ("Cleared active contract template (child)"); + } + + (void) close (contracts_fd); + + contracts_fd = -1; +} + +void +contracts_post_fork_parent (int fork_succeeded) +{ + char path[PATH_MAX]; + int cfd; + ct_stathdl_t status; + ctid_t latest; + + /* Clear active template, abandon latest contract. */ + if (contracts_fd == -1) + return; + + if ((errno = ct_tmpl_clear (contracts_fd))) + g_debug ("Error while clearing active contract template: %s", + strerror (errno)); + else + g_debug ("Cleared active contract template (parent)"); + + if (!fork_succeeded) + return; + + if ((cfd = open64 (CTFS_ROOT "/process/latest", O_RDONLY)) == -1) { + g_debug ("Error getting latest contract: %s", + strerror(errno)); + return; + } + + if ((errno = ct_status_read (cfd, CTD_COMMON, &status)) != 0) { + g_debug ("Error getting latest contract ID: %s", + strerror(errno)); + (void) close (cfd); + return; + } + + latest = ct_status_get_id (status); + ct_status_free (status); + (void) close (cfd); + + if ((snprintf (path, PATH_MAX, CTFS_ROOT "/all/%ld/ctl", latest)) >= + PATH_MAX) { + g_debug ("Error opening the latest contract ctl file: %s", + strerror (ENAMETOOLONG)); + return; + } + + cfd = open64 (path, O_WRONLY); + if (cfd == -1) { + g_debug ("Error opening the latest contract ctl file: %s", + strerror (errno)); + return; + } + + if ((errno = ct_ctl_abandon (cfd))) + g_debug ("Error abandoning latest contract: %s", + strerror (errno)); + else + g_debug ("Abandoned latest contract"); + + (void) close (cfd); +} +#endif HAVE_SMF_CONTRACTS + static void spawn_child_setup (SpawnChildData *data) { +#ifdef HAVE_SMF_CONTRACTS + contracts_post_fork_child (); +#endif if (data->log_file != NULL) { int logfd; @@ -174,6 +317,10 @@ spawn_command_line_async (const char *co data.log_file = log_file; +#ifdef HAVE_SMF_CONTRACTS + contracts_pre_fork (); +#endif + local_error = NULL; res = g_spawn_async (NULL, argv, @@ -190,6 +337,10 @@ spawn_command_line_async (const char *co goto out; } +#ifdef HAVE_SMF_CONTRACTS + contracts_post_fork_parent ((*child_pid > 0)); +#endif + ret = TRUE; out: g_strfreev (argv);