/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandosclient.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-02 21:06:12 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080802210612-4c1waup4z0f66ya7
Non-tested commit for merge purposes.

* plugbasedclient.c (getplugin, addargument, set_cloexec): Made static.

* plugins.d/passprompt.c (termination_handler): Made static.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
#include <errno.h>              /* perror() */
64
64
#include <gpgme.h>
65
65
 
66
 
// getopt long
 
66
// getopt_long
67
67
#include <getopt.h>
68
68
 
69
69
#define BUFFER_SIZE 256
70
 
#define DH_BITS 1024
71
 
 
72
 
static const char *certdir = "/conf/conf.d/mandos";
73
 
static const char *certfile = "openpgp-client.txt";
74
 
static const char *certkey = "openpgp-client-key.txt";
 
70
 
 
71
static int dh_bits = 1024;
 
72
 
 
73
static const char *keydir = "/conf/conf.d/mandos";
 
74
static const char *pubkeyfile = "pubkey.txt";
 
75
static const char *seckeyfile = "seckey.txt";
75
76
 
76
77
bool debug = false;
77
78
 
 
79
/* Used for  */
78
80
typedef struct {
79
81
  gnutls_session_t session;
80
82
  gnutls_certificate_credentials_t cred;
280
282
  
281
283
  if(debug){
282
284
    fprintf(stderr, "Attempting to use OpenPGP certificate %s"
283
 
            " and keyfile %s as GnuTLS credentials\n", certfile,
284
 
            certkey);
 
285
            " and keyfile %s as GnuTLS credentials\n", pubkeyfile,
 
286
            seckeyfile);
285
287
  }
286
288
  
287
289
  ret = gnutls_certificate_set_openpgp_key_file
288
 
    (es->cred, certfile, certkey, GNUTLS_OPENPGP_FMT_BASE64);
 
290
    (es->cred, pubkeyfile, seckeyfile, GNUTLS_OPENPGP_FMT_BASE64);
289
291
  if (ret != GNUTLS_E_SUCCESS) {
290
292
    fprintf
291
293
      (stderr, "Error[%d] while reading the OpenPGP key pair ('%s',"
292
294
       " '%s')\n",
293
 
       ret, certfile, certkey);
 
295
       ret, pubkeyfile, seckeyfile);
294
296
    fprintf(stdout, "The Error is: %s\n",
295
297
            safer_gnutls_strerror(ret));
296
298
    return -1;
304
306
    return -1;
305
307
  }
306
308
  
307
 
  if ((ret = gnutls_dh_params_generate2 (es->dh_params, DH_BITS))
 
309
  if ((ret = gnutls_dh_params_generate2 (es->dh_params, dh_bits))
308
310
      != GNUTLS_E_SUCCESS) {
309
311
    fprintf (stderr, "Error in prime generation: %s\n",
310
312
             safer_gnutls_strerror(ret));
340
342
  gnutls_certificate_server_set_request (es->session,
341
343
                                         GNUTLS_CERT_IGNORE);
342
344
  
343
 
  gnutls_dh_set_prime_bits (es->session, DH_BITS);
 
345
  gnutls_dh_set_prime_bits (es->session, dh_bits);
344
346
  
345
347
  return 0;
346
348
}
401
403
  
402
404
  if(debug){
403
405
    fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
404
 
/*     char addrstr[INET6_ADDRSTRLEN]; */
405
 
/*     if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr, */
406
 
/*               sizeof(addrstr)) == NULL){ */
407
 
/*       perror("inet_ntop"); */
408
 
/*     } else { */
409
 
/*       fprintf(stderr, "Really connecting to: %s, port %d\n", */
410
 
/*            addrstr, ntohs(to.sin6_port)); */
411
 
/*     } */
 
406
    char addrstr[INET6_ADDRSTRLEN] = "";
 
407
    if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr,
 
408
                 sizeof(addrstr)) == NULL){
 
409
      perror("inet_ntop");
 
410
    } else {
 
411
      if(strcmp(addrstr, ip) != 0){
 
412
        fprintf(stderr, "Canonical address form: %s\n",
 
413
                addrstr, ntohs(to.sin6_port));
 
414
      }
 
415
    }
