Initial GPG support

Run 'git-crypt add-collab KEYID' to authorize the holder of the given
GPG secret key to access the encrypted files.  The secret git-crypt key
will be encrypted with the corresponding GPG public key and stored in the
root of the Git repository under .git-crypt/keys.

After cloning a repo with encrypted files, run 'git-crypt unlock'
(with no arguments) to use a secret key in your GPG keyring to unlock
the repository.

Multiple collaborators are supported, however commands to list the
collaborators ('git-crypt ls-collabs') and to remove a collaborator
('git-crypt rm-collab') are not yet supported.
This commit is contained in:
Andrew Ayer
2014-03-28 14:02:25 -07:00
parent 2b5e4a752e
commit 7687d11219
9 changed files with 415 additions and 14 deletions

View File

@@ -146,6 +146,48 @@ int exec_command (const char* command, std::ostream& output)
return status;
}
int exec_command_with_input (const char* command, const char* p, size_t len)
{
int pipefd[2];
if (pipe(pipefd) == -1) {
throw System_error("pipe", "", errno);
}
pid_t child = fork();
if (child == -1) {
int fork_errno = errno;
close(pipefd[0]);
close(pipefd[1]);
throw System_error("fork", "", fork_errno);
}
if (child == 0) {
close(pipefd[1]);
if (pipefd[0] != 0) {
dup2(pipefd[0], 0);
close(pipefd[0]);
}
execl("/bin/sh", "sh", "-c", command, NULL);
perror("/bin/sh");
_exit(-1);
}
close(pipefd[0]);
while (len > 0) {
ssize_t bytes_written = write(pipefd[1], p, len);
if (bytes_written == -1) {
int write_errno = errno;
close(pipefd[1]);
throw System_error("write", "", write_errno);
}
p += bytes_written;
len -= bytes_written;
}
close(pipefd[1]);
int status = 0;
if (waitpid(child, &status, 0) == -1) {
throw System_error("waitpid", "", errno);
}
return status;
}
bool successful_exit (int status)
{
return status != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0;