/[LeafOK_CVS]/lbbs/include/user_priv.h
ViewVC logotype

Contents of /lbbs/include/user_priv.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Tue Nov 4 14:58:56 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.8: +1 -1 lines
Content type: text/x-chdr
Refine file header information comments

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * user_priv
4 * - basic operations of user privilege
5 *
6 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 */
8
9 #ifndef _USER_PRIV_H_
10 #define _USER_PRIV_H_
11
12 #include "bbs.h"
13 #include <mysql/mysql.h>
14
15 // User privilege
16 #define S_NONE 0x0
17 #define S_LIST 0x1
18 #define S_GETEXP 0x2
19 #define S_POST 0x4
20 #define S_MSG 0x8
21 #define S_MAN_S 0x20
22 #define S_MAN_M 0x60 //(0x40 | 0x20)
23 #define S_ADMIN 0xe0 //(0x80 | 0x40 | 0x20)
24 #define S_ALL 0xff
25 #define S_DEFAULT 0x3 // 0x1 | 0x2
26
27 #define P_GUEST 0x0 // 游客
28 #define P_USER 0x1 // 普通用户
29 // #define P_AUTH_USER 0x2 // Reserved
30 #define P_MAN_S 0x4 // 副版主
31 #define P_MAN_M 0x8 // 正版主
32 #define P_MAN_C 0x10 // Reserved
33 #define P_ADMIN_S 0x20 // 副系统管理员
34 #define P_ADMIN_M 0x40 // 主系统管理员
35
36 struct user_priv
37 {
38 int uid;
39 int level;
40 int g_priv;
41 struct
42 {
43 int sid;
44 int s_priv;
45 int is_favor;
46 } s_priv_list[BBS_max_section];
47 int s_count;
48 };
49
50 typedef struct user_priv BBS_user_priv;
51
52 extern BBS_user_priv BBS_priv;
53
54 // Check whether user level matches any bit in the given param
55 inline int checklevel(BBS_user_priv *p_priv, int level)
56 {
57 if (level == P_GUEST)
58 {
59 return 1;
60 }
61
62 return ((p_priv->level & level) ? 1 : 0);
63 }
64
65 // Check whether user level is equal or greater than the given param
66 inline int checklevel2(BBS_user_priv *p_priv, int level)
67 {
68 return ((p_priv->level >= level) ? 1 : 0);
69 }
70
71 extern int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor);
72
73 extern int getpriv(BBS_user_priv *p_priv, int sid, int *p_is_favor);
74
75 inline int checkpriv(BBS_user_priv *p_priv, int sid, int priv)
76 {
77 int is_favor = 0;
78 return (((getpriv(p_priv, sid, &is_favor) & priv)) == priv ? 1 : 0);
79 }
80
81 inline int is_favor(BBS_user_priv *p_priv, int sid)
82 {
83 int is_favor = 0;
84 getpriv(p_priv, sid, &is_favor);
85 return is_favor;
86 }
87
88 extern int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid);
89
90 #endif //_USER_PRIV_H_

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1