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

Commit acd96b11 authored by Nick Kralevich's avatar Nick Kralevich Committed by Android Git Automerger
Browse files

am 12db3eb6: Merge "Move restorecon and restorecon_recursive code to libselinux."

* commit '12db3eb6':
  Move restorecon and restorecon_recursive code to libselinux.
parents 9aaba5ca 12db3eb6
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -867,6 +867,7 @@ struct selabel_handle* selinux_android_prop_context_handle(void)
void selinux_init_all_handles(void)
void selinux_init_all_handles(void)
{
{
    sehandle = selinux_android_file_context_handle();
    sehandle = selinux_android_file_context_handle();
    selinux_android_set_sehandle(sehandle);
    sehandle_prop = selinux_android_prop_context_handle();
    sehandle_prop = selinux_android_prop_context_handle();
}
}


+4 −51
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <ftw.h>
#include <ftw.h>


#include <selinux/label.h>
#include <selinux/label.h>
#include <selinux/android.h>


#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
@@ -524,60 +525,12 @@ int make_dir(const char *path, mode_t mode)
    return rc;
    return rc;
}
}


static int restorecon_sb(const char *pathname, const struct stat *sb)
{
    char *secontext = NULL;
    char *oldsecontext = NULL;
    int i;

    if (selabel_lookup(sehandle, &secontext, pathname, sb->st_mode) < 0)
        return -errno;

    if (lgetfilecon(pathname, &oldsecontext) < 0) {
        freecon(secontext);
        return -errno;
    }

    if (strcmp(oldsecontext, secontext) != 0) {
        if (lsetfilecon(pathname, secontext) < 0) {
            freecon(oldsecontext);
            freecon(secontext);
            return -errno;
        }
    }
    freecon(oldsecontext);
    freecon(secontext);
    return 0;
}

int restorecon(const char* pathname)
int restorecon(const char* pathname)
{
{
    struct stat sb;
    return selinux_android_restorecon(pathname);

    if (is_selinux_enabled() <= 0 || !sehandle)
        return 0;

    if (lstat(pathname, &sb) < 0)
        return -errno;

    return restorecon_sb(pathname, &sb);
}

static int nftw_restorecon(const char* filename, const struct stat* statptr,
    int fileflags __attribute__((unused)),
    struct FTW* pftw __attribute__((unused)))
{
    restorecon_sb(filename, statptr);
    return 0;
}
}


int restorecon_recursive(const char* pathname)
int restorecon_recursive(const char* pathname)
{
{
    int fd_limit = 20;
    return selinux_android_restorecon_recursive(pathname);
    int flags = FTW_DEPTH | FTW_MOUNT | FTW_PHYS;

    if (is_selinux_enabled() <= 0 || !sehandle)
        return 0;

    return nftw(pathname, nftw_restorecon, fd_limit, flags);
}
}