Remove Stale Licenses on Reprovisioning

Merges change 267713c (Remove stale licenses on reprovisioning) from
the Widevine CDM repository.  This change removes licenses belonging
to the previous provisioning when provisioning changes.

Bug: 9761923
Change-Id: I473816dd11dd950f4fb009b5b004630bd2d2b579
This commit is contained in:
John "Juce" Bruce
2013-08-08 14:57:40 -07:00
parent ba66224ef4
commit 0fa3e16999
13 changed files with 250 additions and 104 deletions

View File

@@ -14,9 +14,11 @@
#include "log.h"
namespace {
const char* kCurrentDirectory = ".";
const char* kParentDirectory = "..";
} // namespace
const char kCurrentDirectory[] = ".";
const char kParentDirectory[] = "..";
const char kPathDelimiter[] = "/";
const char kWildcard[] = "*";
} // namespace
namespace wvcdm {
@@ -49,9 +51,9 @@ bool File::Open(const std::string& name, int flags) {
}
if (flags & File::kBinary) {
open_flags = (flags & File::kReadOnly)? "rb" : "rb+";
open_flags = (flags & File::kReadOnly) ? "rb" : "rb+";
} else {
open_flags = (flags & File::kReadOnly)? "r" : "r+";
open_flags = (flags & File::kReadOnly) ? "r" : "r+";
}
impl_->file_ = fopen(name.c_str(), open_flags.c_str());
@@ -104,14 +106,15 @@ bool File::Exists(const std::string& path) {
bool File::Remove(const std::string& path) {
if (IsDirectory(path)) {
// Handle directory deletion
DIR* dir;
if ((dir = opendir(path.c_str())) != NULL) {
// first remove files and dir within it
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, kCurrentDirectory) &&
(strcmp(entry->d_name, kParentDirectory))) {
std::string path_to_remove = path + '/';
(strcmp(entry->d_name, kParentDirectory))) {
std::string path_to_remove = path + kPathDelimiter;
path_to_remove += entry->d_name;
if (!Remove(path_to_remove)) {
closedir(dir);
@@ -127,9 +130,46 @@ bool File::Remove(const std::string& path) {
}
return true;
} else {
if (unlink(path.c_str()) && (errno != ENOENT)) {
LOGW("File::Remove: unlink failed: %d", errno);
return false;
size_t wildcard_pos = path.find(kWildcard);
if (wildcard_pos == std::string::npos) {
// Handle file deletion
if (unlink(path.c_str()) && (errno != ENOENT)) {
LOGW("File::Remove: unlink failed: %d", errno);
return false;
}
} else {
// Handle wildcard specified file deletion
size_t delimiter_pos = path.rfind(kPathDelimiter, wildcard_pos);
if (delimiter_pos == std::string::npos) {
LOGW("File::Remove: unable to find path delimiter before wildcard");
return false;
}
DIR* dir;
std::string dir_path = path.substr(0, delimiter_pos);
if ((dir = opendir(dir_path.c_str())) == NULL) {
LOGW("File::Remove: directory open failed for wildcard");
return false;
}
struct dirent* entry;
std::string ext = path.substr(wildcard_pos + 1);
while ((entry = readdir(dir)) != NULL) {
size_t filename_len = strlen(entry->d_name);
if (filename_len > ext.size()) {
if (strcmp(entry->d_name + filename_len - ext.size(), ext.c_str()) ==
0) {
std::string file_path_to_remove =
dir_path + kPathDelimiter + entry->d_name;
if (!Remove(file_path_to_remove)) {
closedir(dir);
return false;
}
}
}
}
closedir(dir);
}
return true;
}
@@ -137,13 +177,11 @@ bool File::Remove(const std::string& path) {
bool File::CreateDirectory(std::string path) {
size_t size = path.size();
if ((size == 1) && (path[0] == '/'))
return true;
if ((size == 1) && (path[0] == '/')) return true;
if (size <= 1)
return false;
if (size <= 1) return false;
if (path.at(size-1) == '/') {
if (path.at(size - 1) == '/') {
--size;
path.resize(size);
}
@@ -158,7 +196,7 @@ bool File::CreateDirectory(std::string path) {
}
}
path.at(pos) = '/';
pos = path.find('/', pos+1);
pos = path.find('/', pos + 1);
}
if (mkdir(path.c_str(), 0775) != 0) {
if (errno != EEXIST) {

View File

@@ -11,6 +11,12 @@
namespace {
const char kBasePathPrefix[] = "/data/mediadrm/IDM";
const char kL1Dir[] = "/L1";
const char kL2Dir[] = "/L2";
const char kL3Dir[] = "/L3";
const char kFactoryKeyboxPath[] = "/factory/wv.keys";
bool GetAndroidProperty(const char* key, std::string* value) {
char val[PROPERTY_VALUE_MAX];
if (!key) {
@@ -81,13 +87,24 @@ bool Properties::GetBuildInfo(std::string* build_info) {
return GetAndroidProperty("ro.build.fingerprint", build_info);
}
bool Properties::GetDeviceFilesBasePath(std::string* base_path) {
bool Properties::GetDeviceFilesBasePath(CdmSecurityLevel security_level,
std::string* base_path) {
if (!base_path) {
LOGW("Properties::GetDeviceFilesBasePath: Invalid parameter");
return false;
}
std::stringstream ss;
ss << "/data/mediadrm/IDM" << getuid() << "/";
ss << kBasePathPrefix << getuid();
switch (security_level) {
case kSecurityLevelL1: ss << kL1Dir; break;
case kSecurityLevelL2: ss << kL2Dir; break;
case kSecurityLevelL3: ss << kL3Dir; break;
default:
LOGW("Properties::GetDeviceFilesBasePath: Unknown security level: %d",
security_level);
return false;
}
*base_path = ss.str();
return true;
}
@@ -97,7 +114,7 @@ bool Properties::GetFactoryKeyboxPath(std::string* keybox) {
LOGW("Properties::GetFactoryKeyboxPath: Invalid parameter");
return false;
}
*keybox = "/factory/wv.keys";
*keybox = kFactoryKeyboxPath;
return true;
}