412
416
  }
413
417
  
414
418
  ret = connect(tcp_sd, (struct sockaddr *) &to, sizeof(to));
493
497
    decrypted_buffer_size = pgp_packet_decrypt(buffer,
494
498
                                               buffer_length,
495
499
                                               &decrypted_buffer,
496
 
                                               certdir);
 
500
                                               keydir);
497
501
    if (decrypted_buffer_size >= 0){
498
502
      while(written < (size_t) decrypted_buffer_size){
499
503
        ret = (int)fwrite (decrypted_buffer + written, 1,
654
658
    AvahiSServiceBrowser *sb = NULL;
655
659
    int error;
656
660
    int ret;
 
661
    int debug_int = 0;
657
662
    int returncode = EXIT_SUCCESS;
658
663
    const char *interface = NULL;
659
664
    AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
660
665
    char *connect_to = NULL;
661
666
    
 
667
    debug_int = debug ? 1 : 0;
662
668
    while (true){
663
669
      static struct option long_options[] = {
664
 
        {"debug", no_argument, (int *)&debug, 1},
665
 
        {"connect", required_argument, 0, 'C'},
666
 
        {"interface", required_argument, 0, 'i'},
667
 
        {"certdir", required_argument, 0, 'd'},
668
 
        {"certkey", required_argument, 0, 'c'},
669
 
        {"certfile", required_argument, 0, 'k'},
 
670
        {"debug", no_argument, &debug_int, 1},
 
671
        {"connect", required_argument, NULL, 'C'},
 
672
        {"interface", required_argument, NULL, 'i'},
 
673
        {"keydir", required_argument, NULL, 'd'},
 
674
        {"seckey", required_argument, NULL, 'c'},
 
675
        {"pubkey", required_argument, NULL, 'k'},
 
676
        {"dh-bits", required_argument, NULL, 'D'},
670
677
        {0, 0, 0, 0} };
671
678
      
672
679
      int option_index = 0;
687
694
        connect_to = optarg;
688
695
        break;
689
696
      case 'd':
690
 
        certdir = optarg;
 
697
        keydir = optarg;
691
698
        break;
692
699
      case 'c':
693
 
        certfile = optarg;
 
700
        pubkeyfile = optarg;
694
701
        break;
695
702
      case 'k':
696
 
        certkey = optarg;
697
 
        break;
 
703
        seckeyfile = optarg;
 
704
        break;
 
705
      case 'D':
 
706
        dh_bits = atoi(optarg);
 
707
        break;
 
708
      case '?':
 
709
        break
698
710
      default:
699
711
        exit(EXIT_FAILURE);
700
712
      }
701
713
    }
 
714
    debug = debug_int ? true : false;
702
715
    
703
 
    certfile = combinepath(certdir, certfile);
704
 
    if (certfile == NULL){
 
716
    pubkeyfile = combinepath(keydir, pubkeyfile);
 
717
    if (pubkeyfile == NULL){
705
718
      perror("combinepath");
706
719
      goto exit;
707
720
    }
738
751
      }
739
752
    }
740
753
    
741
 
    certkey = combinepath(certdir, certkey);
742
 
    if (certkey == NULL){
 
754
    seckeyfile = combinepath(keydir, seckeyfile);
 
755
    if (seckeyfile == NULL){
743
756
      perror("combinepath");
744
757
      goto exit;
745
758
    }
815
828
 
816
829
    if (simple_poll)
817
830
        avahi_simple_poll_free(simple_poll);
818
 
    free(certfile);
819
 
    free(certkey);
 
831
    free(pubkeyfile);
 
832
    free(seckeyfile);
820
833
    
821
834
    return returncode;
822
835
}