| | 84 | wd_account_t * wd_accounts_read_user_and_group(wi_string_t *name) { |
|---|
| | 85 | wd_account_t *user, *group; |
|---|
| | 86 | |
|---|
| | 87 | user = wd_accounts_read_user(name); |
|---|
| | 88 | |
|---|
| | 89 | if(!user) |
|---|
| | 90 | return NULL; |
|---|
| | 91 | |
|---|
| | 92 | if(wi_string_length(user->group) > 0) { |
|---|
| | 93 | group = wd_accounts_read_group(user->group); |
|---|
| | 94 | |
|---|
| | 95 | if(group) { |
|---|
| | 96 | user->get_user_info = group->get_user_info; |
|---|
| | 97 | user->broadcast = group->broadcast; |
|---|
| | 98 | user->post_news = group->post_news; |
|---|
| | 99 | user->clear_news = group->clear_news; |
|---|
| | 100 | user->download = group->download; |
|---|
| | 101 | user->upload = group->upload; |
|---|
| | 102 | user->upload_anywhere = group->upload_anywhere; |
|---|
| | 103 | user->create_folders = group->create_folders; |
|---|
| | 104 | user->alter_files = group->alter_files; |
|---|
| | 105 | user->delete_files = group->delete_files; |
|---|
| | 106 | user->view_dropboxes = group->view_dropboxes; |
|---|
| | 107 | user->create_accounts = group->create_accounts; |
|---|
| | 108 | user->edit_accounts = group->edit_accounts; |
|---|
| | 109 | user->delete_accounts = group->delete_accounts; |
|---|
| | 110 | user->elevate_privileges = group->elevate_privileges; |
|---|
| | 111 | user->kick_users = group->kick_users; |
|---|
| | 112 | user->ban_users = group->ban_users; |
|---|
| | 113 | user->cannot_be_kicked = group->cannot_be_kicked; |
|---|
| | 114 | user->download_speed = group->download_speed; |
|---|
| | 115 | user->upload_speed = group->upload_speed; |
|---|
| | 116 | user->download_limit = group->download_limit; |
|---|
| | 117 | user->upload_limit = group->upload_limit; |
|---|
| | 118 | user->set_topic = group->set_topic; |
|---|
| | 119 | |
|---|
| | 120 | wi_release(user->files); |
|---|
| | 121 | user->files = wi_retain(group->files); |
|---|
| | 122 | } |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | return user; |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| | 128 | |
|---|
| | 129 | |
|---|
| | 130 | wd_account_t * wd_accounts_read_user(wi_string_t *name) { |
|---|
| | 131 | wi_file_t *file; |
|---|
| | 132 | wi_array_t *array; |
|---|
| | 133 | wi_string_t *string; |
|---|
| | 134 | wd_account_t *account = NULL; |
|---|
| | 135 | |
|---|
| | 136 | wi_lock_lock(wd_users_lock); |
|---|
| | 137 | |
|---|
| | 138 | file = wi_file_for_reading(wd_settings.users); |
|---|
| | 139 | |
|---|
| | 140 | if(!file) { |
|---|
| | 141 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.users); |
|---|
| | 142 | |
|---|
| | 143 | goto end; |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | while((string = wi_file_read_config_line(file))) { |
|---|
| | 147 | array = wi_string_components_separated_by_string(string, WI_STR(":")); |
|---|
| | 148 | |
|---|
| | 149 | if(wi_array_count(array) > 0 && wi_is_equal(WI_ARRAY(array, 0), name)) { |
|---|
| | 150 | account = wd_account_init_user_with_array(wd_account_alloc(), array); |
|---|
| | 151 | |
|---|
| | 152 | break; |
|---|
| | 153 | } |
|---|
| | 154 | } |
|---|
| | 155 | |
|---|
| | 156 | end: |
|---|
| | 157 | wi_lock_unlock(wd_users_lock); |
|---|
| | 158 | |
|---|
| | 159 | return wi_autorelease(account); |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | |
|---|
| | 163 | |
|---|
| | 164 | wd_account_t * wd_accounts_read_group(wi_string_t *name) { |
|---|
| | 165 | wi_file_t *file; |
|---|
| | 166 | wi_array_t *array; |
|---|
| | 167 | wi_string_t *string; |
|---|
| | 168 | wd_account_t *account = NULL; |
|---|
| | 169 | |
|---|
| | 170 | wi_lock_lock(wd_groups_lock); |
|---|
| | 171 | |
|---|
| | 172 | file = wi_file_for_reading(wd_settings.groups); |
|---|
| | 173 | |
|---|
| | 174 | if(!file) { |
|---|
| | 175 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.groups); |
|---|
| | 176 | |
|---|
| | 177 | goto end; |
|---|
| | 178 | } |
|---|
| | 179 | |
|---|
| | 180 | while((string = wi_file_read_config_line(file))) { |
|---|
| | 181 | array = wi_string_components_separated_by_string(string, WI_STR(":")); |
|---|
| | 182 | |
|---|
| | 183 | if(wi_array_count(array) > 0 && wi_is_equal(WI_ARRAY(array, 0), name)) { |
|---|
| | 184 | account = wd_account_init_group_with_array(wd_account_alloc(), array); |
|---|
| | 185 | |
|---|
| | 186 | break; |
|---|
| | 187 | } |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | end: |
|---|
| | 191 | wi_lock_unlock(wd_groups_lock); |
|---|
| | 192 | |
|---|
| | 193 | return wi_autorelease(account); |
|---|
| | 194 | } |
|---|
| | 195 | |
|---|
| | 196 | |
|---|
| | 197 | |
|---|
| | 198 | wi_boolean_t wd_accounts_create_user(wd_account_t *account) { |
|---|
| | 199 | wi_file_t *file; |
|---|
| | 200 | wi_boolean_t result = false; |
|---|
| | 201 | |
|---|
| | 202 | wi_lock_lock(wd_users_lock); |
|---|
| | 203 | |
|---|
| | 204 | file = wi_file_for_updating(wd_settings.users); |
|---|
| | 205 | |
|---|
| | 206 | if(!file) { |
|---|
| | 207 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.users); |
|---|
| | 208 | |
|---|
| | 209 | goto end; |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | wi_file_write(file, WI_STR("%#@:%#@:%#@:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%u:%u:%u:%u:%d:%#@\n"), |
|---|
| | 213 | account->name, |
|---|
| | 214 | account->password, |
|---|
| | 215 | account->group, |
|---|
| | 216 | account->get_user_info, |
|---|
| | 217 | account->broadcast, |
|---|
| | 218 | account->post_news, |
|---|
| | 219 | account->clear_news, |
|---|
| | 220 | account->download, |
|---|
| | 221 | account->upload, |
|---|
| | 222 | account->upload_anywhere, |
|---|
| | 223 | account->create_folders, |
|---|
| | 224 | account->alter_files, |
|---|
| | 225 | account->delete_files, |
|---|
| | 226 | account->view_dropboxes, |
|---|
| | 227 | account->create_accounts, |
|---|
| | 228 | account->edit_accounts, |
|---|
| | 229 | account->delete_accounts, |
|---|
| | 230 | account->elevate_privileges, |
|---|
| | 231 | account->kick_users, |
|---|
| | 232 | account->ban_users, |
|---|
| | 233 | account->cannot_be_kicked, |
|---|
| | 234 | account->download_speed, |
|---|
| | 235 | account->upload_speed, |
|---|
| | 236 | account->download_limit, |
|---|
| | 237 | account->upload_limit, |
|---|
| | 238 | account->set_topic, |
|---|
| | 239 | account->files); |
|---|
| | 240 | |
|---|
| | 241 | result = true; |
|---|
| | 242 | |
|---|
| | 243 | end: |
|---|
| | 244 | wi_lock_unlock(wd_users_lock); |
|---|
| | 245 | |
|---|
| | 246 | return result; |
|---|
| | 247 | } |
|---|
| | 248 | |
|---|
| | 249 | |
|---|
| | 250 | |
|---|
| | 251 | wi_boolean_t wd_accounts_create_group(wd_account_t *account) { |
|---|
| | 252 | wi_file_t *file; |
|---|
| | 253 | wi_boolean_t result = false; |
|---|
| | 254 | |
|---|
| | 255 | wi_lock_lock(wd_groups_lock); |
|---|
| | 256 | |
|---|
| | 257 | file = wi_file_for_updating(wd_settings.groups); |
|---|
| | 258 | |
|---|
| | 259 | if(!file) { |
|---|
| | 260 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.groups); |
|---|
| | 261 | |
|---|
| | 262 | goto end; |
|---|
| | 263 | } |
|---|
| | 264 | |
|---|
| | 265 | wi_file_write(file, WI_STR("%#@:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%u:%u:%u:%u:%d:%#@\n"), |
|---|
| | 266 | account->name, |
|---|
| | 267 | account->get_user_info, |
|---|
| | 268 | account->broadcast, |
|---|
| | 269 | account->post_news, |
|---|
| | 270 | account->clear_news, |
|---|
| | 271 | account->download, |
|---|
| | 272 | account->upload, |
|---|
| | 273 | account->upload_anywhere, |
|---|
| | 274 | account->create_folders, |
|---|
| | 275 | account->alter_files, |
|---|
| | 276 | account->delete_files, |
|---|
| | 277 | account->view_dropboxes, |
|---|
| | 278 | account->create_accounts, |
|---|
| | 279 | account->edit_accounts, |
|---|
| | 280 | account->delete_accounts, |
|---|
| | 281 | account->elevate_privileges, |
|---|
| | 282 | account->kick_users, |
|---|
| | 283 | account->ban_users, |
|---|
| | 284 | account->cannot_be_kicked, |
|---|
| | 285 | account->download_speed, |
|---|
| | 286 | account->upload_speed, |
|---|
| | 287 | account->download_limit, |
|---|
| | 288 | account->upload_limit, |
|---|
| | 289 | account->set_topic, |
|---|
| | 290 | account->files); |
|---|
| | 291 | |
|---|
| | 292 | result = true; |
|---|
| | 293 | |
|---|
| | 294 | end: |
|---|
| | 295 | wi_lock_unlock(wd_groups_lock); |
|---|
| | 296 | |
|---|
| | 297 | return result; |
|---|
| | 298 | } |
|---|
| | 299 | |
|---|
| | 300 | |
|---|
| | 301 | |
|---|
| | 302 | wi_boolean_t wd_accounts_edit_user(wd_account_t *account) { |
|---|
| | 303 | if(!wd_accounts_delete_user(account->name)) |
|---|
| | 304 | return false; |
|---|
| | 305 | |
|---|
| | 306 | if(!wd_accounts_create_user(account)) |
|---|
| | 307 | return false; |
|---|
| | 308 | |
|---|
| | 309 | _wd_accounts_reload_user(account->name); |
|---|
| | 310 | |
|---|
| | 311 | return true; |
|---|
| | 312 | } |
|---|
| | 313 | |
|---|
| | 314 | |
|---|
| | 315 | |
|---|
| | 316 | wi_boolean_t wd_accounts_edit_group(wd_account_t *account) { |
|---|
| | 317 | if(!wd_accounts_delete_group(account->name)) |
|---|
| | 318 | return false; |
|---|
| | 319 | |
|---|
| | 320 | if(!wd_accounts_create_group(account)) |
|---|
| | 321 | return false; |
|---|
| | 322 | |
|---|
| | 323 | _wd_accounts_reload_group(account->name); |
|---|
| | 324 | |
|---|
| | 325 | return true; |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | |
|---|
| | 329 | |
|---|
| | 330 | wi_boolean_t wd_accounts_delete_user(wi_string_t *name) { |
|---|
| | 331 | wi_file_t *file; |
|---|
| | 332 | wi_boolean_t result; |
|---|
| | 333 | |
|---|
| | 334 | wi_lock_lock(wd_users_lock); |
|---|
| | 335 | |
|---|
| | 336 | file = wi_file_for_updating(wd_settings.users); |
|---|
| | 337 | |
|---|
| | 338 | if(!file) { |
|---|
| | 339 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.users); |
|---|
| | 340 | |
|---|
| | 341 | result = -1; |
|---|
| | 342 | goto end; |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | result = _wd_accounts_delete_from_file(file, name); |
|---|
| | 346 | |
|---|
| | 347 | if(!result) |
|---|
| | 348 | wd_reply(513, WI_STR("Account Not Found")); |
|---|
| | 349 | |
|---|
| | 350 | end: |
|---|
| | 351 | wi_lock_unlock(wd_users_lock); |
|---|
| | 352 | |
|---|
| | 353 | return result; |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | |
|---|
| | 357 | |
|---|
| | 358 | wi_boolean_t wd_accounts_delete_group(wi_string_t *name) { |
|---|
| | 359 | wi_file_t *file; |
|---|
| | 360 | wi_boolean_t result; |
|---|
| | 361 | |
|---|
| | 362 | wi_lock_lock(wd_groups_lock); |
|---|
| | 363 | |
|---|
| | 364 | file = wi_file_for_updating(wd_settings.groups); |
|---|
| | 365 | |
|---|
| | 366 | if(!file) { |
|---|
| | 367 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.groups); |
|---|
| | 368 | |
|---|
| | 369 | result = -1; |
|---|
| | 370 | goto end; |
|---|
| | 371 | } |
|---|
| | 372 | |
|---|
| | 373 | result = _wd_accounts_delete_from_file(file, name); |
|---|
| | 374 | |
|---|
| | 375 | if(!result) |
|---|
| | 376 | wd_reply(513, WI_STR("Account Not Found")); |
|---|
| | 377 | |
|---|
| | 378 | end: |
|---|
| | 379 | wi_lock_unlock(wd_groups_lock); |
|---|
| | 380 | |
|---|
| | 381 | return result; |
|---|
| | 382 | } |
|---|
| | 383 | |
|---|
| | 384 | |
|---|
| | 385 | |
|---|
| | 386 | wi_boolean_t wd_accounts_clear_group(wi_string_t *name) { |
|---|
| | 387 | wi_file_t *file, *tmpfile = NULL; |
|---|
| | 388 | wi_array_t *array; |
|---|
| | 389 | wi_string_t *string; |
|---|
| | 390 | wi_boolean_t result = false; |
|---|
| | 391 | |
|---|
| | 392 | wi_lock_lock(wd_users_lock); |
|---|
| | 393 | |
|---|
| | 394 | file = wi_file_for_updating(wd_settings.users); |
|---|
| | 395 | |
|---|
| | 396 | if(!file) { |
|---|
| | 397 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.users); |
|---|
| | 398 | |
|---|
| | 399 | goto end; |
|---|
| | 400 | } |
|---|
| | 401 | |
|---|
| | 402 | tmpfile = wi_file_temporary_file(); |
|---|
| | 403 | |
|---|
| | 404 | if(!tmpfile) { |
|---|
| | 405 | wi_log_err(WI_STR("Could not create a temporary file: %m")); |
|---|
| | 406 | |
|---|
| | 407 | goto end; |
|---|
| | 408 | } |
|---|
| | 409 | |
|---|
| | 410 | while((string = wi_file_read_line(file))) |
|---|
| | 411 | wi_file_write(tmpfile, WI_STR("%@\n"), string); |
|---|
| | 412 | |
|---|
| | 413 | wi_file_truncate(file, 0); |
|---|
| | 414 | wi_file_seek(tmpfile, 0); |
|---|
| | 415 | |
|---|
| | 416 | while((string = wi_file_read_line(tmpfile))) { |
|---|
| | 417 | if(wi_string_length(string) > 0 && !wi_string_has_prefix(string, WI_STR("#"))) { |
|---|
| | 418 | array = wi_string_components_separated_by_string(string, WI_STR(":")); |
|---|
| | 419 | |
|---|
| | 420 | if(wi_array_count(array) > 2 && wi_is_equal(WI_ARRAY(array, 2), name)) { |
|---|
| | 421 | wi_array_replace_data_at_index(array, WI_STR(""), 2); |
|---|
| | 422 | |
|---|
| | 423 | string = wi_array_components_joined_by_string(array, WI_STR(":")); |
|---|
| | 424 | } |
|---|
| | 425 | } |
|---|
| | 426 | |
|---|
| | 427 | wi_file_write(file, WI_STR("%@\n"), string); |
|---|
| | 428 | } |
|---|
| | 429 | |
|---|
| | 430 | end: |
|---|
| | 431 | wi_lock_unlock(wd_users_lock); |
|---|
| | 432 | |
|---|
| | 433 | return result; |
|---|
| | 434 | } |
|---|
| | 435 | |
|---|
| | 436 | |
|---|
| | 437 | |
|---|
| | 438 | wi_boolean_t wd_accounts_check_privileges(wd_account_t *account) { |
|---|
| | 439 | wd_client_t *client = wd_client(); |
|---|
| | 440 | |
|---|
| | 441 | if(!client->account->elevate_privileges) { |
|---|
| | 442 | if(account->get_user_info && !client->account->get_user_info) |
|---|
| | 443 | return false; |
|---|
| | 444 | |
|---|
| | 445 | if(account->broadcast && !client->account->broadcast) |
|---|
| | 446 | return false; |
|---|
| | 447 | |
|---|
| | 448 | if(account->post_news && !client->account->post_news) |
|---|
| | 449 | return false; |
|---|
| | 450 | |
|---|
| | 451 | if(account->clear_news && !client->account->clear_news) |
|---|
| | 452 | return false; |
|---|
| | 453 | |
|---|
| | 454 | if(account->download && !client->account->download) |
|---|
| | 455 | return false; |
|---|
| | 456 | |
|---|
| | 457 | if(account->upload && !client->account->upload) |
|---|
| | 458 | return false; |
|---|
| | 459 | |
|---|
| | 460 | if(account->upload_anywhere && !client->account->upload_anywhere) |
|---|
| | 461 | return false; |
|---|
| | 462 | |
|---|
| | 463 | if(account->create_folders && !client->account->create_folders) |
|---|
| | 464 | return false; |
|---|
| | 465 | |
|---|
| | 466 | if(account->alter_files && !client->account->alter_files) |
|---|
| | 467 | return false; |
|---|
| | 468 | |
|---|
| | 469 | if(account->delete_files && !client->account->delete_files) |
|---|
| | 470 | return false; |
|---|
| | 471 | |
|---|
| | 472 | if(account->view_dropboxes && !client->account->view_dropboxes) |
|---|
| | 473 | return false; |
|---|
| | 474 | |
|---|
| | 475 | if(account->create_accounts && !client->account->create_accounts) |
|---|
| | 476 | return false; |
|---|
| | 477 | |
|---|
| | 478 | if(account->edit_accounts && !client->account->edit_accounts) |
|---|
| | 479 | return false; |
|---|
| | 480 | |
|---|
| | 481 | if(account->delete_accounts && !client->account->delete_accounts) |
|---|
| | 482 | return false; |
|---|
| | 483 | |
|---|
| | 484 | if(account->elevate_privileges && !client->account->elevate_privileges) |
|---|
| | 485 | return false; |
|---|
| | 486 | |
|---|
| | 487 | if(account->kick_users && !client->account->kick_users) |
|---|
| | 488 | return false; |
|---|
| | 489 | |
|---|
| | 490 | if(account->ban_users && !client->account->ban_users) |
|---|
| | 491 | return false; |
|---|
| | 492 | |
|---|
| | 493 | if(account->cannot_be_kicked && !client->account->cannot_be_kicked) |
|---|
| | 494 | return false; |
|---|
| | 495 | |
|---|
| | 496 | if(account->set_topic && !client->account->set_topic) |
|---|
| | 497 | return false; |
|---|
| | 498 | } |
|---|
| | 499 | |
|---|
| | 500 | return true; |
|---|
| | 501 | } |
|---|
| | 502 | |
|---|
| | 503 | |
|---|
| | 504 | |
|---|
| | 505 | void wd_accounts_reload_users(void) { |
|---|
| | 506 | wi_enumerator_t *enumerator; |
|---|
| | 507 | wd_client_t *client; |
|---|
| | 508 | |
|---|
| | 509 | wi_hash_rdlock(wd_clients); |
|---|
| | 510 | |
|---|
| | 511 | enumerator = wi_hash_data_enumerator(wd_clients); |
|---|
| | 512 | |
|---|
| | 513 | while((client = wi_enumerator_next_data(enumerator))) |
|---|
| | 514 | _wd_accounts_reload_client(client); |
|---|
| | 515 | |
|---|
| | 516 | wi_hash_unlock(wd_clients); |
|---|
| | 517 | } |
|---|
| | 518 | |
|---|
| | 519 | |
|---|
| | 520 | |
|---|
| | 521 | #pragma mark - |
|---|
| | 522 | |
|---|
| | 523 | static int _wd_accounts_delete_from_file(wi_file_t *file, wi_string_t *name) { |
|---|
| | 524 | wi_file_t *tmpfile; |
|---|
| | 525 | wi_array_t *array; |
|---|
| | 526 | wi_string_t *string; |
|---|
| | 527 | wi_boolean_t result = false; |
|---|
| | 528 | |
|---|
| | 529 | tmpfile = wi_file_temporary_file(); |
|---|
| | 530 | |
|---|
| | 531 | if(!tmpfile) { |
|---|
| | 532 | wi_log_err(WI_STR("Could not create a temporary file: %m")); |
|---|
| | 533 | |
|---|
| | 534 | return false; |
|---|
| | 535 | } |
|---|
| | 536 | |
|---|
| | 537 | while((string = wi_file_read_line(file))) { |
|---|
| | 538 | if(wi_string_length(string) == 0 || wi_string_has_prefix(string, WI_STR("#"))) { |
|---|
| | 539 | wi_file_write(tmpfile, WI_STR("%@\n"), string); |
|---|
| | 540 | } else { |
|---|
| | 541 | array = wi_string_components_separated_by_string(string, WI_STR(":")); |
|---|
| | 542 | |
|---|
| | 543 | if(wi_array_count(array) > 0 && wi_is_equal(WI_ARRAY(array, 0), name)) |
|---|
| | 544 | result = true; |
|---|
| | 545 | else |
|---|
| | 546 | wi_file_write(tmpfile, WI_STR("%@\n"), string); |
|---|
| | 547 | } |
|---|
| | 548 | } |
|---|
| | 549 | |
|---|
| | 550 | wi_file_truncate(file, 0); |
|---|
| | 551 | wi_file_seek(tmpfile, 0); |
|---|
| | 552 | |
|---|
| | 553 | while((string = wi_file_read(tmpfile, WI_FILE_BUFFER_SIZE))) |
|---|
| | 554 | wi_file_write(file, WI_STR("%@"), string); |
|---|
| | 555 | |
|---|
| | 556 | return result; |
|---|
| | 557 | } |
|---|
| | 558 | |
|---|
| | 559 | |
|---|
| | 560 | |
|---|
| | 561 | static void _wd_accounts_reload_user(wi_string_t *name) { |
|---|
| | 562 | wi_enumerator_t *enumerator; |
|---|
| | 563 | wd_client_t *client; |
|---|
| | 564 | |
|---|
| | 565 | wi_hash_rdlock(wd_clients); |
|---|
| | 566 | |
|---|
| | 567 | enumerator = wi_hash_data_enumerator(wd_clients); |
|---|
| | 568 | |
|---|
| | 569 | while((client = wi_enumerator_next_data(enumerator))) { |
|---|
| | 570 | if(wi_is_equal(client->account->name, name)) |
|---|
| | 571 | _wd_accounts_reload_client(client); |
|---|
| | 572 | } |
|---|
| | 573 | |
|---|
| | 574 | wi_hash_unlock(wd_clients); |
|---|
| | 575 | } |
|---|
| | 576 | |
|---|
| | 577 | |
|---|
| | 578 | |
|---|
| | 579 | static void _wd_accounts_reload_group(wi_string_t *name) { |
|---|
| | 580 | wi_enumerator_t *enumerator; |
|---|
| | 581 | wd_client_t *client; |
|---|
| | 582 | |
|---|
| | 583 | wi_hash_rdlock(wd_clients); |
|---|
| | 584 | |
|---|
| | 585 | enumerator = wi_hash_data_enumerator(wd_clients); |
|---|
| | 586 | |
|---|
| | 587 | while((client = wi_enumerator_next_data(enumerator))) { |
|---|
| | 588 | if(wi_is_equal(client->account->group, name)) |
|---|
| | 589 | _wd_accounts_reload_client(client); |
|---|
| | 590 | } |
|---|
| | 591 | |
|---|
| | 592 | wi_hash_unlock(wd_clients); |
|---|
| | 593 | } |
|---|
| | 594 | |
|---|
| | 595 | |
|---|
| | 596 | |
|---|
| | 597 | static void _wd_accounts_reload_client(wd_client_t *client) { |
|---|
| | 598 | wd_account_t *account; |
|---|
| | 599 | wi_boolean_t admin; |
|---|
| | 600 | |
|---|
| | 601 | account = wd_accounts_read_user_and_group(client->account->name); |
|---|
| | 602 | |
|---|
| | 603 | if(!account) |
|---|
| | 604 | return; |
|---|
| | 605 | |
|---|
| | 606 | wi_retain(account); |
|---|
| | 607 | wi_release(client->account); |
|---|
| | 608 | |
|---|
| | 609 | client->account = account; |
|---|
| | 610 | |
|---|
| | 611 | wi_lock_lock(client->flag_lock); |
|---|
| | 612 | admin = client->admin; |
|---|
| | 613 | client->admin = (client->account->kick_users || client->account->ban_users); |
|---|
| | 614 | wi_lock_unlock(client->flag_lock); |
|---|
| | 615 | |
|---|
| | 616 | if(client->admin != admin) |
|---|
| | 617 | wd_client_broadcast_status(client); |
|---|
| | 618 | |
|---|
| | 619 | wd_client_lock_socket(client); |
|---|
| | 620 | _wd_accounts_sreply_privileges(client); |
|---|
| | 621 | wd_client_unlock_socket(client); |
|---|
| | 622 | } |
|---|
| | 623 | |
|---|
| | 624 | |
|---|
| | 625 | |
|---|
| | 626 | static void _wd_accounts_sreply_privileges(wd_client_t *client) { |
|---|
| | 627 | wd_sreply(client->socket, 602, WI_STR("%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%u%c%u%c%u%c%u%c%d"), |
|---|
| | 628 | client->account->get_user_info, WD_FIELD_SEPARATOR, |
|---|
| | 629 | client->account->broadcast, WD_FIELD_SEPARATOR, |
|---|
| | 630 | client->account->post_news, WD_FIELD_SEPARATOR, |
|---|
| | 631 | client->account->clear_news, WD_FIELD_SEPARATOR, |
|---|
| | 632 | client->account->download, WD_FIELD_SEPARATOR, |
|---|
| | 633 | client->account->upload, WD_FIELD_SEPARATOR, |
|---|
| | 634 | client->account->upload_anywhere, WD_FIELD_SEPARATOR, |
|---|
| | 635 | client->account->create_folders, WD_FIELD_SEPARATOR, |
|---|
| | 636 | client->account->alter_files, WD_FIELD_SEPARATOR, |
|---|
| | 637 | client->account->delete_files, WD_FIELD_SEPARATOR, |
|---|
| | 638 | client->account->view_dropboxes, WD_FIELD_SEPARATOR, |
|---|
| | 639 | client->account->create_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 640 | client->account->edit_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 641 | client->account->delete_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 642 | client->account->elevate_privileges, WD_FIELD_SEPARATOR, |
|---|
| | 643 | client->account->kick_users, WD_FIELD_SEPARATOR, |
|---|
| | 644 | client->account->ban_users, WD_FIELD_SEPARATOR, |
|---|
| | 645 | client->account->cannot_be_kicked, WD_FIELD_SEPARATOR, |
|---|
| | 646 | client->account->download_speed, WD_FIELD_SEPARATOR, |
|---|
| | 647 | client->account->upload_speed, WD_FIELD_SEPARATOR, |
|---|
| | 648 | client->account->download_limit, WD_FIELD_SEPARATOR, |
|---|
| | 649 | client->account->upload_limit, WD_FIELD_SEPARATOR, |
|---|
| | 650 | client->account->set_topic); |
|---|
| | 651 | } |
|---|
| | 652 | |
|---|
| | 653 | |
|---|
| | 654 | |
|---|
| | 655 | #pragma mark - |
|---|
| | 656 | |
|---|
| | 657 | void wd_accounts_reply_privileges(void) { |
|---|
| | 658 | _wd_accounts_sreply_privileges(wd_client()); |
|---|
| | 659 | } |
|---|
| | 660 | |
|---|
| | 661 | |
|---|
| | 662 | |
|---|
| | 663 | void wd_accounts_reply_user_account(wi_string_t *name) { |
|---|
| | 664 | wd_account_t *account; |
|---|
| | 665 | |
|---|
| | 666 | account = wd_accounts_read_user(name); |
|---|
| | 667 | |
|---|
| | 668 | if(!account) { |
|---|
| | 669 | wd_reply(513, WI_STR("Account Not Found")); |
|---|
| | 670 | |
|---|
| | 671 | return; |
|---|
| | 672 | } |
|---|
| | 673 | |
|---|
| | 674 | wd_reply(600, WI_STR("%#@%c%#@%c%#@%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%u%c%u%c%u%c%u%c%d"), |
|---|
| | 675 | account->name, WD_FIELD_SEPARATOR, |
|---|
| | 676 | account->password, WD_FIELD_SEPARATOR, |
|---|
| | 677 | account->group, WD_FIELD_SEPARATOR, |
|---|
| | 678 | account->get_user_info, WD_FIELD_SEPARATOR, |
|---|
| | 679 | account->broadcast, WD_FIELD_SEPARATOR, |
|---|
| | 680 | account->post_news, WD_FIELD_SEPARATOR, |
|---|
| | 681 | account->clear_news, WD_FIELD_SEPARATOR, |
|---|
| | 682 | account->download, WD_FIELD_SEPARATOR, |
|---|
| | 683 | account->upload, WD_FIELD_SEPARATOR, |
|---|
| | 684 | account->upload_anywhere, WD_FIELD_SEPARATOR, |
|---|
| | 685 | account->create_folders, WD_FIELD_SEPARATOR, |
|---|
| | 686 | account->alter_files, WD_FIELD_SEPARATOR, |
|---|
| | 687 | account->delete_files, WD_FIELD_SEPARATOR, |
|---|
| | 688 | account->view_dropboxes, WD_FIELD_SEPARATOR, |
|---|
| | 689 | account->create_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 690 | account->edit_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 691 | account->delete_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 692 | account->elevate_privileges, WD_FIELD_SEPARATOR, |
|---|
| | 693 | account->kick_users, WD_FIELD_SEPARATOR, |
|---|
| | 694 | account->ban_users, WD_FIELD_SEPARATOR, |
|---|
| | 695 | account->cannot_be_kicked, WD_FIELD_SEPARATOR, |
|---|
| | 696 | account->download_speed, WD_FIELD_SEPARATOR, |
|---|
| | 697 | account->upload_speed, WD_FIELD_SEPARATOR, |
|---|
| | 698 | account->download_limit, WD_FIELD_SEPARATOR, |
|---|
| | 699 | account->upload_limit, WD_FIELD_SEPARATOR, |
|---|
| | 700 | account->set_topic); |
|---|
| | 701 | } |
|---|
| | 702 | |
|---|
| | 703 | |
|---|
| | 704 | |
|---|
| | 705 | void wd_accounts_reply_group_account(wi_string_t *name) { |
|---|
| | 706 | wd_account_t *account; |
|---|
| | 707 | |
|---|
| | 708 | account = wd_accounts_read_group(name); |
|---|
| | 709 | |
|---|
| | 710 | if(!account) { |
|---|
| | 711 | wd_reply(513, WI_STR("Account Not Found")); |
|---|
| | 712 | |
|---|
| | 713 | return; |
|---|
| | 714 | } |
|---|
| | 715 | |
|---|
| | 716 | wd_reply(601, WI_STR("%#@%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%d%c%u%c%u%c%u%c%u%c%d"), |
|---|
| | 717 | account->name, WD_FIELD_SEPARATOR, |
|---|
| | 718 | account->get_user_info, WD_FIELD_SEPARATOR, |
|---|
| | 719 | account->broadcast, WD_FIELD_SEPARATOR, |
|---|
| | 720 | account->post_news, WD_FIELD_SEPARATOR, |
|---|
| | 721 | account->clear_news, WD_FIELD_SEPARATOR, |
|---|
| | 722 | account->download, WD_FIELD_SEPARATOR, |
|---|
| | 723 | account->upload, WD_FIELD_SEPARATOR, |
|---|
| | 724 | account->upload_anywhere, WD_FIELD_SEPARATOR, |
|---|
| | 725 | account->create_folders, WD_FIELD_SEPARATOR, |
|---|
| | 726 | account->alter_files, WD_FIELD_SEPARATOR, |
|---|
| | 727 | account->delete_files, WD_FIELD_SEPARATOR, |
|---|
| | 728 | account->view_dropboxes, WD_FIELD_SEPARATOR, |
|---|
| | 729 | account->create_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 730 | account->edit_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 731 | account->delete_accounts, WD_FIELD_SEPARATOR, |
|---|
| | 732 | account->elevate_privileges, WD_FIELD_SEPARATOR, |
|---|
| | 733 | account->kick_users, WD_FIELD_SEPARATOR, |
|---|
| | 734 | account->ban_users, WD_FIELD_SEPARATOR, |
|---|
| | 735 | account->cannot_be_kicked, WD_FIELD_SEPARATOR, |
|---|
| | 736 | account->download_speed, WD_FIELD_SEPARATOR, |
|---|
| | 737 | account->upload_speed, WD_FIELD_SEPARATOR, |
|---|
| | 738 | account->download_limit, WD_FIELD_SEPARATOR, |
|---|
| | 739 | account->upload_limit, WD_FIELD_SEPARATOR, |
|---|
| | 740 | account->set_topic); |
|---|
| | 741 | } |
|---|
| | 742 | |
|---|
| | 743 | |
|---|
| | 744 | |
|---|
| | 745 | void wd_accounts_reply_user_list(void) { |
|---|
| | 746 | wi_file_t *file; |
|---|
| | 747 | wi_string_t *string; |
|---|
| | 748 | uint32_t index; |
|---|
| | 749 | |
|---|
| | 750 | wi_lock_lock(wd_users_lock); |
|---|
| | 751 | |
|---|
| | 752 | file = wi_file_for_reading(wd_settings.users); |
|---|
| | 753 | |
|---|
| | 754 | if(!file) { |
|---|
| | 755 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.users); |
|---|
| | 756 | |
|---|
| | 757 | goto end; |
|---|
| | 758 | } |
|---|
| | 759 | |
|---|
| | 760 | while((string = wi_file_read_config_line(file))) { |
|---|
| | 761 | index = wi_string_index_of_string(string, WI_STR(":"), 0); |
|---|
| | 762 | |
|---|
| | 763 | if(index != WI_NOT_FOUND && index > 0) { |
|---|
| | 764 | wi_string_delete_characters_from_index(string, index); |
|---|
| | 765 | |
|---|
| | 766 | wd_reply(610, WI_STR("%#@"), string); |
|---|
| | 767 | } |
|---|
| | 768 | } |
|---|
| | 769 | |
|---|
| | 770 | end: |
|---|
| | 771 | wd_reply(611, WI_STR("Done")); |
|---|
| | 772 | |
|---|
| | 773 | wi_lock_unlock(wd_users_lock); |
|---|
| | 774 | } |
|---|
| | 775 | |
|---|
| | 776 | |
|---|
| | 777 | |
|---|
| | 778 | void wd_accounts_reply_group_list(void) { |
|---|
| | 779 | wi_file_t *file; |
|---|
| | 780 | wi_string_t *string; |
|---|
| | 781 | uint32_t index; |
|---|
| | 782 | |
|---|
| | 783 | wi_lock_lock(wd_groups_lock); |
|---|
| | 784 | |
|---|
| | 785 | file = wi_file_for_reading(wd_settings.groups); |
|---|
| | 786 | |
|---|
| | 787 | if(!file) { |
|---|
| | 788 | wi_log_err(WI_STR("Could not open %@: %m"), wd_settings.groups); |
|---|
| | 789 | |
|---|
| | 790 | goto end; |
|---|
| | 791 | } |
|---|
| | 792 | |
|---|
| | 793 | while((string = wi_file_read_config_line(file))) { |
|---|
| | 794 | index = wi_string_index_of_string(string, WI_STR(":"), 0); |
|---|
| | 795 | |
|---|
| | 796 | if(index != WI_NOT_FOUND && index > 0) { |
|---|
| | 797 | wi_string_delete_characters_from_index(string, index); |
|---|
| | 798 | |
|---|
| | 799 | wd_reply(620, WI_STR("%#@"), string); |
|---|
| | 800 | } |
|---|
| | 801 | } |
|---|
| | 802 | |
|---|
| | 803 | end: |
|---|
| | 804 | wd_reply(621, WI_STR("Done")); |
|---|
| | 805 | |
|---|
| | 806 | wi_lock_unlock(wd_groups_lock); |
|---|
| | 807 | } |
|---|
| | 808 | |
|---|
| | 809 | |
|---|
| | 810 | |
|---|
| | 811 | #pragma mark - |
|---|
| | 812 | |
|---|