Fixed to use security_server_label_access() instead of lsetxattr().
[platform/core/uifw/download-fonts-service.git] / pkgmgr_font / src / font_service_register.c
1 /*
2  * Copyright 2013 Samsung Electronics Co., Ltd
3  *
4  *
5  * Contact: Minsu Seo <minsu15.seo@samsung.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/xattr.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <dirent.h>
26 #include <glib.h>
27 #include <dlog.h>
28 #include <fontconfig/fontconfig.h>
29 #include <Elementary.h>
30 #include <pkgmgr-info.h>
31 #include <security-server.h>
32 #include "system_settings.h"
33
34
35 #define FONT_SERVICE_TAG                "FONT_SERVICE"
36 #define DEBUG_LOG(frmt, args...)                \
37         do { SLOG(LOG_DEBUG,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
38         __func__, ##args);} while (0)
39 #define DEBUG_WARNING(frmt, args...)            \
40         do { SLOG(LOG_WARN,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
41         __func__, ##args);} while (0)
42 #define DEBUG_ERROR(frmt, args...)              \
43         do { SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
44         __func__, ##args);} while (0)
45
46 static const char *PARENT_PATH = "/opt/share/fonts";
47 static const char *DOWNLOAD_PATH = "/opt/share/fonts/download";
48 static const char *PRELOADED_PATH = "/opt/share/fonts/preloaded";
49
50 static const char *ELM_PROFILE_CFG = "/opt/home/app/.elementary/config/profile.cfg";
51 #define MAX_FILE_LEN 4096
52 #define APP_OWNER_ID 5000
53 #define APP_GROUP_ID 5000
54
55 static int make_dir(const char *path);
56 static int symbolic_link(const char *srcpath, const char *destpath);
57 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle);
58 static int do_uninstall(const char *deletedir);
59 static int move_file(const char *srcpath, const char *destpath);
60 static const char* check_preloaded(const char *app_root_path);
61 #ifdef CHECK_FAMILY_NAME
62 static int check_family_name(const char *srcpath);
63 #endif
64
65 static const char* check_preloaded(const char *app_root_path)
66 {
67         char tpk_path[MAX_FILE_LEN];
68         char wgt_path[MAX_FILE_LEN];
69
70         sprintf(tpk_path, "%s/preloaded", app_root_path);
71         sprintf(wgt_path, "%s/res/wgt/preloaded", app_root_path);
72
73         if ((access(tpk_path, F_OK) == 0) || (access(wgt_path, F_OK) == 0))
74         {
75                 return PRELOADED_PATH;
76         }
77
78         return DOWNLOAD_PATH;
79 }
80
81 static int make_dir(const char *path)
82 {
83         int ret = 0;
84
85         if (access(path, F_OK) == 0)
86         {
87                 return ret;
88         }
89         else
90         {
91                 ret = mkdir(path, 0755);
92                 if (ret < 0)
93                 {
94                         DEBUG_ERROR("make current directory %s is failed \n",path);
95                         return ret;
96                 }
97
98                 ret = chmod (path, 0755);
99                 if (ret < 0)
100                 {
101                         DEBUG_ERROR("chmod is failed %s\n",path);
102                         rmdir(path);
103                         return ret;
104                 }
105         }
106         ret = security_server_label_access(path, "_");
107
108         if (ret < 0)
109         {
110                 DEBUG_ERROR("security_server_label_access is failed %s\n",path);
111                 return ret;
112         }
113
114         return ret;
115 }
116
117 static int symbolic_link(const char *srcpath, const char *destpath)
118 {
119         DIR *d;
120         struct dirent *e;
121         int ret = 0;
122
123         d = opendir(srcpath);
124         while ((e = readdir (d)))
125         {
126                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
127                 {
128                         char srcdir[MAX_FILE_LEN];
129                         char destdir[MAX_FILE_LEN];
130                         struct stat       statb;
131
132                         if (strlen (srcpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
133                         {
134                                 DEBUG_ERROR("srcdir length is not available \n");
135                                 goto FAIL;
136                         }
137
138                         if (strlen (destpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
139                         {
140                                 DEBUG_ERROR("destdir length is not available \n");
141                                 goto FAIL;
142                         }
143
144                         sprintf(srcdir,"%s/%s",srcpath,(char *) e->d_name);
145                         sprintf(destdir,"%s/%s",destpath,(char *) e->d_name);
146                         if (stat (srcdir, &statb) == -1)
147                         {
148                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
149                                 goto FAIL;
150                         }
151
152                         if (S_ISDIR (statb.st_mode))
153                         {
154                                 if (make_dir(destdir)<0)
155                                 {
156                                         DEBUG_ERROR("make current directory %s is failed \n",destdir);
157                                         goto FAIL;
158                                 }
159                                 ret = symbolic_link(srcdir,destdir);
160                                 if (ret < 0)
161                                 {
162                                         DEBUG_ERROR("symlink is failed \n");
163                                         goto FAIL;
164                                 }
165                                 continue;
166                         }
167                         DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
168                         DEBUG_LOG("destdir =%s\n",(char *) destdir);
169                         DEBUG_LOG("file name =%s\n",(char *) e->d_name);
170
171                         ret = symlink((const char *)srcdir,(const char *)destdir);
172                         if (ret < 0)
173                         {
174                                 DEBUG_ERROR("symlink is failed \n");
175                                 goto FAIL;
176                         }
177
178                         ret = security_server_label_access(destdir, "_");
179
180                         if (ret < 0)
181                         {
182                                 DEBUG_ERROR("security_server_label_access is failed %s\n",destdir);
183                                 goto FAIL;
184                         }
185                 }
186         }
187         closedir (d);
188         return ret;
189
190 FAIL:
191         closedir (d);
192         return -1;
193 }
194
195
196 static int move_file(const char *srcpath, const char *destpath)
197 {
198         DIR *d;
199         struct dirent *e;
200         int ret = 0;
201
202         d = opendir (srcpath);
203         while ((e = readdir (d)))
204         {
205                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
206                 {
207                         char srcdir[MAX_FILE_LEN];
208                         char destdir[MAX_FILE_LEN];
209                         struct stat       statb;
210
211                         if (strlen (srcpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
212                         {
213                                 DEBUG_ERROR("srcdir length is not available \n");
214                                 goto FAIL;
215                         }
216
217                         if (strlen (destpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
218                         {
219                                 DEBUG_ERROR("destdir length is not available \n");
220                                 goto FAIL;
221                         }
222
223                         sprintf(srcdir,"%s/%s",srcpath,(char *) e->d_name);
224                         sprintf(destdir,"%s/%s",destpath,(char *) e->d_name);
225                         if (stat (srcdir, &statb) == -1)
226                         {
227                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
228                                 goto FAIL;
229                         }
230
231                         if (S_ISDIR (statb.st_mode))
232                         {
233                                 if (make_dir(destdir)<0)
234                                 {
235                                         DEBUG_ERROR("make current directory %s is failed \n",destdir);
236                                         goto FAIL;
237                                 }
238                                 continue;
239                         }
240                         DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
241                         DEBUG_LOG("destdir =%s\n",(char *) destdir);
242                         DEBUG_LOG("file name =%s\n",(char *) e->d_name);
243
244                         ret = rename((const char *)srcdir,(const char *)destdir);
245                         if (ret < 0)
246                         {
247                                 DEBUG_ERROR("symlink is failed \n");
248                                 goto FAIL;
249                         }
250
251                         ret = security_server_label_access(destdir, "_");
252
253                         if (ret < 0)
254                         {
255                                 DEBUG_ERROR("security_server_label_access is failed %s\n",destdir);
256                                 goto FAIL;
257                         }
258                 }
259         }
260         closedir (d);
261         return ret;
262
263 FAIL:
264         closedir (d);
265         return -1;
266 }
267
268 #ifdef CHECK_FAMILY_NAME
269 static int check_family_name(const char *srcpath)
270 {
271         FcObjectSet *os = NULL;
272         FcFontSet* fs = NULL;
273         FcPattern* pat = NULL;
274         FcConfig* font_config = NULL;
275         bool is_only_one_family = false;
276
277         font_config = FcInitLoadConfigAndFonts();
278
279         if(font_config == NULL) {
280                 DEBUG_ERROR("Failed: FcInitLoadConfigAndFonts");
281                 return -1;
282         }
283
284         pat = FcPatternCreate();
285
286         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
287
288         if (os) {
289                 fs = FcFontList(font_config, pat, os);
290                 FcObjectSetDestroy(os);
291                 os = NULL;
292         }
293
294         if (pat) {
295                 FcPatternDestroy(pat);
296                 pat = NULL;
297         }
298
299         if (fs)
300         {
301                 int j;
302                 char* only_one_family = NULL;
303
304                 for (j = 0; j < fs->nfont; j++)
305                 {
306                         FcChar8 *family = NULL;
307                         FcChar8 *file = NULL;
308
309                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
310                         {
311                                 int font_path_len = strlen(srcpath);
312
313                                         /* always shown for src path */
314                                         if (strncmp((const char*)file, srcpath, font_path_len) == 0)
315                                         {
316                                                                 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch)
317                                                                 {
318                                                                         DEBUG_ERROR("Family name is invalid");
319                                                                         continue;
320                                                                 }
321                                                                 //DEBUG_ERROR("-------- FOUND FONT - family = %s", (char *)family);
322
323                                                                 // first found family name
324                                                                 if (only_one_family == NULL  && strlen((char *)family) > 0)
325                                                                 {
326                                                                         is_only_one_family = true;
327                                                                         only_one_family = (char *)family;
328                                                                         //DEBUG_ERROR("--------First FOUND FONT - family = %s", only_one_family);
329                                                                 }
330                                                                 else if (only_one_family != NULL  && strlen((char *)family) > 0)// after first
331                                                                 {
332                                                                                 if (strcmp(only_one_family,  (char *)family) != 0)
333                                                                                 {
334                                                                                         DEBUG_ERROR("Not supported various font famliy. only one font famliy. %s %s", only_one_family, (char *)family);
335                                                                                         is_only_one_family = false;
336                                                                                         break;
337                                                                                 }
338                                                                 }
339                                                                 else
340                                                                 {
341                                                                         DEBUG_ERROR("invalid fonts");
342                                                                         break;
343                                                                 }
344                                         }
345                         }
346                 }
347
348                 FcFontSetDestroy(fs);
349                 fs = NULL;
350         }
351
352         FcConfigDestroy(font_config);
353         font_config = NULL;
354
355         if (is_only_one_family == false)
356         {
357                 //DEBUG_ERROR("Not supported various font famliy. only one font famliy");
358                 return -1;
359         }
360
361         return 0;
362 }
363 #endif
364
365 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle)
366 {
367         char destdir[MAX_FILE_LEN];
368         char path[MAX_FILE_LEN];
369         char *type = NULL;
370         int ret = 0;
371
372         if (strlen (parent) + strlen (appid) + 2 >= MAX_FILE_LEN )
373         {
374                 DEBUG_ERROR("appid length is not available \n");
375                 return -1;
376         }
377
378         sprintf(destdir,"%s/%s",parent,appid);
379         ret = make_dir(destdir);
380         if (ret < 0)
381         {
382                 DEBUG_ERROR("make current directory %s is failed \n", destdir);
383                 goto FAIL;
384         }
385
386         if (strlen (rootpath) + 2 >= MAX_FILE_LEN )
387         {
388                 DEBUG_ERROR("rootpath length is not available \n");
389                 goto FAIL;
390         }
391
392         ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
393         if (ret < 0)
394         {
395                 DEBUG_ERROR("pkgmgrinfo_pkginfo_get_type is failed\n");
396                 goto FAIL;
397         }
398
399         sprintf(path,"%s/shared/res", rootpath);
400
401         if (!strcmp(type,"wgt"))
402         {
403                 char srcpath[MAX_FILE_LEN];
404                 sprintf(srcpath,"%s/res/wgt/shared/res", rootpath);
405                 ret = move_file(srcpath, path);
406         }
407
408         if (ret < 0)
409         {
410                 DEBUG_ERROR("move_file is failed\n");
411                 goto FAIL;
412         }
413
414         ret = symbolic_link(path, destdir);
415
416         if (ret < 0)
417         {
418                 DEBUG_ERROR("install is failed \n", destdir);
419                 goto FAIL;
420         }
421
422 #ifdef CHECK_FAMILY_NAME
423         ret = check_family_name(destdir);
424
425         if (ret < 0)
426         {
427                 DEBUG_ERROR("Invaid font files\n");
428                 goto FAIL;
429         }
430 #endif
431
432         return ret;
433
434 FAIL:
435         do_uninstall(destdir);
436         return -1;
437 }
438
439
440 static int do_uninstall(const char *deletedir)
441 {
442         DIR     *d;
443         struct dirent *e;
444
445         d = opendir(deletedir);
446         while((e = readdir (d)))
447         {
448                 if (e->d_name[0] != '.')
449                 {
450                         char destfile[MAX_FILE_LEN];
451                         struct stat       statb;
452
453                         if (strlen (deletedir) + strlen ((char *) e->d_name) + 2 >= MAX_FILE_LEN )
454                         {
455                                 DEBUG_ERROR("destfile length is not available \n");
456                                 goto FAIL;
457                         }
458
459                         sprintf(destfile,"%s/%s",deletedir,(char *) e->d_name);
460                         if (lstat (destfile, &statb) == -1)
461                         {
462                                 DEBUG_ERROR("lstat %s is failed \n",destfile);
463                                 goto FAIL;
464                         }
465
466                         if (S_ISDIR (statb.st_mode))
467                         {
468                                 if (do_uninstall(destfile)<0)
469                                         goto FAIL;
470                         }
471                         else if (unlink(destfile) < 0)
472                         {
473                                 DEBUG_ERROR("unlink is failed %s\n",destfile);
474                                 goto FAIL;
475                         }
476                         DEBUG_LOG("destfile =%s\n",destfile);
477                 }
478         }
479
480         closedir (d);
481
482         if (rmdir(deletedir) < 0)
483         {
484                 DEBUG_ERROR("rmdir is failed \n");
485                 return -1;
486         }
487
488         DEBUG_LOG("rmdir =%s\n",deletedir);
489         return 0;
490
491 FAIL:
492         closedir (d);
493         return -1;
494 }
495
496
497 int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
498 {
499         int ret;
500         pkgmgrinfo_pkginfo_h handle = NULL;
501         const char *app_root_path = NULL;
502         const char *dest_path = NULL;
503
504         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
505         if (ret < 0)
506         {
507                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
508                 return -1;
509         }
510
511         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
512         if (ret < 0)
513         {
514                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
515                 goto FAIL;
516         }
517
518         if (appid == NULL)
519         {
520                 DEBUG_ERROR("appid is NULL \n");
521                 goto FAIL;
522         }
523
524         ret = make_dir(PARENT_PATH);
525
526         if (ret < 0)
527         {
528                 DEBUG_ERROR("make current directory is failed \n");
529                 goto FAIL;
530         }
531
532         dest_path = check_preloaded(app_root_path);
533
534         if (make_dir(dest_path)<0)
535         {
536                 DEBUG_ERROR("make current directory is failed \n");
537                 return -1;
538         }
539
540         ret = do_install(dest_path,appid, app_root_path, handle);
541         if (ret < 0)
542         {
543                 DEBUG_ERROR("font install is failed \n");
544                 goto FAIL;
545         }
546
547         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
548
549         return ret;
550
551 FAIL:
552         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
553         return -1;
554 }
555
556
557 int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
558 {
559         char deletedir[MAX_FILE_LEN];
560         int ret = 0;
561         pkgmgrinfo_pkginfo_h handle = NULL;
562         const char* app_root_path = NULL;
563         const char* dest_path = NULL;
564
565         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
566         if (ret < 0)
567         {
568                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
569                 return -1;
570         }
571
572         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
573         if (ret < 0)
574         {
575                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
576                 goto FAIL;
577         }
578
579         if (appid == NULL)
580         {
581                 DEBUG_ERROR("appid is NULL \n");
582                 goto FAIL;
583         }
584
585         dest_path = check_preloaded(app_root_path);
586
587         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
588         {
589                 DEBUG_ERROR("appid length is not available \n");
590                 goto FAIL;
591         }
592
593         sprintf(deletedir,"%s/%s", dest_path, appid);
594
595         if (access(deletedir, F_OK) == -1)
596         {
597                 DEBUG_ERROR("dest directory is not exist \n");
598                 goto FAIL;
599         }
600
601         ret = do_uninstall(deletedir);
602         if (ret < 0)
603         {
604                 DEBUG_ERROR("do_uninstall is failed \n");
605                 goto FAIL;
606         }
607
608         ret = make_dir(PARENT_PATH);
609
610         if (ret < 0)
611         {
612                 DEBUG_ERROR("make current directory is failed \n");
613                 goto FAIL;
614         }
615
616         ret = make_dir(dest_path);
617
618         if (ret < 0)
619         {
620                 DEBUG_ERROR("make current directory is failed \n");
621                 goto FAIL;
622         }
623
624         ret = do_install(dest_path, appid, app_root_path, handle);
625         if (ret < 0)
626         {
627                 DEBUG_ERROR("do_install is failed \n");
628                 goto FAIL;
629         }
630
631         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
632         return ret;
633
634 FAIL:
635         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
636         return -1;
637 }
638
639
640
641 int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
642 {
643         char deletedir[MAX_FILE_LEN];
644         FcObjectSet *os = NULL;
645         FcPattern *pat = NULL;
646         FcFontSet *fs = NULL;
647         const char* app_root_path = NULL;
648         const char *dest_path = NULL;
649         int ret;
650
651         elm_init(0, NULL);
652
653         if (appid == NULL)
654         {
655                 DEBUG_ERROR("appid is NULL \n");
656                 return -1;
657         }
658
659         pkgmgrinfo_pkginfo_h handle = NULL;
660
661
662         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
663         if (ret < 0)
664         {
665                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
666                 return -1;
667         }
668
669         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
670         if (ret < 0)
671         {
672                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
673                 goto FAIL;
674         }
675
676         dest_path = check_preloaded(app_root_path);
677
678         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
679         {
680                 DEBUG_ERROR("appid length is not available \n");
681                 goto FAIL;
682         }
683
684         sprintf(deletedir,"%s/%s", dest_path, appid);
685
686         //check if current using font is same with uninstall font
687         int deletedir_len = strlen(deletedir);
688
689         pat = FcPatternCreate();
690         if (pat == NULL)
691         {
692                 DEBUG_ERROR("FcPatternCreate is NULL \n");
693                 goto FAIL;
694         }
695
696         char *current_font_name = NULL;
697         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &current_font_name);
698         if (ret < 0)
699         {
700                 DEBUG_ERROR("Get current font is failed \n");
701                 goto FAIL;
702         }
703
704         DEBUG_LOG("current_font_name =%s\n",current_font_name);
705
706         FcInitLoadConfigAndFonts();
707         FcPatternAddString (pat, FC_FAMILY,(FcChar8*)current_font_name);
708         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
709         fs = FcFontList(NULL, pat, os);
710
711         FcPatternDestroy(pat);
712         free(current_font_name);
713
714         if (fs)
715         {
716                 int j;
717                 for (j = 0; j < fs->nfont; j++)
718                 {
719                         FcChar8 *file = NULL;
720                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
721                         {
722                                 DEBUG_LOG("file =%s\n",file);
723                                 if (strncmp((const char*)file , deletedir , deletedir_len) == 0 )
724                                 {
725                                         DEBUG_LOG("change to default font\n");
726                                         char *default_font_name = NULL;
727
728                                         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, &default_font_name);
729                                         if (ret < 0)
730                                         {
731                                                 DEBUG_ERROR("Get default font is failed \n");
732                                                 goto FAIL;
733                                         }
734
735                                         DEBUG_LOG("default_font_name = %s \n",default_font_name);
736                                         setenv("HOME", "/opt/home/app", 1);
737
738                                         ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, default_font_name);
739                                         if (ret < 0)
740                                         {
741                                                 DEBUG_ERROR("Set default font is failed ret=%d \n",ret);
742                                                 free(default_font_name);
743                                                 break;
744                                         }
745
746                                         char *elm_profile_path = (char*)elm_config_profile_dir_get(elm_config_profile_get(), EINA_TRUE);
747
748                                         setenv("HOME", "/root", 1);
749
750                                         ret = chown(ELM_PROFILE_CFG, APP_OWNER_ID, APP_GROUP_ID);
751                                         if (ret < 0)
752                                         {
753                                                 chmod (ELM_PROFILE_CFG, 0777);
754                                         }
755
756                                         ret = security_server_label_access(ELM_PROFILE_CFG, "system::homedir");
757                                         if (ret < 0)
758                                         {
759                                                 chmod (ELM_PROFILE_CFG, 0777);
760                                         }
761
762                                         DIR *d = NULL;
763                                         struct dirent *e;
764
765                                         if (elm_profile_path)
766                                                 d = opendir (elm_profile_path);
767
768                                         if (d)
769                                         {
770                                                 while ((e = readdir (d)))
771                                                 {
772                                                         if (e->d_name[0] != '.' &&  (strstr(e->d_name, ".cfg") != 0 || strstr(e->d_name, ".CFG") != 0))
773                                                         {
774                                                                 char file_full_path[100];
775
776                                                                 sprintf(file_full_path, "%s/%s", elm_profile_path, e->d_name);
777
778                                                                 ret = chown(file_full_path, APP_OWNER_ID, APP_GROUP_ID);
779                                                                 if (ret < 0)
780                                                                 {
781                                                                         DEBUG_LOG("chown is failed %s", file_full_path);
782                                                                         chmod (file_full_path, 0777);
783                                                                 }
784
785                                                                 ret = security_server_label_access(file_full_path, "system::homedir");
786                                                                 if (ret < 0)
787                                                                 {
788                                                                         DEBUG_LOG("chsmack is failed %s", file_full_path);
789                                                                         chmod (file_full_path, 0777);
790                                                                 }
791                                                         }
792                                                 }
793
794                                                 closedir (d);
795                                         }
796
797                                         free(default_font_name);
798                                         free(elm_profile_path);
799                                         DEBUG_LOG("success change to default font\n");
800                                         break;
801                                 }
802                         }
803                 }
804         }
805
806         if (access(deletedir, F_OK) == -1)
807         {
808                 DEBUG_ERROR("dest directory(%s) is not exist \n", deletedir);
809                 goto FAIL;
810         }
811
812         elm_shutdown();
813         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
814
815         return do_uninstall(deletedir);
816
817 FAIL:
818         elm_shutdown();
819         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
820
821         return -1;
822 }
823
824 #if USE_META_DATA
825 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
826 {
827         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
828 }
829
830 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
831 {
832         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
833 }
834
835 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
836 {
837         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
838 }
839 #endif
840
841 int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
842 {
843         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
844 }
845
846 int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
847 {
848         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
849 }
850
851 int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
852 {
853         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
854 }
855
856
857 /* End of a file */