Backward compatibility for licenses and certificates

Certificates and offline licenses are stored in security level
specific directories in klp. When devices transition from jb-mr2,
their persistent information has to be ported to these directories.

bug:10366036

Merge of https://widevine-internal-review.googlesource.com/#/c/7310/
from the widevine CDM repo

Change-Id: I70b4a79dc5b69bda7fc3a4b92fdcde7ef8b41836
This commit is contained in:
Jeff Tinker
2013-08-22 09:37:18 -07:00
parent 2fa6b63292
commit db41502f86
10 changed files with 455 additions and 12 deletions

View File

@@ -6,8 +6,10 @@
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
@@ -175,18 +177,80 @@ bool File::Remove(const std::string& path) {
}
}
bool File::Copy(const std::string& src, const std::string& dest) {
struct stat stat_buf;
if (stat(src.c_str(), &stat_buf)) {
LOGV("File::Copy: file %s does not exist: %d", src.c_str(), errno);
return false;
}
int fd_src = open(src.c_str(), O_RDONLY);
if (fd_src < 0) {
LOGV("File::Copy: unable to open file %s: %d", src.c_str(), errno);
return false;
}
int fd_dest = open(dest.c_str(), O_WRONLY|O_CREAT, stat_buf.st_mode);
if (fd_dest < 0) {
LOGV("File::Copy: unable to open file %s: %d", dest.c_str(), errno);
close(fd_src);
return false;
}
off_t offset = 0;
bool sts = true;
if (sendfile(fd_dest, fd_src, &offset, stat_buf.st_size) < 0) {
LOGV("File::Copy: unable to copy %s to %s: %d", src.c_str(), dest.c_str(),
errno);
sts = false;
}
close(fd_src);
close(fd_dest);
return sts;
}
bool File::List(const std::string& path, std::vector<std::string>* files) {
if (NULL == files) {
LOGV("File::List: files destination not provided");
return false;
}
if (!Exists(path)) {
LOGV("File::List: path %s does not exist: %d", path.c_str(), errno);
return false;
}
DIR* dir;
if ((dir = opendir(path.c_str())) == NULL) {
LOGW("File::List: unable to open directory %s: %d", path.c_str(), errno);
return false;
}
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, kCurrentDirectory) &&
(strcmp(entry->d_name, kParentDirectory))) {
files->push_back(entry->d_name);
}
}
closedir(dir);
return true;
}
bool File::CreateDirectory(std::string path) {
size_t size = path.size();
if ((size == 1) && (path[0] == '/')) return true;
if ((size == 1) && (path[0] == kPathDelimiter[0])) return true;
if (size <= 1) return false;
if (path.at(size - 1) == '/') {
if (path.at(size - 1) == kPathDelimiter[0]) {
--size;
path.resize(size);
}
size_t pos = path.find('/', 1);
size_t pos = path.find(kPathDelimiter[0], 1);
while (pos < size) {
path.at(pos) = '\0';
if (mkdir(path.c_str(), 0775) != 0) {
@@ -195,8 +259,8 @@ bool File::CreateDirectory(std::string path) {
return false;
}
}
path.at(pos) = '/';
pos = path.find('/', pos + 1);
path.at(pos) = kPathDelimiter[0];
pos = path.find(kPathDelimiter[0], pos + 1);
}
if (mkdir(path.c_str(), 0775) != 0) {
if (errno != EEXIST) {