2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file access_provider.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Common functions and macros used in security-tests package.
22 #include <sys/types.h>
24 #include <sys/smack.h>
28 #include <tests_common.h>
30 #include <access_provider.h>
32 namespace SecurityServer {
34 AccessProvider::AccessProvider(const std::string &mySubject)
35 : m_mySubject(mySubject)
38 void AccessProvider::allowSS() {
39 m_smackAccess.add(m_mySubject, "System::Run", "x");
42 void AccessProvider::addObjectRule(const std::string &object, const std::string &rule) {
43 m_smackAccess.add(m_mySubject, object, rule);
46 void AccessProvider::apply() {
47 m_smackAccess.apply();
50 void AccessProvider::applyAndSwithToUser(int uid, int gid) {
51 RUNNER_ASSERT_MSG_BT(0 == smack_revoke_subject(m_mySubject.c_str()),
52 "Error in smack_revoke_subject(" << m_mySubject << ")");
54 RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(m_mySubject.c_str()),
55 "Error in smack_set_label_for_self.");
56 RUNNER_ASSERT_MSG_BT(0 == setgid(gid),
58 RUNNER_ASSERT_MSG_BT(0 == setuid(uid),
62 } // namespace SecurityServer