Artifact 70827414995447c6309aeb283d2c75d15d7fa81461e6b37197b21b039c8100d4:
- File
src/remote.h
— part of check-in
[fe29cebc6a]
at
2026-11-13 20:38:51
on branch trunk
— Phase 7b-1: a wardrobe syncs with a remote, over file:// and http://
suit remote sets, shows or clears a wardrobe's remote address. An address that carries a user name or password is refused. suit login reads a secret from standard input into a credentials file of mode 0600, and suit refuses to use that file if anyone else can read it. The secret is never printed, never put in an error message or another file, and is wiped from memory after each use.
suit sync pulls, brings the working copy forward with the safe update, and pushes. When both sides have new check-ins it tries a merge as a dry run. A clean merge is checked in and pushed. A conflicting one changes no file, is pushed as a fork so nothing is lost, and is written to the attention file. No conflict marker is ever written to a live file. With local changes in the working copy the pull is kept and nothing else happens.
suit tend now continues into a sync after its check-in.
Three limits of libfossil, each handled here: its merge drops a file the other side deleted, so suit finds those itself and treats a delete against an edit as a conflict; a merge that changes no file cannot be checked in, so the files are put back and the fork stays open; and a file:// remote is reached through the stock fossil program, which must be on the path. http:// uses libfossil's own socket code and starts no other program.
An https:// address is accepted and stored, and syncing it says this build cannot use https yet. There is no clone command yet.
Also: LICENSE (BSD 2-Clause, the same as libfossil), a license section and current status in the README, and a state table in docs/phases.md.
1204 unit checks, 227 shell cases, 555 store cases, 612 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask. 100% coverage in all 22 source files. Seven fuzz targets. No suite has fewer cases than at the last check-in. (user: dmestas, size: 3057) [annotate] [blame] [check-ins using]
#ifndef SUIT_REMOTE_H #define SUIT_REMOTE_H #include <stddef.h> #include <stdint.h> // Two small files in $SUIT_HOME, each parsed strictly (a line that is not // exactly what is described is an error and the whole file is rejected) and // rewritten atomically. // // remotes: one line per wardrobe, "NAME URL". A URL is file://ABSOLUTE/PATH, // http://HOST[:PORT]/PATH or https://HOST[:PORT]/PATH, with no user name or // password in it. // // credentials: mode 0600, one line per wardrobe, "NAME USER SECRET". The // secret is printable ASCII with no space. It is never printed or written // anywhere else, and is wiped from memory after use. constexpr size_t REMOTE_FILE_MAX = 65536; constexpr size_t REMOTE_URL_MAX = 1024; constexpr size_t REMOTE_LINE_MAX = 1280; constexpr uint32_t REMOTE_ENTRY_MAX = 256; constexpr size_t CRED_USER_MAX = 64; constexpr size_t CRED_SECRET_MAX = 256; typedef struct { int line; // 0 when the error concerns the whole file char msg[200]; } RemoteError; typedef struct { char name[129]; char url[REMOTE_URL_MAX + 1]; } RemoteEntry; typedef struct { uint32_t n; RemoteEntry e[REMOTE_ENTRY_MAX]; } Remotes; typedef struct { char name[129]; char user[CRED_USER_MAX + 1]; char secret[CRED_SECRET_MAX + 1]; } CredEntry; typedef struct { uint32_t n; CredEntry e[REMOTE_ENTRY_MAX]; } Creds; // Nullptr if the LEN bytes are an address suit accepts, else why not. The // reason never repeats the address, which might carry a password. const char *remote_url_check(const char *url, size_t len); // Parse DATA. On failure R is empty and ERR says what and where. [[nodiscard]] bool remotes_parse(Remotes *r, const char *data, size_t len, RemoteError *err); [[nodiscard]] bool creds_parse(Creds *c, const char *data, size_t len, RemoteError *err); // Read PATH. A file that is not there is an empty list. creds_load also // refuses a file that anyone but its owner can use. [[nodiscard]] bool remotes_load(Remotes *r, const char *path, RemoteError *err); [[nodiscard]] bool creds_load(Creds *c, const char *path, RemoteError *err); // Write the entries sorted by name, atomically. Returns 0 or an errno value. int remotes_write(const Remotes *r, const char *path); int creds_write(const Creds *c, const char *path); RemoteEntry *remotes_find(Remotes *r, const char *name); CredEntry *creds_find(Creds *c, const char *name); // Overwrite N bytes at P so the compiler cannot drop it. void secret_wipe(void *p, size_t n); // The host (and port) part of URL, or for file:// its path, for messages. void remote_host(const char *url, char *out, size_t cap); // The commands. Each returns an exit code after reporting on stderr or stdout. // cmd_remote: URL null shows (exit 1 if none), "--none" clears. int cmd_remote(const char *name, const char *url); // Reads the secret from standard input. int cmd_login(const char *name, const char *user); int cmd_logout(const char *name); // The files' paths for the sync. int remote_paths(char *remotes, char *creds, size_t cap); #endif