list file measurement hashes
[strongswan.git] / src / libimcv / plugins / imv_attestation / attest.c
index 6b45daf..81807b2 100644 (file)
@@ -48,7 +48,9 @@ static void do_args(int argc, char *argv[])
                OP_FILES,
                OP_PRODUCTS,
                OP_HASHES,
                OP_FILES,
                OP_PRODUCTS,
                OP_HASHES,
-       } operation = OP_UNDEF;
+               OP_ADD,
+               OP_DEL,
+       } op = OP_UNDEF;
 
        /* reinit getopt state */
        optind = 0;
 
        /* reinit getopt state */
        optind = 0;
@@ -62,7 +64,11 @@ static void do_args(int argc, char *argv[])
                        { "files", no_argument, NULL, 'f' },
                        { "products", no_argument, NULL, 'p' },
                        { "hashes", no_argument, NULL, 'H' },
                        { "files", no_argument, NULL, 'f' },
                        { "products", no_argument, NULL, 'p' },
                        { "hashes", no_argument, NULL, 'H' },
+                       { "add", no_argument, NULL, 'a' },
+                       { "delete", no_argument, NULL, 'd' },
+                       { "del", no_argument, NULL, 'd' },
                        { "directory", required_argument, NULL, 'D' },
                        { "directory", required_argument, NULL, 'D' },
+                       { "dir", required_argument, NULL, 'D' },
                        { "file", required_argument, NULL, 'F' },
                        { "product", required_argument, NULL, 'P' },
                        { "sha1", no_argument, NULL, '1' },
                        { "file", required_argument, NULL, 'F' },
                        { "product", required_argument, NULL, 'P' },
                        { "sha1", no_argument, NULL, '1' },
@@ -80,31 +86,40 @@ static void do_args(int argc, char *argv[])
                        case EOF:
                                break;
                        case 'h':
                        case EOF:
                                break;
                        case 'h':
-                               operation = OP_USAGE;
+                               op = OP_USAGE;
                                break;
                        case 'f':
                                break;
                        case 'f':
-                               operation = OP_FILES;
+                               op = OP_FILES;
                                continue;
                        case 'p':
                                continue;
                        case 'p':
-                               operation = OP_PRODUCTS;
+                               op = OP_PRODUCTS;
                                continue;
                        case 'H':
                                continue;
                        case 'H':
-                               operation = OP_HASHES;
+                               op = OP_HASHES;
+                               continue;
+                       case 'a':
+                               op = OP_ADD;
+                               continue;
+                       case 'd':
+                               op = OP_DEL;
                                continue;
                        case 'D':
                                continue;
                        case 'D':
-                               if (!attest->set_directory(attest, optarg))
+                               if (!attest->set_directory(attest, optarg, op == OP_ADD))
                                {
                                        exit(EXIT_FAILURE);
                                }
                                continue;
                                {
                                        exit(EXIT_FAILURE);
                                }
                                continue;
+                       case 'H':
+                               operation = OP_HASHES;
+                               continue;
                        case 'F':
                        case 'F':
-                               if (!attest->set_file(attest, optarg))
+                               if (!attest->set_file(attest, optarg, op == OP_ADD))
                                {
                                        exit(EXIT_FAILURE);
                                }
                                continue;
                        case 'P':
                                {
                                        exit(EXIT_FAILURE);
                                }
                                continue;
                        case 'P':
-                               if (!attest->set_product(attest, optarg))
+                               if (!attest->set_product(attest, optarg, op == OP_ADD))
                                {
                                        exit(EXIT_FAILURE);
                                }
                                {
                                        exit(EXIT_FAILURE);
                                }
@@ -140,7 +155,7 @@ static void do_args(int argc, char *argv[])
                break;
        }
 
                break;
        }
 
-       switch (operation)
+       switch (op)
        {
                case OP_USAGE:
                        usage();
        {
                case OP_USAGE:
                        usage();
@@ -154,10 +169,36 @@ static void do_args(int argc, char *argv[])
                case OP_HASHES:
                        attest->list_hashes(attest);
                        break;
                case OP_HASHES:
                        attest->list_hashes(attest);
                        break;
+               case OP_ADD:
+                       attest->add(attest);
+                       break;
+               case OP_DEL:
+                       attest->delete(attest);
+                       break;
+               case OP_HASHES:
+                       if ((!product || *product == '\0') && (!file || *file == '\0'))
+                       {
+                               list_hashes(algo);
+                       }
+                       else
+                       {
+                               list_hashes_for_product(algo, product, pid);
+                       }
+                       break;
                default:
                        usage();
                        exit(EXIT_FAILURE);
        }
                default:
                        usage();
                        exit(EXIT_FAILURE);
        }
+
+       if (fid)
+       {
+               free(file);
+       }
+       if (pid)
+       {
+               free(product);
+       }
+
 }
 
 int main(int argc, char *argv[])
 }
 
 int main(int argc, char *argv[])