Browse Source

Initialize GPGME for signing

tags/v0.1.0
Damien Goutte-Gattat 9 years ago
parent
commit
e71b696043
2 changed files with 49 additions and 1 deletions
  1. +6
    -0
      configure.ac
  2. +43
    -1
      src/fmail.c

+ 6
- 0
configure.ac View File

@@ -18,6 +18,12 @@ AC_PROG_INSTALL
dnl Check for some non-ubiquitous functions
ICP_CHECK_NOTCH_FUNCS

dnl Check for GPGME
AM_PATH_GPGME([],
[CFLAGS="$CFLAGS $GPGME_CFLAGS"
LIBS="$LIBS $GPGME_LIBS"],
[AC_MSG_ERROR([libgpgme not found])])

dnl Output files
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile])
AC_OUTPUT


+ 43
- 1
src/fmail.c View File

@@ -23,9 +23,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <locale.h>
#include <ctype.h>
#include <time.h>

#include <gpgme.h>

#include <sbuffer.h>

@@ -43,6 +46,11 @@ Read a mail from standard input and send it.\n");
-v, --version Display the version message.\n\
");

puts("\
Cryptography options:\n\
-s, --sign Sign the message.\n\
");

printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);

exit(status);
@@ -167,6 +175,27 @@ process_text_body(FILE *in, FILE *out)


/* Signing stuff. */

gpgme_ctx_t
initialize_gpgme(void)
{
gpgme_ctx_t ctx;
gpg_error_t gerr;

gpgme_check_version(NULL);
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));

if ( (gerr = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR )
errx(EXIT_FAILURE, "cannot initialize GPGME: %s",
gpgme_strerror(gerr));

return ctx;
}


/* Main function. */

int
@@ -174,17 +203,22 @@ main(int argc, char *argv[])
{
char c;
string_buffer_t *headers;
gpgme_ctx_t sign_ctx;

struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "sign", 0, NULL, 's' },
{ NULL, 0, NULL, 0 }
};

setprogname(argv[0]);
setlocale(LC_ALL, "");

headers = sb_new(0);
sign_ctx = NULL;

while ( (c = getopt_long(argc, argv, "hv",
while ( (c = getopt_long(argc, argv, "hvs",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@@ -198,6 +232,10 @@ main(int argc, char *argv[])
case 'v':
info();
break;

case 's':
sign_ctx = initialize_gpgme();
break;
}
}

@@ -214,5 +252,9 @@ main(int argc, char *argv[])
/* Write encoded body. */
process_text_body(stdin, stdout);

/* Clean-up. */
if ( sign_ctx )
gpgme_release(sign_ctx);

return EXIT_SUCCESS;
}

Loading…
Cancel
Save