summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-08 20:32:27 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-08 20:33:09 +0900
commit501b1cd5fcef6ebcf3151eeed5412e81304147af (patch)
treea5c93d05095c290ad410c03bc66875230151c304
parent2e34bf2633fea87c24f674c87f66865b90043627 (diff)
setuid safeness - ensure if an app that is setuid doesn't do bad things
this makes efl ignore certain env vars for thnigs and entirely removes user modules (that no one ever used) etc. etc. to ensure that *IF* an app is setuid, there isn't a priv escalation path that is easy.
-rw-r--r--src/lib/elm_cnp.c4
-rw-r--r--src/lib/elm_config.c81
-rw-r--r--src/lib/elm_conform.c18
-rw-r--r--src/lib/elm_module.c47
-rw-r--r--src/lib/elm_url.c9
5 files changed, 87 insertions, 72 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index f0464fbf0..0d8deabbb 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -3508,13 +3508,13 @@ _tempfile_new(int size)
3508{ 3508{
3509#ifdef HAVE_MMAN_H 3509#ifdef HAVE_MMAN_H
3510 Tmp_Info *info; 3510 Tmp_Info *info;
3511 const char *tmppath; 3511 const char *tmppath = NULL;
3512 mode_t cur_umask; 3512 mode_t cur_umask;
3513 int len; 3513 int len;
3514 3514
3515 info = calloc(1, sizeof(Tmp_Info)); 3515 info = calloc(1, sizeof(Tmp_Info));
3516 if (!info) return NULL; 3516 if (!info) return NULL;
3517 tmppath = getenv("TMP"); 3517 if (getuid() == getuid()) tmppath = getenv("TMP");
3518 if (!tmppath) tmppath = P_tmpdir; 3518 if (!tmppath) tmppath = P_tmpdir;
3519 len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-"); 3519 len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
3520 if (len < 0) goto on_error; 3520 if (len < 0) goto on_error;
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 17a7bdc75..502eef939 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -8,6 +8,7 @@
8 8
9#include <Elementary.h> 9#include <Elementary.h>
10#include "elm_priv.h" 10#include "elm_priv.h"
11#include <pwd.h>
11 12
12EAPI int ELM_EVENT_CONFIG_ALL_CHANGED = 0; 13EAPI int ELM_EVENT_CONFIG_ALL_CHANGED = 0;
13 14
@@ -508,7 +509,7 @@ _elm_config_user_dir_snprintf(char *dst,
508 ...) 509 ...)
509{ 510{
510 const char *home = NULL; 511 const char *home = NULL;
511 size_t user_dir_len, off; 512 size_t user_dir_len = 0, off = 0;
512 va_list ap; 513 va_list ap;
513 514
514#ifdef _WIN32 515#ifdef _WIN32
@@ -517,28 +518,47 @@ _elm_config_user_dir_snprintf(char *dst,
517 (dst, size, '/', home, strlen(home), 518 (dst, size, '/', home, strlen(home),
518 ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1); 519 ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1);
519#else 520#else
520#ifdef DOXDG 521 if (getuid() == getuid())
521 home = getenv("XDG_CONFIG_HOME");
522 if (home)
523 { 522 {
524 user_dir_len = eina_str_join_len 523#ifdef DOXDG
525 (dst, size, '/', home, strlen(home), 524 home = getenv("XDG_CONFIG_HOME");
526 "elementary", sizeof("elementary") - 1); 525 if (home)
526 {
527 user_dir_len = eina_str_join_len
528 (dst, size, '/', home, strlen(home),
529 "elementary", sizeof("elementary") - 1);
530 }
531 else
532#endif
533 {
534 home = getenv("HOME");
535 if (!home) home = "/";
536#ifdef DOXDG
537 user_dir_len = eina_str_join_len
538 (dst, size, '/', home, strlen(home),
539 ".config", sizeof(".config") - 1,
540 "elementary", sizeof("elementary") - 1);
541#else
542 user_dir_len = eina_str_join_len
543 (dst, size, '/', home, strlen(home),
544 ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1);
545#endif
546 }
527 } 547 }
528 else 548 else
529#endif
530 { 549 {
531 home = getenv("HOME"); 550 struct passwd *pw = getpwent();
532 if (!home) home = "/"; 551
552 if ((!pw) || (!pw->pw_dir)) goto end;
533#ifdef DOXDG 553#ifdef DOXDG
534 user_dir_len = eina_str_join_len 554 user_dir_len = eina_str_join_len
535 (dst, size, '/', home, strlen(home), 555 (dst, size, '/', pw->pw_dir, strlen(pw->pw_dir),
536 ".config", sizeof(".config") - 1, 556 ".config", sizeof(".config") - 1,
537 "elementary", sizeof("elementary") - 1); 557 "elementary", sizeof("elementary") - 1);
538#else 558#else
539 user_dir_len = eina_str_join_len 559 user_dir_len = eina_str_join_len
540 (dst, size, '/', home, strlen(home), 560 (dst, size, '/', pw->pw_dir, strlen(pw->pw_dir),
541 ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1); 561 ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1);
542#endif 562#endif
543 } 563 }
544#endif 564#endif
@@ -872,6 +892,11 @@ _profile_fetch_from_conf(void)
872 if (s) 892 if (s)
873 { 893 {
874 _elm_profile = strdup(s); 894 _elm_profile = strdup(s);
895 if (_elm_profile)
896 {
897 p = strchr(_elm_profile, '/');
898 if (p) *p = 0;
899 }
875 return; 900 return;
876 } 901 }
877 902
@@ -884,10 +909,16 @@ _profile_fetch_from_conf(void)
884 if (p) 909 if (p)
885 { 910 {
886 _elm_profile = malloc(len + 1); 911 _elm_profile = malloc(len + 1);
887 memcpy(_elm_profile, p, len); 912 if (_elm_profile)
888 _elm_profile[len] = 0; 913 {
889 free(p); 914 memcpy(_elm_profile, p, len);
915 _elm_profile[len] = 0;
916 free(p);
917 }
918 else free(p);
890 eet_close(ef); 919 eet_close(ef);
920 p = strchr(_elm_profile, '/');
921 if (p) *p = 0;
891 return; 922 return;
892 } 923 }
893 eet_close(ef); 924 eet_close(ef);
@@ -902,10 +933,16 @@ _profile_fetch_from_conf(void)
902 if (p) 933 if (p)
903 { 934 {
904 _elm_profile = malloc(len + 1); 935 _elm_profile = malloc(len + 1);
905 memcpy(_elm_profile, p, len); 936 if (_elm_profile)
906 _elm_profile[len] = 0; 937 {
907 free(p); 938 memcpy(_elm_profile, p, len);
939 _elm_profile[len] = 0;
940 free(p);
941 }
942 else free(p);
908 eet_close(ef); 943 eet_close(ef);
944 p = strchr(_elm_profile, '/');
945 if (p) *p = 0;
909 return; 946 return;
910 } 947 }
911 eet_close(ef); 948 eet_close(ef);
@@ -2538,6 +2575,8 @@ _elm_config_sub_init(void)
2538 } 2575 }
2539 _elm_profile = s; 2576 _elm_profile = s;
2540 if (changed) _prop_config_get(); 2577 if (changed) _prop_config_get();
2578 s = strchr(_elm_profile, '/');
2579 if (s) *s = 0;
2541 } 2580 }
2542 } 2581 }
2543 } 2582 }
diff --git a/src/lib/elm_conform.c b/src/lib/elm_conform.c
index ca42c4b46..7317074db 100644
--- a/src/lib/elm_conform.c
+++ b/src/lib/elm_conform.c
@@ -309,6 +309,11 @@ _port_indicator_connect_cb(void *data)
309 sd->port_indi_timer = NULL; 309 sd->port_indi_timer = NULL;
310 return ECORE_CALLBACK_CANCEL; 310 return ECORE_CALLBACK_CANCEL;
311 } 311 }
312 if (strchr(indicator_serv_name, '/'))
313 {
314 sd->port_indi_timer = NULL;
315 return ECORE_CALLBACK_CANCEL;
316 }
312 if (elm_plug_connect(sd->portrait_indicator, indicator_serv_name, 0, EINA_FALSE)) 317 if (elm_plug_connect(sd->portrait_indicator, indicator_serv_name, 0, EINA_FALSE))
313 { 318 {
314 DBG("Conformant connect to server[%s]\n", indicator_serv_name); 319 DBG("Conformant connect to server[%s]\n", indicator_serv_name);
@@ -339,6 +344,11 @@ _land_indicator_connect_cb(void *data)
339 sd->land_indi_timer = NULL; 344 sd->land_indi_timer = NULL;
340 return ECORE_CALLBACK_CANCEL; 345 return ECORE_CALLBACK_CANCEL;
341 } 346 }
347 if (strchr(indicator_serv_name, '/'))
348 {
349 sd->port_indi_timer = NULL;
350 return ECORE_CALLBACK_CANCEL;
351 }
342 if (elm_plug_connect(sd->landscape_indicator, indicator_serv_name, 0, EINA_FALSE)) 352 if (elm_plug_connect(sd->landscape_indicator, indicator_serv_name, 0, EINA_FALSE))
343 { 353 {
344 DBG("Conformant connect to server[%s]\n", indicator_serv_name); 354 DBG("Conformant connect to server[%s]\n", indicator_serv_name);
@@ -386,6 +396,10 @@ _create_portrait_indicator(Evas_Object *obj)
386 DBG("Conformant cannot get portrait indicator service name\n"); 396 DBG("Conformant cannot get portrait indicator service name\n");
387 return NULL; 397 return NULL;
388 } 398 }
399 if (strchr(port_indicator_serv_name, '/'))
400 {
401 return NULL;
402 }
389 403
390 port_indicator = elm_plug_add(obj); 404 port_indicator = elm_plug_add(obj);
391 if (!port_indicator) 405 if (!port_indicator)
@@ -423,6 +437,10 @@ _create_landscape_indicator(Evas_Object *obj)
423 DBG("Conformant cannot get portrait indicator service name\n"); 437 DBG("Conformant cannot get portrait indicator service name\n");
424 return NULL; 438 return NULL;
425 } 439 }
440 if (strchr(land_indicator_serv_name, '/'))
441 {
442 return NULL;
443 }
426 444
427 land_indicator = elm_plug_add(obj); 445 land_indicator = elm_plug_add(obj);
428 if (!land_indicator) 446 if (!land_indicator)
diff --git a/src/lib/elm_module.c b/src/lib/elm_module.c
index 11dca417b..f0e0903a0 100644
--- a/src/lib/elm_module.c
+++ b/src/lib/elm_module.c
@@ -122,55 +122,10 @@ _elm_module_find_as(const char *as)
122Eina_Bool 122Eina_Bool
123_elm_module_load(Elm_Module *m) 123_elm_module_load(Elm_Module *m)
124{ 124{
125 const char *home;
126 char buf[PATH_MAX]; 125 char buf[PATH_MAX];
127 126
128 if (m->module) return EINA_TRUE; 127 if (m->module) return EINA_TRUE;
129 128 if (strchr(m->name, '/')) return EINA_FALSE;
130 home = getenv("HOME");
131 if (home)
132 {
133 snprintf(buf, sizeof(buf),
134 "%s/"ELEMENTARY_BASE_DIR "/modules/%s/%s/module"
135 EFL_SHARED_EXTENSION, home, m->name, MODULE_ARCH);
136 m->module = eina_module_new(buf);
137 if ((m->module) && (eina_module_load(m->module) == EINA_TRUE))
138 {
139 m->init_func =
140 eina_module_symbol_get(m->module, "elm_modapi_init");
141 if (m->init_func)
142 {
143 m->shutdown_func =
144 eina_module_symbol_get(m->module, "elm_modapi_shutdown");
145 m->so_path = eina_stringshare_add(buf);
146 snprintf(buf, sizeof(buf),
147 "%s/"ELEMENTARY_BASE_DIR "/modules/%s/%s",
148 home, m->name, MODULE_ARCH);
149 m->bin_dir = eina_stringshare_add(buf);
150 snprintf(buf, sizeof(buf),
151 "%s/"ELEMENTARY_BASE_DIR "/modules/%s",
152 home, m->name);
153 m->data_dir = eina_stringshare_add(buf);
154 }
155 else
156 {
157 if (m->module)
158 {
159 eina_module_unload(m->module);
160 eina_module_free(m->module);
161 m->module = NULL;
162 }
163 return EINA_FALSE;
164 }
165 }
166 else if (m->module)
167 {
168 eina_module_free(m->module);
169 m->module = NULL;
170 }
171 }
172
173 if (m->module) return EINA_TRUE;
174 129
175 snprintf(buf, sizeof(buf), 130 snprintf(buf, sizeof(buf),
176 "%s/elementary/modules/%s/%s/module"EFL_SHARED_EXTENSION, 131 "%s/elementary/modules/%s/%s/module"EFL_SHARED_EXTENSION,
diff --git a/src/lib/elm_url.c b/src/lib/elm_url.c
index 736d1a0fd..c4bbc52ba 100644
--- a/src/lib/elm_url.c
+++ b/src/lib/elm_url.c
@@ -98,9 +98,12 @@ elm_url_download(const char *url, Elm_Url_Done done_cb, Elm_Url_Cancel cancel_cb
98 target = ecore_con_url_new(url); 98 target = ecore_con_url_new(url);
99 if (!target) goto on_error; 99 if (!target) goto on_error;
100 100
101 if (getenv("http_proxy")) ecore_con_url_proxy_set(target, getenv("http_proxy")); 101 if (getuid() == getuid())
102 if (getenv("https_proxy")) ecore_con_url_proxy_set(target, getenv("https_proxy")); 102 {
103 if (getenv("ftp_proxy")) ecore_con_url_proxy_set(target, getenv("ftp_proxy")); 103 if (getenv("http_proxy")) ecore_con_url_proxy_set(target, getenv("http_proxy"));
104 if (getenv("https_proxy")) ecore_con_url_proxy_set(target, getenv("https_proxy"));
105 if (getenv("ftp_proxy")) ecore_con_url_proxy_set(target, getenv("ftp_proxy"));
106 }
104 107
105 r = malloc(sizeof (Elm_Url)); 108 r = malloc(sizeof (Elm_Url));
106 if (!r) goto on_error; 109 if (!r) goto on_error;