Commit Graph

186 Commits

Author SHA1 Message Date
Levi Neely beaa76adfb
Fix uninitialized keyParams in ptools_create_backend_event (#299)
keyParams is only allocated when pCnt > 0 but freed unconditionally.
When pCnt == 0, free() is called on an uninitialized pointer (UB).

Initialize to NULL so free() is a no-op when allocation is skipped.

Fixes GH #214

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 12:10:44 +01:00
Levi Neely c514fa1a29
Fix MAP_FAILED detection in pmem_mmap (#298)
mmap(2) returns MAP_FAILED ((void*)-1) on error, not NULL. The check
'if (likely(ret))' treats MAP_FAILED as truthy, so the emergency retry
path is never reached and callers receive MAP_FAILED as a valid pointer.

Normalize pmem_mmap() to return NULL on failure (converting MAP_FAILED
to NULL in the mmap path). This confines the platform-specific error
handling to one place and eliminates the need for preprocessor checks
in pmem_mmap_safe() and psync_mmap_anon_emergency().

Fixes GH #226

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 12:03:30 +01:00
Levi Neely 0f23a32793
Fix input validation: stoull exception and buffer bounds (#297)
- Wrap std::stoull() in try/catch to prevent daemon crash on invalid folder ID
- Add proper read loop for RPC messages to handle partial reads
- Validate msg->length before memcpy to prevent heap over-read
- Handle daemon bugs gracefully (EOF before full message)
- Fix operator precedence in sync remove command

Fixes #205, #206

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 11:55:54 +01:00
Levi Neely 73a57c994b
Fix exception handling and operator precedence bugs (#296)
- Add return statement in catch(...) block to prevent fallthrough
- Fix operator precedence in GetState() to capture Call() return value

Fixes #201, #202

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 11:55:36 +01:00
Levi Neely 175a46a109
Fix exception handling and operator precedence bugs (#295)
- Add return statement in catch(...) block to prevent fallthrough
- Fix operator precedence in GetState() to capture Call() return value

Fixes #201, #202

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 11:25:25 +01:00
Levi Neely c0cc893cc7
Fix umask and password memory wipe (#294)
* Fix debug build segfault: add strong overrides for psql_lock/unlock functions

The weak/strong symbol approach requires that psql.c undefs the debug
macros to define function implementations. This means functions in psql.c
call psql_lock()/psql_unlock() as functions, not macros.

In debug builds, these must be strong overrides that call the _do_
variants to properly maintain lockctr/rdlockctr. Without these overrides,
the weak stubs are used which don't update counters, causing assertion
failures in psql_unlock().

Added strong overrides in psql_debug.c for:
- psql_lock() -> psql_do_lock(__FILE__, __LINE__)
- psql_rdlock() -> psql_do_rdlock(__FILE__, __LINE__)
- psql_statement() (calls psql_do_lock directly)

Also made psql_statement, psql_start, and all query/prepare functions
weak in psql.c to allow debug overrides.

Fixes #138

* Fix umask and password memory wipe

- Set umask(0077) in daemonize() to prevent world-readable files
- Wipe password from memory after psync_set_user_pass()

Fixes #203, #204

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 11:20:07 +01:00
Levi Neely 61259858c8
Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177)
The weak/strong symbol approach requires that psql.c undefs the debug
macros to define function implementations. This means functions in psql.c
call psql_lock()/psql_unlock() as functions, not macros.

In debug builds, these must be strong overrides that call the _do_
variants to properly maintain lockctr/rdlockctr. Without these overrides,
the weak stubs are used which don't update counters, causing assertion
failures in psql_unlock().

Added strong overrides in psql_debug.c for:
- psql_lock() -> psql_do_lock(__FILE__, __LINE__)
- psql_rdlock() -> psql_do_rdlock(__FILE__, __LINE__)
- psql_statement() (calls psql_do_lock directly)

Also made psql_statement, psql_start, and all query/prepare functions
weak in psql.c to allow debug overrides.

Fixes #138

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 07:59:30 +01:00
Levi Neely 4d64b645a1
Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176)
* Fix #103: Refactor putil to use putil_ namespace and enforce encapsulation

All public functions in putil now use the putil_ prefix (e.g., putil_strdup,
putil_strcat, putil_time_format, putil_base64_encode, etc.). Internal
variables (normalize_table, base64_reverse_table) and the constructor remain
static. Updated all 34 call-site files across pclsync accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix #96: Refactor pfs to use pfs_ namespace and enforce encapsulation

All public functions in the pfs module renamed from psync_fs_ to pfs_
(e.g., pfs_update_openfile, pfs_refresh, pfs_start, pfs_stop, etc.).
Extern vars psync_fake_prefix/psync_fake_prefix_len renamed to
pfs_fake_prefix/pfs_fake_prefix_len. Functions only used within pfs.c
(pfs_update_openfile_fileid_locked, pfs_chown) made static. Updated all
call sites across 17 files including pclsync_lib.cpp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Refactor pfsxattr to use pfs_xattr_ namespace

All psync_fs_ prefixed functions in the pfsxattr module renamed to
pfs_xattr_ (e.g., pfs_xattr_set, pfs_xattr_get, pfs_xattr_list,
pfs_xattr_remove, pfs_xattr_file_deleted, pfs_xattr_task_to_file, etc.).
Local macro psync_fs_set_thread_name renamed to pfs_xattr_set_thread_name.
Internal static helpers (delete_object_id, update_object_id,
xattr_get_object_id_locked) remain static and unchanged.
Updated all call sites in pfs.c, pfsupload.c, and pdiff.c.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Rename pfs_xattr_ namespace to pfs_xatr_

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Refactor pfs sub-modules to use namespaced function prefixes

- pfscrypto_* → pfs_crpt_*
- psync_fsstatic_* → pfs_stat_*
- psync_fsupload_* → pfs_upld_*
- psync_fstask_* → pfs_task_* (functions only; typedefs unchanged)
- psync_fsfolder_*/psync_fsfolderid_*/psync_fsfolderflags_*/
  get_decname_for_folder/psync_get_folderid → pfs_fldr_*

Type names, macro constants, and typedef aliases are unchanged.
Updated all call sites across 17 files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 22:51:25 +01:00
Levi Neely d6858a0166
Fix #90, #109: Support 2FA when running as a daemon (#175)
* Fix #90: Support 2FA when running as a daemon

In daemon mode, when PSTATUS_TFA_REQUIRED fires:
- Automatically send an SMS 2FA code via psync_tfa_send_sms()
- Log delivery details to syslog with instructions to use
  `echo 'tfa CODE' | pcloudcc -k`
- Block on a condition variable until the code arrives via RPC

Add a new `tfa <code>` command to the pcloudcc -k control interface.
This sends the code to the daemon over the existing Unix socket RPC
channel (SENDTFA message type).

Bad codes (PSTATUS_BAD_TFA_CODE) are handled: the daemon logs a syslog
warning and waits for a corrected code without re-sending SMS.

Devices are trusted by default (trusted=1 in psync_tfa_set_code) so
repeated 2FA prompts are avoided for the configured trust period.
TFA codes are wiped from memory after use.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add auth command: supply password to running daemon

Mirrors the tfa command pattern. When PSTATUS_LOGIN_REQUIRED fires in
daemon mode, read_password() now logs a syslog notice and blocks on a
condition variable rather than calling exit(1).

The new `auth <password>` control command (SENDAUTH RPC type) signals
the condvar and unblocks the daemon. Usage:

  echo 'auth PASSWORD' | pcloudcc -k

The password is wiped from the CLI-side buffer immediately after the
RPC call. putil_wipe() is used for both the tfa and auth transient
strings on the sending side.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add status command: show current sync state from CLI

Adds a `status` (alias `st`) command to the interactive CLI and to the
pcloudcc -k control interface. The daemon-side handler calls
psync_get_status(), formats the status name plus download/upload
strings, and writes the result to shared memory. The client reads and
prints it.

Example output:
  Status:   READY
  Download: idle
  Upload:   idle

Also works non-interactively:
  echo 'status' | pcloudcc -k

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 21:36:33 +01:00
Levi Neely e3b9f7bfd8
Remove obsolete Pending Transfers section from README (#174)
* Fix #67: Add sync pause and sync resume commands

Wire psync_pause() and psync_resume() from the C library into the RPC
command layer, registering SYNCPAUSE and SYNCRESUME handlers and exposing
them as 'sync pause' and 'sync resume' CLI subcommands.

Note: daemon quit is already handled by the existing 'finalize' command,
which calls psync_destroy() and exits the daemon process cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Remove obsolete Pending Transfers section from README

The pending command now provides a proper way to check for pending
transfers, making the manual cache-inspection workaround obsolete.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 20:17:10 +01:00
Levi Neely 79371d9aac
Fix #67: Add sync pause and sync resume commands (#173)
Wire psync_pause() and psync_resume() from the C library into the RPC
command layer, registering SYNCPAUSE and SYNCRESUME handlers and exposing
them as 'sync pause' and 'sync resume' CLI subcommands.

Note: daemon quit is already handled by the existing 'finalize' command,
which calls psync_destroy() and exits the daemon process cleanly.

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 20:12:53 +01:00
Levi Neely 0a697794dd
Add new pCloud SSL certificate fingerprint (#172)
Add SHA256 fingerprint 1b1b4d26a98774c84709c5400cd5c0b5e2f0bc7d46ef6053c9a872efe825b116 to fix OFFLINE status after pCloud SSL key rotation.

Fixes #171

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-01 09:14:29 +01:00
Levi Neely 4a870f8835
Add reference to pcloudcc-service (#170)
* Fix #162: Add distro-agnostic mbedtls detection

- Use pkg-config to dynamically detect mbedtls variants (mbedtls3.x, mbedtls)
- Fallback to /usr/local if pkg-config unavailable
- Tested on Fedora 41 (mbedtls3.6), Arch Linux (mbedtls 3.6.5), Debian Bookworm, and Slackware
- Eliminates need for hardcoded version-specific paths

* Add reference to pcloudcc-service

Closes #159

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-02-27 09:26:46 +01:00
Levi Neely 63d650b6c8
Fix #162: Add distro-agnostic mbedtls detection (#169)
- Use pkg-config to dynamically detect mbedtls variants (mbedtls3.x, mbedtls)
- Fallback to /usr/local if pkg-config unavailable
- Tested on Fedora 41 (mbedtls3.6), Arch Linux (mbedtls 3.6.5), Debian Bookworm, and Slackware
- Eliminates need for hardcoded version-specific paths

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-02-27 09:20:06 +01:00
Levi Neely 0900f742bb
Fix MBEDTLS-3.x.md: Add LIBLDFLAGS update to linker path (#168)
Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-02-27 08:44:38 +01:00
Chris82111 29b45cf218
Retry opening without the O_NOATIME flag (#167)
Change looks good, much appreciated! :) Merged.
2026-02-27 08:40:38 +01:00
Jonathan Senkerik 441a0d69ed
Refactor logging, add cache-size, fs-event-log (#163)
Much appreciated! Merged. :)
2026-02-27 08:38:28 +01:00
Levi Neely b9ea6ca4c9 Remove unused psync_status_file/folder wrappers
- Both functions were pure aliases to psync_filesystem_status()
- Never called anywhere in the codebase
- Simplified API documentation to reference only psync_filesystem_status()
2026-02-14 20:08:01 +01:00
Levi Neely 2c5e32e910 Fix #95: Remove unused get_token() wrapper from pclsync_lib
- Eliminates thin wrapper that just called psync_get_token()
- Function was declared but never used
- Simplifies pclsync_lib API as per issue #95
2026-02-14 20:08:01 +01:00
Levi Neely 11074655db Fix #8: Add pending transfer check feature
- Add new 'pending' command (alias 'p') to check for pending transfers
- Enhance 'finalize' command to warn about pending transfers
- Prompt for confirmation in interactive mode before shutdown
- Use psync_get_status() API for reliable transfer detection
- Shows upload/download counts separately
- Fix mbedtls 3.6 compatibility issues in pssl.c
- Update Makefile for mbedtls 3.x static linking
2026-02-14 19:43:13 +01:00
Levi Neely e566c7822a Fix #107: Add SMS 2FA support
- Enhance read_tfa_code() to offer SMS option
- User can type 'sms' to receive code via SMS
- Display phone number when SMS is sent
- Falls back to authenticator app if SMS fails
- Uses existing psync_tfa_send_sms() API
2026-02-14 19:20:10 +01:00
Levi 0a14098935 arm64 arch devhost 2025-07-20 16:01:47 +02:00
Levi Neely a11575b9da
fix compile errors (#155) 2025-05-15 19:14:57 +02:00
ahuemmer 95cbf63a57
fix: add stdlib to fix build (#153) 2025-04-20 22:41:33 +02:00
Levi Neely 6540e14732
move folder-related code from psynclib to pfolder 2025-04-18 15:23:50 +02:00
Levi Neely 1dd703142d
Merge branch 'nix-shell' [#151] 2025-04-18 13:29:37 +02:00
Levi Neely 2df5ef876f
add watchexec to dev shell 2025-04-18 11:32:16 +02:00
kost a4b92682ba
Musl fixes (#143)
* use libunwind where glibc is not available

* use sys/stat.h for struct stat definition
2025-04-13 09:11:11 +02:00
Levi Neely 9842c90f89
direnv (#150)
* enable direnv for dev shell
2025-04-13 08:53:41 +02:00
Levi Neely 376fbfffc9
Merge branch 'main' into nix-shell 2025-04-13 08:52:37 +02:00
Levi Neely 0ce5713f0f enable direnv for dev shell 2025-04-13 08:47:23 +02:00
Levi Neely 3dfb8de927
Nix shell uses flakes (#147)
* nix shell now uses flakes
2025-04-11 20:55:58 +02:00
Levi Neely 1ae036c032 nix shell now uses flakes 2025-04-11 20:54:28 +02:00
Levi Neely 1938924218 Merge branch 'main' into nix-shell 2025-04-11 20:54:08 +02:00
Levi Neely 1e2d16cb7f
nix dev shell (#146) 2025-04-11 00:44:35 +02:00
Levi Neely 87bbab2d06 nix dev shell 2025-04-11 00:41:26 +02:00
Levi Neely cf818e539e
Update README.md (#145) 2025-04-08 14:45:08 +02:00
Levi Neely 9087e5d3ac
update devscripts, new arch devhost (#144) 2025-04-06 23:01:31 +02:00
V10lator bd576e3c5b
Allow custom flags (#141)
Signed-off-by: Thomas Rohloff <v10lator@myway.de>
2025-03-18 19:55:15 +01:00
Levi Neely 6994a3cac9
102 create a psql namespace (#142)
* another stupid macro gone

* more stupid macros gone. moved util functions from plibs to putil

* remaining plist and ptask functions moved to appropriate namespaces

* dead code beleted!

* bugfixes

* move sql functions to psql.c

* move sort functions into ppagecache

* psql namespace

* change plibs.h include to pdbg.h

* cleanup includes
2025-03-18 19:52:15 +01:00
Levi Neely 58461232db
fix weird name (#140) 2025-03-13 20:44:42 +01:00
Levi Neely 9014edb99a
98 create a pdbg namespace (#139)
* pdbg split from plibs
* pdbg namespace
* add SSLDBGLVL build option
2025-03-13 20:28:09 +01:00
Levi Neely 9da561c767
131 remove custom memory management wrappers (#137)
* psync_free removed

* psync_malloc removed

* psync_realloc removed

* remove dead code

* remove pmemlock

* remove dead code
2025-03-11 22:27:30 +01:00
Levi Neely 3fd249f3f8
manual formatting (#136) 2025-03-11 21:36:26 +01:00
Levi Neely 3e177864ec
use process_command in process_commands (#135) 2025-03-11 20:49:22 +01:00
Levi Neely ce6033fe95
130 use trustworthy location for log and socket (#134)
* trustworthy location for log and socket
- socket in => $HOME/.pcloud/prpc.sock (mode 0600)
- debug log => $HOME/.pcloud/debug.log
* documentation updates
2025-03-11 19:03:58 +01:00
Levi Neely 79141898c3
84 security enhancements (#133)
- DoD 5220.22-M compliant memory wipe replaces single-pass zero wipe
- Wipe in-memory request and response messages before freeing
- Wipe in-memory private keys and salt data before freeing
- Wipe all passwords on unlink / logout
- Wipe crypto password on all pcryptofolder_unlock return paths
2025-03-11 15:05:43 +01:00
Levi Neely 3c713d6437
remove version check and download code (#127) 2025-03-09 20:36:25 +01:00
Levi Neely 28b985649f
rpcclient is now part of the CLI program (#126) 2025-03-09 20:20:33 +01:00
Levi Neely d3bea1c641
access pcryptofolder directly from pclsync_lib (#125)
* access pcryptofolder directly from pclsync_lib
* move issetup to pcryptofolder
2025-03-09 19:58:00 +01:00