summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2012-08-20 11:49:35 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-08-20 11:49:35 -0700
commitcd8df62842b81c93022feabfacda8efd257e1754 (patch)
tree992188c476db298f4b79beec361650217d5b4941
parentd3c598c12c1317f592b8da19e00c8122dba6b0c1 (diff)
parent878c359db8ecac6390592f7f3de19c77f28113a2 (diff)
downloadsecurity-cd8df62842b81c93022feabfacda8efd257e1754.tar.gz
* commit '878c359db8ecac6390592f7f3de19c77f28113a2': Add getmtime command for keys
-rw-r--r--keystore/keystore.cpp34
-rw-r--r--keystore/keystore.h4
2 files changed, 37 insertions, 1 deletions
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index d90b9991..ef4c7d4a 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -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}},
};
diff --git a/keystore/keystore.h b/keystore/keystore.h
index fe2ce562..f5e44390 100644
--- a/keystore/keystore.h
+++ b/keystore/keystore.h
@@ -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
};
/**