QtPass Developer documentation
QtPass test coverage
Current view: top level - src/realpass.h (source / functions) Coverage Total Hit
Test: QtPass Lines: 50.0 % 4 2
Test Date: 2026-12-03 23:34:20 Functions: 50.0 % 2 1

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief RealPass, the backend that hands every store operation to the `pass`
       6              :  * command-line tool.
       7              :  */
       8              : #ifndef SRC_REALPASS_H_
       9              : #define SRC_REALPASS_H_
      10              : 
      11              : #include "nativegrep.h"
      12              : #include "pass.h"
      13              : #include <QHash>
      14              : #include <optional>
      15              : 
      16              : class GpgIdSigner;
      17              : class QFileInfo;
      18              : #include <QQueue>
      19              : #include <QSet>
      20              : 
      21              : /**
      22              :  * @class RealPass
      23              :  * @ingroup backend
      24              :  * @brief Implementation of Pass that wraps the 'pass' command-line tool.
      25              :  *
      26              :  * RealPass delegates all password store operations to the external 'pass'
      27              :  * utility. It provides a Qt-native interface while handling:
      28              :  * - Git integration (init, pull, push)
      29              :  * - Password CRUD (show, insert, remove, move, copy)
      30              :  * - OTP generation
      31              :  * - Store initialization with GPG keys
      32              :  *
      33              :  * This is the primary implementation when 'pass' is available on the system.
      34              :  */
      35              : class RealPass : public Pass {
      36              :   /// The store's own search: `pass grep` runs `find -L`, which follows a
      37              :   /// link out of the store and decrypts what it finds there.
      38              :   NativeGrep m_grep;
      39              :   /// A linked folder whose removal commit is queued, with the store it
      40              :   /// was queued for: the profile may change before the commit ends.
      41              :   struct LinkCommit {
      42              :     QString rel;            ///< The folder, relative to the store.
      43              :     QString passExecutable; ///< The pass that runs the commit.
      44              :     /// Its environment (PASSWORD_STORE_DIR). Not "environ": a macro on
      45              :     /// Windows (stdlib.h).
      46              :     QProcessEnvironment environment;
      47              :   };
      48              :   /// Queued linked-folder removal commits (as GIT_COMMIT), oldest first;
      49              :   /// finished() judges each.
      50              :   QQueue<LinkCommit> m_linkCommits;
      51              : 
      52              :   /**
      53              :    * @brief Report a `pass init`, `mv` or `cp` that exited 0 having left
      54              :    * entries encrypted to the previous recipients: a critical message and
      55              :    * processErrorExit() instead of the completion signal, so the store is
      56              :    * not pushed as it now is (a later push still sends what pass committed).
      57              :    * @param pid PASS_INIT, PASS_MOVE or PASS_COPY.
      58              :    * @param out pass's standard output.
      59              :    * @param err pass's and gpg's standard error, status lines included.
      60              :    */
      61              :   void reportReencryptFailure(Enums::PROCESS pid, const QString &out,
      62              :                               const QString &err);
      63              :   /**
      64              :    * @brief Finish a `pass init`, `mv` or `cp`: hold the automatic push for
      65              :    * a run that left entries to the previous recipients or failed after its
      66              :    * commit, release the holds a clean init covers, report what Git did not
      67              :    * record, then send any deferred push and hand the completion on.
      68              :    * @param pid PASS_INIT, PASS_MOVE or PASS_COPY.
      69              :    * @param exitCode pass's exit code.
      70              :    * @param out pass's standard output.
      71              :    * @param err pass's and gpg's standard error, status lines included.
      72              :    */
      73              :   void finishRecipientRun(Enums::PROCESS pid, int exitCode, const QString &out,
      74              :                           const QString &err);
      75              :   /**
      76              :    * @brief Remove a linked folder for Remove(): unlink it here, so that
      77              :    * `pass rm -rf` cannot follow it, and have pass's git forget and commit
      78              :    * it. Reports a failure, or ends with finishedRemove() or the queued
      79              :    * commit.
      80              :    * @param full The link's cleaned absolute path.
      81              :    */
      82              :   void removeLinkedFolder(const QString &full);
      83              :   /**
      84              :    * @brief Once the last queued init, move or copy has completed, make the
      85              :    * push asked for meanwhile (GitPush()). An automatic one is dropped while
      86              :    * a re-encryption in this store is held, and the status line says why; one
      87              :    * asked for by hand goes.
      88              :    */
      89              :   void sendDeferredPush();
      90              :   /**
      91              :    * @brief Judge a queued linked-folder removal commit by what is left
      92              :    * staged in the store it ran in: `pass git` exits 0 whatever git did.
      93              :    * @param commit The folder and the store it was queued for.
      94              :    * @param out The commit's standard output.
      95              :    * @param err The commit's standard error.
      96              :    */
      97              :   void finishLinkCommit(const LinkCommit &commit, const QString &out,
      98              :                         const QString &err);
      99              : 
     100              :   /**
     101              :    * @brief Execute pass command with arguments.
     102              :    * @param id Process identifier.
     103              :    * @param args Command arguments.
     104              :    * @param input Input to pass to stdin.
     105              :    * @param readStdout Capture stdout.
     106              :    * @param readStderr Capture stderr.
     107              :    */
     108              :   void executePass(PROCESS id, const QStringList &args,
     109              :                    QString input = QString(), bool readStdout = true,
     110              :                    bool readStderr = true);
     111              :   /**
     112              :    * @brief Shared implementation of Move and Copy via `pass mv`/`pass cp`.
     113              :    * @param id Process id (PASS_MOVE or PASS_COPY).
     114              :    * @param subcommand The pass subcommand, "mv" or "cp".
     115              :    * @param src Source path.
     116              :    * @param dest Destination path.
     117              :    * @param force Overwrite an existing entry named as @p dest; without it
     118              :    *        that is refused (pass would otherwise force). Nothing else that
     119              :    *        exists where pass would write is overwritten, with or without it.
     120              :    */
     121              :   void passMoveOrCopy(PROCESS id, const QString &subcommand, const QString &src,
     122              :                       const QString &dest, bool force);
     123              :   /// What `pass mv`/`pass cp` is handed and what it then does with it.
     124              :   struct PassMoveTarget {
     125              :     QString passSrc;  ///< The source name handed to pass.
     126              :     QString passDest; ///< The destination name handed to pass.
     127              :     /// pass's own destination ($new_path): what it re-encrypts and stages,
     128              :     /// absolute.
     129              :     QString newPath;
     130              :     /// What comes out: newPath, or the source's name inside it when newPath
     131              :     /// is a folder (mv and cp put it there), absolute.
     132              :     QString written;
     133              :   };
     134              :   /**
     135              :    * @brief Name @p src and @p dest for `pass mv`/`pass cp`, and work out
     136              :    * where pass 1.7.4 then puts the source.
     137              :    *
     138              :    * pass resolves the names by its own rules: it takes the entry `<name>.gpg`
     139              :    * over a folder of the same name unless the name ends in a slash, appends
     140              :    * `.gpg` to the destination unless a folder is moved or the destination is
     141              :    * a folder (a link to one included), and mv and cp put the source inside
     142              :    * such a folder. The checks run on what this returns, not on the names as
     143              :    * the caller spelled them.
     144              :    * @param src The entry file or folder to move or copy, absolute.
     145              :    * @param dest Where to, absolute, as the caller spelled it.
     146              :    * @return The names for pass and the paths it touches.
     147              :    */
     148              :   auto passMoveTarget(const QString &src, const QString &dest) const
     149              :       -> PassMoveTarget;
     150              :   /**
     151              :    * @brief Whether a move or copy stops at what already lies where pass
     152              :    * writes: a file @p dest the user declined to overwrite, the source
     153              :    * itself under its own name (nothing to do), or anything else there,
     154              :    * which is refused with a message.
     155              :    * @param id PASS_MOVE or PASS_COPY, for the message title.
     156              :    * @param src The entry file or folder, absolute.
     157              :    * @param srcFileInfo @p src, as the caller already asked about it.
     158              :    * @param dest The destination as the caller spelled it, absolute.
     159              :    * @param occupied Where pass writes (PassMoveTarget::written).
     160              :    * @param force Consent to overwrite the entry named as @p dest only.
     161              :    * @return true when pass must not run.
     162              :    */
     163              :   auto stopsAtOccupiedTarget(PROCESS id, const QString &src,
     164              :                              const QFileInfo &srcFileInfo, const QString &dest,
     165              :                              const QString &occupied, bool force) -> bool;
     166              :   /**
     167              :    * @brief Whether a move or copy is refused for what pass would do along
     168              :    * the way: re-encrypt to an unverified list, follow a link inside a copied
     169              :    * folder, commit over unfinished or unrecorded Git work, move ignored
     170              :    * files, or encrypt to a key line two key blocks hold.
     171              :    * @param id PASS_MOVE or PASS_COPY.
     172              :    * @param src The entry file or folder, absolute.
     173              :    * @param srcFileInfo @p src, as the caller already asked about it.
     174              :    * @param target Where pass puts it.
     175              :    * @return true when refused; the refusal has been shown.
     176              :    */
     177              :   auto refuseMoveOrCopyRisks(PROCESS id, const QString &src,
     178              :                              const QFileInfo &srcFileInfo,
     179              :                              const PassMoveTarget &target) -> bool;
     180              :   /**
     181              :    * @brief The recipient lines pass re-encrypts to when it moves or copies
     182              :    * @p src as @p target says: the destination's list, the lists in a moved
     183              :    * folder, and those in a folder it writes into.
     184              :    * @param src The entry file or folder, absolute.
     185              :    * @param target Where pass puts it.
     186              :    * @param srcIsDir Whether @p src is a folder, as already established.
     187              :    * @param intoFolder Whether pass writes into an existing folder, as
     188              :    *        already established.
     189              :    * @return The lines, unsorted, possibly repeated.
     190              :    */
     191              :   [[nodiscard]] auto linesPassEncryptsTo(const QString &src,
     192              :                                          const PassMoveTarget &target,
     193              :                                          bool srcIsDir, bool intoFolder)
     194              :       -> QStringList;
     195              :   /**
     196              :    * @brief @p path as `pass` names it: relative to the store, without the
     197              :    * `.gpg` pass appends itself.
     198              :    * @param path The file or folder, absolute or relative to the working
     199              :    *        directory.
     200              :    * @param stripGpg Whether to drop a trailing `.gpg`.
     201              :    * @return The store-relative name.
     202              :    */
     203              :   auto passName(const QString &path, bool stripGpg) const -> QString;
     204              : 
     205              :   /**
     206              :    * @brief Whether the failed `pass insert` wrote its entry before its git
     207              :    * step failed. pass does not say, so: the entry's bytes differ from what
     208              :    * they were when that insert started to run (a new entry appeared, or an
     209              :    * existing one was rewritten), and pass did not say that the encryption
     210              :    * broke off (gpg can leave a partial file behind then).
     211              :    * @param err What pass reported on stderr.
     212              :    * @return true when the entry was written.
     213              :    */
     214              :   [[nodiscard]] auto insertWritten(const QString &err) const -> bool override;
     215              : 
     216              :   /**
     217              :    * @brief Refuse to have pass encrypt @p file when the list it would use
     218              :    * is a link (refuseLinkedList()), pass would read it differently from
     219              :    * QtPass (refuseMisreadList()), or, with signing on, not one QtPass
     220              :    * accepts: its folder's own list was passed over, the signature does not
     221              :    * verify, or the list is older than one this device accepted or signed
     222              :    * for another folder.
     223              :    * @param file The entry (or the place a move or copy writes to).
     224              :    * @return Whether it was refused (and the user told).
     225              :    */
     226              :   auto refuseUnverifiedList(const QString &file) -> bool;
     227              :   /**
     228              :    * @brief The lines of every folder's own `.gpg-id` that pass's walk of
     229              :    *        @p dir meets, for keyLinesHeldTwice(): pass re-encrypts each
     230              :    *        entry there to its folder's nearest list.
     231              :    * @param dir The folder pass walks.
     232              :    * @param except A list left out (the one Init() replaces); empty for none.
     233              :    * @return Their lines, together.
     234              :    */
     235              :   auto listLinesUnder(const QString &dir, const QString &except) -> QStringList;
     236              :   /**
     237              :    * @brief Whether pass re-encrypting @p entry to @p target would hand it to
     238              :    *        someone who cannot read it now, less whom the change from
     239              :    *        @p before to @p target adds.
     240              :    * @param entry The entry.
     241              :    * @param target The list pass would encrypt it to.
     242              :    * @param before The list that applied to it until now.
     243              :    * @param probes Probes of lists made so far, by their joined lines.
     244              :    * @return true when it would gain such a reader, or the target list
     245              :    *         cannot be probed.
     246              :    */
     247              :   auto entryWouldGain(const QString &entry, const QStringList &target,
     248              :                       const QStringList &before,
     249              :                       QHash<QString, std::optional<QSet<QString>>> &probes)
     250              :       -> bool;
     251              : 
     252              :   /**
     253              :    * @brief Refuse to have pass encrypt @p file when the walk to its list
     254              :    * meets a `.gpg-id` that is a link or junction (Pass::linkedGpgId()),
     255              :    * with or without a signing key: pass would follow it, while QtPass shows
     256              :    * the list of a folder above it.
     257              :    * @param file The entry or folder.
     258              :    * @param within When set, only a link under this folder (absolute,
     259              :    *        cleaned, with a trailing "/") is refused.
     260              :    * @param except A list about to be written (`pass init`'s own), not
     261              :    *        refused.
     262              :    * @param walks Passed on to Pass::linkedGpgId(), for a check of many
     263              :    *        folders; null for none.
     264              :    * @return Whether it was refused (and the user told).
     265              :    */
     266              :   auto refuseLinkedList(const QString &file, const QString &within = QString(),
     267              :                         const QString &except = QString(),
     268              :                         LinkedWalks *walks = nullptr) -> bool;
     269              : 
     270              :   /**
     271              :    * @brief Refuse to have pass encrypt @p file when its nearest `.gpg-id`
     272              :    * holds lines pass reads differently from the Users dialog
     273              :    * (Pass::passReadsDifferently()), with or without a signing key: pass
     274              :    * would encrypt to recipients the dialog does not show. A list that is
     275              :    * there but not a regular file within Util::kMaxGpgIdBytes is refused
     276              :    * too; a missing one is left to pass.
     277              :    * @param file The entry or folder.
     278              :    * @param within When set, only a list under this folder (absolute,
     279              :    *        cleaned, with a trailing "/") is refused.
     280              :    * @param except A list about to be written (`pass init`'s own), not
     281              :    *        refused.
     282              :    * @param checked Lists already found fine in this walk; the list is added
     283              :    *        when it is.
     284              :    * @return Whether it was refused (and the user told).
     285              :    */
     286              :   auto refuseMisreadList(const QString &file, const QString &within,
     287              :                          const QString &except, QSet<QString> &checked) -> bool;
     288              : 
     289              :   /**
     290              :    * @brief Run a git command in the store through `pass git`, blocking.
     291              :    * @param args The git arguments (without `git`).
     292              :    * @param out Receives stdout; may be null.
     293              :    * @return true when `pass git` ran and exited 0 (git on).
     294              :    */
     295              :   auto storeGit(const QStringList &args, QString *out) -> bool override;
     296              : 
     297              :   /**
     298              :    * @brief The Git repository pass commits @p path in: the store's own, or
     299              :    * one a folder in it holds (pass looks for the repository from the
     300              :    * path's folder, as git does).
     301              :    * @param path An absolute path in the store; it need not exist yet.
     302              :    * @return The repository's folder relative to the store, empty for the
     303              :    *         store's own (or when git cannot say).
     304              :    */
     305              :   auto repositoryOf(const QString &path) -> QString;
     306              : 
     307              :   /**
     308              :    * @brief `git status --porcelain -z` through `pass git`, read: one
     309              :    * "XY name" per entry, a rename's old name dropped. Empty without Git, or
     310              :    * when git cannot say.
     311              :    * @param args Further status arguments (options, then a pathspec relative
     312              :    *        to @p repository).
     313              :    * @param repository The repository to ask, as repositoryOf() gives it;
     314              :    *        its entries are named from the store.
     315              :    * @return The entries.
     316              :    */
     317              :   auto statusEntries(const QStringList &args,
     318              :                      const QString &repository = QString()) -> QStringList;
     319              : 
     320              :   /**
     321              :    * @brief What git has not recorded at @p paths: `git status --porcelain`
     322              :    * lines, through `pass git`. Empty without Git, or when git cannot say.
     323              :    * @param paths Absolute paths in the store.
     324              :    * @param ignored Whether ignored files are listed too (as `!!`).
     325              :    * @return The status entries, "XY name" each.
     326              :    */
     327              :   auto unrecorded(const QStringList &paths, bool ignored) -> QStringList;
     328              : 
     329              :   /**
     330              :    * @brief Refuse a `pass init`, `mv`, `cp` or `insert` when @p paths hold
     331              :    * changes git has not recorded, or anything at all is staged in the
     332              :    * repository it commits in. pass stages the folder it wrote with
     333              :    * `git add` and then commits the whole index, so a plaintext export lying
     334              :    * in the folder or staged anywhere, or files a failed pull wrote, would be
     335              :    * committed and pushed along with the change. Ignored files are left
     336              :    * alone, as `git add` leaves them. When the changes include untracked
     337              :    * files a file manager writes by itself (`.DS_Store`, `Thumbs.db`), the
     338              :    * message says which `.gitignore` lines keep them out for good, for the
     339              :    * `.gitignore` of each repository that reports them (unless a deeper
     340              :    * rule there un-ignores them again).
     341              :    * @param paths Absolute paths in the store that pass will stage; empty
     342              :    *        for none (an insert stages its own entry alone).
     343              :    * @param committing Absolute paths pass commits: the index of each one's
     344              :    *        repository (see repositoryOf()) is checked.
     345              :    * @return Whether it was refused (and the user told).
     346              :    */
     347              :   auto refuseUnrecordedChanges(const QStringList &paths,
     348              :                                const QStringList &committing) -> bool;
     349              : 
     350              :   /**
     351              :    * @brief After a `pass insert`, `init`, `mv` or `cp` that exited 0, say
     352              :    * so when git did not record the entries it wrote: pass exits 0 whatever
     353              :    * its `git add` and commit did (an entry a .gitignore matches, say), and
     354              :    * an unrecorded entry is not pushed and a pull may overwrite it.
     355              :    * @param paths Absolute paths the change wrote.
     356              :    */
     357              :   void reportUnrecorded(const QStringList &paths);
     358              : 
     359              :   /**
     360              :    * @brief Refuse a `pass cp` of the folder @p src when anything in it is a
     361              :    * symbolic link or NTFS junction, or a folder in it holds a name Qt cannot
     362              :    * read.
     363              :    *
     364              :    * pass copies with `cp -r`. GNU cp copies a link as a link, but BSD and
     365              :    * macOS cp follow it with `-r`, so what a link pushed into a shared store
     366              :    * points to (a file in the user's home) would be copied into the store and
     367              :    * committed. Refused on every platform, so the result does not depend on
     368              :    * which cp pass finds. Hidden folders are walked too; links are not
     369              :    * followed.
     370              :    * @param src The folder to copy.
     371              :    * @return Whether it was refused (and the user told).
     372              :    */
     373              :   auto refuseLinkInCopiedFolder(const QString &src) -> bool;
     374              : 
     375              :   /**
     376              :    * @brief Refuse a `pass mv` or `cp` of the folder @p src when a file in
     377              :    * it that Git ignores would not be ignored where it lands: a rule naming
     378              :    * the old place (`/team/export.csv`) does not follow the file, and pass
     379              :    * stages the new path whole. Entries and recipient lists are not counted:
     380              :    * committing those is what pass is for.
     381              :    * @param src The folder moved or copied (anything else passes).
     382              :    * @param dest Where to, as handed to pass: an existing folder takes it in.
     383              :    * @return Whether it was refused (and the user told).
     384              :    */
     385              :   auto refuseIgnoredThatMoves(const QString &src, const QString &dest) -> bool;
     386              : 
     387              :   /**
     388              :    * @brief Those of @p moving that a `.gitignore` inside the folder
     389              :    * @p from ignores, by `git check-ignore -v`: the rule moves with them.
     390              :    * @param repository Where the files lie now, as repositoryOf() gives it.
     391              :    * @param from The folder, relative to that repository.
     392              :    * @param moving Its ignored files, relative to that repository.
     393              :    * @return The files a rule within @p from ignores; none when git could
     394              :    *         not say.
     395              :    */
     396              :   auto ignoredByRulesWithin(const QString &repository, const QString &from,
     397              :                             const QStringList &moving) -> QStringList;
     398              : 
     399              :   /**
     400              :    * @brief `git check-ignore --stdin -z` on @p paths through `pass git`.
     401              :    * @param repository Where to ask, as repositoryOf() gives it.
     402              :    * @param paths Paths relative to that repository.
     403              :    * @param verbose Whether to ask which rule matched (`-v`): four fields
     404              :    *        per ignored path (rule's file, line, pattern, path).
     405              :    * @param fields Receives the output's fields: the ignored paths, or the
     406              :    *        four fields each with @p verbose.
     407              :    * @return false when git could not say.
     408              :    */
     409              :   auto checkIgnore(const QString &repository, const QStringList &paths,
     410              :                    bool verbose, QStringList *fields) -> bool;
     411              : 
     412              :   /**
     413              :    * @brief Refuse, and tell the user, when @p entry is set: an entry named
     414              :    * like a password that is no regular file, which pass would hand to gpg.
     415              :    * @param entry Its path, or empty when there is none.
     416              :    * @return Whether it was refused.
     417              :    */
     418              :   auto refuseSpecialEntry(const QString &entry) -> bool;
     419              : 
     420              :   /**
     421              :    * @brief Refuse, and tell the user, when the store-relative name of
     422              :    * @p path holds a line feed or carriage return.
     423              :    *
     424              :    * pass finds an entry's folder with `$(dirname -- "$path")`, and command
     425              :    * substitution drops trailing line feeds: for `Finance<LF>/x` pass reads
     426              :    * `Finance/.gpg-id`, not the list QtPass checked. A co-writer can push
     427              :    * such a folder beside a real one. Move and copy are not refused: pass
     428              :    * finds the folder there without a command substitution, and renaming is
     429              :    * how the user gets rid of such a name.
     430              :    * @param path An entry or folder in the store.
     431              :    * @return Whether it was refused.
     432              :    */
     433              :   auto refuseLineBreakName(const QString &path) -> bool;
     434              : 
     435              :   /**
     436              :    * @brief For a folder pass is about to re-encrypt in a move or copy:
     437              :    * refuse when an entry pass's walk takes (hidden ones included) is no
     438              :    * regular file (refuseSpecialEntry()), or when the signed list of one of
     439              :    * them is not one QtPass accepts where it lies now (as
     440              :    * refuseUnverifiedList()).
     441              :    * @param dir The folder moved or copied, or the existing folder written
     442              :    *        into. Each of its folders' lists counts, used by an entry yet or
     443              :    *        not: a copy merges into a folder of the same name, so lists on
     444              :    *        either side meet the other side's entries.
     445              :    * @param onlyListsWithin Whether only lists inside @p dir count: for the
     446              :    *        folder that moves, whose entries get the destination's list in
     447              :    *        place of any list above it.
     448              :    * @param except A list about to be written (`pass init`'s own), neither
     449              :    *        verified nor refused for being missing.
     450              :    * @return Whether it was refused (and the user told).
     451              :    */
     452              :   auto refuseUnverifiedTree(const QString &dir, bool onlyListsWithin,
     453              :                             const QString &except = QString()) -> bool;
     454              : 
     455              :   /**
     456              :    * @brief The verifier for signed lists, gpg in the store's environment.
     457              :    * @return A GpgIdSigner with the configured signing keys.
     458              :    */
     459              :   auto listSigner() -> GpgIdSigner;
     460              : 
     461              :   /**
     462              :    * @brief The checks of refuseUnverifiedList() for @p file's nearest list,
     463              :    * once per list.
     464              :    * @param file The entry.
     465              :    * @param signer The verifier.
     466              :    * @param verified The lists already found good; extended.
     467              :    * @param within When set, only a list under this folder (absolute,
     468              :    *        cleaned, with a trailing "/") is verified; the skipped-list check
     469              :    *        applies regardless.
     470              :    * @param except A list about to be written, neither verified nor refused
     471              :    *        for being missing.
     472              :    * @param walks Passed on to skippedGpgId(), for a check of many folders;
     473              :    *        null for none.
     474              :    * @return Whether it was refused (and the user told).
     475              :    */
     476              :   auto refuseList(const QString &file, const GpgIdSigner &signer,
     477              :                   QSet<QString> &verified, const QString &within = QString(),
     478              :                   const QString &except = QString(),
     479              :                   SkippedWalks *walks = nullptr) -> bool;
     480              : 
     481              :   /**
     482              :    * @brief The executor is about to run (or drop) its next item: for an
     483              :    * insert, take its entry from m_insertQueue and fingerprint it now, not
     484              :    * when it was queued, so an earlier queued save of the same entry counts
     485              :    * as "before". Kept in m_insertPending for that insert's own completion.
     486              :    * For `pass init`, `mv` and `cp`, add `--status-fd 2` to that one
     487              :    * process's PASSWORD_STORE_GPG_OPTS, so finished() can tell whether every
     488              :    * entry was re-encrypted (reencryptFailed()), and move its scope from
     489              :    * m_reencryptScopes to m_reencryptPending (dropped when it does not
     490              :    * complete).
     491              :    * @param id The item's process id.
     492              :    * @param completes Whether a completion follows (not for a dropped one).
     493              :    */
     494              :   void onDequeuing(int id, bool completes);
     495              : 
     496              :   /**
     497              :    * @brief A SHA-256 of the size and first 64 KiB of the regular file
     498              :    * @p path (opened without following a link or blocking on a FIFO).
     499              :    *
     500              :    * Enough to tell a rewritten entry: each encryption starts with a fresh
     501              :    * session key. Not the whole file, which a co-writer could pad to
     502              :    * gigabytes on the GUI thread's way.
     503              :    * @param path The entry's file.
     504              :    * @return The hash; empty when @p path is no readable regular file.
     505              :    */
     506              :   static auto entryFingerprint(const QString &path) -> QByteArray;
     507              : 
     508              :   /// An insert's entry and its fingerprint when the insert started to run
     509              :   /// (empty when the entry did not exist).
     510          143 :   struct InsertRecord {
     511              :     QString target;    ///< The entry's file.
     512              :     QByteArray before; ///< Its fingerprint when the insert started.
     513              :   };
     514              :   /// The entries of the queued inserts, oldest first.
     515              :   QQueue<QString> m_insertQueue;
     516              :   /// The inserts that left the queue and have yet to complete, in the
     517              :   /// order their completions come (a failed start's error is posted, and
     518              :   /// the executor starts nothing else until it is out).
     519              :   QQueue<InsertRecord> m_insertPending;
     520              :   /// The insert whose completion is being handled.
     521              :   InsertRecord m_insertDone;
     522              :   /// What each queued init, move or copy re-encrypts (its folder, or the
     523              :   /// destination), oldest first, for the push hold.
     524              :   QQueue<QString> m_reencryptScopes;
     525              :   /// The scopes of the inits, moves and copies that left the queue and have
     526              :   /// yet to complete, in completion order; one the executor drops never
     527              :   /// gets here, so it cannot pair with a later command's completion.
     528              :   QQueue<QString> m_reencryptPending;
     529              :   /// A push was asked for while an init, move or copy was queued or
     530              :   /// running: sendDeferredPush() makes it once they have completed.
     531              :   bool m_pushAfterReencrypt = false;
     532              :   /// One of those pushes was asked for by hand: it goes despite a hold.
     533              :   bool m_deferredPushByHand = false;
     534              : 
     535              : public:
     536              :   /**
     537              :    * @brief Construct a RealPass instance.
     538              :    */
     539              :   RealPass();
     540              :   /**
     541              :    * @brief Whether a `pass init`, `mv` or `cp` that exited 0 left entries
     542              :    * as they were: pass carries on past an entry gpg could not re-encrypt.
     543              :    *
     544              :    * Judged by gpg's status lines (onDequeuing() adds `--status-fd 2`),
     545              :    * which no locale changes: an INV_RECP, FAILURE or DECRYPTION_FAILED
     546              :    * line, or fewer END_ENCRYPTION lines than the entries pass said it was
     547              :    * re-encrypting ("name: reencrypting to ..." on stdout). KEYEXPIRED and
     548              :    * NO_SECKEY alone are not failures.
     549              :    * @param out pass's standard output.
     550              :    * @param err pass's and gpg's standard error.
     551              :    * @return true on a failure; false without any status line, since then
     552              :    *         the option did not reach gpg and there is nothing to judge by.
     553              :    */
     554              :   static auto reencryptFailed(const QString &out, const QString &err) -> bool;
     555              :   /**
     556              :    * @brief reencryptFailed() on status records already counted, as the
     557              :    *        Executor counts them over the whole of stderr
     558              :    *        (Executor::lastStatusCounts()): the stderr text it hands on is
     559              :    *        capped, and a large store's END_ENCRYPTION lines would not all
     560              :    *        be in it.
     561              :    * @param out pass's standard output.
     562              :    * @param status gpg status keyword to the number of its lines.
     563              :    * @return As reencryptFailed().
     564              :    */
     565              :   static auto reencryptFailed(const QString &out,
     566              :                               const QHash<QString, qint64> &status) -> bool;
     567              :   /**
     568              :    * @brief Destructor; lets the search workers wind down.
     569              :    */
     570              :   ~RealPass() override;
     571              : 
     572              :   // Git operations
     573              :   /**
     574              :    * @brief Initialize Git repository in password store.
     575              :    */
     576              :   void GitInit() override;
     577              :   /**
     578              :    * @brief Pull changes from remote.
     579              :    */
     580              :   void GitPull() override;
     581              :   /**
     582              :    * @brief Run `pass git pull` and wait for it, at most @p timeoutMs.
     583              :    * @param timeoutMs Most milliseconds to wait (Pass::kBlockingPullMs).
     584              :    */
     585              :   void GitPull_b(int timeoutMs) override;
     586              :   /**
     587              :    * @brief Push changes to remote.
     588              :    */
     589              :   void GitPush() override;
     590              : 
     591              :   // Password operations
     592              :   /**
     593              :    * @brief Show decrypted password.
     594              :    * @param file Path to password file.
     595              :    */
     596              :   void Show(QString file) override;
     597              :   /**
     598              :    * @brief Insert new password.
     599              :    * @param file Path to password file.
     600              :    * @param newValue Password content.
     601              :    * @param overwrite true to overwrite existing.
     602              :    */
     603              :   void Insert(QString file, QString newValue, bool overwrite) override;
     604              :   /**
     605              :    * @brief Remove an entry or folder with `pass rm`.
     606              :    *
     607              :    * A folder that is a link is unlinked here instead, without deleting its
     608              :    * target; that removal is committed only when Git is enabled and the
     609              :    * tracking lookup and index removal both report success.
     610              :    * @param file Store-relative entry path, without `.gpg` for a password
     611              :    *        file.
     612              :    * @param isDir true to remove a directory; false to remove a password
     613              :    *        file.
     614              :    */
     615              :   void Remove(QString file, bool isDir) override;
     616              :   auto entriesInitWouldWiden(const QString &dir, const QList<UserInfo> &users)
     617              :       -> QStringList override;
     618              :   auto entriesMoveWouldWiden(const QString &src, const QString &dest)
     619              :       -> QStringList override;
     620              :   /**
     621              :    * @brief As written: pass hands each line to gpg itself, so the probe
     622              :    *        must reach what pass will.
     623              :    * @param line One recipient line.
     624              :    * @return @p line.
     625              :    */
     626            0 :   [[nodiscard]] auto recipientArgument(const QString &line) const
     627              :       -> QString override {
     628            0 :     return line;
     629              :   }
     630              :   /**
     631              :    * @brief Initialize password store.
     632              :    * @param path Store root path.
     633              :    * @param users GPG recipients.
     634              :    */
     635              :   void Init(QString path, const QList<UserInfo> &users) override;
     636              : 
     637              : protected:
     638              :   /**
     639              :    * @brief Finish a process; a linked-folder removal commit (GIT_COMMIT,
     640              :    * which RealPass uses for nothing else) is judged by finishLinkCommit().
     641              :    * @param id Process identifier.
     642              :    * @param exitCode Exit code.
     643              :    * @param out Standard output.
     644              :    * @param err Standard error.
     645              :    */
     646              :   void finished(int id, int exitCode, const QString &out,
     647              :                 const QString &err) override;
     648              : 
     649              :   // Pass interface
     650              : public:
     651              :   /**
     652              :    * @brief Move password file or directory.
     653              :    * @param src Source path.
     654              :    * @param dest Destination path.
     655              :    * @param force Overwrite existing.
     656              :    */
     657              :   void Move(const QString src, const QString dest, const bool force) override;
     658              :   /**
     659              :    * @brief Copy password file or directory.
     660              :    * @param src Source path.
     661              :    * @param dest Destination path.
     662              :    * @param force Overwrite existing.
     663              :    */
     664              :   void Copy(const QString src, const QString dest, const bool force) override;
     665              :   /**
     666              :    * @brief Search all password content by GPG-decrypting each real `.gpg`
     667              :    * file, as ImitatePass does.
     668              :    *
     669              :    * Not `pass grep`: that enumerates with `find -L`, which follows a link
     670              :    * out of the store and decrypts what it finds there. Same pattern
     671              :    * semantics as ImitatePass::Grep (QRegularExpression).
     672              :    * @param pattern Search pattern (QRegularExpression).
     673              :    * @param caseInsensitive true for case-insensitive search.
     674              :    */
     675              :   void Grep(QString pattern, bool caseInsensitive) override;
     676              :   /**
     677              :    * @brief Stop the running search (NativeGrep::cancel()).
     678              :    */
     679           28 :   void CancelGrep() override { m_grep.cancel(); }
     680              : };
     681              : 
     682              : #endif // SRC_REALPASS_H_
        

Generated by: LCOV version 2.0-1