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