/[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.1 by sysadm, Fri Oct 22 15:21:28 2004 UTC Revision 1.8 by sysadm, Wed Apr 30 09:18:20 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            user_priv.c  -  description                                                    user_priv.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 22 2004          begin                : Mon Oct 22 2004
5      copyright            : (C) 2004 by Leaflet          copyright            : (C) 2004 by Leaflet
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "user_priv.h"
19  #include "bbs.h"  #include "bbs.h"
20    #include "common.h"
21    #include "log.h"
22    #include <stdio.h>
23  #include <mysql.h>  #include <mysql.h>
24    
25  int  BBS_user_priv BBS_priv;
26  load_priv (MYSQL * db, BBS_user_priv * p_priv, int uid,  
27    int auth_uid, int priv_excluse)  int checklevel(BBS_user_priv *p_priv, int level)
28    {
29            return (((p_priv->level & level)) ^ level ? 0 : 1);
30    }
31    
32    int setpriv(BBS_user_priv *p_priv, int sid, int priv)
33    {
34            int i;
35            if (sid > 0)
36            {
37                    for (i = 0; i < p_priv->s_count; i++)
38                    {
39                            if (p_priv->s_priv_list[i].sid == sid)
40                            {
41                                    p_priv->s_priv_list[i].s_priv = priv;
42                                    return 0;
43                            }
44                    }
45                    if (i < BBS_max_section)
46                    {
47                            p_priv->s_priv_list[i].s_priv = priv;
48                    }
49                    else
50                    {
51                            return -1;
52                    }
53            }
54            else
55            {
56                    p_priv->g_priv = priv;
57            }
58    
59            return 0;
60    }
61    
62    int getpriv(BBS_user_priv *p_priv, int sid)
63    {
64            int i;
65            for (i = 0; i < p_priv->s_count; i++)
66            {
67                    if (p_priv->s_priv_list[i].sid == sid)
68                            return p_priv->s_priv_list[i].s_priv;
69            }
70    
71            return (sid >= 0 ? p_priv->g_priv : S_NONE);
72    }
73    
74    int checkpriv(BBS_user_priv *p_priv, int sid, int priv)
75    {
76            return (((getpriv(p_priv, sid) & priv)) ^ priv ? 0 : 1);
77    }
78    
79    int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)
80  {  {
81            MYSQL_RES *rs;
82            MYSQL_ROW row;
83            char sql[1024];
84            int i;
85    
86            p_priv->uid = uid;
87            p_priv->level = (uid == 0 ? P_GUEST : P_USER);
88            p_priv->g_priv = S_DEFAULT;
89    
90            if (db == NULL)
91                    return 1;
92    
93            // Permission
94            sprintf(sql, "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",
95                            uid);
96            if (mysql_query(db, sql) != 0)
97            {
98                    log_error("Query user_list failed\n");
99                    return -1;
100            }
101            if ((rs = mysql_store_result(db)) == NULL)
102            {
103                    log_error("Get user_list data failed\n");
104                    return -1;
105            }
106            if (row = mysql_fetch_row(rs))
107            {
108                    p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0);
109                    p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0);
110            }
111            mysql_free_result(rs);
112    
113            // Admin
114            sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld "
115                                     "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",
116                            uid);
117            if (mysql_query(db, sql) != 0)
118            {
119                    log_error("Query admin_config failed\n");
120                    return -1;
121            }
122            if ((rs = mysql_store_result(db)) == NULL)
123            {
124                    log_error("Get admin_config data failed\n");
125                    return -1;
126            }
127            if (row = mysql_fetch_row(rs))
128            {
129                    p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S);
130                    p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN);
131            }
132            mysql_free_result(rs);
133    
134            // Section Master
135            sprintf(sql, "SELECT section_master.SID, major FROM section_master "
136                                     "INNER JOIN section_config ON section_master.SID = section_config.SID "
137                                     "WHERE UID = %ld AND section_master.enable AND section_config.enable "
138                                     "AND (NOW() BETWEEN begin_dt AND end_dt)",
139                            uid);
140            if (mysql_query(db, sql) != 0)
141            {
142                    log_error("Query section_master failed\n");
143                    return -1;
144            }
145            if ((rs = mysql_store_result(db)) == NULL)
146            {
147                    log_error("Get section_master data failed\n");
148                    return -1;
149            }
150            while (row = mysql_fetch_row(rs))
151            {
152                    p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S);
153                    setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S));
154            }
155            mysql_free_result(rs);
156    
157            // Section status
158            sprintf(sql, "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config "
159                                     "INNER JOIN section_class ON section_config.CID = section_class.CID "
160                                     "WHERE section_config.enable AND section_class.enable "
161                                     "ORDER BY SID");
162            if (mysql_query(db, sql) != 0)
163            {
164                    log_error("Query section_config failed\n");
165                    return -1;
166            }
167            if ((rs = mysql_store_result(db)) == NULL)
168            {
169                    log_error("Get section_config data failed\n");
170                    return -1;
171            }
172            while (row = mysql_fetch_row(rs))
173            {
174                    int priv = getpriv(p_priv, atoi(row[0]));
175                    if (p_priv->level < atoi(row[2]))
176                    {
177                            priv &= (~S_LIST);
178                    }
179                    if (p_priv->level < atoi(row[3]))
180                    {
181                            priv &= (~S_POST);
182                    }
183                    if (!atoi(row[1]))
184                    {
185                            priv &= (~S_GETEXP);
186                    }
187                    setpriv(p_priv, atoi(row[0]), priv);
188            }
189            mysql_free_result(rs);
190    
191            // Section ban
192            sprintf(sql, "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "
193                                     "AND (NOW() BETWEEN ban_dt AND unban_dt)",
194                            uid);
195            if (mysql_query(db, sql) != 0)
196            {
197                    log_error("Query ban_user_list failed\n");
198                    return -1;
199            }
200            if ((rs = mysql_store_result(db)) == NULL)
201            {
202                    log_error("Get ban_user_list data failed\n");
203                    return -1;
204            }
205            while (row = mysql_fetch_row(rs))
206            {
207                    setpriv(p_priv, atoi(row[0]),
208                                    getpriv(p_priv, atoi(row[0])) & (~S_POST));
209            }
210            mysql_free_result(rs);
211    
212    return 0;          return 0;
213  }  }


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

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