• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "useriam_common.h"
17 
18 extern "C" {
19 #include <sys/stat.h>
20 #include <unistd.h>
21 
22 #include "pool.h"
23 #include "idm_database.h"
24 #include "coauth.h"
25 #include "context_manager.h"
26 #include "adaptor_log.h"
27 #include "lock.h"
28 #include "token_key.h"
29 }
30 
31 namespace OHOS {
32 namespace UserIAM {
33 namespace Common {
34 static const char *IDM_USER_FOLDER = "/data/useriam";
35 static bool g_isInitUserIAM = false;
36 
Init()37 int32_t Init()
38 {
39     GlobalLock();
40     LOG_INFO("check useriam folder exist or init it");
41     if (IDM_USER_FOLDER && access(IDM_USER_FOLDER, 0) == -1) {
42         mkdir(IDM_USER_FOLDER, S_IRWXU);
43     }
44     if (InitUserAuthContextList() != RESULT_SUCCESS) {
45         LOG_ERROR("init user auth failed");
46         goto FAIL;
47     }
48 
49     if (InitResourcePool() != RESULT_SUCCESS) {
50         LOG_ERROR("init resource pool failed");
51         goto FAIL;
52     }
53     if (InitUserInfoList() != RESULT_SUCCESS) {
54         LOG_ERROR("init user info failed");
55         goto FAIL;
56     }
57     if (InitCoAuth() != RESULT_SUCCESS) {
58         LOG_ERROR("init user auth failed");
59         goto FAIL;
60     }
61     if (InitTokenKey() != RESULT_SUCCESS) {
62         LOG_ERROR("init token key failed");
63         goto FAIL;
64     }
65     g_isInitUserIAM = true;
66     GlobalUnLock();
67     return RESULT_SUCCESS;
68 
69 FAIL:
70     Close();
71     GlobalUnLock();
72     return RESULT_UNKNOWN;
73 }
74 
Close()75 int32_t Close()
76 {
77     GlobalLock();
78     DestoryUserAuthContextList();
79     DestoryCoAuth();
80     DestroyUserInfoList();
81     DestroyResourcePool();
82     g_isInitUserIAM = false;
83     GlobalUnLock();
84     return RESULT_SUCCESS;
85 }
86 
IsIAMInited()87 bool IsIAMInited()
88 {
89     return g_isInitUserIAM;
90 }
91 } // Common
92 } // UserIAM
93 } // OHOS