• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _LOS_DEVICELIMIT_H
32 #define _LOS_DEVICELIMIT_H
33 
34 #include "los_typedef.h"
35 #include "los_list.h"
36 #include "vfs_config.h"
37 
38 #ifdef __cplusplus
39 #if __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42 #endif /* __cplusplus */
43 
44 #define DEVLIMIT_ACC_MKNOD 1
45 #define DEVLIMIT_ACC_READ  2
46 #define DEVLIMIT_ACC_WRITE 4
47 #define DEVLIMIT_ACC_MASK (DEVLIMIT_ACC_MKNOD | DEVLIMIT_ACC_READ | DEVLIMIT_ACC_WRITE)
48 
49 #define DEVLIMIT_DEV_BLOCK 1
50 #define DEVLIMIT_DEV_CHAR  2
51 #define DEVLIMIT_DEV_ALL   4 /* all devices */
52 
53 #define DEVLIMIT_ALLOW 1
54 #define DEVLIMIT_DENY 2
55 
56 #define ACCLEN 4
57 
58 struct SeqBuf;
59 typedef struct TagPLimiterSet ProcLimitSet;
60 
61 enum DevLimitBehavior {
62     DEVLIMIT_DEFAULT_NONE,
63     DEVLIMIT_DEFAULT_ALLOW,
64     DEVLIMIT_DEFAULT_DENY,
65 };
66 
67 typedef struct DevAccessItem {
68     INT16 type;
69     INT16 access;
70     LOS_DL_LIST list;
71     CHAR name[PATH_MAX];
72 } DevAccessItem;
73 
74 typedef struct ProcDevLimit {
75     struct ProcDevLimit *parent;
76     UINT8 allowFile;
77     UINT8 denyFile;
78     LOS_DL_LIST accessList; // device belong to devicelimite
79     enum DevLimitBehavior behavior;
80 } ProcDevLimit;
81 
82 VOID OsDevLimitInit(UINTPTR limit);
83 VOID *OsDevLimitAlloc(VOID);
84 VOID OsDevLimitFree(UINTPTR limit);
85 VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src);
86 UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
87 UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
88 UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf);
89 UINT32 OsDevLimitCheckPermission(INT32 vnodeType, const CHAR *pathName, INT32 flags);
90 
91 #ifdef __cplusplus
92 #if __cplusplus
93 }
94 #endif /* __cplusplus */
95 #endif /* __cplusplus */
96 #endif /* _LOS_DEVICELIMIT_H */
97