Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 679e2100 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Steve Kondik
Browse files

toolbox: Add levelFromUid categorization support to restorecon

This is necessary for the app data relabeling on migrated devices
to include the proper app context. Freshly installed apps get this
done automagically, as do newly created files.

Change-Id: If7421dac01c6ae8bd78e66f71e69298ed850a7ab
parent 63749649
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#include <selinux/selinux.h>
#include <selinux/label.h>
#include <selinux/android.h>
#include <private/android_filesystem_config.h>

static struct selabel_handle *sehandle;
static const char *progname;
@@ -34,6 +35,16 @@ static int restore(const char *pathname, const struct stat *sb)
                strerror(errno));
        return -1;
    }
    if (sb->st_uid >= AID_APP && strcmp(newcontext,",c") && strcmp(newcontext,"app_data_file") >= 0) {
        char *catcontext;
        uid_t appid = sb->st_uid - AID_APP;

        catcontext = malloc(strlen(newcontext)+16);
        sprintf(catcontext,"%s:c%d,c%d",newcontext,appid & 0xff,
                                         256 + (appid>>8 & 0xff));
        freecon(newcontext);
        newcontext = catcontext;
    }
    if (strcmp(newcontext, "<<none>>") &&
        strcmp(oldcontext, newcontext)) {
        if (verbose)