| 21 |
#include "log.h" |
#include "log.h" |
| 22 |
#include <stdio.h> |
#include <stdio.h> |
| 23 |
#include <mysql.h> |
#include <mysql.h> |
| 24 |
|
#include <stdlib.h> |
| 25 |
|
|
| 26 |
BBS_user_priv BBS_priv; |
BBS_user_priv BBS_priv; |
| 27 |
|
|
| 28 |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
int setpriv(BBS_user_priv *p_priv, int sid, int priv) |
| 29 |
{ |
{ |
| 30 |
int i; |
int left = 0; |
| 31 |
if (sid > 0) |
int right = p_priv->s_count - 1; |
| 32 |
|
int mid; |
| 33 |
|
|
| 34 |
|
if (sid == 0) |
| 35 |
{ |
{ |
| 36 |
for (i = 0; i < p_priv->s_count; i++) |
p_priv->g_priv = priv; |
| 37 |
{ |
return 0; |
| 38 |
if (p_priv->s_priv_list[i].sid == sid) |
} |
| 39 |
{ |
|
| 40 |
p_priv->s_priv_list[i].s_priv = priv; |
while (left < right) |
| 41 |
return 0; |
{ |
| 42 |
} |
mid = (left + right) / 2; |
| 43 |
} |
|
| 44 |
if (i < BBS_max_section) |
if (sid <= p_priv->s_priv_list[mid].sid) |
| 45 |
{ |
{ |
| 46 |
p_priv->s_priv_list[i].s_priv = priv; |
right = mid; |
| 47 |
} |
} |
| 48 |
else |
else |
| 49 |
{ |
{ |
| 50 |
return -1; |
left = mid + 1; |
| 51 |
} |
} |
| 52 |
} |
} |
| 53 |
else |
|
| 54 |
|
if (sid == p_priv->s_priv_list[left].sid) // found |
| 55 |
{ |
{ |
| 56 |
p_priv->g_priv = priv; |
p_priv->s_priv_list[left].s_priv = priv; |
| 57 |
|
return 0; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
// not found |
| 61 |
|
if (p_priv->s_count >= BBS_max_section) |
| 62 |
|
{ |
| 63 |
|
return -1; |
| 64 |
} |
} |
| 65 |
|
|
| 66 |
|
// move items at [left, p_priv->s_count - 1] to [left + 1, p_priv->s_count] |
| 67 |
|
for (right = p_priv->s_count - 1; right >= left; right--) |
| 68 |
|
{ |
| 69 |
|
p_priv->s_priv_list[right + 1] = p_priv->s_priv_list[right]; |
| 70 |
|
} |
| 71 |
|
// insert new item at offset left |
| 72 |
|
p_priv->s_priv_list[left].s_priv = priv; |
| 73 |
|
|
| 74 |
return 0; |
return 0; |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
int getpriv(BBS_user_priv *p_priv, int sid) |
int getpriv(BBS_user_priv *p_priv, int sid) |
| 78 |
{ |
{ |
| 79 |
int i; |
int left = 0; |
| 80 |
for (i = 0; i < p_priv->s_count; i++) |
int right = p_priv->s_count - 1; |
| 81 |
|
int mid; |
| 82 |
|
|
| 83 |
|
while (left < right) |
| 84 |
|
{ |
| 85 |
|
mid = (left + right) / 2; |
| 86 |
|
|
| 87 |
|
if (sid <= p_priv->s_priv_list[mid].sid) |
| 88 |
|
{ |
| 89 |
|
right = mid; |
| 90 |
|
} |
| 91 |
|
else |
| 92 |
|
{ |
| 93 |
|
left = mid + 1; |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
if (sid == p_priv->s_priv_list[left].sid) // found |
| 98 |
{ |
{ |
| 99 |
if (p_priv->s_priv_list[i].sid == sid) |
return p_priv->s_priv_list[left].s_priv; |
|
return p_priv->s_priv_list[i].s_priv; |
|
| 100 |
} |
} |
| 101 |
|
|
| 102 |
return (sid >= 0 ? p_priv->g_priv : S_NONE); |
return (sid >= 0 ? p_priv->g_priv : S_NONE); |
| 118 |
|
|
| 119 |
// Permission |
// Permission |
| 120 |
snprintf(sql, sizeof(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", |
| 121 |
uid); |
uid); |
| 122 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 123 |
{ |
{ |
| 124 |
log_error("Query user_list failed\n"); |
log_error("Query user_list error: %s\n", mysql_error(db)); |
| 125 |
return -1; |
return -1; |
| 126 |
} |
} |
| 127 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 138 |
|
|
| 139 |
// Admin |
// Admin |
| 140 |
snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld " |
snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld " |
| 141 |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 142 |
uid); |
uid); |
| 143 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 144 |
{ |
{ |
| 145 |
log_error("Query admin_config failed\n"); |
log_error("Query admin_config error: %s\n", mysql_error(db)); |
| 146 |
return -1; |
return -1; |
| 147 |
} |
} |
| 148 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 159 |
|
|
| 160 |
// Section Master |
// Section Master |
| 161 |
snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master " |
snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master " |
| 162 |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
"INNER JOIN section_config ON section_master.SID = section_config.SID " |
| 163 |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
"WHERE UID = %ld AND section_master.enable AND section_config.enable " |
| 164 |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
"AND (NOW() BETWEEN begin_dt AND end_dt)", |
| 165 |
uid); |
uid); |
| 166 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 167 |
{ |
{ |
| 168 |
log_error("Query section_master failed\n"); |
log_error("Query section_master error: %s\n", mysql_error(db)); |
| 169 |
return -1; |
return -1; |
| 170 |
} |
} |
| 171 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 182 |
|
|
| 183 |
// Section status |
// Section status |
| 184 |
snprintf(sql, sizeof(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 " |
| 185 |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
"INNER JOIN section_class ON section_config.CID = section_class.CID " |
| 186 |
"WHERE section_config.enable AND section_class.enable " |
"WHERE section_config.enable AND section_class.enable " |
| 187 |
"ORDER BY SID"); |
"ORDER BY SID"); |
| 188 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 189 |
{ |
{ |
| 190 |
log_error("Query section_config failed\n"); |
log_error("Query section_config error: %s\n", mysql_error(db)); |
| 191 |
return -1; |
return -1; |
| 192 |
} |
} |
| 193 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 216 |
|
|
| 217 |
// Section ban |
// Section ban |
| 218 |
snprintf(sql, sizeof(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 " |
| 219 |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
"AND (NOW() BETWEEN ban_dt AND unban_dt)", |
| 220 |
uid); |
uid); |
| 221 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 222 |
{ |
{ |
| 223 |
log_error("Query ban_user_list failed\n"); |
log_error("Query ban_user_list error: %s\n", mysql_error(db)); |
| 224 |
return -1; |
return -1; |
| 225 |
} |
} |
| 226 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |