| 18 |
#include "user_priv.h" |
#include "user_priv.h" |
| 19 |
#include "bbs.h" |
#include "bbs.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 21 |
|
#include "database.h" |
| 22 |
#include "log.h" |
#include "log.h" |
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 24 |
#include <mysql.h> |
#include <mysql.h> |
| 27 |
|
|
| 28 |
int checklevel(BBS_user_priv *p_priv, int level) |
int checklevel(BBS_user_priv *p_priv, int level) |
| 29 |
{ |
{ |
| 30 |
return (((p_priv->level & level)) ^ level ? 0 : 1); |
if (level == P_GUEST) |
| 31 |
|
{ |
| 32 |
|
return 1; |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
return ((p_priv->level & level) ? 1 : 0); |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
| 79 |
|
|
| 80 |
int checkpriv(BBS_user_priv *p_priv, int sid, int priv) |
int checkpriv(BBS_user_priv *p_priv, int sid, int priv) |
| 81 |
{ |
{ |
| 82 |
return (((getpriv(p_priv, sid) & priv)) ^ priv ? 0 : 1); |
return (((getpriv(p_priv, sid) & priv)) == priv ? 1 : 0); |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
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) |
| 86 |
{ |
{ |
| 87 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 88 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 89 |
char sql[1024]; |
char sql[SQL_BUFFER_LEN]; |
|
int i; |
|
| 90 |
|
|
| 91 |
p_priv->uid = uid; |
p_priv->uid = uid; |
| 92 |
p_priv->level = (uid == 0 ? P_GUEST : P_USER); |
p_priv->level = (uid == 0 ? P_GUEST : P_USER); |
| 96 |
return 1; |
return 1; |
| 97 |
|
|
| 98 |
// Permission |
// Permission |
| 99 |
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", |
| 100 |
uid); |
uid); |
| 101 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 102 |
{ |
{ |
| 108 |
log_error("Get user_list data failed\n"); |
log_error("Get user_list data failed\n"); |
| 109 |
return -1; |
return -1; |
| 110 |
} |
} |
| 111 |
if (row = mysql_fetch_row(rs)) |
if ((row = mysql_fetch_row(rs))) |
| 112 |
{ |
{ |
| 113 |
p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); |
p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); |
| 114 |
p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); |
p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); |
| 116 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 117 |
|
|
| 118 |
// Admin |
// Admin |
| 119 |
sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld " |
snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld " |
| 120 |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 121 |
uid); |
uid); |
| 122 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 129 |
log_error("Get admin_config data failed\n"); |
log_error("Get admin_config data failed\n"); |
| 130 |
return -1; |
return -1; |
| 131 |
} |
} |
| 132 |
if (row = mysql_fetch_row(rs)) |
if ((row = mysql_fetch_row(rs))) |
| 133 |
{ |
{ |
| 134 |
p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S); |
p_priv->level |= (atoi(row[0]) ? P_ADMIN_M : P_ADMIN_S); |
| 135 |
p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN); |
p_priv->g_priv |= (atoi(row[0]) ? S_ALL : S_ADMIN); |
| 136 |
} |
} |
| 137 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 138 |
|
|
| 139 |
// Section Master |
// Section Master |
| 140 |
sprintf(sql, "SELECT section_master.SID, major FROM section_master " |
snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master " |
| 141 |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
| 142 |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
| 143 |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 152 |
log_error("Get section_master data failed\n"); |
log_error("Get section_master data failed\n"); |
| 153 |
return -1; |
return -1; |
| 154 |
} |
} |
| 155 |
while (row = mysql_fetch_row(rs)) |
while ((row = mysql_fetch_row(rs))) |
| 156 |
{ |
{ |
| 157 |
p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S); |
p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S); |
| 158 |
setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S)); |
setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S)); |
| 160 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 161 |
|
|
| 162 |
// Section status |
// Section status |
| 163 |
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 " |
| 164 |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
| 165 |
"WHERE section_config.enable AND section_class.enable " |
"WHERE section_config.enable AND section_class.enable " |
| 166 |
"ORDER BY SID"); |
"ORDER BY SID"); |
| 174 |
log_error("Get section_config data failed\n"); |
log_error("Get section_config data failed\n"); |
| 175 |
return -1; |
return -1; |
| 176 |
} |
} |
| 177 |
while (row = mysql_fetch_row(rs)) |
while ((row = mysql_fetch_row(rs))) |
| 178 |
{ |
{ |
| 179 |
int priv = getpriv(p_priv, atoi(row[0])); |
int priv = getpriv(p_priv, atoi(row[0])); |
| 180 |
if (p_priv->level < atoi(row[2])) |
if (p_priv->level < atoi(row[2])) |
| 194 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 195 |
|
|
| 196 |
// Section ban |
// Section ban |
| 197 |
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 " |
| 198 |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
| 199 |
uid); |
uid); |
| 200 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 207 |
log_error("Get ban_user_list data failed\n"); |
log_error("Get ban_user_list data failed\n"); |
| 208 |
return -1; |
return -1; |
| 209 |
} |
} |
| 210 |
while (row = mysql_fetch_row(rs)) |
while ((row = mysql_fetch_row(rs))) |
| 211 |
{ |
{ |
| 212 |
setpriv(p_priv, atoi(row[0]), |
setpriv(p_priv, atoi(row[0]), |
| 213 |
getpriv(p_priv, atoi(row[0])) & (~S_POST)); |
getpriv(p_priv, atoi(row[0])) & (~S_POST)); |