From 2d9b6113ff276dae13a520c4e0ff6ea5189e9489 Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Thu, 18 Nov 2021 13:28:07 +0100 Subject: [PATCH] move 'check_for_invalid_chars' helper to common code --- bacula/src/lib/edit.c | 49 +++++++++++++++++++++++++++++++++++++++++ bacula/src/lib/protos.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index 5a19b305c..081125820 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -546,7 +546,56 @@ bool is_name_valid(const char *name, POOLMEM **msg, const char *accept) return true; } +/* Small helper method, so far used only by the PostgreSQL and MySQL plugins + * to check if name provided by the user can be used. + * Checks if given string does not contain suspicious characters, as well as + * informs the called if it's already double-quoted or not, to know if it needs + * some further processing. + * @ret false if no invalid character is found + * @ret true if some invalid character is found ('err' is filed with message in that case) + */ +bool check_for_invalid_chars(const char *str, POOLMEM **err, bool *quote_needed) +{ + *quote_needed = true; + int len = strlen(str); + for (int i=0; i