/[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.6 - (show annotations)
Mon Apr 28 04:23:38 2025 UTC (10 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.5: +1 -71 lines
Content type: text/x-csrc
Remove legacy code

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 "bbs.h"
19 #include "common.h"
20 #include <mysql.h>
21
22 int checklevel(BBS_user_priv *p_priv, int level)
23 {
24 return (((p_priv->level & level)) ^ level ? 0 : 1);
25 }
26
27 int setpriv(BBS_user_priv *p_priv, int sid, int priv)
28 {
29 int i;
30 if (sid > 0)
31 {
32 for (i = 0; i < p_priv->s_count; i++)
33 {
34 if (p_priv->s_priv_list[i].sid == sid)
35 {
36 p_priv->s_priv_list[i].s_priv = priv;
37 return 0;
38 }
39 }
40 if (i < BBS_max_section)
41 {
42 p_priv->s_priv_list[i].s_priv = priv;
43 }
44 else
45 {
46 return -1;
47 }
48 }
49 else
50 {
51 p_priv->g_priv = priv;
52 }
53
54 return 0;
55 }
56
57 int getpriv(BBS_user_priv *p_priv, int sid)
58 {
59 int i;
60 for (i = 0; i < p_priv->s_count; i++)
61 {
62 if (p_priv->s_priv_list[i].sid == sid)
63 return p_priv->s_priv_list[i].s_priv;
64 }
65
66 return (sid >= 0 ? p_priv->g_priv : S_NONE);
67 }
68
69 int checkpriv(BBS_user_priv *p_priv, int sid, int priv)
70 {
71 return (((getpriv(p_priv, sid) & priv)) ^ priv ? 0 : 1);
72 }
73
74 int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)
75 {
76 MYSQL_RES *rs;
77 MYSQL_ROW row;
78 char sql[1024];
79 int i;
80
81 p_priv->uid = uid;
82 p_priv->level = (uid == 0 ? P_GUEST : P_USER);
83 p_priv->g_priv = S_DEFAULT;
84
85 if (db == NULL)
86 return 1;
87
88 // Admin
89 sprintf(sql, "select aid,major from admin_config where UID=%ld"
90 " and enable and (now() between begin_dt and end_dt)",
91 uid);
92 if (mysql_query(db, sql) != 0)
93 {
94 log_error("Query admin_config failed\n");
95 return -1;
96 }
97 if ((rs = mysql_store_result(db)) == NULL)
98 {
99 log_error("Get admin_config data failed\n");
100 return -1;
101 }
102 if (row = mysql_fetch_row(rs))
103 {
104 p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S);
105 p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN);
106 }
107 mysql_free_result(rs);
108
109 // Permission
110 sprintf(sql, "select p_post,p_msg,p_mail "
111 "from user_list where UID=%ld",
112 uid);
113 if (mysql_query(db, sql) != 0)
114 {
115 log_error("Query user_list failed\n");
116 return -1;
117 }
118 if ((rs = mysql_store_result(db)) == NULL)
119 {
120 log_error("Get user_list data failed\n");
121 return -1;
122 }
123 if (row = mysql_fetch_row(rs))
124 {
125 p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0);
126 p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0);
127 p_priv->g_priv |= (atoi(row[2]) ? S_MAIL : 0);
128 }
129 mysql_free_result(rs);
130
131 // Section Master
132 sprintf(sql, "select SID,major from section_master where"
133 " UID=%ld and enable and (now() between begin_dt and"
134 " end_dt)",
135 uid);
136 if (mysql_query(db, sql) != 0)
137 {
138 log_error("Query section_master failed\n");
139 return -1;
140 }
141 if ((rs = mysql_store_result(db)) == NULL)
142 {
143 log_error("Get section_master data failed\n");
144 return -1;
145 }
146 while (row = mysql_fetch_row(rs))
147 {
148 p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S);
149 setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S));
150 }
151 mysql_free_result(rs);
152
153 // Section status
154 sprintf(sql, "select SID,exp_get,read_user_level,"
155 "write_user_level from section_config"
156 " left join section_class on section_config.CID="
157 "section_class.CID where section_config.enable and"
158 " section_class.enable order by SID");
159 if (mysql_query(db, sql) != 0)
160 {
161 log_error("Query section_config failed\n");
162 return -1;
163 }
164 if ((rs = mysql_store_result(db)) == NULL)
165 {
166 log_error("Get section_config data failed\n");
167 return -1;
168 }
169 while (row = mysql_fetch_row(rs))
170 {
171 if (p_priv->level < atoi(row[2]))
172 setpriv(p_priv, atoi(row[0]),
173 getpriv(p_priv, atoi(row[0])) & (~S_LIST));
174 if (p_priv->level < atoi(row[3]))
175 setpriv(p_priv, atoi(row[0]),
176 getpriv(p_priv, atoi(row[0])) & (~S_POST));
177 if (!atoi(row[1]))
178 setpriv(p_priv, atoi(row[0]),
179 getpriv(p_priv, atoi(row[0])) & (~S_GETEXP));
180 }
181 mysql_free_result(rs);
182
183 // Section User priv
184 sprintf(sql, "select SID,`read`,`write` from section_user_priv"
185 " where UID=%ld order by SID",
186 uid);
187 if (mysql_query(db, sql) != 0)
188 {
189 log_error("Query section_user_priv failed\n");
190 return -1;
191 }
192 if ((rs = mysql_store_result(db)) == NULL)
193 {
194 log_error("Get section_user_priv data failed\n");
195 return -1;
196 }
197 while (row = mysql_fetch_row(rs))
198 {
199 setpriv(p_priv, atoi(row[0]),
200 atoi(row[1]) ? (getpriv(p_priv, atoi(row[0])) | S_LIST)
201 : (getpriv(p_priv, atoi(row[0])) & ~S_LIST));
202 setpriv(p_priv, atoi(row[0]),
203 atoi(row[2]) ? (getpriv(p_priv, atoi(row[0])) | S_POST)
204 : (getpriv(p_priv, atoi(row[0])) & ~S_POST));
205 }
206 mysql_free_result(rs);
207
208 // Section ban
209 sprintf(sql, "select SID from ban_user_list where"
210 " UID=%ld and enable and unban_UID=0 and"
211 " (now() between ban_dt and unban_dt)",
212 uid);
213 if (mysql_query(db, sql) != 0)
214 {
215 log_error("Query ban_user_list failed\n");
216 return -1;
217 }
218 if ((rs = mysql_store_result(db)) == NULL)
219 {
220 log_error("Get ban_user_list data failed\n");
221 return -1;
222 }
223 while (row = mysql_fetch_row(rs))
224 {
225 setpriv(p_priv, atoi(row[0]),
226 getpriv(p_priv, atoi(row[0])) & (~S_POST));
227 }
228 mysql_free_result(rs);
229
230 return 0;
231 }

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