Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/settings.c @ 1988:dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Patch merged from isbear's mcabber-experimental repository.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 27 Mar 2011 18:57:42 +0200 |
parents | e6d355e50d7a |
children | 038c4d601011 |
comparison
equal
deleted
inserted
replaced
1987:212c9589b25c | 1988:dd65a18dc480 |
---|---|
181 | 181 |
182 // Ignore empty lines and comments | 182 // Ignore empty lines and comments |
183 if ((*line == '\n') || (*line == '\0') || (*line == '#')) | 183 if ((*line == '\n') || (*line == '\0') || (*line == '#')) |
184 continue; | 184 continue; |
185 | 185 |
186 // We only allow assignments line, except for commands "pgp", "source", | 186 // If we aren't in runtime (i.e. startup) we'll only accept "safe" commands |
187 // "color", "load" and "otrpolicy", unless we're in runtime (i.e. not startup). | 187 if (!runtime) { |
188 if (runtime || | 188 const gchar *cmdend = strchr(line, ' '); |
189 (strchr(line, '=') != NULL) || | 189 gchar *cmdname = NULL; |
190 startswith(line, "pgp ", FALSE) || | 190 gboolean safe; |
191 startswith(line, "source ", FALSE) || | 191 if (cmdend) |
192 startswith(line, "color ", FALSE) || | 192 cmdname = g_strndup(line, cmdend - line); |
193 #ifdef MODULES_ENABLE | 193 safe = cmd_is_safe(cmdname ? cmdname : line); |
194 startswith(line, "module ", FALSE) || | 194 g_free(cmdname); |
195 #endif | 195 if (!safe) { |
196 startswith(line, "status ", FALSE) || | 196 scr_log_print(LPRINT_LOGNORM, "Error in configuration file (l. %d): " |
197 startswith(line, "otrpolicy", FALSE)) { | 197 "this command can't be used here", ln); |
198 // Only accept a few "safe" commands | |
199 if (!runtime && | |
200 !startswith(line, "set ", FALSE) && | |
201 !startswith(line, "bind ", FALSE) && | |
202 !startswith(line, "alias ", FALSE) && | |
203 !startswith(line, "pgp ", FALSE) && | |
204 !startswith(line, "source ", FALSE) && | |
205 !startswith(line, "status ", FALSE) && | |
206 !startswith(line, "color ", FALSE) && | |
207 #ifdef MODULES_ENABLE | |
208 !startswith(line, "module ", FALSE) && | |
209 #endif | |
210 !startswith(line, "otrpolicy ", FALSE)) { | |
211 scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): " | |
212 "this command can't be used here", ln); | |
213 err++; | 198 err++; |
214 continue; | 199 continue; |
215 } | 200 } |
216 // Set the leading COMMAND_CHAR to build a command line | 201 } |
217 // and process the command | 202 |
218 *(--line) = COMMAND_CHAR; | 203 // Set the leading COMMAND_CHAR to build a command line |
219 if (process_command(line, TRUE) == 255) | 204 // and process the command |
220 mcabber_set_terminate_ui(); | 205 *(--line) = COMMAND_CHAR; |
221 } else { | 206 if (process_command(line, TRUE) == 255) |
222 scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): " | 207 mcabber_set_terminate_ui(); |
223 "this is not an assignment", ln); | |
224 err++; | |
225 } | |
226 } | 208 } |
227 g_free(buf); | 209 g_free(buf); |
228 fclose(fp); | 210 fclose(fp); |
229 | 211 |
230 if (filename) | 212 if (filename) |