@@ -188,6 +188,33 @@ void AclFamily::SetUser(CmdArgList args, ConnectionContext* cntx) {
188
188
std::visit (Overloaded{error_case, update_case}, std::move (req));
189
189
}
190
190
191
+ void AclFamily::EvictOpenConnectionsOnAllProactors (std::string_view user) {
192
+ auto close_cb = [user]([[maybe_unused]] size_t id, util::Connection* conn) {
193
+ DCHECK (conn);
194
+ auto connection = static_cast <facade::Connection*>(conn);
195
+ auto ctx = static_cast <ConnectionContext*>(connection->cntx ());
196
+ if (ctx && ctx->authed_username == user) {
197
+ connection->ShutdownSelf ();
198
+ }
199
+ };
200
+
201
+ if (main_listener_) {
202
+ main_listener_->TraverseConnections (close_cb);
203
+ }
204
+ }
205
+
206
+ void AclFamily::DelUser (CmdArgList args, ConnectionContext* cntx) {
207
+ std::string_view username = facade::ToSV (args[0 ]);
208
+ auto & registry = *ServerState::tlocal ()->user_registry ;
209
+ if (!registry.RemoveUser (username)) {
210
+ cntx->SendError (absl::StrCat (" User " , username, " does not exist" ));
211
+ return ;
212
+ }
213
+
214
+ EvictOpenConnectionsOnAllProactors (username);
215
+ cntx->SendOk ();
216
+ }
217
+
191
218
using CI = dfly::CommandId;
192
219
193
220
using MemberFunc = void (AclFamily::*)(CmdArgList args, ConnectionContext* cntx);
@@ -201,6 +228,7 @@ inline CommandId::Handler HandlerFunc(AclFamily* acl, MemberFunc f) {
201
228
constexpr uint32_t kAcl = acl::CONNECTION;
202
229
constexpr uint32_t kList = acl::ADMIN | acl::SLOW | acl::DANGEROUS;
203
230
constexpr uint32_t kSetUser = acl::ADMIN | acl::SLOW | acl::DANGEROUS;
231
+ constexpr uint32_t kDelUser = acl::ADMIN | acl::SLOW | acl::DANGEROUS;
204
232
205
233
// We can't implement the ACL commands and its respective subcommands LIST, CAT, etc
206
234
// the usual way, (that is, one command called ACL which then dispatches to the subcommand
@@ -215,6 +243,8 @@ void AclFamily::Register(dfly::CommandRegistry* registry) {
215
243
List);
216
244
*registry << CI{" ACL SETUSER" , CO::ADMIN | CO::NOSCRIPT | CO::LOADING, -2 , 0 , 0 , 0 , acl::kSetUser }
217
245
.HFUNC (SetUser);
246
+ *registry << CI{" ACL DELUSER" , CO::ADMIN | CO::NOSCRIPT | CO::LOADING, 2 , 0 , 0 , 0 , acl::kDelUser }
247
+ .HFUNC (DelUser);
218
248
}
219
249
220
250
#undef HFUNC
0 commit comments