| 4660 | } |
| 4661 | |
| 4662 | static win_rendezvous_status_t win_endpoint_refresh_rendezvous( |
| 4663 | const cbm_daemon_ipc_endpoint_t *endpoint) { |
| 4664 | if (!endpoint || !endpoint->user_sid || endpoint->user_sid_length == 0) { |
| 4665 | return WIN_RENDEZVOUS_ERROR; |
| 4666 | } |
| 4667 | cbm_private_lock_directory_t *directory = NULL; |
| 4668 | cbm_private_file_lock_t *record_lock = NULL; |
| 4669 | cbm_private_file_lock_status_t directory_status = |
| 4670 | cbm_daemon_ipc_private_lock_directory_new(endpoint, &directory); |
| 4671 | if (directory_status != CBM_PRIVATE_FILE_LOCK_OK) { |
| 4672 | win_endpoint_generation_invalidate(endpoint); |
| 4673 | return WIN_RENDEZVOUS_ERROR; |
| 4674 | } |
| 4675 | cbm_private_file_lock_status_t lock_status = cbm_private_file_lock_try_acquire( |
| 4676 | directory, CBM_DAEMON_IPC_WINDOWS_RENDEZVOUS_FILE, CBM_PRIVATE_FILE_LOCK_SH, &record_lock); |
| 4677 | if (lock_status != CBM_PRIVATE_FILE_LOCK_OK) { |
| 4678 | win_private_lock_release_complete(&record_lock); |
| 4679 | cbm_private_lock_directory_close(directory); |
| 4680 | win_endpoint_generation_invalidate(endpoint); |
| 4681 | return lock_status == CBM_PRIVATE_FILE_LOCK_BUSY ? WIN_RENDEZVOUS_BUSY |
| 4682 | : WIN_RENDEZVOUS_ERROR; |
| 4683 | } |
| 4684 | |
| 4685 | uint8_t record[CBM_DAEMON_IPC_WINDOWS_RENDEZVOUS_RECORD_SIZE]; |
| 4686 | size_t record_length = 0; |
| 4687 | cbm_private_file_lock_status_t read_status = |
| 4688 | cbm_private_file_lock_payload_read(record_lock, record, sizeof(record), &record_length); |
| 4689 | uint8_t nonce[CBM_DAEMON_IPC_WINDOWS_NONCE_SIZE]; |
| 4690 | char address[CBM_DAEMON_IPC_WINDOWS_NAME_CAP]; |
| 4691 | bool decoded = |
| 4692 | read_status == CBM_PRIVATE_FILE_LOCK_OK && |
| 4693 | cbm_daemon_ipc_windows_rendezvous_record_decode(record, record_length, nonce, address); |
| 4694 | char expected[CBM_DAEMON_IPC_WINDOWS_NAME_CAP]; |
| 4695 | bool bound = |
| 4696 | decoded && |
| 4697 | cbm_daemon_ipc_windows_generation_address(endpoint->user_sid, endpoint->user_sid_length, |
| 4698 | endpoint->instance_key, nonce, expected) && |
| 4699 | strcmp(expected, address) == 0; |
| 4700 | win_rendezvous_status_t result; |
| 4701 | if (read_status != CBM_PRIVATE_FILE_LOCK_OK) { |
| 4702 | win_endpoint_generation_invalidate(endpoint); |
| 4703 | result = WIN_RENDEZVOUS_ERROR; |
| 4704 | } else if (record_length == 0) { |
| 4705 | win_endpoint_generation_invalidate(endpoint); |
| 4706 | result = WIN_RENDEZVOUS_ABSENT; |
| 4707 | } else if (!bound) { |
| 4708 | win_endpoint_generation_invalidate(endpoint); |
| 4709 | result = WIN_RENDEZVOUS_CORRUPT; |
| 4710 | } else if (!win_endpoint_generation_install(endpoint, address)) { |
| 4711 | win_endpoint_generation_invalidate(endpoint); |
| 4712 | result = WIN_RENDEZVOUS_ERROR; |
| 4713 | } else { |
| 4714 | result = WIN_RENDEZVOUS_VALID; |
| 4715 | } |
| 4716 | /* Keep the record lock through the in-memory snapshot update. Otherwise |
| 4717 | * a reader of generation N could install/invalidate after a startup owner |
| 4718 | * has published generation N+1, regressing this endpoint to stale state. */ |
| 4719 | win_private_lock_release_complete(&record_lock); |
no test coverage detected