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

Contents of /lbbs/src/user_priv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Fri May 2 02:19:18 2025 UTC (10 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.8: +9 -4 lines
Content type: text/x-csrc
Fix bug

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

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