From 2ed4630c612b9e82d1a61d7cc565b88fbcb61a94 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 29 May 2024 04:21:15 +0200 Subject: [PATCH] Add: validate source names in CREATE_USER and MODIFY_USER --- src/gmp.c | 2 ++ src/manage_sql.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 11dfcd8a6..e60b4b7da 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -23393,6 +23393,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, log_event_fail ("user", "User", NULL, "created"); break; case -3: + case -4: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_user", "Error in SOURCE")); log_event_fail ("user", "User", NULL, "created"); @@ -25995,6 +25996,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, ("modify_user", "Unknown role")); break; case -3: + case -4: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("modify_user", "Error in SOURCES")); break; diff --git a/src/manage_sql.c b/src/manage_sql.c index 152d5f9be..d321cedaf 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -53652,7 +53652,8 @@ find_user_by_name (const char* name, user_t *user) * * @return 0 if the user has been added successfully, 1 failed to find group, * 2 failed to find role, 3 syntax error in hosts, 99 permission denied, - * -1 on error, -2 if user exists already. + * -1 on error, -2 if user exists already, -3 if wrong number of methods, + * -4 error in method. */ int create_user (const gchar * name, const gchar * password, const gchar *comment, @@ -53681,7 +53682,10 @@ create_user (const gchar * name, const gchar * password, const gchar *comment, if (allowed_methods && (allowed_methods->len == 0)) allowed_methods = NULL; - // TODO validate methods single source, one of ldap, ... + if (allowed_methods + && (auth_method_name_valid (g_ptr_array_index (allowed_methods, 0)) + == 0)) + return -4; if (validate_username (name) != 0) { @@ -54713,7 +54717,8 @@ delete_user (const char *user_id_arg, const char *name_arg, int ultimate, * 2 failed to find user, 3 success and user gained admin, 4 success * and user lost admin, 5 failed to find role, 6 syntax error in hosts, * 7 syntax error in new name, 99 permission denied, -1 on error, - * -2 for an unknown role, -3 if wrong number of methods. + * -2 for an unknown role, -3 if wrong number of methods, -4 error in + * method. */ int modify_user (const gchar * user_id, gchar **name, const gchar *new_name, @@ -54745,7 +54750,10 @@ modify_user (const gchar * user_id, gchar **name, const gchar *new_name, || (strlen (g_ptr_array_index (allowed_methods, 0)) == 0))) allowed_methods = NULL; - // TODO Validate methods: single source, one of "", "ldap", ... + if (allowed_methods + && (auth_method_name_valid (g_ptr_array_index (allowed_methods, 0)) + == 0)) + return -4; sql_begin_immediate ();