Commit 878c359d authored by Kenny Root's avatar Kenny Root Committed by android code review
Browse files

Merge "Add getmtime command for keys"

parents e7f9da44 344e0bc2
......@@ -1273,6 +1273,39 @@ static ResponseCode ungrant(KeyStore* keyStore, int, uid_t uid, Value* keyName,
return keyStore->removeGrant(filename, granteeData) ? NO_ERROR : KEY_NOT_FOUND;
}
static ResponseCode getmtime(KeyStore*, int sock, uid_t uid, Value* keyName,
Value*, Value*) {
char filename[NAME_MAX];
encode_key_for_uid(filename, uid, keyName);
if (access(filename, R_OK) == -1) {
return (errno != ENOENT) ? SYSTEM_ERROR : KEY_NOT_FOUND;
}
int fd = open(filename, O_NOFOLLOW, O_RDONLY);
if (fd < 0) {
return SYSTEM_ERROR;
}
struct stat s;
int ret = fstat(fd, &s);
close(fd);
if (ret == -1) {
return SYSTEM_ERROR;
}
uint8_t *data;
int dataLength = asprintf(reinterpret_cast<char**>(&data), "%lu", s.st_mtime);
if (dataLength < 0) {
return SYSTEM_ERROR;
}
send_code(sock, NO_ERROR);
send_message(sock, data, dataLength);
free(data);
return NO_ERROR_RESPONSE_CODE_SENT;
}
/* Here are the permissions, actions, users, and the main function. */
enum perm {
P_TEST = 1 << TEST,
......@@ -1322,6 +1355,7 @@ static struct action {
{del_key, CommandCodes[DEL_KEY], STATE_ANY, P_DELETE, {KEY_SIZE, 0, 0}},
{grant, CommandCodes[GRANT], STATE_NO_ERROR, P_GRANT, {KEY_SIZE, KEY_SIZE, 0}},
{ungrant, CommandCodes[UNGRANT], STATE_NO_ERROR, P_GRANT, {KEY_SIZE, KEY_SIZE, 0}},
{getmtime, CommandCodes[GETMTIME], STATE_ANY, P_SAW, {KEY_SIZE, 0, 0}},
{NULL, 0, STATE_ANY, 0, {0, 0, 0}},
};
......
......@@ -63,12 +63,13 @@ enum CommandNames {
DEL_KEY = 16,
GRANT = 17,
UNGRANT = 18,
GETMTIME = 19,
};
typedef uint8_t command_code_t;
// Taken: a b c d e f g h i j k l m n o p q r s t u v w x y z
// * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * *
command_code_t CommandCodes[] = {
't', // TEST
'g', // GET
......@@ -89,6 +90,7 @@ command_code_t CommandCodes[] = {
'k', // DEL_KEY
'x', // GRANT
'y', // UNGRANT
'c', // GETMTIME
};
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment