/[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.13 by sysadm, Mon May 19 02:16:24 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            user_priv.c  -  description                                                    user_priv.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 22 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "user_priv.h"
18  #include "bbs.h"  #include "bbs.h"
19    #include "common.h"
20    #include "database.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 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 load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid)
70  {  {
71            MYSQL_RES *rs;
72            MYSQL_ROW row;
73            char sql[SQL_BUFFER_LEN];
74    
75            p_priv->uid = uid;
76            p_priv->level = (uid == 0 ? P_GUEST : P_USER);
77            p_priv->g_priv = S_DEFAULT;
78    
79            if (db == NULL)
80                    return 1;
81    
82            // Permission
83            snprintf(sql, sizeof(sql), "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified",
84                            uid);
85            if (mysql_query(db, sql) != 0)
86            {
87                    log_error("Query user_list failed\n");
88                    return -1;
89            }
90            if ((rs = mysql_store_result(db)) == NULL)
91            {
92                    log_error("Get user_list data failed\n");
93                    return -1;
94            }
95            if ((row = mysql_fetch_row(rs)))
96            {
97                    p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0);
98                    p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0);
99            }
100            mysql_free_result(rs);
101    
102            // Admin
103            snprintf(sql, sizeof(sql), "SELECT major FROM admin_config WHERE UID = %ld "
104                                     "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)",
105                            uid);
106            if (mysql_query(db, sql) != 0)
107            {
108                    log_error("Query admin_config failed\n");
109                    return -1;
110            }
111            if ((rs = mysql_store_result(db)) == NULL)
112            {
113                    log_error("Get admin_config data failed\n");
114                    return -1;
115            }
116            if ((row = mysql_fetch_row(rs)))
117            {
118                    p_priv->level |= (atoi(row[0]) ? P_ADMIN_M : P_ADMIN_S);
119                    p_priv->g_priv |= (atoi(row[0]) ? S_ALL : S_ADMIN);
120            }
121            mysql_free_result(rs);
122    
123            // Section Master
124            snprintf(sql, sizeof(sql), "SELECT section_master.SID, major FROM section_master "
125                                     "INNER JOIN section_config ON section_master.SID = section_config.SID "
126                                     "WHERE UID = %ld AND section_master.enable AND section_config.enable "
127                                     "AND (NOW() BETWEEN begin_dt AND end_dt)",
128                            uid);
129            if (mysql_query(db, sql) != 0)
130            {
131                    log_error("Query section_master failed\n");
132                    return -1;
133            }
134            if ((rs = mysql_store_result(db)) == NULL)
135            {
136                    log_error("Get section_master data failed\n");
137                    return -1;
138            }
139            while ((row = mysql_fetch_row(rs)))
140            {
141                    p_priv->level |= (atoi(row[1]) ? P_MAN_M : P_MAN_S);
142                    setpriv(p_priv, atoi(row[0]), getpriv(p_priv, atoi(row[0])) | (atoi(row[1]) ? S_MAN_M : S_MAN_S));
143            }
144            mysql_free_result(rs);
145    
146            // Section status
147            snprintf(sql, sizeof(sql), "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config "
148                                     "INNER JOIN section_class ON section_config.CID = section_class.CID "
149                                     "WHERE section_config.enable AND section_class.enable "
150                                     "ORDER BY SID");
151            if (mysql_query(db, sql) != 0)
152            {
153                    log_error("Query section_config failed\n");
154                    return -1;
155            }
156            if ((rs = mysql_store_result(db)) == NULL)
157            {
158                    log_error("Get section_config data failed\n");
159                    return -1;
160            }
161            while ((row = mysql_fetch_row(rs)))
162            {
163                    int priv = getpriv(p_priv, atoi(row[0]));
164                    if (p_priv->level < atoi(row[2]))
165                    {
166                            priv &= (~S_LIST);
167                    }
168                    if (p_priv->level < atoi(row[3]))
169                    {
170                            priv &= (~S_POST);
171                    }
172                    if (!atoi(row[1]))
173                    {
174                            priv &= (~S_GETEXP);
175                    }
176                    setpriv(p_priv, atoi(row[0]), priv);
177            }
178            mysql_free_result(rs);
179    
180            // Section ban
181            snprintf(sql, sizeof(sql), "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable "
182                                     "AND (NOW() BETWEEN ban_dt AND unban_dt)",
183                            uid);
184            if (mysql_query(db, sql) != 0)
185            {
186                    log_error("Query ban_user_list failed\n");
187                    return -1;
188            }
189            if ((rs = mysql_store_result(db)) == NULL)
190            {
191                    log_error("Get ban_user_list data failed\n");
192                    return -1;
193            }
194            while ((row = mysql_fetch_row(rs)))
195            {
196                    setpriv(p_priv, atoi(row[0]),
197                                    getpriv(p_priv, atoi(row[0])) & (~S_POST));
198            }
199            mysql_free_result(rs);
200    
201    return 0;          return 0;
202  }  }


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

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