/[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.6 by sysadm, Mon Apr 28 04:23:38 2025 UTC Revision 1.9 by sysadm, Fri May 2 02:19:18 2025 UTC
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "user_priv.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "common.h"  #include "common.h"
21    #include "log.h"
22    #include <stdio.h>
23  #include <mysql.h>  #include <mysql.h>
24    
25    BBS_user_priv BBS_priv;
26    
27  int checklevel(BBS_user_priv *p_priv, int level)  int checklevel(BBS_user_priv *p_priv, int level)
28  {  {
29          return (((p_priv->level & level)) ^ level ? 0 : 1);          if (level == P_GUEST)
30            {
31                    return 1;
32            }
33    
34            return ((p_priv->level & level) ? 1 : 0);
35  }  }
36    
37  int setpriv(BBS_user_priv *p_priv, int sid, int priv)  int setpriv(BBS_user_priv *p_priv, int sid, int priv)
# Line 68  int getpriv(BBS_user_priv *p_priv, int s Line 78  int getpriv(BBS_user_priv *p_priv, int s
78    
79  int checkpriv(BBS_user_priv *p_priv, int sid, int priv)  int checkpriv(BBS_user_priv *p_priv, int sid, int priv)
80  {  {
81          return (((getpriv(p_priv, sid) & priv)) ^ priv ? 0 : 1);          return (((getpriv(p_priv, sid) & priv)) == priv ? 1 : 0);
82  }  }
83    
84  int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)  int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)
# Line 85  int load_priv(MYSQL *db, BBS_user_priv * Line 95  int load_priv(MYSQL *db, BBS_user_priv *
95          if (db == NULL)          if (db == NULL)
96                  return 1;                  return 1;
97    
98          // Admin          // Permission
99          sprintf(sql, "select aid,major from admin_config where UID=%ld"          sprintf(sql, "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",
                                  " and enable and (now() between begin_dt and end_dt)",  
100                          uid);                          uid);
101          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
102          {          {
103                  log_error("Query admin_config failed\n");                  log_error("Query user_list failed\n");
104                  return -1;                  return -1;
105          }          }
106          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
107          {          {
108                  log_error("Get admin_config data failed\n");                  log_error("Get user_list data failed\n");
109                  return -1;                  return -1;
110          }          }
111          if (row = mysql_fetch_row(rs))          if (row = mysql_fetch_row(rs))
112          {          {
113                  p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S);                  p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0);
114                  p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN);                  p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0);
115          }          }
116          mysql_free_result(rs);          mysql_free_result(rs);
117    
118          // Permission          // Admin
119          sprintf(sql, "select p_post,p_msg,p_mail "          sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld "
120                                   "from user_list where UID=%ld",                                   "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",
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 admin_config failed\n");
125                  return -1;                  return -1;
126          }          }
127          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
128          {          {
129                  log_error("Get user_list data failed\n");                  log_error("Get admin_config data failed\n");
130                  return -1;                  return -1;
131          }          }
132          if (row = mysql_fetch_row(rs))          if (row = mysql_fetch_row(rs))
133          {          {
134                  p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0);                  p_priv->level |= (atoi(row[0]) ? P_ADMIN_M : P_ADMIN_S);
135                  p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0);                  p_priv->g_priv |= (atoi(row[0]) ? S_ALL : S_ADMIN);
                 p_priv->g_priv |= (atoi(row[2]) ? S_MAIL : 0);  
136          }          }
137          mysql_free_result(rs);          mysql_free_result(rs);
138    
139          // Section Master          // Section Master
140          sprintf(sql, "select SID,major from section_master where"          sprintf(sql, "SELECT section_master.SID, major FROM section_master "
141                                   " UID=%ld and enable and (now() between begin_dt and"                                   "INNER JOIN section_config ON section_master.SID = section_config.SID "
142                                   " end_dt)",                                   "WHERE UID = %ld AND section_master.enable AND section_config.enable "
143                                     "AND (NOW() BETWEEN begin_dt AND end_dt)",
144                          uid);                          uid);
145          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
146          {          {
# Line 151  int load_priv(MYSQL *db, BBS_user_priv * Line 160  int load_priv(MYSQL *db, BBS_user_priv *
160          mysql_free_result(rs);          mysql_free_result(rs);
161    
162          // Section status          // Section status
163          sprintf(sql, "select SID,exp_get,read_user_level,"          sprintf(sql, "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config "
164                                   "write_user_level from section_config"                                   "INNER JOIN section_class ON section_config.CID = section_class.CID "
165                                   " left join section_class on section_config.CID="                                   "WHERE section_config.enable AND section_class.enable "
166                                   "section_class.CID where section_config.enable and"                                   "ORDER BY SID");
                                  " section_class.enable order by SID");  
167          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
168          {          {
169                  log_error("Query section_config failed\n");                  log_error("Query section_config failed\n");
# Line 168  int load_priv(MYSQL *db, BBS_user_priv * Line 176  int load_priv(MYSQL *db, BBS_user_priv *
176          }          }
177          while (row = mysql_fetch_row(rs))          while (row = mysql_fetch_row(rs))
178          {          {
179                    int priv = getpriv(p_priv, atoi(row[0]));
180                  if (p_priv->level < atoi(row[2]))                  if (p_priv->level < atoi(row[2]))
181                          setpriv(p_priv, atoi(row[0]),                  {
182                                          getpriv(p_priv, atoi(row[0])) & (~S_LIST));                          priv &= (~S_LIST);
183                    }
184                  if (p_priv->level < atoi(row[3]))                  if (p_priv->level < atoi(row[3]))
185                          setpriv(p_priv, atoi(row[0]),                  {
186                                          getpriv(p_priv, atoi(row[0])) & (~S_POST));                          priv &= (~S_POST);
187                    }
188                  if (!atoi(row[1]))                  if (!atoi(row[1]))
189                          setpriv(p_priv, atoi(row[0]),                  {
190                                          getpriv(p_priv, atoi(row[0])) & (~S_GETEXP));                          priv &= (~S_GETEXP);
191          }                  }
192          mysql_free_result(rs);                  setpriv(p_priv, atoi(row[0]), priv);
   
         // Section User priv  
         sprintf(sql, "select SID,`read`,`write` from section_user_priv"  
                                  " where UID=%ld order by SID",  
                         uid);  
         if (mysql_query(db, sql) != 0)  
         {  
                 log_error("Query section_user_priv failed\n");  
                 return -1;  
         }  
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get section_user_priv data failed\n");  
                 return -1;  
         }  
         while (row = mysql_fetch_row(rs))  
         {  
                 setpriv(p_priv, atoi(row[0]),  
                                 atoi(row[1]) ? (getpriv(p_priv, atoi(row[0])) | S_LIST)  
                                                          : (getpriv(p_priv, atoi(row[0])) & ~S_LIST));  
                 setpriv(p_priv, atoi(row[0]),  
                                 atoi(row[2]) ? (getpriv(p_priv, atoi(row[0])) | S_POST)  
                                                          : (getpriv(p_priv, atoi(row[0])) & ~S_POST));  
193          }          }
194          mysql_free_result(rs);          mysql_free_result(rs);
195    
196          // Section ban          // Section ban
197          sprintf(sql, "select SID from ban_user_list where"          sprintf(sql, "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "
198                                   " UID=%ld and enable and unban_UID=0 and"                                   "AND (NOW() BETWEEN ban_dt AND unban_dt)",
                                  " (now() between ban_dt and unban_dt)",  
199                          uid);                          uid);
200          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
201          {          {


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

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