• 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 "trans_channel_limit.h"
17 
18 #include <securec.h>
19 
20 #include "softbus_def.h"
21 #include "softbus_log.h"
22 
23 
24 #define AUTH_SESSION_WHITE_LIST_NUM (3)
25 
26 static char g_sessionWhiteList[AUTH_SESSION_WHITE_LIST_NUM][SESSION_NAME_SIZE_MAX] = {
27     "ohos.distributedhardware.devicemanager.resident",
28     "com.huawei.devicegroupmanage",
29     "IShareAuthSession"
30 };
31 
CheckSessionNameValidOnAuthChannel(const char * sessionName)32 bool CheckSessionNameValidOnAuthChannel(const char *sessionName)
33 {
34     if (sessionName == NULL) {
35         return false;
36     }
37 
38     uint16_t index = 0;
39     size_t len = 0;
40     for (; index < AUTH_SESSION_WHITE_LIST_NUM; ++index) {
41         len = strnlen(g_sessionWhiteList[index], SESSION_NAME_SIZE_MAX);
42         if (strncmp(sessionName, g_sessionWhiteList[index], len) == 0) {
43             return true;
44         }
45     }
46     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO,
47         "auth channel sessionname[%s] invalid.", sessionName);
48     return false;
49 }
50 
51