| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
user_priv.h - description |
/* |
| 3 |
------------------- |
* user_priv |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - basic operations of user privilege |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* This program is free software; you can redistribute it and/or modify * |
|
|
* it under the terms of the GNU General Public License as published by * |
|
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
| 9 |
#ifndef _USER_PRIV_H_ |
#ifndef _USER_PRIV_H_ |
| 10 |
#define _USER_PRIV_H_ |
#define _USER_PRIV_H_ |
| 13 |
#include <mysql.h> |
#include <mysql.h> |
| 14 |
|
|
| 15 |
// User privilege |
// User privilege |
| 16 |
#define S_NONE 0x0 |
enum user_priv_t |
| 17 |
#define S_LIST 0x1 |
{ |
| 18 |
#define S_GETEXP 0x2 |
S_NONE = 0x0, |
| 19 |
#define S_POST 0x4 |
S_LIST = 0x1, |
| 20 |
#define S_MSG 0x8 |
S_GETEXP = 0x2, |
| 21 |
#define S_MAN_S 0x20 |
S_POST = 0x4, |
| 22 |
#define S_MAN_M 0x60 //(0x40 | 0x20) |
S_MSG = 0x8, |
| 23 |
#define S_ADMIN 0xe0 //(0x80 | 0x40 | 0x20) |
S_MAN_S = 0x20, |
| 24 |
#define S_ALL 0xff |
S_MAN_M = 0x60, //(0x40 | 0x20) |
| 25 |
#define S_DEFAULT 0x3 // 0x1 | 0x2 |
S_ADMIN = 0xe0, //(0x80 | 0x40 | 0x20) |
| 26 |
|
S_ALL = 0xff, |
| 27 |
#define P_GUEST 0x0 //游客 |
S_DEFAULT = 0x3, // 0x1 | 0x2 |
| 28 |
#define P_USER 0x1 //普通用户 |
}; |
| 29 |
//#define P_AUTH_USER 0x2 // Reserved |
|
| 30 |
#define P_MAN_S 0x4 //副版主 |
enum user_level_t |
| 31 |
#define P_MAN_M 0x8 //正版主 |
{ |
| 32 |
#define P_MAN_C 0x10 // Reserved |
P_GUEST = 0x0, // 娓稿 |
| 33 |
#define P_ADMIN_S 0x20 //副系统管理员 |
P_USER = 0x1, // 鏅氱敤鎴 |
| 34 |
#define P_ADMIN_M 0x40 //主系统管理员 |
P_AUTH_USER = 0x2, // Reserved |
| 35 |
|
P_MAN_S = 0x4, // 鍓増涓 |
| 36 |
|
P_MAN_M = 0x8, // 姝g増涓 |
| 37 |
|
P_MAN_C = 0x10, // Reserved |
| 38 |
|
P_ADMIN_S = 0x20, // 鍓郴缁熺鐞嗗憳 |
| 39 |
|
P_ADMIN_M = 0x40, // 涓荤郴缁熺鐞嗗憳 |
| 40 |
|
}; |
| 41 |
|
|
| 42 |
struct user_priv |
struct user_priv |
| 43 |
{ |
{ |
| 44 |
long int uid; |
int uid; |
| 45 |
int level; |
int level; |
| 46 |
int g_priv; |
int g_priv; |
| 47 |
struct |
struct |
| 48 |
{ |
{ |
| 49 |
int sid; |
int sid; |
| 50 |
int s_priv; |
int s_priv; |
| 51 |
|
int is_favor; |
| 52 |
} s_priv_list[BBS_max_section]; |
} s_priv_list[BBS_max_section]; |
| 53 |
int s_count; |
int s_count; |
| 54 |
}; |
}; |
| 57 |
|
|
| 58 |
extern BBS_user_priv BBS_priv; |
extern BBS_user_priv BBS_priv; |
| 59 |
|
|
| 60 |
extern int checklevel(BBS_user_priv *p_priv, int level); |
// Check whether user level matches any bit in the given param |
| 61 |
|
inline int checklevel(BBS_user_priv *p_priv, int level) |
| 62 |
|
{ |
| 63 |
|
if (level == P_GUEST) |
| 64 |
|
{ |
| 65 |
|
return 1; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
extern int setpriv(BBS_user_priv *p_priv, int sid, int priv); |
return ((p_priv->level & level) ? 1 : 0); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
extern int getpriv(BBS_user_priv *p_priv, int sid); |
// Check whether user level is equal or greater than the given param |
| 72 |
|
inline int checklevel2(BBS_user_priv *p_priv, int level) |
| 73 |
|
{ |
| 74 |
|
return ((p_priv->level >= level) ? 1 : 0); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
extern int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor); |
| 78 |
|
|
| 79 |
|
extern int getpriv(BBS_user_priv *p_priv, int sid, int *p_is_favor); |
| 80 |
|
|
| 81 |
extern int checkpriv(BBS_user_priv *p_priv, int sid, int priv); |
inline int checkpriv(BBS_user_priv *p_priv, int sid, int priv) |
| 82 |
|
{ |
| 83 |
|
int is_favor = 0; |
| 84 |
|
return (((getpriv(p_priv, sid, &is_favor) & priv)) == priv ? 1 : 0); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
inline int is_favor(BBS_user_priv *p_priv, int sid) |
| 88 |
|
{ |
| 89 |
|
int is_favor = 0; |
| 90 |
|
getpriv(p_priv, sid, &is_favor); |
| 91 |
|
return is_favor; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
extern int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid); |
extern int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid); |
| 95 |
|
|
| 96 |
#endif //_USER_PRIV_H_ |
#endif //_USER_PRIV_H_ |