| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
user_priv.c - description |
user_priv.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 22 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 24 |
|
|
| 25 |
BBS_user_priv BBS_priv; |
BBS_user_priv BBS_priv; |
| 26 |
|
|
|
int checklevel(BBS_user_priv *p_priv, int level) |
|
|
{ |
|
|
if (level == P_GUEST) |
|
|
{ |
|
|
return 1; |
|
|
} |
|
|
|
|
|
return ((p_priv->level & level) ? 1 : 0); |
|
|
} |
|
|
|
|
| 27 |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
| 28 |
{ |
{ |
| 29 |
int i; |
int i; |
| 66 |
return (sid >= 0 ? p_priv->g_priv : S_NONE); |
return (sid >= 0 ? p_priv->g_priv : S_NONE); |
| 67 |
} |
} |
| 68 |
|
|
|
int checkpriv(BBS_user_priv *p_priv, int sid, int priv) |
|
|
{ |
|
|
return (((getpriv(p_priv, sid) & priv)) == priv ? 1 : 0); |
|
|
} |
|
|
|
|
| 69 |
int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid) |
int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid) |
| 70 |
{ |
{ |
| 71 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 75 |
p_priv->uid = uid; |
p_priv->uid = uid; |
| 76 |
p_priv->level = (uid == 0 ? P_GUEST : P_USER); |
p_priv->level = (uid == 0 ? P_GUEST : P_USER); |
| 77 |
p_priv->g_priv = S_DEFAULT; |
p_priv->g_priv = S_DEFAULT; |
| 78 |
|
p_priv->s_count = 0; |
| 79 |
|
|
| 80 |
if (db == NULL) |
if (db == NULL) |
| 81 |
return 1; |
return 1; |
| 82 |
|
|
| 83 |
// Permission |
// Permission |
| 84 |
sprintf(sql, "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified", |
snprintf(sql, sizeof(sql), "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified", |
| 85 |
uid); |
uid); |
| 86 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 87 |
{ |
{ |
| 101 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 102 |
|
|
| 103 |
// Admin |
// Admin |
| 104 |
sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld " |
snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld " |
| 105 |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 106 |
uid); |
uid); |
| 107 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 122 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 123 |
|
|
| 124 |
// Section Master |
// Section Master |
| 125 |
sprintf(sql, "SELECT section_master.SID, major FROM section_master " |
snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master " |
| 126 |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
| 127 |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
| 128 |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 145 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 146 |
|
|
| 147 |
// Section status |
// Section status |
| 148 |
sprintf(sql, "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config " |
snprintf(sql, sizeof(sql), "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config " |
| 149 |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
| 150 |
"WHERE section_config.enable AND section_class.enable " |
"WHERE section_config.enable AND section_class.enable " |
| 151 |
"ORDER BY SID"); |
"ORDER BY SID"); |
| 179 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 180 |
|
|
| 181 |
// Section ban |
// Section ban |
| 182 |
sprintf(sql, "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable " |
snprintf(sql, sizeof(sql), "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable " |
| 183 |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
| 184 |
uid); |
uid); |
| 185 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |