Fix coverity issue
[platform/core/security/ode.git] / server / kernel-keyring.h
1 /*
2  *  Copyright (c) 2015 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 #ifndef __KERNEL_KEY_RING_H__
18 #define __KERNEL_KEY_RING_H__
19
20 #include <sys/types.h>
21 #include <linux/keyctl.h>
22
23 #include <string>
24
25 /* special process keyring shortcut IDs */
26 #define KEY_SPEC_THREAD_KEYRING                 -1
27 #define KEY_SPEC_PROCESS_KEYRING                -2
28 #define KEY_SPEC_SESSION_KEYRING                -3
29 #define KEY_SPEC_USER_KEYRING                   -4
30 #define KEY_SPEC_USER_SESSION_KEYRING   -5
31 #define KEY_SPEC_GROUP_KEYRING                  -6
32
33 class KernelKeyRing final {
34 public:
35         KernelKeyRing() = delete;
36         KernelKeyRing(const KernelKeyRing&) = delete;
37         KernelKeyRing(KernelKeyRing&&) = delete;
38
39         KernelKeyRing& operator=(const KernelKeyRing&) = delete;
40         KernelKeyRing& operator=(KernelKeyRing&&) = delete;
41
42         static int32_t add(const std::string& type, const std::string& description, const void* payload, size_t plen, int32_t ringid);
43
44         static long search(int32_t ringid, const std::string& type, const std::string& description, int32_t destringid);
45
46         static long link(int32_t keyid, int32_t ringid);
47         static long unlink(int32_t keyid, int32_t ringid);
48
49         static int32_t getKeyringId(int32_t keyid, bool create);
50 };
51
52 #endif //!__KERNEL_KEY_RING_H__