/[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.16 by sysadm, Fri May 30 00:58:02 2025 UTC Revision 1.17 by sysadm, Fri May 30 02:56:02 2025 UTC
# Line 25  Line 25 
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, int is_favor)
29  {  {
30          int left = 0;          int left = 0;
31          int right = p_priv->s_count - 1;          int right = p_priv->s_count - 1;
32          int mid;          int mid = 0;
33    
34          if (sid == 0)          if (sid == 0)
35          {          {
# Line 51  int setpriv(BBS_user_priv *p_priv, int s Line 51  int setpriv(BBS_user_priv *p_priv, int s
51                  }                  }
52          }          }
53    
54          if (sid == p_priv->s_priv_list[left].sid) // found          if (left == right && sid == p_priv->s_priv_list[left].sid) // found
55          {          {
56                  p_priv->s_priv_list[left].s_priv = priv;                  p_priv->s_priv_list[left].s_priv = priv;
57                    p_priv->s_priv_list[left].is_favor = is_favor;
58                  return 0;                  return 0;
59          }          }
60    
# Line 68  int setpriv(BBS_user_priv *p_priv, int s Line 69  int setpriv(BBS_user_priv *p_priv, int s
69          {          {
70                  p_priv->s_priv_list[right + 1] = p_priv->s_priv_list[right];                  p_priv->s_priv_list[right + 1] = p_priv->s_priv_list[right];
71          }          }
72            p_priv->s_count++;
73    
74          // insert new item at offset left          // insert new item at offset left
75            p_priv->s_priv_list[left].sid = sid;
76          p_priv->s_priv_list[left].s_priv = priv;          p_priv->s_priv_list[left].s_priv = priv;
77            p_priv->s_priv_list[left].is_favor = is_favor;
78    
79          return 0;          return 0;
80  }  }
81    
82  int getpriv(BBS_user_priv *p_priv, int sid)  int getpriv(BBS_user_priv *p_priv, int sid, int *p_is_favor)
83  {  {
84          int left = 0;          int left = 0;
85          int right = p_priv->s_count - 1;          int right = p_priv->s_count - 1;
86          int mid;          int mid = 0;
87    
88          while (left < right)          while (left < right)
89          {          {
# Line 94  int getpriv(BBS_user_priv *p_priv, int s Line 99  int getpriv(BBS_user_priv *p_priv, int s
99                  }                  }
100          }          }
101    
102          if (sid == p_priv->s_priv_list[left].sid) // found          if (left == right && sid == p_priv->s_priv_list[left].sid) // found
103          {          {
104                    *p_is_favor = p_priv->s_priv_list[left].is_favor;
105                  return p_priv->s_priv_list[left].s_priv;                  return p_priv->s_priv_list[left].s_priv;
106          }          }
107    
108            if (sid != 0)
109            {
110                    *p_is_favor = 0;
111            }
112    
113          return (sid >= 0 ? p_priv->g_priv : S_NONE);          return (sid >= 0 ? p_priv->g_priv : S_NONE);
114  }  }
115    
# Line 107  int load_priv(MYSQL *db, BBS_user_priv * Line 118  int load_priv(MYSQL *db, BBS_user_priv *
118          MYSQL_RES *rs;          MYSQL_RES *rs;
119          MYSQL_ROW row;          MYSQL_ROW row;
120          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
121            int priv;
122            int is_favor;
123    
124          p_priv->uid = uid;          p_priv->uid = uid;
125          p_priv->level = (uid == 0 ? P_GUEST : P_USER);          p_priv->level = (uid == 0 ? P_GUEST : P_USER);
# Line 117  int load_priv(MYSQL *db, BBS_user_priv * Line 130  int load_priv(MYSQL *db, BBS_user_priv *
130                  return 1;                  return 1;
131    
132          // Permission          // Permission
133          snprintf(sql, sizeof(sql), "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",          snprintf(sql, sizeof(sql),
134                             "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",
135                           uid);                           uid);
136          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
137          {          {
# Line 137  int load_priv(MYSQL *db, BBS_user_priv * Line 151  int load_priv(MYSQL *db, BBS_user_priv *
151          mysql_free_result(rs);          mysql_free_result(rs);
152    
153          // Admin          // Admin
154          snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld "          snprintf(sql, sizeof(sql),
155                                                             "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",                           "SELECT major FROM admin_config WHERE UID = %ld "
156                             "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",
157                           uid);                           uid);
158          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
159          {          {
# Line 158  int load_priv(MYSQL *db, BBS_user_priv * Line 173  int load_priv(MYSQL *db, BBS_user_priv *
173          mysql_free_result(rs);          mysql_free_result(rs);
174    
175          // Section Master          // Section Master
176          snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master "          snprintf(sql, sizeof(sql),
177                                                             "INNER JOIN section_config ON section_master.SID = section_config.SID "                           "SELECT section_master.SID, major FROM section_master "
178                                                             "WHERE UID = %ld AND section_master.enable AND section_config.enable "                           "INNER JOIN section_config ON section_master.SID = section_config.SID "
179                                                             "AND (NOW() BETWEEN begin_dt AND end_dt)",                           "WHERE UID = %ld AND section_master.enable AND section_config.enable "
180                             "AND (NOW() BETWEEN begin_dt AND end_dt)",
181                           uid);                           uid);
182          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
183          {          {
# Line 176  int load_priv(MYSQL *db, BBS_user_priv * Line 192  int load_priv(MYSQL *db, BBS_user_priv *
192          while ((row = mysql_fetch_row(rs)))          while ((row = mysql_fetch_row(rs)))
193          {          {
194                  p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S);                  p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S);
195                  setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S));                  priv = (getpriv(p_priv, atoi(row[0]), &is_favor) | (atoi(row[1]) ? S_MAN_M : S_MAN_S));
196                    setpriv(p_priv, atoi(row[0]), priv, is_favor);
197          }          }
198          mysql_free_result(rs);          mysql_free_result(rs);
199    
200          // Section status          // Section status
201          snprintf(sql, sizeof(sql), "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config "          snprintf(sql, sizeof(sql),
202                                                             "INNER JOIN section_class ON section_config.CID = section_class.CID "                           "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config "
203                                                             "WHERE section_config.enable AND section_class.enable "                           "INNER JOIN section_class ON section_config.CID = section_class.CID "
204                                                             "ORDER BY SID");                           "WHERE section_config.enable AND section_class.enable "
205                             "ORDER BY SID");
206          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
207          {          {
208                  log_error("Query section_config error: %s\n", mysql_error(db));                  log_error("Query section_config error: %s\n", mysql_error(db));
# Line 197  int load_priv(MYSQL *db, BBS_user_priv * Line 215  int load_priv(MYSQL *db, BBS_user_priv *
215          }          }
216          while ((row = mysql_fetch_row(rs)))          while ((row = mysql_fetch_row(rs)))
217          {          {
218                  int priv = getpriv(p_priv, atoi(row[0]));                  int priv = getpriv(p_priv, atoi(row[0]), &is_favor);
219                  if (p_priv->level < atoi(row[2]))                  if (p_priv->level < atoi(row[2]))
220                  {                  {
221                          priv &= (~S_LIST);                          priv &= (~S_LIST);
# Line 210  int load_priv(MYSQL *db, BBS_user_priv * Line 228  int load_priv(MYSQL *db, BBS_user_priv *
228                  {                  {
229                          priv &= (~S_GETEXP);                          priv &= (~S_GETEXP);
230                  }                  }
231                  setpriv(p_priv, atoi(row[0]), priv);                  setpriv(p_priv, atoi(row[0]), priv, is_favor);
232          }          }
233          mysql_free_result(rs);          mysql_free_result(rs);
234    
235          // Section ban          // Section ban
236          snprintf(sql, sizeof(sql), "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "          snprintf(sql, sizeof(sql),
237                                                             "AND (NOW() BETWEEN ban_dt AND unban_dt)",                           "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "
238                             "AND (NOW() BETWEEN ban_dt AND unban_dt)",
239                           uid);                           uid);
240          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
241          {          {
# Line 230  int load_priv(MYSQL *db, BBS_user_priv * Line 249  int load_priv(MYSQL *db, BBS_user_priv *
249          }          }
250          while ((row = mysql_fetch_row(rs)))          while ((row = mysql_fetch_row(rs)))
251          {          {
252                  setpriv(p_priv, atoi(row[0]),                  priv = getpriv(p_priv, atoi(row[0]), &is_favor) & (~S_POST);
253                                  getpriv(p_priv, atoi(row[0])) & (~S_POST));                  setpriv(p_priv, atoi(row[0]), priv, is_favor);
254            }
255            mysql_free_result(rs);
256    
257            // User favor section
258            snprintf(sql, sizeof(sql),
259                             "SELECT SID FROM section_favorite WHERE UID = %ld",
260                             uid);
261            if (mysql_query(db, sql) != 0)
262            {
263                    log_error("Query section_favorite error: %s\n", mysql_error(db));
264                    return -1;
265            }
266            if ((rs = mysql_store_result(db)) == NULL)
267            {
268                    log_error("Get section_favorite data failed\n");
269                    return -1;
270            }
271            while ((row = mysql_fetch_row(rs)))
272            {
273                    priv = getpriv(p_priv, atoi(row[0]), &is_favor);
274                    if (!is_favor)
275                    {
276                            setpriv(p_priv, atoi(row[0]), priv, 1);
277                            priv = getpriv(p_priv, atoi(row[0]), &is_favor);
278                    }
279          }          }
280          mysql_free_result(rs);          mysql_free_result(rs);
281    


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

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