Process the new location of the ICEauthority file

+ our internal implementation of IceAuthFileName tests
  whether the ICEauthority file exists in the folder
  specified by the XDG_RUNTIME_DIR variable
+ DCOP client tests whether the ICEauthority file for
  a specific user exists in the user's folder based on
  the XDG_RUNTIME_DIR variable
+ tdeinit uses the IceAuthFileName() function
  instead of building the file name

This relates to bug 3027.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/55/head
Slávek Banko 5 years ago
parent 0810a81ba1
commit 38b2b0be78
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -81,11 +81,13 @@ char *
IceAuthFileName () IceAuthFileName ()
{ {
static char baseICEauthority[] = "ICEauthority";
#ifdef _WIN32 #ifdef _WIN32
static char slashDotICEauthority[] = "\\.ICEauthority"; static char pathSep[] = "\\";
#else #else
static char slashDotICEauthority[] = "/.ICEauthority"; static char pathSep[] = "/";
#endif #endif
char fileSep[2];
char *name; char *name;
static char *buf; static char *buf;
static int bsize; static int bsize;
@ -95,37 +97,70 @@ IceAuthFileName ()
#endif #endif
name = getenv ("ICEAUTHORITY"); name = getenv ("ICEAUTHORITY");
if ( name ) if (name && name[0])
return (name); return (name);
name = getenv ("HOME"); name = getenv("XDG_RUNTIME_DIR");
if (name && name[0])
{
char *testBuf;
strcpy(fileSep, "");
size = strlen(name) + strlen(pathSep) + strlen(fileSep) + strlen(baseICEauthority) + 1;
testBuf = malloc(size);
if (!testBuf)
{
return (NULL);
}
snprintf(testBuf, size, "%s%s%s%s", name, pathSep, fileSep, baseICEauthority);
if (access(testBuf, F_OK))
{
name = NULL;
}
free(testBuf);
}
if (!name) if (!name || !name[0])
{ {
name = getenv ("HOME");
strcpy(fileSep, ".");
#ifdef _WIN32 #ifdef _WIN32
if(name = getenv ("HOMEDRIVE")) if (!name || !name[0])
{ {
strcpy (dir, name); if(name = getenv ("HOMEDRIVE"))
if(name = getenv ("HOMEPATH")) {
strcat (dir, name); strcpy (dir, name);
} if(name = getenv ("HOMEPATH"))
else
{ {
if(name = getenv ("USERPROFILE")) strcat (dir, name);
strcpy (dir, name); }
} name = dir;
name = dir; }
if (!name) else
{
name = getenv ("USERPROFILE");
}
}
#endif #endif
#ifdef __EMX__ #ifdef __EMX__
strcpy (dir,"c:"); if (!name || !name[0])
name = dir; {
if (!name) strcpy (dir,"c:");
name = dir;
}
#endif #endif
}
if (!name || !name[0])
{
return (NULL); return (NULL);
} }
size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2; /* Special case for "/". We will add our own '/' later. */
if (strcmp(name, pathSep) == 0)
{
name++;
}
size = strlen(name) + strlen(pathSep) + strlen(fileSep) + strlen(baseICEauthority) + 1;
if (size > bsize) if (size > bsize)
{ {
@ -137,8 +172,7 @@ IceAuthFileName ()
bsize = size; bsize = size;
} }
strcpy (buf, name); snprintf(buf, bsize, "%s%s%s%s", name, pathSep, fileSep, baseICEauthority);
strcat (buf, slashDotICEauthority + (name[1] == '\0' ? 1 : 0));
return (buf); return (buf);
} }

@ -594,9 +594,29 @@ int runDCOP( QCStringList args, UserList users, Session session,
( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) ) ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) )
{ {
// Check for ICE authority file and if the file can be read by us // Check for ICE authority file and if the file can be read by us
TQString home = it.data(); TQString iceFileBase = "ICEauthority";
TQString iceFile = it.data() + "/.ICEauthority"; TQString iceFile;
TQFileInfo fi( iceFile ); TQFileInfo fi;
if (getenv("XDG_RUNTIME_DIR") != 0 )
{
TQFileInfo xdgRuntime(getenv("XDG_RUNTIME_DIR"));
passwd* pstruct = getpwnam(it.key().local8Bit());
if (pstruct)
{
iceFile = TQString("%1/%2/%3").arg(xdgRuntime.dirPath()).arg(pstruct->pw_uid).arg(iceFileBase);
fi.setFile(iceFile);
}
if (!pstruct || !fi.exists())
{
iceFile = TQString::null;
}
}
if (iceFile.isEmpty())
{
iceFile = TQString("%1/.%2").arg(it.data()).arg(iceFileBase);
fi.setFile(iceFile);
}
if( iceFile.isEmpty() ) if( iceFile.isEmpty() )
{ {
cerr_ << "WARNING: Cannot determine home directory for user " cerr_ << "WARNING: Cannot determine home directory for user "

@ -40,7 +40,7 @@ set( ${target}_SRCS
tde_add_executable( ${target} tde_add_executable( ${target}
SOURCES ${${target}_SRCS} SOURCES ${${target}_SRCS}
LINK ltdlc-static tdeparts-shared ${XFT_LIBRARIES} LINK kICE-static ltdlc-static tdeparts-shared ${XFT_LIBRARIES}
DESTINATION ${BIN_INSTALL_DIR} DESTINATION ${BIN_INSTALL_DIR}
) )

@ -59,6 +59,7 @@
#include <klibloader.h> #include <klibloader.h>
#include <tdeapplication.h> #include <tdeapplication.h>
#include <tdelocale.h> #include <tdelocale.h>
#include <dcopglobal.h>
#ifdef HAVE_SYS_PRCTL_H #ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h> #include <sys/prctl.h>
@ -852,12 +853,7 @@ static void init_tdeinit_socket()
exit(255); exit(255);
} }
} }
path = getenv("ICEAUTHORITY"); path = IceAuthFileName();
if (path.isEmpty())
{
path = home_dir;
path += "/.ICEauthority";
}
if (access(path.data(), R_OK|W_OK) && (errno != ENOENT)) if (access(path.data(), R_OK|W_OK) && (errno != ENOENT))
{ {
fprintf(stderr, "[tdeinit] Aborting. No write access to '%s'.\n", path.data()); fprintf(stderr, "[tdeinit] Aborting. No write access to '%s'.\n", path.data());

Loading…
Cancel
Save