1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright 2017 Couchbase, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <daemon/connection.h> 19 #include <daemon/cookie.h> 20 drop_privilege_executor(Cookie& cookie)21void drop_privilege_executor(Cookie& cookie) { 22 cookie.logCommand(); 23 auto* request = reinterpret_cast<cb::mcbp::DropPrivilegeRequest*>( 24 cookie.getPacketAsVoidPtr()); 25 26 cb::engine_errc status; 27 try { 28 const auto key = request->getKey(); 29 std::string priv{reinterpret_cast<const char*>(key.data()), key.size()}; 30 auto privilege = cb::rbac::to_privilege(priv); 31 status = cookie.getConnection().dropPrivilege(privilege); 32 } catch (const std::invalid_argument&) { 33 // Invalid name of privilege 34 status = cb::engine_errc::no_such_key; 35 } 36 37 cookie.sendResponse(status); 38 } 39