dtlogin.c revision 1351
970N/A * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. 970N/A * Permission is hereby granted, free of charge, to any person obtaining a 970N/A * copy of this software and associated documentation files (the "Software"), 970N/A * to deal in the Software without restriction, including without limitation 970N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 970N/A * and/or sell copies of the Software, and to permit persons to whom the 970N/A * Software is furnished to do so, subject to the following conditions: 970N/A * The above copyright notice and this permission notice (including the next 970N/A * paragraph) shall be included in all copies or substantial portions of the 970N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 970N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 970N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 970N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 970N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 970N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 970N/A * DEALINGS IN THE SOFTWARE. 970N/A * communication pipe. The Display Manager process will start 970N/A * the X window server at system boot time before any user 970N/A * has logged into the system. The X server is by default 970N/A * started as the root UID "0". 970N/A * At login time the Xserver local communication pipe is provided 977N/A * by the Xserver for user specific configuration data supplied 970N/A * by the display manager. It notifies the Xserver it needs to change 970N/A * over to the user's credentials (UID, GID, GID_LIST) and 970N/A * also switch CWD (current working directory) of to match 970N/A * When shutting down, the Xserver restores it's original uid/gid as 970N/A * For the original definition, see Sun ASARC case 1995/390 /* Data about the user we need to switch to */ char *
buf;
/* contains characters to be processed */ int bufsize;
/* size allocated for buf */ struct dmuser user;
/* target user, to switch to on login */ /* Data stored in screen privates */ * initialize DTLOGIN: create pipe; set handlers. DtloginError(
"Failed to allocate %d bytes for display manager pipe",
* cleanup dtlogin pipe at exit if still running, reset privs back to * root as needed for various cleanup tasks. * Called from main loop in os/main.c & CloseScreen wrappers if (
geteuid() != 0) {
/* reset privs back to root */ /* Unwrap CloseScreen and call down to further levels */ /* dmd may have been freed in dtlogin_receive_packet, do not use after this point */ /* To make sure root has rw permissions. */ /* Read data from pipe and split into tokens, buffering the rest */ * Realloc only if buf has filled up and we don't have a record * delimiter yet. Keep track of alloced size. return;
/* return to WaitFor, wait for select() */ if (
nbRead == 0) {
/* End of file */ while ((n =
strchr(p,
';')) !=
NULL) {
/* Next complete packet */ /* save the rest for the next iteration */ /* Parse data from packet * G_LIST_ID="aaa" G_LIST_ID="bbb" G_LIST_ID="ccc"; /* format is key="value" - split into key & value pair */ for (k = s ; (*k !=
'\0') &&
isspace(*k); k++) {
/* Skip over whitespace */ *p =
'\0';
/* end of key string */ v = p +
1;
/* start of value string */ *p =
'\0';
/* end of value string */ s = p +
1;
/* start of next pair */ /* Found key & value, now process & put into dmd */ /* End of transmission, process & close */ else if (
strcmp(k,
"HOME") == 0) {
else if ( (
strcmp(k,
"UID") == 0) || (
strcmp(k,
"GID") == 0)
|| (
strcmp(k,
"G_LIST_ID") == 0) ) {
/* Value is numeric, convert to int */ /* strtol couldn't parse the results */ else if (
strcmp(k,
"GID") == 0) {
else if (
strcmp(k,
"G_LIST_ID") == 0) {
/* This gid dance is necessary in order to make sure our "saved-set-gid" is 0 so that we can regain gid 0 when necessary for priocntl & power management. The first step sets rgid to the user's gid and makes the egid & saved-gid be 0. The second then sets the egid to the users gid, but leaves the * BUG: 4462531: Set project ID for Xserver * Get user name and default project. * Set before the uid value is set. /* Wrap closeScreen to allow resetting uid on closedown */ /* Inform the kernel whether a user has logged in on this VT device */