/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
* communication pipe. The Display Manager process will start
* the X window server at system boot time before any user
* has logged into the system. The X server is by default
* started as the root UID "0".
*
* At login time the Xserver local communication pipe is provided
* by the Xserver for user specific configuration data supplied
* by the display manager. It notifies the Xserver it needs to change
* over to the user's credentials (UID, GID, GID_LIST) and
* also switch CWD (current working directory) of to match
* the user's CWD home.
*
*
* For the original definition, see Sun ASARC case 1995/390
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <netdb.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include "misc.h"
#include "osdep.h"
#include "input.h"
#include "dixstruct.h"
#include "dixfont.h"
#include "opaque.h"
#include <pwd.h>
#include <project.h>
#include <ctype.h>
#include "scrnintstr.h"
extern const char *GetAuthFilename(void);
/* Data about the user we need to switch to */
struct dmuser {
int groupid_cnt;
char * homedir;
};
struct dmdata {
int pipeFD;
};
/* Data stored in screen privates */
struct dmScreenPriv {
};
static void DtloginBlockHandler(void *, struct timeval **, void *);
static void DtloginWakeupHandler(void *, int, void *);
static int dtlogin_create_pipe(int, struct dmdata *);
static void dtlogin_receive_packet(struct dmdata *);
static int dtlogin_parse_packet(struct dmdata *, char *);
static void dtlogin_close_pipe(struct dmdata *);
/*
* initialize DTLOGIN: create pipe; set handlers.
*/
_X_HIDDEN void
DtloginInit(void)
{
int displayNumber = 0;
if (serverGeneration != 1) return;
if (getuid() != 0) return;
DtloginError("Failed to allocate %d bytes for display manager pipe",
(int) sizeof(struct dmdata));
return;
}
return;
}
dmHandlerData = dmd;
(void *) dmd);
}
/*
* cleanup dtlogin pipe at exit if still running, reset privs back to
* root as needed for various cleanup tasks.
*/
_X_HIDDEN void
DtloginCloseDown(void)
{
if (geteuid() != 0) { /* reset privs back to root */
if (seteuid(0) < 0) {
DtloginError("Error in resetting euid to %d", 0);
}
dtlogin_process(&originalUser, 0);
}
if (dmHandlerData != NULL) {
}
}
static Bool
{
/* Unwrap CloseScreen and call down to further levels */
pScreenPriv = (struct dmScreenPriv *)
free (pScreenPriv);
}
static void
void *data,
void *pReadmask)
{
}
static void
void *data, /* unused */
int i,
void *pReadmask)
{
if (i > 0)
{
{
/* dmd may have been freed in dtlogin_receive_packet, do
not use after this point */
}
}
}
static int
{
DtloginError("Cannot create %s directory for display "
"manager pipe", DTLOGIN_PATH);
return -1;
}
DtloginError("Cannot create display manager pipe: "
"%s is not a directory", DTLOGIN_PATH);
return -1;
}
return -1;
return -1;
}
/* To make sure root has rw permissions. */
return pipeFD;
}
{
if (dmHandlerData == dmd) {
}
}
static void
{
char *p, *n;
int done = 0;
}
/* Read data from pipe and split into tokens, buffering the rest */
while (!done) {
/*
* Realloc only if buf has filled up and we don't have a record
* delimiter yet. Keep track of alloced size.
*/
}
if (nbRead == -1) {
continue;
return; /* return to WaitFor, wait for select() */
} else {
return;
}
}
if (nbRead == 0) { /* End of file */
return;
}
*n = '\0';
DtloginInfo("Next packet: %s\n", p);
if (done) {
return;
}
p = n+1;
}
/* save the rest for the next iteration */
DtloginInfo("Left over: %s\n", p);
}
}
}
/* Parse data from packet
*
* Example Record:
* UID="xxx" GID="yyy";
* G_LIST_ID="aaa" G_LIST_ID="bbb" G_LIST_ID="ccc";
*/
static int
{
char *k, *v, *p;
/* format is key="value" - split into key & value pair */
for (k = s ; (*k != '\0') && isspace(*k); k++) {
/* Skip over whitespace */
}
if (*k == '\0') {
break;
}
p = strchr(k, '=');
if (p == NULL) {
DtloginInfo("Malformed key \'%s\'\n", k);
return 0;
}
*p = '\0'; /* end of key string */
p++;
if (*p != '\"') {
DtloginInfo("Bad delimiter at \'%s\'\n", p);
return 0;
}
v = p + 1; /* start of value string */
p = strchr(v, '\"');
if (p == NULL) {
DtloginInfo("Missing quote after value \'%s\'\n", v);
break;
}
*p = '\0'; /* end of value string */
s = p + 1; /* start of next pair */
DtloginInfo("Received key \"%s\" =>", k);
DtloginInfo(" value \"%s\"\n", v);
/* Found key & value, now process & put into dmd */
if (strcmp(k, "EOF") == 0) {
/* End of transmission, process & close */
return 1;
}
else if (strcmp(k, "HOME") == 0) {
}
|| (strcmp(k, "G_LIST_ID") == 0) ) {
/* Value is numeric, convert to int */
long val;
errno = 0;
/* strtol couldn't parse the results */
DtloginInfo("Invalid number \"%s\"\n", v);
continue;
}
/* Value out of range */
DtloginInfo("Out of range number \"%s\"\n", v);
continue;
}
if (strcmp(k, "UID") == 0) {
}
else if (strcmp(k, "GID") == 0) {
}
else if (strcmp(k, "G_LIST_ID") == 0) {
}
}
}
else {
DtloginInfo("Unrecognized key \"%s\"\n", k);
}
}
return 0;
}
static void
{
auth_file = GetAuthFilename();
if (auth_file) {
}
/* 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
saved-gid as 0. */
}
if (user->groupid_cnt >= 0) {
DtloginError("Error in setting supplemental (%d) groups",
user->groupid_cnt);
}
/*
* BUG: 4462531: Set project ID for Xserver
* Get user name and default project.
* Set before the uid value is set.
*/
}
} else {
DtloginError("Error in getting project id for %s",
} else {
TASK_NORMAL) == -1) {
DtloginError("Error in setting project to %s",
}
}
}
}
/* Wrap closeScreen to allow resetting uid on closedown */
int i;
for (i = 0; i < screenInfo.numScreens; i++)
{
if (pScreenPriv != NULL) {
} else {
DtloginError("Failed to allocate %d bytes"
" for uid reset info",
(int) sizeof(struct dmScreenPriv));
}
}
} else {
DtloginError("Failed to register screen private %s",
"for uid reset info");
}
}
}
} else {
}
DtloginError("Error in changing working directory to %s",
}
/* Inform the kernel whether a user has logged in on this VT device */
if (xf86ConsoleFd != -1)
}