diff options
author | Kenny Root <kroot@google.com> | 2012-08-20 11:32:51 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-08-20 11:32:51 -0700 |
commit | 878c359db8ecac6390592f7f3de19c77f28113a2 (patch) | |
tree | 992188c476db298f4b79beec361650217d5b4941 | |
parent | e7f9da44646b8eb66ef2e7b163176b5272216e86 (diff) | |
parent | 344e0bc23ca46b9acec97ac8bcd87949bde0ccab (diff) | |
download | security-878c359db8ecac6390592f7f3de19c77f28113a2.tar.gz |
Merge "Add getmtime command for keys"
-rw-r--r-- | keystore/keystore.cpp | 34 | ||||
-rw-r--r-- | keystore/keystore.h | 4 |
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 }; /** |