From patchwork Thu Jun 8 01:52:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 13271512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB6F0C7EE2F for ; Thu, 8 Jun 2023 01:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229454AbjFHBxl (ORCPT ); Wed, 7 Jun 2023 21:53:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbjFHBxk (ORCPT ); Wed, 7 Jun 2023 21:53:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15D1C2682 for ; Wed, 7 Jun 2023 18:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686189172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OFq59jc9NksBjDyJXXa0XJFnrvuOdE81wt7jWfFrVKo=; b=jB7CqYbj8r1qK/Age/cBwsprtVa0doX+GvtfRfAfysGZdb1kwGyz5Nzb2Lh2pshUx/W4zc 5EjVvcC4m1A5asBw2JBxqB1QcSNXivB9Svb/7LLRcBu3QrwpTBYmzmdLlG80H4TFOMBEnV 4XyzlNO3XSXvI4H/Sq6ejU09k5vqsUE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-499-J1P6oxFZPk-Qsdape85bdQ-1; Wed, 07 Jun 2023 21:52:50 -0400 X-MC-Unique: J1P6oxFZPk-Qsdape85bdQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CA998002BF for ; Thu, 8 Jun 2023 01:52:50 +0000 (UTC) Received: from dev64.localdomain.com (unknown [10.64.240.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4900403362; Thu, 8 Jun 2023 01:52:49 +0000 (UTC) From: Masatake YAMATO To: selinux@vger.kernel.org Cc: yamato@redhat.com Subject: [PATCH 1/4] dispol: add --help option Date: Thu, 8 Jun 2023 10:52:38 +0900 Message-Id: <20230608015241.2454912-1-yamato@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Signed-off-by: Masatake YAMATO Acked-by: James Carter --- checkpolicy/test/dispol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c index b61f1b4b..50027e40 100644 --- a/checkpolicy/test/dispol.c +++ b/checkpolicy/test/dispol.c @@ -38,7 +38,11 @@ static policydb_t policydb; static __attribute__((__noreturn__)) void usage(const char *progname) { - printf("usage: %s binary_pol_file\n\n", progname); + puts("Usage:"); + printf(" %s [OPTIONS] binary_pol_file\n\n", progname); + puts("Options:"); + puts(" -h, --help print this help message"); + puts("\n"); exit(1); } @@ -481,7 +485,7 @@ int main(int argc, char **argv) int state; struct policy_file pf; - if (argc != 2) + if (argc < 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) usage(argv[0]); fd = open(argv[1], O_RDONLY); From patchwork Thu Jun 8 01:52:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 13271511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16A3CC77B7A for ; Thu, 8 Jun 2023 01:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbjFHBxk (ORCPT ); Wed, 7 Jun 2023 21:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjFHBxj (ORCPT ); Wed, 7 Jun 2023 21:53:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 417ED2680 for ; Wed, 7 Jun 2023 18:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686189176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X/XJvCQ422I/WYtUCWDKieLvXugOS8ab+Zzy4zkAj+0=; b=DpCLd7JIKukSMKwxzI9XcVAR4+tREFcXdObaGcMbZVIBiaQAi32Zr0FQogu41p4POZoNnM QRAUv5HZknJiplx8BA6tshusi5QZ6RfeIe7op8Wt9qHEvKTn+82eJBEGSICfhlkCt6uPZ6 T64JktqyE1VdkZIuaGoRtRT9Z28bukk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-mhsWc_UjPeWmkoYtYZk3XQ-1; Wed, 07 Jun 2023 21:52:54 -0400 X-MC-Unique: mhsWc_UjPeWmkoYtYZk3XQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FCD2811E7C for ; Thu, 8 Jun 2023 01:52:54 +0000 (UTC) Received: from dev64.localdomain.com (unknown [10.64.240.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC5A9477F61; Thu, 8 Jun 2023 01:52:53 +0000 (UTC) From: Masatake YAMATO To: selinux@vger.kernel.org Cc: yamato@redhat.com Subject: [PATCH 2/4] dispol: delete an unnecessary empty line Date: Thu, 8 Jun 2023 10:52:39 +0900 Message-Id: <20230608015241.2454912-2-yamato@redhat.com> In-Reply-To: <20230608015241.2454912-1-yamato@redhat.com> References: <20230608015241.2454912-1-yamato@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Signed-off-by: Masatake YAMATO --- checkpolicy/test/dispol.c | 1 - 1 file changed, 1 deletion(-) diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c index 50027e40..e0748e90 100644 --- a/checkpolicy/test/dispol.c +++ b/checkpolicy/test/dispol.c @@ -1,4 +1,3 @@ - /* Authors: Frank Mayer and Karl MacMillan * * Copyright (C) 2003 Tresys Technology, LLC From patchwork Thu Jun 8 01:52:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 13271513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40FAFC7EE23 for ; Thu, 8 Jun 2023 01:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjFHBxm (ORCPT ); Wed, 7 Jun 2023 21:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbjFHBxk (ORCPT ); Wed, 7 Jun 2023 21:53:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA6C269F for ; Wed, 7 Jun 2023 18:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686189178; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vBJL1bwxU7sXc9bwKfuQaD318hfOQPdvqm5NwzIo8N0=; b=RcCpU7knvHhTCV6qwMZGU1N+cSrW2gh0W/OcbNOmQWZwBqJeOOcc+s6ZgwTi15Rc1DKOf/ r5/Fb/d8wKy6XcE4jFZ55ZfDiCTxdowc5iZEpy+Vj+UmgxrpyyU3BZojnlkYWD/wOHqvz1 7RcgMLS5CMF6RVlrmPteJvO454K03AE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-122-J4SG11zQM2aJa4pNDkvhfw-1; Wed, 07 Jun 2023 21:52:56 -0400 X-MC-Unique: J4SG11zQM2aJa4pNDkvhfw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B8228007D9 for ; Thu, 8 Jun 2023 01:52:56 +0000 (UTC) Received: from dev64.localdomain.com (unknown [10.64.240.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7194403367; Thu, 8 Jun 2023 01:52:55 +0000 (UTC) From: Masatake YAMATO To: selinux@vger.kernel.org Cc: yamato@redhat.com Subject: [PATCH 3/4] dispol: handle EOF in user interaction Date: Thu, 8 Jun 2023 10:52:40 +0900 Message-Id: <20230608015241.2454912-3-yamato@redhat.com> In-Reply-To: <20230608015241.2454912-1-yamato@redhat.com> References: <20230608015241.2454912-1-yamato@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Signed-off-by: Masatake YAMATO --- checkpolicy/test/dispol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c index e0748e90..e1f6d7fc 100644 --- a/checkpolicy/test/dispol.c +++ b/checkpolicy/test/dispol.c @@ -531,6 +531,8 @@ int main(int argc, char **argv) for (;;) { printf("\nCommand (\'m\' for menu): "); if (fgets(ans, sizeof(ans), stdin) == NULL) { + if (feof(stdin)) + break; fprintf(stderr, "fgets failed at line %d: %s\n", __LINE__, strerror(errno)); continue; From patchwork Thu Jun 8 01:52:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 13271514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D939C7EE43 for ; Thu, 8 Jun 2023 01:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbjFHBxm (ORCPT ); Wed, 7 Jun 2023 21:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFHBxk (ORCPT ); Wed, 7 Jun 2023 21:53:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AF5926A6 for ; Wed, 7 Jun 2023 18:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686189179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wcGiQpYrRy/XVGAXvo0YsNFJOTeHq8ZyEf8+W8MQ4CY=; b=GDHb1xq3OwOljybDw2Oj3kcaSQd34jA5jODpvQPxXlkiYZh/VozXc1g6AgTrvD/qsGyVQI lo9XhJ+YvJMMOpxP4PxZhrTZ4I6xrltnCj7hQDu2abUFd96jU/gaHkix2edtTQJDA7yxKp pGmy/31bLQAsvg0Oek2pCE8vU7zNTo0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-448-bVuOd7t6N3GWrdXFweqFLQ-1; Wed, 07 Jun 2023 21:52:58 -0400 X-MC-Unique: bVuOd7t6N3GWrdXFweqFLQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEF8029AB3E1 for ; Thu, 8 Jun 2023 01:52:57 +0000 (UTC) Received: from dev64.localdomain.com (unknown [10.64.240.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4791D403362; Thu, 8 Jun 2023 01:52:57 +0000 (UTC) From: Masatake YAMATO To: selinux@vger.kernel.org Cc: yamato@redhat.com Subject: [PATCH 4/4] dispol: add --actions option for non-interactive use Date: Thu, 8 Jun 2023 10:52:41 +0900 Message-Id: <20230608015241.2454912-4-yamato@redhat.com> In-Reply-To: <20230608015241.2454912-1-yamato@redhat.com> References: <20230608015241.2454912-1-yamato@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Example session: $ ./dispol --help Usage: ./dismod [OPTIONS] binary_pol_file Options: -h, --help print this help message -a, --actions ACTIONS run non-interactively Actions: 1 display unconditional AVTAB 2 display conditional AVTAB (entirely) 3 display conditional AVTAB (only ENABLED rules) 4 display conditional AVTAB (only DISABLED rules) 5 display conditional bools 6 display conditional expressions 8 display role transitions c display policy capabilities b display booleans C display classes r display roles t display types a display type attributes p display the list of permissive types u display unknown handling setting F display filename_trans rules $ ./dispol --actions 1 /etc/selinux/targeted/policy/policy.33 | head Reading policy... libsepol.policydb_index_others: security: 8 users, 15 roles, 5408 types, 358 bools libsepol.policydb_index_others: security: 1 sens, 1024 cats libsepol.policydb_index_others: security: 134 classes, 86750 rules, 8818 cond rules binary policy file loaded allow abrt_dump_oops_t sssd_var_lib_t : sock_file { write getattr append open }; type_transition authconfig_t entropyd_initrc_exec_t : process initrc_t; type_transition glusterd_t syslogd_initrc_exec_t : process initrc_t;xxxx Signed-off-by: Masatake YAMATO --- checkpolicy/test/dispol.c | 121 +++++++++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 35 deletions(-) diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c index e1f6d7fc..bee1a660 100644 --- a/checkpolicy/test/dispol.c +++ b/checkpolicy/test/dispol.c @@ -35,13 +35,58 @@ static policydb_t policydb; +static struct command { + enum { + EOL = 0, + HEADER = 1, + CMD = 1 << 1, + NOOPT = 1 << 2, + } meta; + char cmd; + const char *desc; +} commands[] = { + {HEADER, 0, "\nSelect a command:"}, + {CMD, '1', "display unconditional AVTAB" }, + {CMD, '2', "display conditional AVTAB (entirely)"}, + {CMD, '3', "display conditional AVTAB (only ENABLED rules)"}, + {CMD, '4', "display conditional AVTAB (only DISABLED rules)"}, + {CMD, '5', "display conditional bools"}, + {CMD, '6', "display conditional expressions"}, + {CMD|NOOPT, '7', "change a boolean value"}, + {CMD, '8', "display role transitions"}, + {HEADER, 0, ""}, + {CMD, 'c', "display policy capabilities"}, + {CMD, 'b', "display booleans"}, + {CMD, 'C', "display classes"}, + {CMD, 'r', "display roles"}, + {CMD, 't', "display types"}, + {CMD, 'a', "display type attributes"}, + {CMD, 'p', "display the list of permissive types"}, + {CMD, 'u', "display unknown handling setting"}, + {CMD, 'F', "display filename_trans rules"}, + {HEADER, 0, ""}, + {CMD|NOOPT, 'f', "set output file"}, + {CMD|NOOPT, 'm', "display menu"}, + {CMD|NOOPT, 'q', "quit"}, + {EOL, 0, "" }, +}; + static __attribute__((__noreturn__)) void usage(const char *progname) { puts("Usage:"); printf(" %s [OPTIONS] binary_pol_file\n\n", progname); puts("Options:"); puts(" -h, --help print this help message"); - puts("\n"); + puts(" -a, --actions ACTIONS run non-interactively"); + puts(""); + puts("Actions:"); + for (unsigned int i = 0; commands[i].meta != EOL; i++) { + if (commands[i].meta == HEADER + || commands[i].meta & NOOPT) + continue; + printf(" %c %s\n", commands[i].cmd, commands[i].desc); + } + puts(""); exit(1); } @@ -447,34 +492,20 @@ static void display_filename_trans(policydb_t *p, FILE *fp) static int menu(void) { - printf("\nSelect a command:\n"); - printf("1) display unconditional AVTAB\n"); - printf("2) display conditional AVTAB (entirely)\n"); - printf("3) display conditional AVTAB (only ENABLED rules)\n"); - printf("4) display conditional AVTAB (only DISABLED rules)\n"); - printf("5) display conditional bools\n"); - printf("6) display conditional expressions\n"); - printf("7) change a boolean value\n"); - printf("8) display role transitions\n"); - printf("\n"); - printf("c) display policy capabilities\n"); - printf("b) display booleans\n"); - printf("C) display classes\n"); - printf("r) display roles\n"); - printf("t) display types\n"); - printf("a) display type attributes\n"); - printf("p) display the list of permissive types\n"); - printf("u) display unknown handling setting\n"); - printf("F) display filename_trans rules\n"); - printf("\n"); - printf("f) set output file\n"); - printf("m) display menu\n"); - printf("q) quit\n"); + unsigned int i; + for (i = 0; commands[i].meta != EOL; i++) { + if (commands[i].meta == HEADER) + printf("%s\n", commands[i].desc); + else if (commands[i].meta & CMD) + printf("%c) %s\n", commands[i].cmd, commands[i].desc); + } return 0; } int main(int argc, char **argv) { + char *ops = NULL; + char *bpol; FILE *out_fp = stdout; char ans[81], OutfileName[121]; int fd, ret; @@ -487,22 +518,35 @@ int main(int argc, char **argv) if (argc < 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) usage(argv[0]); - fd = open(argv[1], O_RDONLY); + bpol = argv[1]; + if (strcmp (bpol, "--actions") == 0 || strcmp (bpol, "-a") == 0) { + if (argc != 4) { + fprintf(stderr, "%s: unexpected number of arguments\n", argv[0]); + usage(argv[0]); + } + ops = argv[2]; + bpol = argv[3]; + } else if (bpol[0] == '-') { + fprintf(stderr, "%s: unknown option: %s\n", argv[0], bpol); + usage(argv[0]); + } + + fd = open(bpol, O_RDONLY); if (fd < 0) { fprintf(stderr, "Can't open '%s': %s\n", - argv[1], strerror(errno)); + bpol, strerror(errno)); exit(1); } if (fstat(fd, &sb) < 0) { fprintf(stderr, "Can't stat '%s': %s\n", - argv[1], strerror(errno)); + bpol, strerror(errno)); exit(1); } map = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (map == MAP_FAILED) { fprintf(stderr, "Can't map '%s': %s\n", - argv[1], strerror(errno)); + bpol, strerror(errno)); exit(1); } @@ -527,15 +571,22 @@ int main(int argc, char **argv) fprintf(stdout, "binary policy file loaded\n\n"); close(fd); - menu(); + if (!ops) + menu(); for (;;) { - printf("\nCommand (\'m\' for menu): "); - if (fgets(ans, sizeof(ans), stdin) == NULL) { - if (feof(stdin)) - break; - fprintf(stderr, "fgets failed at line %d: %s\n", __LINE__, + if (ops) { + puts(""); + ans[0] = *ops? *ops++: 'q'; + ans[1] = '\0'; + } else { + printf("\nCommand (\'m\' for menu): "); + if (fgets(ans, sizeof(ans), stdin) == NULL) { + if (feof(stdin)) + break; + fprintf(stderr, "fgets failed at line %d: %s\n", __LINE__, strerror(errno)); - continue; + continue; + } } switch (ans[0]) {