• 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 "identify_funcs.h"
17 
18 #include "securec.h"
19 
20 #include "adaptor_log.h"
21 #include "auth_level.h"
22 #include "context_manager.h"
23 #include "executor_message.h"
24 #include "idm_database.h"
25 
DoIdentify(const IdentifyParam param,LinkedList ** schedule)26 ResultCode DoIdentify(const IdentifyParam param, LinkedList **schedule)
27 {
28     if (schedule == NULL) {
29         LOG_ERROR("schedule is null");
30         return RESULT_BAD_PARAM;
31     }
32     UserAuthContext *identifyContext = GenerateIdentifyContext(param);
33     if (identifyContext == NULL) {
34         LOG_ERROR("authContext is null");
35         return RESULT_GENERAL_ERROR;
36     }
37     ResultCode ret = CopySchedules(identifyContext, schedule);
38     if (ret != RESULT_SUCCESS) {
39         LOG_ERROR("get schedule failed");
40         DestoryContext(identifyContext);
41         return ret;
42     }
43     return ret;
44 }
45 
DoUpdateIdentify(uint64_t contextId,const Buffer * scheduleResult,int32_t * userId,UserAuthTokenHal * token,int32_t * result)46 ResultCode DoUpdateIdentify(uint64_t contextId, const Buffer *scheduleResult, int32_t *userId,
47     UserAuthTokenHal *token, int32_t *result)
48 {
49     if (!IsBufferValid(scheduleResult) || token == NULL || userId == NULL || result == NULL) {
50         LOG_ERROR("param is null");
51         DestoryContextbyId(contextId);
52         return RESULT_BAD_PARAM;
53     }
54 
55     UserAuthContext *identifyContext = GetContext(contextId);
56     if (identifyContext == NULL) {
57         LOG_ERROR("identifyContext is null");
58         return RESULT_GENERAL_ERROR;
59     }
60     ExecutorResultInfo *executorResultInfo = CreateExecutorResultInfo(scheduleResult);
61     if (executorResultInfo == NULL) {
62         LOG_ERROR("executorResultInfo is null");
63         DestoryContext(identifyContext);
64         return RESULT_GENERAL_ERROR;
65     }
66 
67     ResultCode ret = RESULT_GENERAL_ERROR;
68     *result = executorResultInfo->result;
69     if (*result != RESULT_SUCCESS) {
70         LOG_ERROR("executor result is not success, result: %{pubilc}d", executorResultInfo->result);
71         goto EXIT;
72     }
73     uint64_t credentialId;
74     ret = FillInContext(identifyContext, &credentialId, executorResultInfo, SCHEDULE_MODE_IDENTIFY);
75     if (ret != RESULT_SUCCESS) {
76         LOG_ERROR("FillInContext fail");
77         goto EXIT;
78     }
79     ret = GetTokenDataAndSign(identifyContext, credentialId, SCHEDULE_MODE_IDENTIFY, token);
80     if (ret != RESULT_SUCCESS) {
81         LOG_ERROR("get token failed");
82         goto EXIT;
83     }
84     *userId = identifyContext->userId;
85 
86 EXIT:
87     DestoryExecutorResultInfo(executorResultInfo);
88     DestoryContext(identifyContext);
89     return ret;
90 }