CKM: no more "empty password for lockscreen" logics.
[platform/core/test/security-tests.git] / tests / ckm / access_provider2.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        access_provider.cpp
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Common functions and macros used in security-tests package.
21  */
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <sys/smack.h>
25
26 #include <access_provider2.h>
27
28 #include <tests_common.h>
29
30 AccessProvider::AccessProvider(const std::string &mySubject)
31   : m_mySubject(mySubject)
32 {}
33
34 void AccessProvider::allowAPI(const std::string &api, const std::string &rule) {
35     m_smackAccess.add(m_mySubject, api, rule);
36 }
37
38 void AccessProvider::apply() {
39     m_smackAccess.apply();
40 }
41
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 << ")");
45     apply();
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),
49         "Error in setgid.");
50     RUNNER_ASSERT_MSG(0 == setuid(uid),
51         "Error in setuid.");
52 }
53