From 460256d157af358861a3b1ae08cbec4c0e272ad2 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Fri, 13 May 2016 19:09:52 +0100 Subject: [PATCH] Search for .ICEauthority in the ${XDG_RUNTIME_DIR} directory Otherwise fallback to the old logic and seach the user's home directory. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49173 --- src/authutil.c | 73 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/authutil.c b/src/authutil.c index 04c0791..0960808 100644 --- a/src/authutil.c +++ b/src/authutil.c @@ -49,6 +49,7 @@ extern unsigned sleep (); #endif #endif +static char *base_directory (void); static Status read_short (FILE *file, unsigned short *shortp); static Status read_string (FILE *file, char **stringp); static Status read_counted_string (FILE *file, unsigned short *countp, char **stringp); @@ -72,40 +73,13 @@ IceAuthFileName (void) static char *buf; static size_t bsize; size_t size; -#ifdef WIN32 -#ifndef PATH_MAX -#define PATH_MAX 512 -#endif - char dir[PATH_MAX]; -#endif if ((name = getenv ("ICEAUTHORITY"))) return (name); - name = getenv ("HOME"); - + name = base_directory (); if (!name) - { -#ifdef WIN32 - register char *ptr1; - register char *ptr2; - int len1 = 0, len2 = 0; - - if ((ptr1 = getenv("HOMEDRIVE")) && (ptr2 = getenv("HOMEDIR"))) { - len1 = strlen (ptr1); - len2 = strlen (ptr2); - } else if ((ptr2 = getenv("USERNAME"))) { - len1 = strlen (ptr1 = "/users/"); - len2 = strlen (ptr2); - } - if ((len1 + len2 + 1) < PATH_MAX) { - snprintf (dir, sizeof(dir), "%s%s", ptr1, (ptr2) ? ptr2 : ""); - name = dir; - } - if (!name) -#endif - return (NULL); - } + return (NULL); size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2; @@ -367,6 +341,47 @@ IceGetAuthFileEntry ( * local routines */ +static char * +base_directory (void) +{ + char *name; +#ifdef WIN32 +#ifndef PATH_MAX +#define PATH_MAX 512 +#endif + char dir[PATH_MAX]; +#endif + + if ((name = getenv ("XDG_RUNTIME_DIR"))) + return (name); + + name = getenv ("HOME"); + if (!name) + { +#ifdef WIN32 + register char *ptr1; + register char *ptr2; + int len1 = 0, len2 = 0; + + if ((ptr1 = getenv("HOMEDRIVE")) && (ptr2 = getenv("HOMEDIR"))) { + len1 = strlen (ptr1); + len2 = strlen (ptr2); + } else if ((ptr2 = getenv("USERNAME"))) { + len1 = strlen (ptr1 = "/users/"); + len2 = strlen (ptr2); + } + if ((len1 + len2 + 1) < PATH_MAX) { + snprintf (dir, sizeof(dir), "%s%s", ptr1, (ptr2) ? ptr2 : ""); + name = dir; + } + if (!name) +#endif + return (NULL); + } + + return (name); +} + static Status read_short (FILE *file, unsigned short *shortp) { -- 2.1.4