return FALSE;
}
+static bool is_reserved_name(const subsession_user_t subsession)
+{
+ return !strcmp(subsession, "__template_fixed__")
+ || !strcmp(subsession, "__template_reg__");
+}
+
static gboolean error_on_bad_user_id(const char *user_id) {
return (
is_user_id_null(user_id)
user_id_is_not_valid(user))
)
+ if (is_reserved_name(user))
+ return SUBSESSION_ERROR_INVALID_PARAMETER;
+
return_with_log_error_result_(method_call_async(dbus_method_call.AddUser, g_variant_new("(is)", session_uid, user), cb, user_data))
}
session_fixed_size_invalid_size(size_limit_kB)))
)
+ if (is_reserved_name(user))
+ return SUBSESSION_ERROR_INVALID_PARAMETER;
+
return_with_log_error_result_(method_call_async(dbus_method_call.AddUserFixedSize, g_variant_new("(isu)", session_uid, user, size_limit_kB), cb, user_data))
}
user_id_is_not_valid(user))
)
+ if (is_reserved_name(user))
+ return SUBSESSION_ERROR_INVALID_PARAMETER;
+
return_with_log_error_result_(method_call_async(dbus_method_call.RemoveUser, g_variant_new("(is)", session_uid, user), cb, user_data))
}
session_uid_is_not_valid(session_uid))
)
+ if (is_reserved_name(next_user))
+ return SUBSESSION_ERROR_INVALID_PARAMETER;
+
return_with_log_error_result_(method_call_async(dbus_method_call.SwitchUser, g_variant_new("(is)", session_uid, next_user), cb, user_data))
}
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. */
+#include "dir_backend_fixed_size.hpp"
+#include "dir_backend_regular_dir.hpp"
+
#include <chrono>
#include <exception>
#include <stdexcept>
return true;
}
+inline bool check_subsession_id_restricted(const std::string_view subsession_id)
+{
+ return DirBackendAddFixedSize{0}.TemplateName() == subsession_id
+ || DirBackendAddRegularDir{}.TemplateName() == subsession_id;
+}
+
inline bool check_uid_valid(int uid)
{
return uid > 0;
return true;
}
+ if (check_subsession_id_restricted(subsession_id)) {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ get_dbus_error_mapping(SUBSESSION_ERROR_INVALID_PARAMETER), "Reserved subsession_id");
+ return true;
+ }
+
return false;
}
}
// N.B. Switch to user "" (empty string) is possible and it means no subsession is currently active
- if (next_subsession_id != SUBSESSION_INITIAL_SID && !check_subsession_id_valid(next_subsession_id)) {
+ if (next_subsession_id != SUBSESSION_INITIAL_SID && (!check_subsession_id_valid(next_subsession_id) || check_subsession_id_restricted(next_subsession_id))) {
g_dbus_method_invocation_return_dbus_error(invocation,
get_dbus_error_mapping(SUBSESSION_ERROR_INVALID_PARAMETER), "Incorrect subsession_id passed");
return;
#include "test_hlp.hpp"
-const int action_items = 44;
+const int action_items = 50;
TEST(subsession_add_remove_test, FailAtAddRemoveUser) {
using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
.results = std::array<api_call_res_t, action_items> {
+ // Cannot add templates names (2 reserved names x 2 request backends, both names block both backends)
+ api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestBadUserStr::fixed_size_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if add [ " + std::string(TestBadUserStr::fixed_size_template) + " ] returns error (regular dir backend)",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if add [ " + std::string(TestBadUserStr::fixed_size_template) + " ] callback returns error (regular dir backend)", },
+
+ api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestBadUserStr::regular_dir_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if add [ " + std::string(TestBadUserStr::regular_dir_template) + " ] returns error (regular dir backend)",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if add [ " + std::string(TestBadUserStr::regular_dir_template) + " ] callback returns error (regular dir backend)", },
+
+
+ api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestBadUserStr::fixed_size_template, 10*1024)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if add [ " + std::string(TestBadUserStr::fixed_size_template) + " ] returns error (fixed size backend)",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if add [ " + std::string(TestBadUserStr::fixed_size_template) + " ] callback returns error (fixed size backend)", },
+
+ api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestBadUserStr::regular_dir_template, 10*1024)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if add [ " + std::string(TestBadUserStr::regular_dir_template) + " ] returns error (fixed size backend)",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if add [ " + std::string(TestBadUserStr::regular_dir_template) + " ] callback returns error (fixed size backend)", },
+
+ // Cannot remove templates either
+ api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>( TestBadUserStr::regular_dir_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if remove [ " + std::string(TestBadUserStr::regular_dir_template) + " ] returns error",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if remove [ " + std::string(TestBadUserStr::regular_dir_template) + " ] callback returns error", },
+ api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestBadUserStr::fixed_size_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if remove [ " + std::string(TestBadUserStr::fixed_size_template) + " ] returns error",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if remove [ " + std::string(TestBadUserStr::fixed_size_template) + " ] callback returns error", },
+
+
+ // Misc
api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestBadUserStr::bad_user_1)),
.expected = SUBSESSION_ERROR_INVALID_PARAMETER,
.desc = "Check if add [ " + std::string(TestBadUserStr::bad_user_1) + " ] returns error (regular dir backend)",
#include "test_hlp.hpp"
-const int action_items = 12;
+const int action_items = 14;
TEST(subsession_switch_user_test, FailAtSwitchUser) {
.desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] returns no error",
.cb_expected = SUBSESSION_ERROR_NONE,
.cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback returns no error", },
+
+ // Cannot switch into templates
+ api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestBadUserStr::fixed_size_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if switch to template [ " + std::string(TestBadUserStr::fixed_size_template) + " ] returns error",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if switch to template [ " + std::string(TestBadUserStr::fixed_size_template) + " ] callback returns error", },
+
+ api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestBadUserStr::regular_dir_template)),
+ .expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .desc = "Check if switch to template [ " + std::string(TestBadUserStr::regular_dir_template) + " ] returns error",
+ .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+ .cb_desc = "Check if switch to template [ " + std::string(TestBadUserStr::regular_dir_template) + " ] callback returns error", },
}
};
//Below filled subsession_user_t array without '\0' (null) terminator, use only for testing.
[[maybe_unused]] static subsession_user_t bad_user_20 = {'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6',
'7','8','9','0'};
+
+ [[maybe_unused]] static subsession_user_t fixed_size_template = "__template_fixed__";
+ [[maybe_unused]] static subsession_user_t regular_dir_template = "__template_reg__";
};
static constexpr int MAGIC_ADD = 111;