blob: 78e7654f6393cb9533356fecb43c73ba1c077aef [file] [log] [blame]
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -04001/*
2 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <iostream>
20#include <fstream>
21#include <sstream>
22#include <string>
23#include <vector>
24#include <string.h>
25#include <libgen.h>
26#include <unistd.h>
27#include <sys/stat.h>
28#include <dirent.h>
29#include "gui/rapidxml.hpp"
30#include "fixPermissions.hpp"
31#include "twrp-functions.hpp"
Dees_Troy2673cec2013-04-02 20:22:16 +000032#include "twcommon.h"
bigbiff bigbiff872a3b92013-10-18 20:50:25 -040033#ifdef HAVE_SELINUX
34#include "selinux/selinux.h"
35#include "selinux/label.h"
36#include "selinux/android.h"
37#include "selinux/label.h"
38#endif
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -040039
40using namespace std;
41using namespace rapidxml;
42
bigbiff bigbiff872a3b92013-10-18 20:50:25 -040043#ifdef HAVE_SELINUX
44int fixPermissions::restorecon(string entry, struct stat *sb) {
45 char *oldcontext, *newcontext;
46 struct selabel_handle *sehandle;
47
48 sehandle = selinux_android_file_context_handle();
49 if (lgetfilecon(entry.c_str(), &oldcontext) < 0) {
50 LOGINFO("Couldn't get selinux context for %s\n", entry.c_str());
51 return -1;
52 }
53 if (selabel_lookup(sehandle, &newcontext, entry.c_str(), sb->st_mode) < 0) {
54 LOGINFO("Couldn't lookup selinux context for %s\n", entry.c_str());
55 return -1;
56 }
57 LOGINFO("Relabeling %s from %s to %s\n", entry.c_str(), oldcontext, newcontext);
58 if (lsetfilecon(entry.c_str(), newcontext) < 0) {
59 LOGINFO("Couldn't label %s with %s: %s\n", entry.c_str(), newcontext, strerror(errno));
60 }
61 freecon(oldcontext);
62 freecon(newcontext);
63 return 0;
64}
65
66int fixPermissions::fixDataDataContexts(void) {
67 DIR *d;
68 struct dirent *de;
69 struct stat sb;
70 struct selabel_handle *selinux_handle;
71 struct selinux_opt selinux_options[] = {
72 { SELABEL_OPT_PATH, "/file_contexts" }
73 };
74 selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
75 if (!selinux_handle)
76 printf("No file contexts for SELinux\n");
77 else
78 printf("SELinux contexts loaded from /file_contexts\n");
79 d = opendir("/data/data");
80 while (( de = readdir(d)) != NULL) {
81 stat(de->d_name, &sb);
82 string f = "/data/data/";
83 f = f + de->d_name;
84 restorecon(f, &sb);
85 }
86 return 0;
87}
88#endif
89
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -040090int fixPermissions::fixPerms(bool enable_debug, bool remove_data_for_missing_apps) {
91 packageFile = "/data/system/packages.xml";
92 debug = enable_debug;
93 remove_data = remove_data_for_missing_apps;
Dees_Troy201d76b2012-11-16 17:12:02 +000094 multi_user = TWFunc::Path_Exists("/data/user");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -040095
96 if (!(TWFunc::Path_Exists(packageFile))) {
Dees_Troy2673cec2013-04-02 20:22:16 +000097 gui_print("Can't check permissions\n");
98 gui_print("after Factory Reset.\n");
99 gui_print("Please boot rom and try\n");
100 gui_print("again after you reboot into\n");
101 gui_print("recovery.\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400102 return -1;
103 }
104
Dees_Troy2673cec2013-04-02 20:22:16 +0000105 gui_print("Fixing permissions...\nLoading packages...\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400106 if ((getPackages()) != 0) {
107 return -1;
108 }
Dees_Troy32f2ca82013-02-02 17:03:12 +0000109
Dees_Troy2673cec2013-04-02 20:22:16 +0000110 gui_print("Fixing /system/app permissions...\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400111 if ((fixSystemApps()) != 0) {
112 return -1;
113 }
114
grimsrudcbec59f2013-07-29 15:46:22 +0200115 gui_print("Fixing /data/app permissions...\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400116 if ((fixDataApps()) != 0) {
117 return -1;
118 }
119
Dees_Troy201d76b2012-11-16 17:12:02 +0000120 if (multi_user) {
121 DIR *d = opendir("/data/user");
122 string new_path, user_id;
123
124 if (d == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000125 LOGERR("Error opening '/data/user'\n");
Dees_Troy201d76b2012-11-16 17:12:02 +0000126 return -1;
127 }
128
129 if (d) {
130 struct dirent *p;
131 while ((p = readdir(d))) {
132 if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
133 continue;
134
135 new_path = "/data/user/";
136 new_path.append(p->d_name);
137 user_id = "u";
138 user_id += p->d_name;
139 user_id += "_";
140 if (p->d_type == DT_LNK) {
141 char link[512], realPath[512];
142 strcpy(link, new_path.c_str());
143 memset(realPath, 0, sizeof(realPath));
144 while (readlink(link, realPath, sizeof(realPath)) > 0) {
145 strcpy(link, realPath);
146 memset(realPath, 0, sizeof(realPath));
147 }
148 new_path = link;
149 } else if (p->d_type != DT_DIR) {
150 continue;
151 } else {
152 new_path.append("/");
153 // We're probably going to need to fix permissions on multi user but
154 // it will have to wait for another time. Need to figure out where
155 // the uid and gid is stored for other users.
156 continue;
157 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000158 gui_print("Fixing %s permissions...\n", new_path.c_str());
Dees_Troy201d76b2012-11-16 17:12:02 +0000159 if ((fixDataData(new_path)) != 0) {
160 closedir(d);
161 return -1;
162 }
163 }
164 closedir(d);
165 }
166 } else {
grimsrudcbec59f2013-07-29 15:46:22 +0200167 gui_print("Fixing /data/data permissions...\n");
Dees_Troy201d76b2012-11-16 17:12:02 +0000168 if ((fixDataData("/data/data/")) != 0) {
169 return -1;
170 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400171 }
bigbiff bigbiff872a3b92013-10-18 20:50:25 -0400172 #ifdef HAVE_SELINUX
173 gui_print("Fixing /data/data contexts.\n");
174 fixDataDataContexts();
175 #endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000176 gui_print("Done fixing permissions.\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400177 return 0;
178}
179
180int fixPermissions::pchown(string fn, int puid, int pgid) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000181 LOGINFO("Fixing %s, uid: %d, gid: %d\n", fn.c_str(), puid, pgid);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400182 if (chown(fn.c_str(), puid, pgid) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000183 LOGERR("Unable to chown '%s' %i %i\n", fn.c_str(), puid, pgid);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400184 return -1;
185 }
186 return 0;
187}
188
189int fixPermissions::pchmod(string fn, string mode) {
190 long mask = 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000191 LOGINFO("Fixing %s, mode: %s\n", fn.c_str(), mode.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400192 for ( std::string::size_type n = 0; n < mode.length(); ++n) {
193 if (n == 0) {
194 if (mode[n] == '0')
195 continue;
196 else if (mode[n] == '1')
197 mask = S_ISVTX;
198 else if (mode[n] == '2')
199 mask = S_ISGID;
200 }
201 else if (n == 1) {
202 if (mode[n] == '7') {
203 mask |= S_IRWXU;
204 }
205 if (mode[n] == '6') {
206 mask |= S_IRUSR;
207 mask |= S_IWUSR;
208 }
209 if (mode[n] == '5') {
210 mask |= S_IRUSR;
211 mask |= S_IXUSR;
212 }
213 if (mode[n] == '4')
214 mask |= S_IRUSR;
215 if (mode[n] == '3') {
216 mask |= S_IWUSR;
217 mask |= S_IRUSR;
218 }
219 if (mode[n] == '2')
220 mask |= S_IWUSR;
221 if (mode[n] == '1')
222 mask |= S_IXUSR;
223 }
224 else if (n == 2) {
225 if (mode[n] == '7') {
226 mask |= S_IRWXG;
227 }
228 if (mode[n] == '6') {
229 mask |= S_IRGRP;
230 mask |= S_IWGRP;
231 }
232 if (mode[n] == '5') {
233 mask |= S_IRGRP;
234 mask |= S_IXGRP;
235 }
236 if (mode[n] == '4')
237 mask |= S_IRGRP;
238 if (mode[n] == '3') {
239 mask |= S_IWGRP;
240 mask |= S_IXGRP;
241 }
242 if (mode[n] == '2')
243 mask |= S_IWGRP;
244 if (mode[n] == '1')
245 mask |= S_IXGRP;
246 }
247 else if (n == 3) {
248 if (mode[n] == '7') {
249 mask |= S_IRWXO;
250 }
251 if (mode[n] == '6') {
252 mask |= S_IROTH;
253 mask |= S_IWOTH;
254 }
255 if (mode[n] == '5') {
256 mask |= S_IROTH;
257 mask |= S_IXOTH;
258 }
259 if (mode[n] == '4')
260 mask |= S_IROTH;
261 if (mode[n] == '3') {
262 mask |= S_IWOTH;
263 mask |= S_IXOTH;
264 }
265 if (mode[n] == '2')
Dees_Troy6480ce02012-10-10 10:26:54 -0400266 mask |= S_IWOTH;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400267 if (mode[n] == '1')
Dees_Troy6480ce02012-10-10 10:26:54 -0400268 mask |= S_IXOTH;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400269 }
270 }
271
272 if (chmod(fn.c_str(), mask) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000273 LOGERR("Unable to chmod '%s' %l\n", fn.c_str(), mask);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400274 return -1;
275 }
276
277 return 0;
278}
279
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400280int fixPermissions::fixSystemApps() {
281 temp = head;
282 while (temp != NULL) {
283 if (TWFunc::Path_Exists(temp->codePath)) {
284 if (temp->appDir.compare("/system/app") == 0) {
bigbiff bigbiff872a3b92013-10-18 20:50:25 -0400285 if (debug) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000286 LOGINFO("Looking at '%s'\n", temp->codePath.c_str());
287 LOGINFO("Fixing permissions on '%s'\n", temp->pkgName.c_str());
288 LOGINFO("Directory: '%s'\n", temp->appDir.c_str());
289 LOGINFO("Original package owner: %d, group: %d\n", temp->uid, temp->gid);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400290 }
291 if (pchown(temp->codePath, 0, 0) != 0)
292 return -1;
293 if (pchmod(temp->codePath, "0644") != 0)
294 return -1;
295 }
296 } else {
297 //Remove data directory since app isn't installed
298 if (remove_data && TWFunc::Path_Exists(temp->dDir) && temp->appDir.size() >= 9 && temp->appDir.substr(0, 9) != "/mnt/asec") {
299 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000300 LOGINFO("Looking at '%s', removing data dir: '%s', appDir: '%s'", temp->codePath.c_str(), temp->dDir.c_str(), temp->appDir.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500301 if (TWFunc::removeDir(temp->dDir, false) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000302 LOGINFO("Unable to removeDir '%s'\n", temp->dDir.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400303 return -1;
304 }
305 }
306 }
307 temp = temp->next;
308 }
309 return 0;
310}
311
312int fixPermissions::fixDataApps() {
313 bool fix = false;
314 int new_gid = 0;
315 string perms = "0000";
316
317 temp = head;
318 while (temp != NULL) {
319 if (TWFunc::Path_Exists(temp->codePath)) {
320 if (temp->appDir.compare("/data/app") == 0 || temp->appDir.compare("/sd-ext/app") == 0) {
321 fix = true;
322 new_gid = 1000;
323 perms = "0644";
324 } else if (temp->appDir.compare("/data/app-private") == 0 || temp->appDir.compare("/sd-ext/app-private") == 0) {
325 fix = true;
326 new_gid = temp->gid;
327 perms = "0640";
328 } else
329 fix = false;
330 if (fix) {
331 if (debug) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000332 LOGINFO("Looking at '%s'\n", temp->codePath.c_str());
333 LOGINFO("Fixing permissions on '%s'\n", temp->pkgName.c_str());
334 LOGINFO("Directory: '%s'\n", temp->appDir.c_str());
335 LOGINFO("Original package owner: %d, group: %d\n", temp->uid, temp->gid);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400336 }
337 if (pchown(temp->codePath, 1000, new_gid) != 0)
338 return -1;
339 if (pchmod(temp->codePath, perms) != 0)
340 return -1;
341 }
342 } else {
343 //Remove data directory since app isn't installed
344 if (remove_data && TWFunc::Path_Exists(temp->dDir) && temp->appDir.size() >= 9 && temp->appDir.substr(0, 9) != "/mnt/asec") {
345 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000346 LOGINFO("Looking at '%s', removing data dir: '%s', appDir: '%s'", temp->codePath.c_str(), temp->dDir.c_str(), temp->appDir.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500347 if (TWFunc::removeDir(temp->dDir, false) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000348 LOGINFO("Unable to removeDir '%s'\n", temp->dDir.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400349 return -1;
350 }
351 }
352 }
353 temp = temp->next;
354 }
355 return 0;
356}
357
358int fixPermissions::fixAllFiles(string directory, int gid, int uid, string file_perms) {
359 vector <string> files;
360 string file;
361
362 files = listAllFiles(directory);
363 for (unsigned i = 0; i < files.size(); ++i) {
364 file = directory + "/";
365 file.append(files.at(i));
366 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000367 LOGINFO("Looking at file '%s'\n", file.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400368 if (pchmod(file, file_perms) != 0)
369 return -1;
370 if (pchown(file, uid, gid) != 0)
371 return -1;
372 }
373 return 0;
374}
375
Dees_Troy201d76b2012-11-16 17:12:02 +0000376int fixPermissions::fixDataData(string dataDir) {
377 string directory, dir;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400378
379 temp = head;
380 while (temp != NULL) {
Dees_Troy201d76b2012-11-16 17:12:02 +0000381 dir = dataDir + temp->dDir;
382 if (TWFunc::Path_Exists(dir)) {
383 vector <string> dataDataDirs = listAllDirectories(dir);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400384 for (unsigned n = 0; n < dataDataDirs.size(); ++n) {
Dees_Troy201d76b2012-11-16 17:12:02 +0000385 directory = dir + "/";
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400386 directory.append(dataDataDirs.at(n));
387 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000388 LOGINFO("Looking at data directory: '%s'\n", directory.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400389 if (dataDataDirs.at(n) == ".") {
Dees_Troy201d76b2012-11-16 17:12:02 +0000390 if (pchmod(directory, "0755") != 0)
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400391 return -1;
392 if (pchown(directory.c_str(), temp->uid, temp->gid) != 0)
393 return -1;
394 if (fixAllFiles(directory, temp->uid, temp->gid, "0755") != 0)
395 return -1;
396 }
397 else if (dataDataDirs.at(n) == "..") {
398 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000399 LOGINFO("Skipping ..\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400400 continue;
401 }
402 else if (dataDataDirs.at(n) == "lib") {
403 if (pchmod(directory.c_str(), "0755") != 0)
404 return -1;
405 if (pchown(directory.c_str(), 1000, 1000) != 0)
406 return -1;
407 if (fixAllFiles(directory, temp->uid, temp->gid, "0755") != 0)
408 return -1;
409 }
410 else if (dataDataDirs.at(n) == "shared_prefs") {
411 if (pchmod(directory.c_str(), "0771") != 0)
412 return -1;
413 if (pchown(directory.c_str(), temp->uid, temp->gid) != 0)
414 return -1;
415 if (fixAllFiles(directory, temp->uid, temp->gid, "0660") != 0)
416 return -1;
417 }
418 else if (dataDataDirs.at(n) == "databases") {
419 if (pchmod(directory.c_str(), "0771") != 0)
420 return -1;
421 if (pchown(directory.c_str(), temp->uid, temp->gid) != 0)
422 return -1;
423 if (fixAllFiles(directory, temp->uid, temp->gid, "0660") != 0)
424 return -1;
425 }
426 else if (dataDataDirs.at(n) == "cache") {
427 if (pchmod(directory.c_str(), "0771") != 0)
428 return -1;
429 if (pchown(directory.c_str(), temp->uid, temp->gid) != 0)
430 return -1;
431 if (fixAllFiles(directory, temp->uid, temp->gid, "0600") != 0)
432 return -1;
433 }
434 else {
435 if (pchmod(directory.c_str(), "0771") != 0)
436 return -1;
437 if (pchown(directory.c_str(), temp->uid, temp->gid) != 0)
438 return -1;
439 if (fixAllFiles(directory, temp->uid, temp->gid, "0755") != 0)
440 return -1;
441 }
442 }
443 }
444 temp = temp->next;
445 }
446 return 0;
447}
448
449vector <string> fixPermissions::listAllDirectories(string path) {
450 DIR *dir = opendir(path.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400451 vector <string> dirs;
452
453 if (dir == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000454 LOGERR("Error opening '%s'\n", path.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400455 return dirs;
456 }
Dees_Troy201d76b2012-11-16 17:12:02 +0000457 struct dirent *entry = readdir(dir);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400458 while (entry != NULL) {
459 if (entry->d_type == DT_DIR)
460 dirs.push_back(entry->d_name);
461 entry = readdir(dir);
462 }
463 closedir(dir);
464 return dirs;
465}
466
467vector <string> fixPermissions::listAllFiles(string path) {
468 DIR *dir = opendir(path.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400469 vector <string> files;
470
471 if (dir == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000472 LOGERR("Error opening '%s'\n", path.c_str());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400473 return files;
474 }
Dees_Troy201d76b2012-11-16 17:12:02 +0000475 struct dirent *entry = readdir(dir);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400476 while (entry != NULL) {
477 if (entry->d_type == DT_REG)
478 files.push_back(entry->d_name);
479 entry = readdir(dir);
480 }
481 closedir(dir);
482 return files;
483}
484
485int fixPermissions::getPackages() {
486 int len = 0;
487 bool skiploop = false;
488 vector <string> skip;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400489 string name;
490 head = NULL;
491
492 skip.push_back("/system/framework/framework-res.apk");
493 skip.push_back("/system/framework/com.htc.resources.apk");
494
495 ifstream xmlFile(packageFile.c_str());
496 xmlFile.seekg(0, ios::end);
497 len = (int) xmlFile.tellg();
498 xmlFile.seekg(0, ios::beg);
499 char xmlBuf[len + 1];
500 xmlFile.read(&xmlBuf[0], len);
501 xmlBuf[len] = '\0';
502 xml_document<> pkgDoc;
Dees_Troy34614eb2013-04-05 12:02:14 -0500503 LOGINFO("parsing package, %i...\n", len);
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400504 pkgDoc.parse<parse_full>(&xmlBuf[0]);
505
506 xml_node<> * pkgNode = pkgDoc.first_node("packages");
Dees_Troy34614eb2013-04-05 12:02:14 -0500507 if (pkgNode == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000508 LOGERR("No packages found to fix.\n");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400509 return -1;
510 }
Dees_Troy34614eb2013-04-05 12:02:14 -0500511 xml_node <> * next = pkgNode->first_node("package");
512 if (next == NULL) {
513 LOGERR("No package found to fix.\n");
514 return -1;
515 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400516
517 //Get packages
518 while (next->first_attribute("name") != NULL) {
519 package* temp = new package;
520 for (unsigned n = 0; n < skip.size(); ++n) {
521 if (skip.at(n).compare(next->first_attribute("codePath")->value()) == 0) {
522 skiploop = true;
523 break;
524 }
525 }
526
527 if (skiploop == true) {
528 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000529 LOGINFO("Skipping package %s\n", next->first_attribute("codePath")->value());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400530 free(temp);
531 next = next->next_sibling();
532 skiploop = false;
533 continue;
534 }
535 name.append((next->first_attribute("name")->value()));
536 temp->pkgName = next->first_attribute("name")->value();
537 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000538 LOGINFO("Loading pkg: %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000539 if (next->first_attribute("codePath") == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000540 LOGINFO("Problem with codePath on %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000541 } else {
542 temp->codePath = next->first_attribute("codePath")->value();
543 temp->app = basename(next->first_attribute("codePath")->value());
544 temp->appDir = dirname(next->first_attribute("codePath")->value());
545 }
546 temp->dDir = name;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400547 if ( next->first_attribute("sharedUserId") != NULL) {
548 temp->uid = atoi(next->first_attribute("sharedUserId")->value());
549 temp->gid = atoi(next->first_attribute("sharedUserId")->value());
550 }
551 else {
Dees_Troy201d76b2012-11-16 17:12:02 +0000552 if (next->first_attribute("userId") == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000553 LOGINFO("Problem with userID on %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000554 } else {
555 temp->uid = atoi(next->first_attribute("userId")->value());
556 temp->gid = atoi(next->first_attribute("userId")->value());
557 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400558 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400559 temp->next = head;
560 head = temp;
Dees_Troy201d76b2012-11-16 17:12:02 +0000561 if (next->next_sibling("package") == NULL)
562 break;
563 name.clear();
564 next = next->next_sibling("package");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400565 }
566 //Get updated packages
567 next = pkgNode->first_node("updated-package");
568 if (next != NULL) {
569 while (next->first_attribute("name") != NULL) {
570 package* temp = new package;
571 for (unsigned n = 0; n < skip.size(); ++n) {
572 if (skip.at(n).compare(next->first_attribute("codePath")->value()) == 0) {
573 skiploop = true;
574 break;
575 }
576 }
577
578 if (skiploop == true) {
579 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000580 LOGINFO("Skipping package %s\n", next->first_attribute("codePath")->value());
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400581 free(temp);
582 next = next->next_sibling();
583 skiploop = false;
584 continue;
585 }
586 name.append((next->first_attribute("name")->value()));
587 temp->pkgName = next->first_attribute("name")->value();
588 if (debug)
Dees_Troy2673cec2013-04-02 20:22:16 +0000589 LOGINFO("Loading pkg: %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000590 if (next->first_attribute("codePath") == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000591 LOGINFO("Problem with codePath on %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000592 } else {
593 temp->codePath = next->first_attribute("codePath")->value();
594 temp->app = basename(next->first_attribute("codePath")->value());
595 temp->appDir = dirname(next->first_attribute("codePath")->value());
596 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400597
Dees_Troy201d76b2012-11-16 17:12:02 +0000598 temp->dDir = name;
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400599 if ( next->first_attribute("sharedUserId") != NULL) {
600 temp->uid = atoi(next->first_attribute("sharedUserId")->value());
601 temp->gid = atoi(next->first_attribute("sharedUserId")->value());
602 }
603 else {
Dees_Troy201d76b2012-11-16 17:12:02 +0000604 if (next->first_attribute("userId") == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000605 LOGINFO("Problem with userID on %s\n", next->first_attribute("name")->value());
Dees_Troy201d76b2012-11-16 17:12:02 +0000606 } else {
607 temp->uid = atoi(next->first_attribute("userId")->value());
608 temp->gid = atoi(next->first_attribute("userId")->value());
609 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400610 }
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400611 temp->next = head;
612 head = temp;
Dees_Troy201d76b2012-11-16 17:12:02 +0000613 if (next->next_sibling("package") == NULL)
614 break;
615 name.clear();
616 next = next->next_sibling("package");
bigbiff bigbiffa0f8a592012-10-09 21:01:03 -0400617 }
618 }
619 return 0;
620}