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>
26 #include <access_provider2.h>
28 #include <tests_common.h>
30 AccessProvider::AccessProvider(const std::string &mySubject)
31 : m_mySubject(mySubject)
34 void AccessProvider::allowAPI(const std::string &api, const std::string &rule) {
35 m_smackAccess.add(m_mySubject, api, rule);
38 void AccessProvider::apply() {
39 m_smackAccess.apply();
42 void AccessProvider::applyAndSwithToUser(int uid, int gid) {
43 RUNNER_ASSERT_MSG(0 == smack_revoke_subject(m_mySubject.c_str()),
44 "Error in smack_revoke_subject(" << m_mySubject << ")");
46 RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(m_mySubject.c_str()),
47 "Error in smack_set_label_for_self.");
48 RUNNER_ASSERT_MSG(0 == setgid(gid),
50 RUNNER_ASSERT_MSG(0 == setuid(uid),