2 Low level event script handling tests
4 Copyright (C) Martin Schwenke 2018
6 Based on run_event_test.c:
8 Copyright (C) Amitay Isaacs 2017
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, see <http://www.gnu.org/licenses/>.
31 #include "common/event_script.c"
33 static void usage(const char *prog)
36 "Usage: %s list <scriptdir>\n",
39 " %s chmod enable <scriptdir> <scriptname>\n",
42 " %s chmod diable <scriptdir> <scriptname>\n",
46 static void do_list(TALLOC_CTX *mem_ctx, int argc, const char **argv)
48 struct event_script_list *script_list = NULL;
57 ret = event_script_get_list(mem_ctx, argv[2], &script_list);
59 printf("Script list %s failed with result=%d\n", argv[2], ret);
63 if (script_list == NULL || script_list->num_scripts == 0) {
64 printf("No scripts found\n");
68 for (i=0; i < script_list->num_scripts; i++) {
69 struct event_script *s = script_list->script[i];
70 printf("%s\n", s->name);
74 static void do_chmod(TALLOC_CTX *mem_ctx,
86 ret = event_script_chmod(argv[2], argv[3], enable);
88 printf("Script %s %s %s completed with result=%d\n",
89 argv[1], argv[2], argv[3], ret);
92 int main(int argc, const char **argv)
101 mem_ctx = talloc_new(NULL);
102 if (mem_ctx == NULL) {
103 fprintf(stderr, "talloc_new() failed\n");
107 if (strcmp(argv[1], "list") == 0) {
108 do_list(mem_ctx, argc, argv);
109 } else if (strcmp(argv[1], "enable") == 0) {
110 do_chmod(mem_ctx, argc, argv, true);
111 } else if (strcmp(argv[1], "disable") == 0) {
112 do_chmod(mem_ctx, argc, argv, false);
114 fprintf(stderr, "Invalid command %s\n", argv[2]);
118 talloc_free(mem_ctx);