diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-08-24 20:43:13 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-08-24 20:43:13 +0200 |
commit | 51a92d357aebc84b45cf8c90061319d22b170bb5 (patch) | |
tree | ef86e6681d7ecded3d543f0238a30dcadb4730c2 /examples | |
parent | 5c340eee0020717c793fd9d7e74e5f065225a8f3 (diff) | |
download | cryptodev-linux-51a92d357aebc84b45cf8c90061319d22b170bb5.tar.gz cryptodev-linux-51a92d357aebc84b45cf8c90061319d22b170bb5.tar.xz cryptodev-linux-51a92d357aebc84b45cf8c90061319d22b170bb5.zip |
Reject prohibited key flags immediately
Silently ignoring user's requests is unexpected.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ncr.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/examples/ncr.c b/examples/ncr.c index 5169a14..7de67ee 100644 --- a/examples/ncr.c +++ b/examples/ncr.c @@ -240,12 +240,18 @@ test_ncr_wrap_key(int cfd) keydata.idata = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; keydata.idata_size = 16; - if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) { + ret = ioctl(cfd, NCRIO_KEY_IMPORT, &keydata); + if (geteuid() == 0 && ret) { fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__); perror("ioctl(NCRIO_KEY_IMPORT)"); return 1; } + if (geteuid() != 0) { + /* cannot test further */ + fprintf(stdout, "\t(Wrapping test not completed. Run as root)\n"); + return 0; + } /* convert it to key */ if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) { @@ -279,19 +285,11 @@ test_ncr_wrap_key(int cfd) kwrap.io = data; kwrap.io_size = sizeof(data); - ret = ioctl(cfd, NCRIO_KEY_WRAP, &kwrap); - - if (geteuid() == 0 && ret) { + if (ioctl(cfd, NCRIO_KEY_WRAP, &kwrap)) { fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__); perror("ioctl(NCRIO_KEY_WRAP)"); return 1; } - - if (geteuid() != 0) { - /* cannot test further */ - fprintf(stdout, "\t(Wrapping test not completed. Run as root)\n"); - return 0; - } data_size = kwrap.io_size; |