Debian Codegraph @

src/bnetd/storage_file.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 1998,1999,2000,2001 Ross Combs ([email protected])
3 * Copyright (C) 2000,2001 Marco Ziech ([email protected])
4 * Copyright (C) 2002,2003,2004 Dizzy
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
21 #include "storage_file.h"cxx . . $ `<file>/src/bnetd/storage_file.h`/
22
23 #include <sstream>
24 #include <cstring>
25 #include <cstdio>
26 #include <cerrno>
27 #include <ctime>
28 #include <cstdlib>
29
30 #ifdef HAVE_UNISTD_Hcxx . . $ `build/config.h:7:9`!
31 # include <unistd.h>
32 #endif
33
34 #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/
35 #include "compat/pdir.h"cxx . . $ `<file>/src/compat/pdir.h`/
36 #include "compat/rename.h"cxx . . $ `<file>/src/compat/rename.h`/
37 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
38 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
39 #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/
40 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
41
42 #define CLAN_INTERNAL_ACCESScxx . . $ `src/bnetd/storage_file.cpp:42:9`!
43 #define TEAM_INTERNAL_ACCESScxx . . $ `src/bnetd/storage_file.cpp:43:9`!
44 #include "team.h"cxx . . $ `<file>/src/bnetd/team.h`/
45 #include "account.h"cxx . . $ `<file>/src/bnetd/account.h`/
46 #include "file_plain.h"cxx . . $ `<file>/src/bnetd/file_plain.h`/
47 #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/
48 #include "clan.h"cxx . . $ `<file>/src/bnetd/clan.h`/
49 #undef CLAN_INTERNAL_ACCESScxx . . $ `src/bnetd/storage_file.cpp:42:9`!
50 #undef TEAM_INTERNAL_ACCESScxx . . $ `src/bnetd/storage_file.cpp:43:9`!
51 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
52
53 namespace pvpgncxx . . $ pvpgn/
54 {
55
56 namespace bnetdcxx . . $ pvpgn/bnetd/
57 {
58
59 /* file storage API functions */
60
61 static int file_initcxx . . $ pvpgn/bnetd/file_init(5c4306d8553b3696).(const char *);
62 static int file_closecxx . . $ pvpgn/bnetd/file_close(b126dc7c1de90089).(void);
63 static unsigned file_read_maxuseridcxx . . $ pvpgn/bnetd/file_read_maxuserid(db52760e79bf9054).(void);
64 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_create_accountcxx . . $ pvpgn/bnetd/file_create_account(fb668cd7b4a39b42).(char const *);
65 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_get_defacctcxx . . $ pvpgn/bnetd/file_get_defacct(7b2cc94cb2e5017b).(void);
66 static int file_free_infocxx . . $ pvpgn/bnetd/file_free_info(aa284d429d6986c8).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *);
67 static int file_read_attrscxx . . $ pvpgn/bnetd/file_read_attrs(b566d5cbb4c2de50).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *, t_read_attr_funccxx . . $ pvpgn/bnetd/t_read_attr_func#, void *, const char *);
68 static t_attrcxx . . $ pvpgn/bnetd/t_attr# *file_read_attrcxx . . $ pvpgn/bnetd/file_read_attr(3a848d2f2d420c87).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *, const char *);
69 static int file_write_attrscxx . . $ pvpgn/bnetd/file_write_attrs(16bd6e774ad74256).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *, const t_hlistcxx . . $ pvpgn/t_hlist# *);
70 static int file_read_accountscxx . . $ pvpgn/bnetd/file_read_accounts(9f24b27f666fa0de).(int, t_read_accounts_funccxx . . $ pvpgn/bnetd/t_read_accounts_func#, void *);
71 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_read_accountcxx . . $ pvpgn/bnetd/file_read_account(3387c51689820232).(const char *, unsigned);
72 static int file_cmp_infocxx . . $ pvpgn/bnetd/file_cmp_info(9148c8c3ff42c9d8).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *, t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *);
73 static const char *file_escape_keycxx . . $ pvpgn/bnetd/file_escape_key(fb58d2e09a2a1ce6).(const char *);
74 static int file_load_clanscxx . . $ pvpgn/bnetd/file_load_clans(53fea8456a5967d6).(t_load_clans_funccxx . . $ pvpgn/bnetd/t_load_clans_func#);
75 static int file_write_clancxx . . $ pvpgn/bnetd/file_write_clan(dedf1e9b1c614a07).(void *);
76 static int file_remove_clancxx . . $ pvpgn/bnetd/file_remove_clan(7864480464b09eea).(int);
77 static int file_remove_clanmembercxx . . $ pvpgn/bnetd/file_remove_clanmember(7864480464b09eea).(int);
78 static int file_load_teamscxx . . $ pvpgn/bnetd/file_load_teams(53fea8456a5967d6).(t_load_teams_funccxx . . $ pvpgn/bnetd/t_load_teams_func#);
79 static int file_write_teamcxx . . $ pvpgn/bnetd/file_write_team(dedf1e9b1c614a07).(void *);
80 static int file_remove_teamcxx . . $ pvpgn/bnetd/file_remove_team(4c679297bf94b9eb).(unsigned int);
81
82 /* storage struct populated with the functions above */
83
84 t_storagecxx . . $ pvpgn/bnetd/t_storage# storage_filecxx . . $ pvpgn/bnetd/storage_file. = {
85 file_initcxx . . $ pvpgn/bnetd/file_init(5c4306d8553b3696).,
86 file_closecxx . . $ pvpgn/bnetd/file_close(b126dc7c1de90089).,
87 file_read_maxuseridcxx . . $ pvpgn/bnetd/file_read_maxuserid(db52760e79bf9054).,
88 file_create_accountcxx . . $ pvpgn/bnetd/file_create_account(fb668cd7b4a39b42).,
89 file_get_defacctcxx . . $ pvpgn/bnetd/file_get_defacct(7b2cc94cb2e5017b).,
90 file_free_infocxx . . $ pvpgn/bnetd/file_free_info(aa284d429d6986c8).,
91 file_read_attrscxx . . $ pvpgn/bnetd/file_read_attrs(b566d5cbb4c2de50).,
92 file_write_attrscxx . . $ pvpgn/bnetd/file_write_attrs(16bd6e774ad74256).,
93 file_read_attrcxx . . $ pvpgn/bnetd/file_read_attr(3a848d2f2d420c87).,
94 file_read_accountscxx . . $ pvpgn/bnetd/file_read_accounts(9f24b27f666fa0de).,
95 file_read_accountcxx . . $ pvpgn/bnetd/file_read_account(3387c51689820232).,
96 file_cmp_infocxx . . $ pvpgn/bnetd/file_cmp_info(9148c8c3ff42c9d8).,
97 file_escape_keycxx . . $ pvpgn/bnetd/file_escape_key(fb58d2e09a2a1ce6).,
98 file_load_clanscxx . . $ pvpgn/bnetd/file_load_clans(53fea8456a5967d6).,
99 file_write_clancxx . . $ pvpgn/bnetd/file_write_clan(dedf1e9b1c614a07).,
100 file_remove_clancxx . . $ pvpgn/bnetd/file_remove_clan(7864480464b09eea).,
101 file_remove_clanmembercxx . . $ pvpgn/bnetd/file_remove_clanmember(7864480464b09eea).,
102 file_load_teamscxx . . $ pvpgn/bnetd/file_load_teams(53fea8456a5967d6).,
103 file_write_teamcxx . . $ pvpgn/bnetd/file_write_team(dedf1e9b1c614a07).,
104 file_remove_teamcxx . . $ pvpgn/bnetd/file_remove_team(4c679297bf94b9eb).
105 };
106
107 /* start of actual file storage code */
108
109 static const char *accountsdircxx . . $ pvpgn/bnetd/accountsdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
110 static const char *clansdircxx . . $ pvpgn/bnetd/clansdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
111 static const char *teamsdircxx . . $ pvpgn/bnetd/teamsdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
112 static const char *defacctcxx . . $ pvpgn/bnetd/defacct. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
113 static t_file_enginecxx . . $ pvpgn/bnetd/t_file_engine# *filecxx . . $ pvpgn/bnetd/file. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
114
115 static unsigned file_read_maxuseridcxx . . $ pvpgn/bnetd/file_read_maxuserid(db52760e79bf9054).(void)
116 {
117 return maxuseridcxx . . $ pvpgn/bnetd/maxuserid.;
118 }
119
120 static int file_initcxx . . $ pvpgn/bnetd/file_init(5c4306d8553b3696).(const char *path)
121 {
122 char *tok, *copy, *tmp, *p;
123 const char *dir = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
124 const char *clan = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
125 const char *team = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
126 const char *def = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
127 const char *driver = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
128
129 if (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || path[0] == '\0')
130 {
131 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL or empty path");
132 return -1;
133 }
134
135 copy = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(path);
136 tmp = copy;
137 while ((tok = stdcxx . . $ std/::strtok(tmp, ";")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
138 {
139 tmp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
140 if ((p = stdcxx . . $ std/::strchr(tok, '=')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
141 {
142 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid storage_path, no '=' present in token");
143 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)copy);
144 return -1;
145 }
146 *p = '\0';
147 if (strcasecmp(tok, "dir") == 0)
148 dir = p + 1;
149 else if (strcasecmp(tok, "clan") == 0)
150 clan = p + 1;
151 else if (strcasecmp(tok, "team") == 0)
152 team = p + 1;
153 else if (strcasecmp(tok, "default") == 0)
154 def = p + 1;
155 else if (strcasecmp(tok, "mode") == 0)
156 driver = p + 1;
157 else
158 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_warncxx . . $ pvpgn/eventlog_level_warn., __FUNCTION__, "unknown token in storage_path : '{}'", tok);
159 }
160
161 if (def == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || clan == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || team == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || dir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || driver == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
162 {
163 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid storage_path line for file module (doesnt have a 'dir', a 'clan', a 'team', a 'default' token and a 'mode' token)");
164 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)copy);
165 return -1;
166 }
167
168 if (!strcasecmp(driver, "plain"))
169 filecxx . . $ pvpgn/bnetd/file. = &file_plaincxx . . $ pvpgn/bnetd/file_plain.;
170 else
171 {
172 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "unknown mode '{}', mode must be plain", driver);
173 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)copy);
174 return -1;
175 }
176
177 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir.)
178 file_closecxx . . $ pvpgn/bnetd/file_close(b126dc7c1de90089).();
179
180 accountsdircxx . . $ pvpgn/bnetd/accountsdir. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(dir);
181 clansdircxx . . $ pvpgn/bnetd/clansdir. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(clan);
182 teamsdircxx . . $ pvpgn/bnetd/teamsdir. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(team);
183 defacctcxx . . $ pvpgn/bnetd/defacct. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(def);
184
185 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)copy);
186
187 return 0;
188 }
189
190 static int file_closecxx . . $ pvpgn/bnetd/file_close(b126dc7c1de90089).(void)
191 {
192 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir.)
193 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)accountsdir);
194 accountsdircxx . . $ pvpgn/bnetd/accountsdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
195
196 if (clansdircxx . . $ pvpgn/bnetd/clansdir.)
197 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)clansdir);
198 clansdircxx . . $ pvpgn/bnetd/clansdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
199
200 if (teamsdircxx . . $ pvpgn/bnetd/teamsdir.)
201 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)teamsdir);
202 teamsdircxx . . $ pvpgn/bnetd/teamsdir. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
203
204 if (defacctcxx . . $ pvpgn/bnetd/defacct.)
205 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)defacct);
206 defacctcxx . . $ pvpgn/bnetd/defacct. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
207
208 filecxx . . $ pvpgn/bnetd/file. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
209
210 return 0;
211 }
212
213 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_create_accountcxx . . $ pvpgn/bnetd/file_create_account(fb668cd7b4a39b42).(const char *username)
214 {
215 char *temp;
216
217 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || filecxx . . $ pvpgn/bnetd/file. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
218 {
219 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
220 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
221 }
222
223 if (prefs_get_savebynamecxx . . $ pvpgn/bnetd/prefs_get_savebyname(db52760e79bf9054).())
224 {
225 char const *safename;
226
227 if (!stdcxx . . $ std/::strcmp(username, defacctcxx . . $ pvpgn/bnetd/defacct.))
228 {
229 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "username as defacct not allowed");
230 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
231 }
232
233 if (!(safename = escape_fs_charscxx . . $ pvpgn/escape_fs_chars(cf893fee19605dd5).(username, stdcxx . . $ std/::strlen(username))))
234 {
235 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not escape username");
236 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
237 }
238 temp = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(accountsdir) + 1 + std::strlen(safename) + 1); /* dir + / + name + NUL */
239 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(temp, "%s/%s", accountsdircxx . . $ pvpgn/bnetd/accountsdir., safename);
240 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)safename); /* avoid warning */
241 }
242 else
243 {
244 temp = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(accountsdir) + 1 + 8 + 1); /* dir + / + uid + NUL */
245 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(temp, "%s/%06u", accountsdircxx . . $ pvpgn/bnetd/accountsdir., maxuseridcxx . . $ pvpgn/bnetd/maxuserid. + 1); /* FIXME: hmm, maybe up the %06 to %08... */
246 }
247
248 return temp;
249 }
250
251 static int file_write_attrscxx . . $ pvpgn/bnetd/file_write_attrs(16bd6e774ad74256).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info, const t_hlistcxx . . $ pvpgn/t_hlist# *attributes)
252 {
253 char *tempname;
254
255 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || filecxx . . $ pvpgn/bnetd/file. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
256 {
257 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
258 return -1;
259 }
260
261 if (info == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
262 {
263 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL info storage");
264 return -1;
265 }
266
267 if (attributes == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
268 {
269 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL attributes");
270 return -1;
271 }
272
273 tempname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(accountsdir) + 1 + std::strlen(BNETD_ACCOUNT_TMP) + 1);
274 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(tempname, "%s/%s", accountsdircxx . . $ pvpgn/bnetd/accountsdir., BNETD_ACCOUNT_TMPcxx . . $ BNETD_ACCOUNT_TMP.);
275
276 if (filecxx . . $ pvpgn/bnetd/file.->write_attrscxx . . $ pvpgn/bnetd/$anonymous_type_4ce267d948dc3905_0#write_attrs.(tempname, attributes))
277 {
278 /* no eventlog here, it should be reported from the file layer */
279 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
280 return -1;
281 }
282
283 if (p_renamecxx . . $ pvpgn/p_rename(5ae29d726ae57f88).(tempname, (const char *)info) < 0)
284 {
285 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not std::rename account file to \"{}\" (std::rename: {})", (char *)info, stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
286 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
287 return -1;
288 }
289
290 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
291
292 return 0;
293 }
294
295 static int file_read_attrscxx . . $ pvpgn/bnetd/file_read_attrs(b566d5cbb4c2de50).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info, t_read_attr_funccxx . . $ pvpgn/bnetd/t_read_attr_func# cb, void *data, const char *ktab)
296 {
297 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || filecxx . . $ pvpgn/bnetd/file. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
298 {
299 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
300 return -1;
301 }
302
303 if (info == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
304 {
305 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL info storage");
306 return -1;
307 }
308
309 if (cb == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
310 {
311 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL callback");
312 return -1;
313 }
314
315 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_debugcxx . . $ pvpgn/eventlog_level_debug., __FUNCTION__, "loading \"{}\"", reinterpret_cast<const char*>(info));
316
317 if (filecxx . . $ pvpgn/bnetd/file.->read_attrscxx . . $ pvpgn/bnetd/$anonymous_type_4ce267d948dc3905_0#read_attrs.((const char *)info, cb, data))
318 {
319 /* no eventlog, error reported earlier */
320 return -1;
321 }
322
323 return 0;
324 }
325
326 static t_attrcxx . . $ pvpgn/bnetd/t_attr# *file_read_attrcxx . . $ pvpgn/bnetd/file_read_attr(3a848d2f2d420c87).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info, const char *key)
327 {
328 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || filecxx . . $ pvpgn/bnetd/file. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
329 {
330 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
331 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
332 }
333
334 if (info == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
335 {
336 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL info storage");
337 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
338 }
339
340 if (key == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
341 {
342 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL key");
343 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
344 }
345
346 return filecxx . . $ pvpgn/bnetd/file.->read_attrcxx . . $ pvpgn/bnetd/$anonymous_type_4ce267d948dc3905_0#read_attr.((const char *)info, key);
347 }
348
349 static int file_free_infocxx . . $ pvpgn/bnetd/file_free_info(aa284d429d6986c8).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info)
350 {
351 if (info)
352 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)info);
353 return 0;
354 }
355
356 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_get_defacctcxx . . $ pvpgn/bnetd/file_get_defacct(7b2cc94cb2e5017b).(void)
357 {
358 t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *info;
359
360 if (defacctcxx . . $ pvpgn/bnetd/defacct. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
361 {
362 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
363 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
364 }
365
366 info = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(defacct);
367
368 return info;
369 }
370
371 static int file_read_accountscxx . . $ pvpgn/bnetd/file_read_accounts(9f24b27f666fa0de).(int flag, t_read_accounts_funccxx . . $ pvpgn/bnetd/t_read_accounts_func# cb, void *data)
372 {
373 if (!accountsdircxx . . $ pvpgn/bnetd/accountsdir.) {
374 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("file storage not initilized");
375 return -1;
376 }
377
378 if (!cb) {
379 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL callback");
380 return -1;
381 }
382
383 try {
384 Directorycxx . . $ pvpgn/Directory# accdircxx . . $ pvpgn/Directory#Directory(a3b17e0268c60856).(accountsdircxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
385
386 char const *dentry;
387 while ((dentry = accdir.readcxx . . $ pvpgn/Directory#read(a9f41ea0e82d88cf).())) {
388 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# ostrcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
389 ostr <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). accountsdircxx . . $ pvpgn/bnetd/accountsdir. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '/' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). dentry;
390
391 cb(xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(ostr.str().c_str()), data);
392 }
393 }
394 catch (const Directorycxx . . $ pvpgn/Directory#::OpenErrorcxx . . $ pvpgn/Directory#OpenError#& ex) {
395 ERROR2cxx . . $ `src/common/eventlog.h:75:9`!("unable to open user directory \"{}\" for reading (error: {})", accountsdir, ex.what());
396 return -1;
397 }
398
399 return 0;
400 }
401
402 static t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# *file_read_accountcxx . . $ pvpgn/bnetd/file_read_account(3387c51689820232).(const char *accname, unsigned uid)
403 {
404 char *pathname;
405
406 if (accountsdircxx . . $ pvpgn/bnetd/accountsdir. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
407 {
408 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "file storage not initilized");
409 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
410 }
411
412 /* ONLY if requesting for a username and if savebyname() is true
413 * PS: yes its kind of a hack, we will make a proper index file
414 */
415 if (accname && prefs_get_savebynamecxx . . $ pvpgn/bnetd/prefs_get_savebyname(db52760e79bf9054).()) {
416 pathname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(accountsdir) + 1 + std::strlen(accname) + 1); /* dir + / + file + NUL */
417 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(pathname, "%s/%s", accountsdircxx . . $ pvpgn/bnetd/accountsdir., accname);
418 if (access(pathname, F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`!)) /* if it doesn't exist */
419 {
420 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)pathname);
421 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
422 }
423 return pathname;
424 }
425
426 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
427 }
428
429 static int file_cmp_infocxx . . $ pvpgn/bnetd/file_cmp_info(9148c8c3ff42c9d8).(t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info1, t_storage_infocxx . . $ pvpgn/bnetd/t_storage_info# * info2)
430 {
431 return stdcxx . . $ std/::strcmp((const char *)info1, (const char *)info2);
432 }
433
434 static const char *file_escape_keycxx . . $ pvpgn/bnetd/file_escape_key(fb58d2e09a2a1ce6).(const char *key)
435 {
436 return key;
437 }
438
439 static int file_load_clanscxx . . $ pvpgn/bnetd/file_load_clans(53fea8456a5967d6).(t_load_clans_funccxx . . $ pvpgn/bnetd/t_load_clans_func# cb)
440 {
441 char const *dentry;
442 char *pathname;
443 int clantag;
444 t_clancxx . . $ pvpgn/bnetd/t_clan# *clan;
445 stdcxx . . $ std/::FILEcxx . . $ std/FILE# *fp;
446 char *clanname, *motd, *p;
447 char line[1024];
448 int cid, creation_time;
449 int member_uid, member_join_time;
450 char member_status;
451 t_clanmembercxx . . $ pvpgn/bnetd/t_clanmember# *member;
452
453 if (cb == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
454 {
455 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "get NULL callback");
456 return -1;
457 }
458
459 try {
460 Directorycxx . . $ pvpgn/Directory# clandircxx . . $ pvpgn/Directory#Directory(a3b17e0268c60856).(clansdircxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
461
462 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "start reading clans");
463
464 pathname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(clansdir) + 1 + 4 + 1);
465 while ((dentry = clandir.readcxx . . $ pvpgn/Directory#read(a9f41ea0e82d88cf).()))
466 {
467 if (stdcxx . . $ std/::strlen(dentry) > 4)
468 {
469 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found too long clan filename in clandir \"{}\"", dentry);
470 continue;
471 }
472
473 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(pathname, "%s/%s", clansdircxx . . $ pvpgn/bnetd/clansdir., dentry);
474
475 clantag = str_to_clantagcxx . . $ pvpgn/bnetd/str_to_clantag(c61c63047ce273de).(dentry);
476
477 if ((fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(pathname, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
478 {
479 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "can't open clanfile \"{}\"", pathname);
480 continue;
481 }
482
483 clan = (t_clancxx . . $ pvpgn/bnetd/t_clan#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_clan));
484 clan->tagcxx . . $ pvpgn/bnetd/clan#tag. = clantag;
485
486 if (!stdcxx . . $ std/::fgetscxx . . $ std/fgets(efb0aaba7ac866ae).(line, 1024, fp))
487 {
488 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: no first line");
489 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
490 continue;
491 }
492
493 clanname = line;
494 if (*clanname != '"')
495 {
496 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
497 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
498 continue;
499 }
500 clanname++;
501 p = stdcxx . . $ std/::strchr(clanname, '"');
502 if (!p)
503 {
504 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
505 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
506 continue;
507 }
508 *p = '\0';
509 if (stdcxx . . $ std/::strlen(clanname) >= CLAN_NAME_MAXcxx . . $ CLAN_NAME_MAX.)
510 {
511 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
512 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
513 continue;
514 }
515
516 p++;
517 if (*p != ',')
518 {
519 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
520 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
521 continue;
522 }
523 p++;
524 if (*p != '"')
525 {
526 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
527 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
528 continue;
529 }
530 motd = p + 1;
531 p = stdcxx . . $ std/::strchr(motd, '"');
532 if (!p)
533 {
534 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid clan file: invalid first line");
535 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
536 continue;
537 }
538 *p = '\0';
539
540 if (stdcxx . . $ std/::sscanfcxx . . $ std/sscanf(6246fabbf6b5312d).(p + 1, ",%d,%d\n", &cid, &creation_time) != 2)
541 {
542 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid first line in clanfile");
543 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)clan);
544 continue;
545 }
546 clan->clannamecxx . . $ pvpgn/bnetd/clan#clanname. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(clanname);
547 clan->clan_motdcxx . . $ pvpgn/bnetd/clan#clan_motd. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(motd);
548 clan->clanidcxx . . $ pvpgn/bnetd/clan#clanid. = cid;
549 clan->creation_timecxx . . $ pvpgn/bnetd/clan#creation_time. = (stdcxx . . $ std/::time_tcxx . . $ std/time_t#) creation_time;
550 clan->createdcxx . . $ pvpgn/bnetd/clan#created. = 1;
551 clan->modifiedcxx . . $ pvpgn/bnetd/clan#modified. = 0;
552 clan->channel_typecxx . . $ pvpgn/bnetd/clan#channel_type. = prefs_get_clan_channel_default_privatecxx . . $ pvpgn/bnetd/prefs_get_clan_channel_default_private(db52760e79bf9054).();
553
554 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "name: {} motd: {} clanid: {} time: {}", clanname, motd, cid, creation_time);
555
556 clan->memberscxx . . $ pvpgn/bnetd/clan#members. = list_create();
557
558 while (stdcxx . . $ std/::fscanfcxx . . $ std/fscanf(bc216f8e5b1ebeac).(fp, "%i,%c,%i\n", &member_uid, &member_status, &member_join_time) == 3)
559 {
560 member = (t_clanmembercxx . . $ pvpgn/bnetd/t_clanmember#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_clanmember));
561 if (!(member->memberacccxx . . $ pvpgn/bnetd/_clanmember#memberacc. = accountlist_find_account_by_uidcxx . . $ pvpgn/bnetd/accountlist_find_account_by_uid(c4505e327c9ccd36).(member_uid)))
562 {
563 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "cannot find uid {}", member_uid);
564 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)member);
565 continue;
566 }
567 member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. = member_status - '0';
568 member->join_timecxx . . $ pvpgn/bnetd/_clanmember#join_time. = member_join_time;
569 member->clancxx . . $ pvpgn/bnetd/_clanmember#clan. = clan;
570 member->fullmembercxx . . $ pvpgn/bnetd/_clanmember#fullmember. = 1; /* In files we have only fullmembers */
571
572 if ((member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. == CLAN_NEWcxx . . $ `src/bnetd/clan.h:102:9`!) && (stdcxx . . $ std/::timecxx . . $ std/time(a7cd306b2d326b09).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) - member->join_timecxx . . $ pvpgn/bnetd/_clanmember#join_time. > prefs_get_clan_newer_timecxx . . $ pvpgn/bnetd/prefs_get_clan_newer_time(db52760e79bf9054).() * 3600))
573 {
574 member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. = CLAN_PEONcxx . . $ `src/bnetd/clan.h:101:9`!;
575 clan->modifiedcxx . . $ pvpgn/bnetd/clan#modified. = 1;
576 }
577
578 list_append_data(clan->memberscxx . . $ pvpgn/bnetd/clan#members., member);
579
580 account_set_clanmembercxx . . $ pvpgn/bnetd/account_set_clanmember(5828098b1d22acf3).((t_accountcxx . . $ pvpgn/bnetd/t_account#*)member->memberacccxx . . $ pvpgn/bnetd/_clanmember#memberacc., member);
581 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "added member: uid: {} status: {} join_time: {}", member_uid, member_status + '0', member_join_time);
582 }
583
584 stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp);
585
586 cb(clan);
587
588 }
589
590 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)pathname);
591
592 }
593 catch (const Directorycxx . . $ pvpgn/Directory#::OpenErrorcxx . . $ pvpgn/Directory#OpenError#& ex) {
594 ERROR2cxx . . $ `src/common/eventlog.h:75:9`!("unable to open clan directory \"{}\" for reading (error: {})", clansdir, ex.what());
595 return -1;
596 }
597
598 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "finished reading clans");
599
600 return 0;
601 }
602
603 static int file_write_clancxx . . $ pvpgn/bnetd/file_write_clan(dedf1e9b1c614a07).(void *data)
604 {
605 stdcxx . . $ std/::FILEcxx . . $ std/FILE# *fp;
606 t_elem *curr;
607 t_clanmembercxx . . $ pvpgn/bnetd/t_clanmember# *member;
608 char *clanfile;
609 t_clancxx . . $ pvpgn/bnetd/t_clan# *clan = (t_clancxx . . $ pvpgn/bnetd/t_clan# *)data;
610
611 clanfile = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(clansdir) + 1 + 4 + 1);
612 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(clanfile, "%s/%s", clansdircxx . . $ pvpgn/bnetd/clansdir., clantag_to_strcxx . . $ pvpgn/bnetd/clantag_to_str(81a3ae90da26a711).(clan->tagcxx . . $ pvpgn/bnetd/clan#tag.));
613
614 if ((fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(clanfile, "w")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
615 {
616 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "can't open clanfile \"{}\"", clanfile);
617 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)clanfile);
618 return -1;
619 }
620
621 stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\"%s\",\"%s\",%i,%i\n", clan->clannamecxx . . $ pvpgn/bnetd/clan#clanname., clan->clan_motdcxx . . $ pvpgn/bnetd/clan#clan_motd., clan->clanidcxx . . $ pvpgn/bnetd/clan#clanid., (int)clan->creation_timecxx . . $ pvpgn/bnetd/clan#creation_time.);
622
623 LIST_TRAVERSEcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/list.h:94:9`!(clan->members, curr)
624 {
625 if (!(member = (t_clanmembercxx . . $ pvpgn/bnetd/t_clanmember#*)elem_get_data(curr)))
626 {
627 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL elem in list");
628 continue;
629 }
630 if ((member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. == CLAN_NEWcxx . . $ `src/bnetd/clan.h:102:9`!) && (stdcxx . . $ std/::timecxx . . $ std/time(a7cd306b2d326b09).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) - member->join_timecxx . . $ pvpgn/bnetd/_clanmember#join_time. > prefs_get_clan_newer_timecxx . . $ pvpgn/bnetd/prefs_get_clan_newer_time(db52760e79bf9054).() * 3600))
631 member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. = CLAN_PEONcxx . . $ `src/bnetd/clan.h:101:9`!;
632 if (member->fullmembercxx . . $ pvpgn/bnetd/_clanmember#fullmember. == 1) /* only fullmembers are stored */
633 stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "%i,%c,%u\n", account_get_uidcxx . . $ `src/bnetd/account.h:91:9`!((t_account*)member->memberacc), member->statuscxx . . $ pvpgn/bnetd/_clanmember#status. + '0', (unsigned)member->join_timecxx . . $ pvpgn/bnetd/_clanmember#join_time.);
634 }
635
636 stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp);
637 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)clanfile);
638 return 0;
639 }
640
641 static int file_remove_clancxx . . $ pvpgn/bnetd/file_remove_clan(7864480464b09eea).(int clantag)
642 {
643 char *tempname;
644
645 tempname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(clansdir) + 1 + 4 + 1);
646 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(tempname, "%s/%s", clansdircxx . . $ pvpgn/bnetd/clansdir., clantag_to_strcxx . . $ pvpgn/bnetd/clantag_to_str(81a3ae90da26a711).(clantag));
647 if (stdcxx . . $ std/::removecxx . . $ std/remove(f5ecf3191ed0cd93).((const char *)tempname) < 0)
648 {
649 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not delete clan file \"{}\" (std::remove: {})", (char *)tempname, stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
650 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
651 return -1;
652 }
653 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
654 return 0;
655 }
656
657 static int file_remove_clanmembercxx . . $ pvpgn/bnetd/file_remove_clanmember(7864480464b09eea).(int uid)
658 {
659 return 0;
660 }
661
662 static int file_load_teamscxx . . $ pvpgn/bnetd/file_load_teams(53fea8456a5967d6).(t_load_teams_funccxx . . $ pvpgn/bnetd/t_load_teams_func# cb)
663 {
664 char const *dentry;
665 char *pathname;
666 unsigned int teamid;
667 t_teamcxx . . $ pvpgn/bnetd/t_team# *team;
668 stdcxx . . $ std/::FILEcxx . . $ std/FILE# *fp;
669 char * line;
670 unsigned int fteamid, lastgame;
671 unsigned char size;
672 char clienttag[5];
673 int i;
674
675 if (cb == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
676 {
677 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "get NULL callback");
678 return -1;
679 }
680
681 try {
682 Directorycxx . . $ pvpgn/Directory# teamdircxx . . $ pvpgn/Directory#Directory(a3b17e0268c60856).(teamsdircxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
683
684 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "start reading teams");
685
686 pathname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(teamsdir) + 1 + 8 + 1);
687 while ((dentry = teamdir.readcxx . . $ pvpgn/Directory#read(a9f41ea0e82d88cf).()))
688 {
689 if (stdcxx . . $ std/::strlen(dentry) != 8)
690 {
691 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found invalid team filename in teamdir \"{}\"", dentry);
692 continue;
693 }
694
695 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(pathname, "%s/%s", teamsdircxx . . $ pvpgn/bnetd/teamsdir., dentry);
696
697 teamid = (unsigned int)stdcxx . . $ std/::strtoul(dentry, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 16); // we use hexadecimal teamid as filename
698
699 if ((fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(pathname, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
700 {
701 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "can't open teamfile \"{}\"", pathname);
702 continue;
703 }
704
705 team = (t_teamcxx . . $ pvpgn/bnetd/t_team#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_team));
706 team->teamidcxx . . $ pvpgn/bnetd/team#teamid. = teamid;
707
708 if (!(line = file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(fp)))
709 {
710 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: file is empty");
711 goto load_team_failure;
712 }
713
714 if (stdcxx . . $ std/::sscanfcxx . . $ std/sscanf(6246fabbf6b5312d).(line, "%u,%c,%4s,%u", &fteamid, &size, clienttag, &lastgame) != 4)
715 {
716 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: invalid number of arguments on first line");
717 goto load_team_failure;
718 }
719
720 if (fteamid != teamid)
721 {
722 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: filename and stored teamid don't match");
723 goto load_team_failure;
724 }
725
726 size -= '0';
727 if ((size<2) || (size>4))
728 {
729 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: invalid team size");
730 goto load_team_failure;
731 }
732 team->sizecxx . . $ pvpgn/bnetd/team#size. = size;
733
734 if (!(tag_check_clientcxx . . $ pvpgn/tag_check_client(4c679297bf94b9eb).(team->clienttagcxx . . $ pvpgn/bnetd/team#clienttag. = tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(clienttag))))
735 {
736 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: invalid clienttag");
737 goto load_team_failure;
738 }
739 team->lastgamecxx . . $ pvpgn/bnetd/team#lastgame. = (stdcxx . . $ std/::time_tcxx . . $ std/time_t#)lastgame;
740
741 if (!(line = file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(fp)))
742 {
743 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: missing 2nd line");
744 goto load_team_failure;
745 }
746
747 if (stdcxx . . $ std/::sscanfcxx . . $ std/sscanf(6246fabbf6b5312d).(line, "%u,%u,%u,%u", &team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[0], &team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[1], &team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[2], &team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[3]) != 4)
748 {
749 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: invalid number of arguments on 2nd line");
750 goto load_team_failure;
751 }
752
753 for (i = 0; i < MAX_TEAMSIZEcxx . . $ `src/bnetd/team.h:36:9`!; i++)
754 {
755 if (i < size)
756 {
757 if ((team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[i] == 0))
758 {
759 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: too few members");
760 goto load_team_failure;
761 }
762 }
763 else
764 {
765 if ((team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[i] != 0))
766 {
767 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: too many members");
768 goto load_team_failure;
769 }
770
771 }
772 team->memberscxx . . $ pvpgn/bnetd/team#members.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
773 }
774
775 if (!(line = file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(fp)))
776 {
777 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: missing 3rd line");
778 goto load_team_failure;
779 }
780
781 if (stdcxx . . $ std/::sscanfcxx . . $ std/sscanf(6246fabbf6b5312d).(line, "%d,%d,%d,%d,%d", &team->winscxx . . $ pvpgn/bnetd/team#wins., &team->lossescxx . . $ pvpgn/bnetd/team#losses., &team->xpcxx . . $ pvpgn/bnetd/team#xp., &team->levelcxx . . $ pvpgn/bnetd/team#level., &team->rankcxx . . $ pvpgn/bnetd/team#rank.) != 5)
782 {
783 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "invalid team file: invalid number of arguments on 3rd line");
784 goto load_team_failure;
785 }
786
787 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "succesfully loaded team {}", dentry);
788 cb(team);
789
790 goto load_team_success;
791 load_team_failure:
792 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)team);
793 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "error while reading file \"{}\"", dentry);
794
795 load_team_success:
796
797 file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); // clear file_get_line buffer
798 stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp);
799
800
801 }
802
803 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)pathname);
804
805 }
806 catch (const Directorycxx . . $ pvpgn/Directory#::OpenErrorcxx . . $ pvpgn/Directory#OpenError#& ex) {
807 ERROR2cxx . . $ `src/common/eventlog.h:75:9`!("unable to open team directory \"{}\" for reading (error: {})", teamsdir, ex.what());
808 return -1;
809 }
810
811 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_tracecxx . . $ pvpgn/eventlog_level_trace., __FUNCTION__, "finished reading teams");
812
813 return 0;
814 }
815
816 static int file_write_teamcxx . . $ pvpgn/bnetd/file_write_team(dedf1e9b1c614a07).(void *data)
817 {
818 stdcxx . . $ std/::FILEcxx . . $ std/FILE# *fp;
819 char *teamfile;
820 t_teamcxx . . $ pvpgn/bnetd/t_team# *team = (t_teamcxx . . $ pvpgn/bnetd/t_team# *)data;
821
822 teamfile = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(teamsdir) + 1 + 8 + 1);
823 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(teamfile, "%s/%08x", teamsdircxx . . $ pvpgn/bnetd/teamsdir., team->teamidcxx . . $ pvpgn/bnetd/team#teamid.);
824
825 if ((fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(teamfile, "w")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
826 {
827 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "can't open teamfile \"{}\"", teamfile);
828 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)teamfile);
829 return -1;
830 }
831
832 stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "%u,%c,%s,%u\n", team->teamidcxx . . $ pvpgn/bnetd/team#teamid., team->sizecxx . . $ pvpgn/bnetd/team#size. + '0', clienttag_uint_to_strcxx . . $ pvpgn/clienttag_uint_to_str(81a3ae90da26a711).(team->clienttagcxx . . $ pvpgn/bnetd/team#clienttag.), (unsigned int)team->lastgamecxx . . $ pvpgn/bnetd/team#lastgame.);
833 stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "%u,%u,%u,%u\n", team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[0], team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[1], team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[2], team->teammemberscxx . . $ pvpgn/bnetd/team#teammembers.[3]);
834 stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "%d,%d,%d,%d,%d\n", team->winscxx . . $ pvpgn/bnetd/team#wins., team->lossescxx . . $ pvpgn/bnetd/team#losses., team->xpcxx . . $ pvpgn/bnetd/team#xp., team->levelcxx . . $ pvpgn/bnetd/team#level., team->rankcxx . . $ pvpgn/bnetd/team#rank.);
835
836 stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp);
837 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)teamfile);
838
839 return 0;
840 }
841
842 static int file_remove_teamcxx . . $ pvpgn/bnetd/file_remove_team(4c679297bf94b9eb).(unsigned int teamid)
843 {
844
845 char *tempname;
846
847 tempname = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(clansdir) + 1 + 8 + 1);
848 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(tempname, "%s/%08x", clansdircxx . . $ pvpgn/bnetd/clansdir., teamid);
849 if (stdcxx . . $ std/::removecxx . . $ std/remove(f5ecf3191ed0cd93).((const char *)tempname) < 0)
850 {
851 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not delete team file \"{}\" (std::remove: {})", (char *)tempname, stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
852 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
853 return -1;
854 }
855 xfreecxx . . $ `src/common/xalloc.h:51:9`!(tempname);
856
857 return 0;
858 }
859
860 }
861
862 }