792N/AFrom 619af82effb9125c904d34c9fbc4bf93385d7b9e Mon Sep 17 00:00:00 2001
792N/AFrom: Alan Coopersmith <alan.coopersmith@sun.com>
792N/ADate: Tue, 22 Sep 2009 13:41:38 -0700
792N/ASubject: [PATCH:app/xdm] Create piddir if needed on startup
792N/A
792N/AAllows setting piddir to /var/run/xdm/
792N/A
792N/ASigned-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
792N/A---
792N/A dm.c | 22 ++++++++++++++++++++++
792N/A 1 files changed, 22 insertions(+), 0 deletions(-)
792N/A
792N/Adiff --git a/dm.c b/dm.c
792N/Aindex c482017..abe4453 100644
792N/A--- a/dm.c
792N/A+++ b/dm.c
792N/A@@ -863,7 +863,29 @@ StorePid (void)
792N/A if (pidFile[0] != '\0') {
792N/A pidFd = open (pidFile, O_RDWR);
792N/A if (pidFd == -1 && errno == ENOENT)
792N/A+ {
792N/A+ /* Make sure directory exists if needed
792N/A+ Allows setting pidDir to /var/run/xdm
792N/A+ */
792N/A+ char *pidDir = strdup(pidFile);
792N/A+
792N/A+ if (pidDir != NULL)
792N/A+ {
792N/A+ char *p = strrchr(pidDir, '/');
792N/A+ int r;
792N/A+
792N/A+ if ((p != NULL) && (p != pidDir)) {
792N/A+ *p = '\0';
792N/A+ }
792N/A+ r = mkdir(pidDir, 0755);
792N/A+ if ( (r < 0) && (errno != EEXIST) ) {
792N/A+ LogError ("process-id directory %s cannot be created\n",
792N/A+ pidDir);
792N/A+ }
792N/A+ }
792N/A+
792N/A pidFd = open (pidFile, O_RDWR|O_CREAT, 0666);
792N/A+ }
792N/A if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+")))
792N/A {
792N/A LogError ("process-id file %s cannot be opened\n",
792N/A--
792N/A1.5.6.5
792N/A
792N/AFrom 748cfcc771c7f599d8087c7aa044bc5ff770da1d Mon Sep 17 00:00:00 2001
792N/AFrom: Alan Coopersmith <alan.coopersmith@sun.com>
792N/ADate: Tue, 22 Sep 2009 13:42:31 -0700
792N/ASubject: [PATCH:app/xdm] Make parent authdir if needed at startup
792N/A
792N/AAllows setting authdir to /var/run/xdm
792N/A
792N/AAlso refactor directory creation code for less duplication
792N/A
792N/ASigned-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
792N/A---
792N/A auth.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-------------------
792N/A 1 files changed, 47 insertions(+), 21 deletions(-)
792N/A
792N/Adiff --git a/auth.c b/auth.c
792N/Aindex a2cd9d6..d7cb30b 100644
792N/A--- a/auth.c
792N/A+++ b/auth.c
792N/A@@ -270,6 +270,38 @@ CleanUpFileName (char *src, char *dst, int len)
792N/A *dst = '\0';
792N/A }
792N/A
792N/A+/* Checks to see if specified directory exists, makes it if not
792N/A+ * Returns: 0 if already exists, 1 if created, < 0 if error occured
792N/A+ */
792N/A+static int
792N/A+CheckServerAuthDir (const char *path, struct stat *statb, int mode)
792N/A+{
792N/A+ int r = stat(path, statb);
792N/A+
792N/A+ if (r != 0) {
792N/A+ if (errno == ENOENT) {
792N/A+ r = mkdir(path, mode);
792N/A+ if (r < 0) {
792N/A+ LogError ("cannot make authentication directory %s: %s\n",
792N/A+ path, _SysErrorMsg (errno));
792N/A+ } else {
792N/A+ r = 1;
792N/A+ }
792N/A+ } else {
792N/A+ LogError ("cannot access authentication directory %s: %s\n",
792N/A+ path, _SysErrorMsg (errno));
792N/A+ }
792N/A+ } else { /* Directory already exists */
792N/A+ if (!S_ISDIR(statb->st_mode)) {
792N/A+ LogError ("cannot make authentication directory %s: %s\n",
792N/A+ path, "file with that name already exists");
792N/A+ return -1;
792N/A+ }
792N/A+ }
792N/A+
792N/A+ return r;
792N/A+}
792N/A+
792N/A static char authdir1[] = "authdir";
792N/A static char authdir2[] = "authfiles";
792N/A
792N/A@@ -298,6 +330,13 @@ MakeServerAuthFile (struct display *d, FILE ** file)
792N/A return FALSE;
792N/A } else {
792N/A CleanUpFileName (d->name, cleanname, NAMELEN - 8);
792N/A+
792N/A+ /* Make authDir if it doesn't already exist */
792N/A+ r = CheckServerAuthDir(authDir, &statb, 0755);
792N/A+ if (r < 0) {
792N/A+ return FALSE;
792N/A+ }
792N/A+
792N/A len = strlen (authDir) + strlen (authdir1) + strlen (authdir2)
792N/A + strlen (cleanname) + 14;
792N/A d->authFile = malloc (len);
792N/A@@ -305,35 +344,22 @@ MakeServerAuthFile (struct display *d, FILE ** file)
792N/A return FALSE;
792N/A
792N/A snprintf (d->authFile, len, "%s/%s", authDir, authdir1);
792N/A- r = stat(d->authFile, &statb);
792N/A+ r = CheckServerAuthDir(d->authFile, &statb, 0700);
792N/A if (r == 0) {
792N/A if (statb.st_uid != 0)
792N/A (void) chown(d->authFile, 0, statb.st_gid);
792N/A if ((statb.st_mode & 0077) != 0)
792N/A (void) chmod(d->authFile, statb.st_mode & 0700);
792N/A- } else {
792N/A- if (errno == ENOENT) {
792N/A- r = mkdir(d->authFile, 0700);
792N/A- if (r < 0) {
792N/A- LogError ("cannot make authentication directory %s: "
792N/A- "%s\n", d->authFile, _SysErrorMsg (errno));
792N/A- }
792N/A- } else {
792N/A- LogError ("cannot access authentication directory %s: "
792N/A- "%s\n", d->authFile, _SysErrorMsg (errno));
792N/A- }
792N/A- if (r < 0) {
792N/A- free (d->authFile);
792N/A- d->authFile = NULL;
792N/A- return FALSE;
792N/A- }
792N/A+ } else if (r < 0) {
792N/A+ free (d->authFile);
792N/A+ d->authFile = NULL;
792N/A+ return FALSE;
792N/A }
792N/A+
792N/A snprintf (d->authFile, len, "%s/%s/%s",
792N/A authDir, authdir1, authdir2);
792N/A- r = mkdir(d->authFile, 0700);
792N/A- if (r < 0 && errno != EEXIST) {
792N/A- LogError ("cannot make authentication directory %s: %s\n",
792N/A- d->authFile, _SysErrorMsg (errno));
792N/A+ r = CheckServerAuthDir(d->authFile, &statb, 0700);
792N/A+ if (r < 0) {
792N/A free (d->authFile);
792N/A d->authFile = NULL;
792N/A return FALSE;
792N/A--
792N/A1.5.6.5
792N/A