| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
user_priv.c - description |
/* |
| 3 |
------------------- |
* user_priv |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - basic operations of user privilege |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "common.h" |
#include "common.h" |
| 17 |
#include "user_priv.h" |
#include "user_priv.h" |
| 18 |
#include <stdio.h> |
#include <stdio.h> |
| 19 |
#include <stdlib.h> |
#include <stdlib.h> |
| 20 |
#include <mysql/mysql.h> |
#include <mysql.h> |
| 21 |
|
|
| 22 |
BBS_user_priv BBS_priv; |
BBS_user_priv BBS_priv; |
| 23 |
|
|
| 24 |
|
// External definitions for inline functions |
| 25 |
|
extern inline int checklevel(BBS_user_priv *p_priv, int level); |
| 26 |
|
extern inline int checklevel2(BBS_user_priv *p_priv, int level); |
| 27 |
|
extern inline int checkpriv(BBS_user_priv *p_priv, int sid, int priv); |
| 28 |
|
extern inline int is_favor(BBS_user_priv *p_priv, int sid); |
| 29 |
|
|
| 30 |
inline static int search_priv(BBS_user_priv *p_priv, int sid, int *p_offset) |
inline static int search_priv(BBS_user_priv *p_priv, int sid, int *p_offset) |
| 31 |
{ |
{ |
| 32 |
int left = 0; |
int left = 0; |
| 37 |
{ |
{ |
| 38 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 39 |
|
|
| 40 |
if (sid <= p_priv->s_priv_list[mid].sid) |
if (sid < p_priv->s_priv_list[mid].sid) |
| 41 |
{ |
{ |
| 42 |
right = mid; |
right = mid - 1; |
| 43 |
} |
} |
| 44 |
else |
else if (sid > p_priv->s_priv_list[mid].sid) |
| 45 |
{ |
{ |
| 46 |
left = mid + 1; |
left = mid + 1; |
| 47 |
} |
} |
| 48 |
|
else // if (sid == p_priv->s_priv_list[mid].sid) |
| 49 |
|
{ |
| 50 |
|
left = mid; |
| 51 |
|
break; |
| 52 |
|
} |
| 53 |
} |
} |
| 54 |
|
|
| 55 |
*p_offset = left; |
*p_offset = left; |
| 56 |
|
|
| 57 |
return (left == right && sid == p_priv->s_priv_list[left].sid); |
return (sid == p_priv->s_priv_list[left].sid); |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor) |
int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor) |
| 68 |
return 0; |
return 0; |
| 69 |
} |
} |
| 70 |
|
|
| 71 |
if (search_priv(p_priv, sid, &offset)) //found |
if (search_priv(p_priv, sid, &offset)) // found |
| 72 |
{ |
{ |
| 73 |
p_priv->s_priv_list[offset].s_priv = priv; |
p_priv->s_priv_list[offset].s_priv = priv; |
| 74 |
p_priv->s_priv_list[offset].is_favor = is_favor; |
p_priv->s_priv_list[offset].is_favor = is_favor; |
| 100 |
{ |
{ |
| 101 |
int offset; |
int offset; |
| 102 |
|
|
| 103 |
if (search_priv(p_priv, sid, &offset)) //found |
if (search_priv(p_priv, sid, &offset)) // found |
| 104 |
{ |
{ |
| 105 |
*p_is_favor = p_priv->s_priv_list[offset].is_favor; |
*p_is_favor = p_priv->s_priv_list[offset].is_favor; |
| 106 |
return p_priv->s_priv_list[offset].s_priv; |
return p_priv->s_priv_list[offset].s_priv; |
| 132 |
uid); |
uid); |
| 133 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 134 |
{ |
{ |
| 135 |
log_error("Query user_list error: %s\n", mysql_error(db)); |
log_error("Query user_list error: %s", mysql_error(db)); |
| 136 |
return -1; |
return -1; |
| 137 |
} |
} |
| 138 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 139 |
{ |
{ |
| 140 |
log_error("Get user_list data failed\n"); |
log_error("Get user_list data failed"); |
| 141 |
return -1; |
return -1; |
| 142 |
} |
} |
| 143 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 154 |
uid); |
uid); |
| 155 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 156 |
{ |
{ |
| 157 |
log_error("Query admin_config error: %s\n", mysql_error(db)); |
log_error("Query admin_config error: %s", mysql_error(db)); |
| 158 |
return -1; |
return -1; |
| 159 |
} |
} |
| 160 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 161 |
{ |
{ |
| 162 |
log_error("Get admin_config data failed\n"); |
log_error("Get admin_config data failed"); |
| 163 |
return -1; |
return -1; |
| 164 |
} |
} |
| 165 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 178 |
uid); |
uid); |
| 179 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 180 |
{ |
{ |
| 181 |
log_error("Query section_master error: %s\n", mysql_error(db)); |
log_error("Query section_master error: %s", mysql_error(db)); |
| 182 |
return -1; |
return -1; |
| 183 |
} |
} |
| 184 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 185 |
{ |
{ |
| 186 |
log_error("Get section_master data failed\n"); |
log_error("Get section_master data failed"); |
| 187 |
return -1; |
return -1; |
| 188 |
} |
} |
| 189 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 202 |
"ORDER BY SID"); |
"ORDER BY SID"); |
| 203 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 204 |
{ |
{ |
| 205 |
log_error("Query section_config error: %s\n", mysql_error(db)); |
log_error("Query section_config error: %s", mysql_error(db)); |
| 206 |
return -1; |
return -1; |
| 207 |
} |
} |
| 208 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 209 |
{ |
{ |
| 210 |
log_error("Get section_config data failed\n"); |
log_error("Get section_config data failed"); |
| 211 |
return -1; |
return -1; |
| 212 |
} |
} |
| 213 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 236 |
uid); |
uid); |
| 237 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 238 |
{ |
{ |
| 239 |
log_error("Query ban_user_list error: %s\n", mysql_error(db)); |
log_error("Query ban_user_list error: %s", mysql_error(db)); |
| 240 |
return -1; |
return -1; |
| 241 |
} |
} |
| 242 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 243 |
{ |
{ |
| 244 |
log_error("Get ban_user_list data failed\n"); |
log_error("Get ban_user_list data failed"); |
| 245 |
return -1; |
return -1; |
| 246 |
} |
} |
| 247 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 257 |
uid); |
uid); |
| 258 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 259 |
{ |
{ |
| 260 |
log_error("Query section_favorite error: %s\n", mysql_error(db)); |
log_error("Query section_favorite error: %s", mysql_error(db)); |
| 261 |
return -1; |
return -1; |
| 262 |
} |
} |
| 263 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 264 |
{ |
{ |
| 265 |
log_error("Get section_favorite data failed\n"); |
log_error("Get section_favorite data failed"); |
| 266 |
return -1; |
return -1; |
| 267 |
} |
} |
| 268 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |