]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/fix_runscript_console_cmd.patch
ebl Add fix to avoid to expect the EndJob message with some
[bacula/bacula] / bacula / patches / testing / fix_runscript_console_cmd.patch
1 Index: src/dird/ua.h
2 ===================================================================
3 --- src/dird/ua.h       (révision 7720)
4 +++ src/dird/ua.h       (copie de travail)
5 @@ -60,6 +60,7 @@
6     bool verbose;                      /* set for normal UA verbosity */
7     bool batch;                        /* set for non-interactive mode */
8     bool gui;                          /* set if talking to GUI program */
9 +   bool runscript;                    /* set if we are in runscript */
10     uint32_t pint32_val;               /* positive integer */
11     int32_t  int32_val;                /* positive/negative */
12     int64_t  int64_val;                /* big int */
13 Index: src/dird/job.c
14 ===================================================================
15 --- src/dird/job.c      (révision 7720)
16 +++ src/dird/job.c      (copie de travail)
17 @@ -1372,6 +1372,8 @@
18     bool ok;
19  
20     ua = new_ua_context(jcr);
21 +   /* run from runscript and check if commands are autorized */
22 +   ua->runscript = true;
23     Mmsg(ua->cmd, "%s", cmd);
24     Dmsg1(100, "Console command: %s\n", ua->cmd);
25     parse_ua_args(ua);
26 Index: src/dird/ua_cmds.c
27 ===================================================================
28 --- src/dird/ua_cmds.c  (révision 7720)
29 +++ src/dird/ua_cmds.c  (copie de travail)
30 @@ -96,50 +96,50 @@
31  int quit_cmd(UAContext *ua, const char *cmd);
32  
33  
34 -struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
35 -static struct cmdstruct commands[] = {
36 - { NT_("add"),        add_cmd,         _("add media to a pool")},
37 - { NT_("autodisplay"), autodisplay_cmd, _("autodisplay [on|off] -- console messages")},
38 - { NT_("automount"),   automount_cmd,  _("automount [on|off] -- after label")},
39 - { NT_("cancel"),     cancel_cmd,    _("cancel [<jobid=nnn> | <job=name>] -- cancel a job")},
40 - { NT_("create"),     create_cmd,    _("create DB Pool from resource")},
41 - { NT_("delete"),     delete_cmd,    _("delete [pool=<pool-name> | media volume=<volume-name>]")},
42 - { NT_("disable"),    disable_cmd,   _("disable <job=name> -- disable a job")},
43 - { NT_("enable"),     enable_cmd,    _("enable <job=name> -- enable a job")},
44 - { NT_("estimate"),   estimate_cmd,  _("performs FileSet estimate, listing gives full listing")},
45 - { NT_("exit"),       quit_cmd,      _("exit = quit")},
46 - { NT_("gui"),        gui_cmd,       _("gui [on|off] -- non-interactive gui mode")},
47 - { NT_("help"),       help_cmd,      _("print this command")},
48 - { NT_("list"),       list_cmd,      _("list [pools | jobs | jobtotals | media <pool=pool-name> | files <jobid=nn>]; from catalog")},
49 - { NT_("label"),      label_cmd,     _("label a tape")},
50 - { NT_("llist"),      llist_cmd,     _("full or long list like list command")},
51 - { NT_("messages"),   messagescmd,   _("messages")},
52 - { NT_("memory"),     memory_cmd,    _("print current memory usage")},
53 - { NT_("mount"),      mount_cmd,     _("mount <storage-name>")},
54 - { NT_("prune"),      prunecmd,      _("prune expired records from catalog")},
55 - { NT_("purge"),      purgecmd,      _("purge records from catalog")},
56 - { NT_("python"),     python_cmd,    _("python control commands")},
57 - { NT_("quit"),       quit_cmd,      _("quit")},
58 - { NT_("query"),      querycmd,      _("query catalog")},
59 - { NT_("restore"),    restore_cmd,   _("restore files")},
60 - { NT_("relabel"),    relabel_cmd,   _("relabel a tape")},
61 - { NT_("release"),    release_cmd,   _("release <storage-name>")},
62 - { NT_("reload"),     reload_cmd,    _("reload conf file")},
63 - { NT_("run"),        run_cmd,       _("run <job-name>")},
64 - { NT_("status"),     status_cmd,    _("status [storage | client]=<name>")},
65 - { NT_("setdebug"),   setdebug_cmd,  _("sets debug level")},
66 - { NT_("setip"),      setip_cmd,     _("sets new client address -- if authorized")},
67 - { NT_("show"),       show_cmd,      _("show (resource records) [jobs | pools | ... | all]")},
68 - { NT_("sqlquery"),   sqlquerycmd,   _("use SQL to query catalog")},
69 - { NT_("time"),       time_cmd,      _("print current time")},
70 - { NT_("trace"),      trace_cmd,     _("turn on/off trace to file")},
71 - { NT_("unmount"),    unmount_cmd,   _("unmount <storage-name>")},
72 - { NT_("umount"),     unmount_cmd,   _("umount <storage-name> for old-time Unix guys")},
73 - { NT_("update"),     update_cmd,    _("update Volume, Pool or slots")},
74 - { NT_("use"),        use_cmd,       _("use catalog xxx")},
75 - { NT_("var"),        var_cmd,       _("does variable expansion")},
76 - { NT_("version"),    version_cmd,   _("print Director version")},
77 - { NT_("wait"),       wait_cmd,      _("wait until no jobs are running [<jobname=name> | <jobid=nnn> | <ujobid=complete_name>]")},
78 +struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; const bool use_in_rs;};
79 +static struct cmdstruct commands[] = {                                      /* Can use it in Console RunScript*/
80 + { NT_("add"),        add_cmd,         _("add media to a pool"),                      false},
81 + { NT_("autodisplay"), autodisplay_cmd, _("autodisplay [on|off] -- console messages"),false},
82 + { NT_("automount"),   automount_cmd,  _("automount [on|off] -- after label"),        false},
83 + { NT_("cancel"),     cancel_cmd,    _("cancel [<jobid=nnn> | <job=name>] -- cancel a job"), false},
84 + { NT_("create"),     create_cmd,    _("create DB Pool from resource"),               false},
85 + { NT_("delete"),     delete_cmd,    _("delete [pool=<pool-name> | media volume=<volume-name>]"), true},
86 + { NT_("disable"),    disable_cmd,   _("disable <job=name> -- disable a job"),        true},
87 + { NT_("enable"),     enable_cmd,    _("enable <job=name> -- enable a job"),          true},
88 + { NT_("estimate"),   estimate_cmd,  _("performs FileSet estimate, listing gives full listing"), true},
89 + { NT_("exit"),       quit_cmd,      _("exit = quit"),                                false},
90 + { NT_("gui"),        gui_cmd,       _("gui [on|off] -- non-interactive gui mode"),   false},
91 + { NT_("help"),       help_cmd,      _("print this command"),                         false},
92 + { NT_("list"),       list_cmd,      _("list [pools | jobs | jobtotals | media <pool=pool-name> | files <jobid=nn>]; from catalog"), true},
93 + { NT_("label"),      label_cmd,     _("label a tape"),                               false},
94 + { NT_("llist"),      llist_cmd,     _("full or long list like list command"),        true},
95 + { NT_("messages"),   messagescmd,   _("messages"),                                   false},
96 + { NT_("memory"),     memory_cmd,    _("print current memory usage"),                 true},
97 + { NT_("mount"),      mount_cmd,     _("mount <storage-name>"),                       false},
98 + { NT_("prune"),      prunecmd,      _("prune expired records from catalog"),         true},
99 + { NT_("purge"),      purgecmd,      _("purge records from catalog"),                 true},
100 + { NT_("python"),     python_cmd,    _("python control commands"),                    false},
101 + { NT_("quit"),       quit_cmd,      _("quit"),                                       false},
102 + { NT_("query"),      querycmd,      _("query catalog"),                              false},
103 + { NT_("restore"),    restore_cmd,   _("restore files"),                              false},
104 + { NT_("relabel"),    relabel_cmd,   _("relabel a tape"),                             false},
105 + { NT_("release"),    release_cmd,   _("release <storage-name>"),                     false},
106 + { NT_("reload"),     reload_cmd,    _("reload conf file"),                           true},
107 + { NT_("run"),        run_cmd,       _("run <job-name>"),                             false},
108 + { NT_("status"),     status_cmd,    _("status [storage | client]=<name>"),           true},
109 + { NT_("setdebug"),   setdebug_cmd,  _("sets debug level"),                           true},
110 + { NT_("setip"),      setip_cmd,     _("sets new client address -- if authorized"),   false},
111 + { NT_("show"),       show_cmd,      _("show (resource records) [jobs | pools | ... | all]"), true},
112 + { NT_("sqlquery"),   sqlquerycmd,   _("use SQL to query catalog"),                   false},
113 + { NT_("time"),       time_cmd,      _("print current time"),                         true},
114 + { NT_("trace"),      trace_cmd,     _("turn on/off trace to file"),                  true},
115 + { NT_("unmount"),    unmount_cmd,   _("unmount <storage-name>"),                     false},
116 + { NT_("umount"),     unmount_cmd,   _("umount <storage-name> for old-time Unix guys"),false},
117 + { NT_("update"),     update_cmd,    _("update Volume, Pool or slots"),               true},
118 + { NT_("use"),        use_cmd,       _("use catalog xxx"),                            false},
119 + { NT_("var"),        var_cmd,       _("does variable expansion"),                    false},
120 + { NT_("version"),    version_cmd,   _("print Director version"),                     true},
121 + { NT_("wait"),       wait_cmd,      _("wait until no jobs are running [<jobname=name> | <jobid=nnn> | <ujobid=complete_name>]"), false},
122               };
123  #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
124  
125 @@ -174,6 +174,11 @@
126               !acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
127              break;
128           }
129 +         /* Check if this command is authorized in RunScript */
130 +         if (ua->runscript && !commands[i].use_in_rs) {
131 +            ua->error_msg(_("Can't use %s command in a runscript"), ua->argk[0]);
132 +            break;
133 +         }
134           if (ua->api) user->signal(BNET_CMD_BEGIN);
135           ok = (*commands[i].func)(ua, ua->cmd);   /* go execute command */
136           found = true;
137 Index: src/dird/ua_dotcmds.c
138 ===================================================================
139 --- src/dird/ua_dotcmds.c       (révision 7720)
140 +++ src/dird/ua_dotcmds.c       (copie de travail)
141 @@ -69,26 +69,26 @@
142  static bool dot_quit_cmd(UAContext *ua, const char *cmd);
143  static bool dot_help_cmd(UAContext *ua, const char *cmd);
144  
145 -struct cmdstruct { const char *key; bool (*func)(UAContext *ua, const char *cmd); const char *help; };
146 -static struct cmdstruct commands[] = {
147 - { NT_(".api"),        api_cmd,        NULL},
148 - { NT_(".backups"),    backupscmd,     NULL},
149 - { NT_(".clients"),    clientscmd,     NULL},
150 - { NT_(".defaults"),   defaultscmd,    NULL},
151 - { NT_(".die"),        diecmd,         NULL},
152 - { NT_(".exit"),       dot_quit_cmd,   NULL},
153 - { NT_(".filesets"),   filesetscmd,    NULL},
154 - { NT_(".help"),       dot_help_cmd,   NULL},
155 - { NT_(".jobs"),       jobscmd,        NULL},
156 - { NT_(".levels"),     levelscmd,      NULL},
157 - { NT_(".messages"),   getmsgscmd,     NULL},
158 - { NT_(".msgs"),       msgscmd,        NULL},
159 - { NT_(".pools"),      poolscmd,       NULL},
160 - { NT_(".quit"),       dot_quit_cmd,   NULL},
161 - { NT_(".sql"),        sql_cmd,        NULL},
162 - { NT_(".status"),     dot_status_cmd, NULL},
163 - { NT_(".storage"),    storagecmd,     NULL},
164 - { NT_(".types"),      typescmd,       NULL} 
165 +struct cmdstruct { const char *key; bool (*func)(UAContext *ua, const char *cmd); const char *help;const bool use_in_rs;};
166 +static struct cmdstruct commands[] = { /* help */  /* can be used in runscript */
167 + { NT_(".api"),        api_cmd,          NULL,       false},
168 + { NT_(".backups"),    backupscmd,       NULL,       false},
169 + { NT_(".clients"),    clientscmd,       NULL,       true},
170 + { NT_(".defaults"),   defaultscmd,      NULL,       false},
171 + { NT_(".die"),        diecmd,           NULL,       false},
172 + { NT_(".exit"),       dot_quit_cmd,     NULL,       false},
173 + { NT_(".filesets"),   filesetscmd,      NULL,       false},
174 + { NT_(".help"),       dot_help_cmd,     NULL,       false},
175 + { NT_(".jobs"),       jobscmd,          NULL,       true},
176 + { NT_(".levels"),     levelscmd,        NULL,       false},
177 + { NT_(".messages"),   getmsgscmd,       NULL,       false},
178 + { NT_(".msgs"),       msgscmd,          NULL,       false},
179 + { NT_(".pools"),      poolscmd,         NULL,       true},
180 + { NT_(".quit"),       dot_quit_cmd,     NULL,       false},
181 + { NT_(".sql"),        sql_cmd,          NULL,       false},
182 + { NT_(".status"),     dot_status_cmd,   NULL,       false},
183 + { NT_(".storage"),    storagecmd,       NULL,       true},
184 + { NT_(".types"),      typescmd,         NULL,       false} 
185               };
186  #define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct)))
187  
188 @@ -116,6 +116,11 @@
189     }
190     for (i=0; i<comsize; i++) {     /* search for command */
191        if (strncasecmp(ua->argk[0],  _(commands[i].key), len) == 0) {
192 +         /* Check if this command is authorized in RunScript */
193 +         if (ua->runscript && !commands[i].use_in_rs) {
194 +            ua->error_msg(_("Can't use %s command in a runscript"), ua->argk[0]);
195 +            break;
196 +         }
197           bool gui = ua->gui;
198           /* Check if command permitted, but "quit" is always OK */
199           if (strcmp(ua->argk[0], NT_(".quit")) != 0 &&