/[LeafOK_CVS]/lbbs/src/user_priv.c
ViewVC logotype

Diff of /lbbs/src/user_priv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.18 by sysadm, Fri May 30 04:28:27 2025 UTC Revision 1.24 by sysadm, Tue Nov 4 14:58:56 2025 UTC
# Line 1  Line 1 
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-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
 #include "user_priv.h"  
9  #include "bbs.h"  #include "bbs.h"
10  #include "common.h"  #include "common.h"
11  #include "database.h"  #include "database.h"
12  #include "log.h"  #include "log.h"
13    #include "user_priv.h"
14  #include <stdio.h>  #include <stdio.h>
 #include <mysql.h>  
15  #include <stdlib.h>  #include <stdlib.h>
16    #include <mysql/mysql.h>
17    
18  BBS_user_priv BBS_priv;  BBS_user_priv BBS_priv;
19    
# Line 35  inline static int search_priv(BBS_user_p Line 27  inline static int search_priv(BBS_user_p
27          {          {
28                  mid = (left + right) / 2;                  mid = (left + right) / 2;
29    
30                  if (sid <= p_priv->s_priv_list[mid].sid)                  if (sid < p_priv->s_priv_list[mid].sid)
31                  {                  {
32                          right = mid;                          right = mid - 1;
33                  }                  }
34                  else                  else if (sid > p_priv->s_priv_list[mid].sid)
35                  {                  {
36                          left = mid + 1;                          left = mid + 1;
37                  }                  }
38                    else // if (sid == p_priv->s_priv_list[mid].sid)
39                    {
40                            left = mid;
41                            break;
42                    }
43          }          }
44    
45          *p_offset = left;          *p_offset = left;
46    
47          return (left == right && sid == p_priv->s_priv_list[left].sid);          return (sid == p_priv->s_priv_list[left].sid);
48  }  }
49    
50  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)
# Line 61  int setpriv(BBS_user_priv *p_priv, int s Line 58  int setpriv(BBS_user_priv *p_priv, int s
58                  return 0;                  return 0;
59          }          }
60    
61          if (search_priv(p_priv, sid, &offset)) //found          if (search_priv(p_priv, sid, &offset)) // found
62          {          {
63                  p_priv->s_priv_list[offset].s_priv = priv;                  p_priv->s_priv_list[offset].s_priv = priv;
64                  p_priv->s_priv_list[offset].is_favor = is_favor;                  p_priv->s_priv_list[offset].is_favor = is_favor;
# Line 93  int getpriv(BBS_user_priv *p_priv, int s Line 90  int getpriv(BBS_user_priv *p_priv, int s
90  {  {
91          int offset;          int offset;
92    
93          if (search_priv(p_priv, sid, &offset)) //found          if (search_priv(p_priv, sid, &offset)) // found
94          {          {
95                  *p_is_favor = p_priv->s_priv_list[offset].is_favor;                  *p_is_favor = p_priv->s_priv_list[offset].is_favor;
96                  return p_priv->s_priv_list[offset].s_priv;                  return p_priv->s_priv_list[offset].s_priv;
# Line 103  int getpriv(BBS_user_priv *p_priv, int s Line 100  int getpriv(BBS_user_priv *p_priv, int s
100          return (sid >= 0 ? p_priv->g_priv : S_NONE);          return (sid >= 0 ? p_priv->g_priv : S_NONE);
101  }  }
102    
103  int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)  int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid)
104  {  {
105          MYSQL_RES *rs;          MYSQL_RES *rs;
106          MYSQL_ROW row;          MYSQL_ROW row;
# Line 121  int load_priv(MYSQL *db, BBS_user_priv * Line 118  int load_priv(MYSQL *db, BBS_user_priv *
118    
119          // Permission          // Permission
120          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
121                           "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",                           "SELECT p_post, p_msg FROM user_list WHERE UID = %d AND verified",
122                           uid);                           uid);
123          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
124          {          {
# Line 142  int load_priv(MYSQL *db, BBS_user_priv * Line 139  int load_priv(MYSQL *db, BBS_user_priv *
139    
140          // Admin          // Admin
141          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
142                           "SELECT major FROM admin_config WHERE UID = %ld "                           "SELECT major FROM admin_config WHERE UID = %d "
143                           "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",                           "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",
144                           uid);                           uid);
145          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 166  int load_priv(MYSQL *db, BBS_user_priv * Line 163  int load_priv(MYSQL *db, BBS_user_priv *
163          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
164                           "SELECT section_master.SID, major FROM section_master "                           "SELECT section_master.SID, major FROM section_master "
165                           "INNER JOIN section_config ON section_master.SID = section_config.SID "                           "INNER JOIN section_config ON section_master.SID = section_config.SID "
166                           "WHERE UID = %ld AND section_master.enable AND section_config.enable "                           "WHERE UID = %d AND section_master.enable AND section_config.enable "
167                           "AND (NOW() BETWEEN begin_dt AND end_dt)",                           "AND (NOW() BETWEEN begin_dt AND end_dt)",
168                           uid);                           uid);
169          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 224  int load_priv(MYSQL *db, BBS_user_priv * Line 221  int load_priv(MYSQL *db, BBS_user_priv *
221    
222          // Section ban          // Section ban
223          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
224                           "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "                           "SELECT SID FROM ban_user_list WHERE UID = %d AND enable "
225                           "AND (NOW() BETWEEN ban_dt AND unban_dt)",                           "AND (NOW() BETWEEN ban_dt AND unban_dt)",
226                           uid);                           uid);
227          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 246  int load_priv(MYSQL *db, BBS_user_priv * Line 243  int load_priv(MYSQL *db, BBS_user_priv *
243    
244          // User favor section          // User favor section
245          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
246                           "SELECT SID FROM section_favorite WHERE UID = %ld",                           "SELECT SID FROM section_favorite WHERE UID = %d",
247                           uid);                           uid);
248          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
249          {          {


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1