| 15 |
* * |
* * |
| 16 |
***************************************************************************/ |
***************************************************************************/ |
| 17 |
|
|
| 18 |
|
#include "user_priv.h" |
| 19 |
#include "bbs.h" |
#include "bbs.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 21 |
|
#include "log.h" |
| 22 |
|
#include <stdio.h> |
| 23 |
#include <mysql.h> |
#include <mysql.h> |
| 24 |
|
|
| 25 |
|
BBS_user_priv BBS_priv; |
| 26 |
|
|
| 27 |
int checklevel(BBS_user_priv *p_priv, int level) |
int checklevel(BBS_user_priv *p_priv, int level) |
| 28 |
{ |
{ |
| 29 |
return (((p_priv->level & level)) ^ level ? 0 : 1); |
return (((p_priv->level & level)) ^ level ? 0 : 1); |
| 90 |
if (db == NULL) |
if (db == NULL) |
| 91 |
return 1; |
return 1; |
| 92 |
|
|
| 93 |
// Admin |
// Permission |
| 94 |
sprintf(sql, "select aid,major from admin_config where UID=%ld" |
sprintf(sql, "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified", |
|
" and enable and (now() between begin_dt and end_dt)", |
|
| 95 |
uid); |
uid); |
| 96 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 97 |
{ |
{ |
| 98 |
log_error("Query admin_config failed\n"); |
log_error("Query user_list failed\n"); |
| 99 |
return -1; |
return -1; |
| 100 |
} |
} |
| 101 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 102 |
{ |
{ |
| 103 |
log_error("Get admin_config data failed\n"); |
log_error("Get user_list data failed\n"); |
| 104 |
return -1; |
return -1; |
| 105 |
} |
} |
| 106 |
if (row = mysql_fetch_row(rs)) |
if (row = mysql_fetch_row(rs)) |
| 107 |
{ |
{ |
| 108 |
p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S); |
p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); |
| 109 |
p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN); |
p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); |
| 110 |
} |
} |
| 111 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 112 |
|
|
| 113 |
// Permission |
// Admin |
| 114 |
sprintf(sql, "select p_post,p_msg,p_mail " |
sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld " |
| 115 |
"from user_list where UID=%ld", |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 116 |
uid); |
uid); |
| 117 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 118 |
{ |
{ |
| 119 |
log_error("Query user_list failed\n"); |
log_error("Query admin_config failed\n"); |
| 120 |
return -1; |
return -1; |
| 121 |
} |
} |
| 122 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 123 |
{ |
{ |
| 124 |
log_error("Get user_list data failed\n"); |
log_error("Get admin_config data failed\n"); |
| 125 |
return -1; |
return -1; |
| 126 |
} |
} |
| 127 |
if (row = mysql_fetch_row(rs)) |
if (row = mysql_fetch_row(rs)) |
| 128 |
{ |
{ |
| 129 |
p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); |
p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S); |
| 130 |
p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); |
p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN); |
|
p_priv->g_priv |= (atoi(row[2]) ? S_MAIL : 0); |
|
| 131 |
} |
} |
| 132 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 133 |
|
|
| 134 |
// Section Master |
// Section Master |
| 135 |
sprintf(sql, "select SID,major from section_master where" |
sprintf(sql, "SELECT section_master.SID, major FROM section_master " |
| 136 |
" UID=%ld and enable and (now() between begin_dt and" |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
| 137 |
" end_dt)", |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
| 138 |
|
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 139 |
uid); |
uid); |
| 140 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 141 |
{ |
{ |
| 155 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 156 |
|
|
| 157 |
// Section status |
// Section status |
| 158 |
sprintf(sql, "select SID,exp_get,read_user_level," |
sprintf(sql, "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config " |
| 159 |
"write_user_level from section_config" |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
| 160 |
" left join section_class on section_config.CID=" |
"WHERE section_config.enable AND section_class.enable " |
| 161 |
"section_class.CID where section_config.enable and" |
"ORDER BY SID"); |
|
" section_class.enable order by SID"); |
|
| 162 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 163 |
{ |
{ |
| 164 |
log_error("Query section_config failed\n"); |
log_error("Query section_config failed\n"); |
| 171 |
} |
} |
| 172 |
while (row = mysql_fetch_row(rs)) |
while (row = mysql_fetch_row(rs)) |
| 173 |
{ |
{ |
| 174 |
|
int priv = getpriv(p_priv, atoi(row[0])); |
| 175 |
if (p_priv->level < atoi(row[2])) |
if (p_priv->level < atoi(row[2])) |
| 176 |
setpriv(p_priv, atoi(row[0]), |
{ |
| 177 |
getpriv(p_priv, atoi(row[0])) & (~S_LIST)); |
priv &= (~S_LIST); |
| 178 |
|
} |
| 179 |
if (p_priv->level < atoi(row[3])) |
if (p_priv->level < atoi(row[3])) |
| 180 |
setpriv(p_priv, atoi(row[0]), |
{ |
| 181 |
getpriv(p_priv, atoi(row[0])) & (~S_POST)); |
priv &= (~S_POST); |
| 182 |
|
} |
| 183 |
if (!atoi(row[1])) |
if (!atoi(row[1])) |
| 184 |
setpriv(p_priv, atoi(row[0]), |
{ |
| 185 |
getpriv(p_priv, atoi(row[0])) & (~S_GETEXP)); |
priv &= (~S_GETEXP); |
| 186 |
} |
} |
| 187 |
mysql_free_result(rs); |
setpriv(p_priv, atoi(row[0]), priv); |
|
|
|
|
// Section User priv |
|
|
sprintf(sql, "select SID,`read`,`write` from section_user_priv" |
|
|
" where UID=%ld order by SID", |
|
|
uid); |
|
|
if (mysql_query(db, sql) != 0) |
|
|
{ |
|
|
log_error("Query section_user_priv failed\n"); |
|
|
return -1; |
|
|
} |
|
|
if ((rs = mysql_store_result(db)) == NULL) |
|
|
{ |
|
|
log_error("Get section_user_priv data failed\n"); |
|
|
return -1; |
|
|
} |
|
|
while (row = mysql_fetch_row(rs)) |
|
|
{ |
|
|
setpriv(p_priv, atoi(row[0]), |
|
|
atoi(row[1]) ? (getpriv(p_priv, atoi(row[0])) | S_LIST) |
|
|
: (getpriv(p_priv, atoi(row[0])) & ~S_LIST)); |
|
|
setpriv(p_priv, atoi(row[0]), |
|
|
atoi(row[2]) ? (getpriv(p_priv, atoi(row[0])) | S_POST) |
|
|
: (getpriv(p_priv, atoi(row[0])) & ~S_POST)); |
|
| 188 |
} |
} |
| 189 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 190 |
|
|
| 191 |
// Section ban |
// Section ban |
| 192 |
sprintf(sql, "select SID from ban_user_list where" |
sprintf(sql, "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable " |
| 193 |
" UID=%ld and enable and unban_UID=0 and" |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
|
" (now() between ban_dt and unban_dt)", |
|
| 194 |
uid); |
uid); |
| 195 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 196 |
{ |
{ |