supprot XDG_RUNTME_DIR for ipc socket and handle failure if someone

already created it - try new names until tries exhausted (4096)



SVN revision: 73072
This commit is contained in:
Carsten Haitzler 2012-06-30 05:33:36 +00:00
parent 892e68e399
commit ecddd2391f
2 changed files with 45 additions and 38 deletions

View File

@ -180,7 +180,7 @@ _e_fm_ipc_init(void)
_e_fm_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_SYSTEM, sdir, 0, NULL); _e_fm_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_SYSTEM, sdir, 0, NULL);
if (!_e_fm_ipc_server) if (!_e_fm_ipc_server)
{ {
printf("Cannot connect to enlightenment - abort\n"); printf("Cannot connect to enlightenment (socket '%s') - abort\n", sdir);
return 0; return 0;
} }

View File

@ -15,59 +15,66 @@ EINTERN int
e_ipc_init(void) e_ipc_init(void)
{ {
#ifdef USE_IPC #ifdef USE_IPC
char buf[1024]; char buf[1024], buf2[128], buf3[4096];
char *tmp, *user, *disp; char *tmp, *user, *disp, *base;
int pid; int pid, trynum = 0;
tmp = getenv("TMPDIR"); tmp = getenv("TMPDIR");
if (!tmp) tmp = "/tmp"; if (!tmp) tmp = "/tmp";
base = tmp;
tmp = getenv("XDG_RUNTIME_DIR");
if (tmp) base = tmp;
tmp = getenv("SD_USER_SOCKETS_DIR");
if (tmp) base = tmp;
user = getenv("USER"); user = getenv("USER");
if (!user) user = "__unknown__"; if (!user)
{
int uidint;
user = "__unknown__";
uidint = getuid();
if (uidint >= 0)
{
snprintf(buf2, sizeof(buf2), "%i", uidint);
user = buf2;
}
}
disp = getenv("DISPLAY"); disp = getenv("DISPLAY");
if (!disp) disp = ":0"; if (!disp) disp = ":0";
e_util_env_set("E_IPC_SOCKET", "");
pid = (int)getpid(); pid = (int)getpid();
snprintf(buf, sizeof(buf), "%s/enlightenment-%s", tmp, user); for (trynum = 0; trynum <= 4096; trynum++)
if (mkdir(buf, S_IRWXU) == 0)
{
}
else
{ {
struct stat st; struct stat st;
int id1 = 0, id2 = 0;
snprintf(buf, sizeof(buf), "%s/enlightenment-%s@%08x%08x",
base, user, id1, id2);
mkdir(buf, S_IRWXU);
if (stat(buf, &st) == 0) if (stat(buf, &st) == 0)
{ {
if ((st.st_uid == getuid()) && if ((st.st_uid == getuid()) &&
((st.st_mode & (S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)) == ((st.st_mode & (S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)) ==
(S_IRWXU | S_IFDIR))) (S_IRWXU | S_IFDIR)))
{ {
} snprintf(buf3, sizeof(buf3), "%s/disp-%s-%i",
else buf, disp, pid);
{ _e_ipc_server = ecore_ipc_server_add
e_error_message_show(_("Possible IPC Hack Attempt. The IPC socket\n" (ECORE_IPC_LOCAL_SYSTEM, buf3, 0, NULL);
"directory already exists BUT has permissions\n" if (_e_ipc_server) break;
"that are too leanient (must only be readable\n" "and writable by the owner, and nobody else)\n"
"or is not owned by you. Please check:\n"
"%s/enlightenment-%s\n"), tmp, user);
return 0;
} }
} }
else id1 = rand();
{ id2 = rand();
e_error_message_show(_("The IPC socket directory cannot be created or\n"
"examined.\n"
"Please check:\n"
"%s/enlightenment-%s\n"),
tmp, user);
return 0;
}
} }
snprintf(buf, sizeof(buf), "%s/enlightenment-%s/disp-%s-%i",
tmp, user, disp, pid);
_e_ipc_server = ecore_ipc_server_add(ECORE_IPC_LOCAL_SYSTEM, buf, 0, NULL);
e_util_env_set("E_IPC_SOCKET", "");
if (!_e_ipc_server) return 0; if (!_e_ipc_server) return 0;
e_util_env_set("E_IPC_SOCKET", buf);
printf("INFO: E_IPC_SOCKET=%s\n", buf); e_util_env_set("E_IPC_SOCKET", buf3);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD,
_e_ipc_cb_client_add, NULL); _e_ipc_cb_client_add, NULL);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL,
@ -220,7 +227,7 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
default: default:
break; break;
} }
return 1; return ECORE_CALLBACK_PASS_ON;
} }
#endif #endif