/mandos/release

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

« back to all changes in this revision

Viewing changes to plugins.d/mandosclient.c

  • Committer: Teddy Hogeborn
  • Date: 2008-07-31 19:48:05 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080731194805-mseis21dxwrdfqhk
* plugins.d/mandosclient.c (start_mandos_communication): Changed
                                                        "if_index" to
                                                        be of type
                                                        "AvahiIfIndex".
                                                        All callers
                                                        changed.
 (main): Add default values to "interface" and "if_index".  Only
         change if_index from default if "interface" was given.

* server.py (IPv6_TCPServer.server_bind): Bug fix: test if interface
                                          is empty, not if equal to
                                          avahi.IF_UNSPEC.
  (if_nametoindex): Bug fix; typo: assign to _func[0], not func[0].
  (main): Bug fix: Do not set service.interface unless the interface
          setting has been given.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * along with this program.  If not, see
26
26
 * <http://www.gnu.org/licenses/>.
27
27
 * 
28
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
28
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
 
29
 * <https://www.fukt.bsnet.se/~teddy/>.
29
30
 */
30
31
 
31
32
/* Needed by GPGME, specifically gpgme_data_seek() */
66
67
// getopt long
67
68
#include <getopt.h>
68
69
 
 
70
#ifndef CERT_ROOT
 
71
#define CERT_ROOT "/conf/conf.d/cryptkeyreq/"
 
72
#endif
 
73
#define CERTFILE CERT_ROOT "openpgp-client.txt"
 
74
#define KEYFILE CERT_ROOT "openpgp-client-key.txt"
69
75
#define BUFFER_SIZE 256
70
76
#define DH_BITS 1024
71
77
 
72
 
const char *certdir = "/conf/conf.d/cryptkeyreq/";
73
 
const char *certfile = "openpgp-client.txt";
74
 
const char *certkey = "openpgp-client-key.txt";
75
 
 
76
78
bool debug = false;
77
79
 
78
80
typedef struct {
98
100
  
99
101
  /* Init GPGME */
100
102
  gpgme_check_version(NULL);
101
 
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
102
 
  if (rc != GPG_ERR_NO_ERROR){
103
 
    fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n",
104
 
            gpgme_strsource(rc), gpgme_strerror(rc));
105
 
    return -1;
106
 
  }
 
103
  gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
107
104
  
108
105
  /* Set GPGME home directory */
109
106
  rc = gpgme_get_engine_info (&engine_info);
195
192
  gpgme_data_release(dh_crypto);
196
193
  
197
194
  /* Seek back to the beginning of the GPGME plaintext data buffer */
198
 
  if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
199
 
    perror("pgpme_data_seek");
200
 
  }
201
 
  
 
195
  gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET);
 
196
 
202
197
  *new_packet = 0;
203
198
  while(true){
204
199
    if (new_packet_length + BUFFER_SIZE > new_packet_capacity){
257
252
  if(debug){
258
253
    fprintf(stderr, "Initializing GnuTLS\n");
259
254
  }
260
 
 
 
255
  
261
256
  if ((ret = gnutls_global_init ())
262
257
      != GNUTLS_E_SUCCESS) {
263
258
    fprintf (stderr, "global_init: %s\n", safer_gnutls_strerror(ret));
279
274
  
280
275
  if(debug){
281
276
    fprintf(stderr, "Attempting to use OpenPGP certificate %s"
282
 
            " and keyfile %s as GnuTLS credentials\n", certfile,
283
 
            certkey);
 
277
            " and keyfile %s as GnuTLS credentials\n", CERTFILE,
 
278
            KEYFILE);
284
279
  }
285
280
  
286
281
  ret = gnutls_certificate_set_openpgp_key_file
287
 
    (es->cred, certfile, certkey, GNUTLS_OPENPGP_FMT_BASE64);
 
282
    (es->cred, CERTFILE, KEYFILE, GNUTLS_OPENPGP_FMT_BASE64);
288
283
  if (ret != GNUTLS_E_SUCCESS) {
289
284
    fprintf
290
285
      (stderr, "Error[%d] while reading the OpenPGP key pair ('%s',"
291
286
       " '%s')\n",
292
 
       ret, certfile, certkey);
 
287
       ret, CERTFILE, KEYFILE);
293
288
    fprintf(stdout, "The Error is: %s\n",
294
289
            safer_gnutls_strerror(ret));
295
290
    return -1;
492
487
    decrypted_buffer_size = pgp_packet_decrypt(buffer,
493
488
                                               buffer_length,
494
489
                                               &decrypted_buffer,
495
 
                                               certdir);
 
490
                                               CERT_ROOT);
496
491
    if (decrypted_buffer_size >= 0){
497
492
      while(written < (size_t) decrypted_buffer_size){
498
493
        ret = (int)fwrite (decrypted_buffer + written, 1,
627
622
    }
628
623
}
629
624
 
630
 
/* combinds file name and path and returns the malloced new string. som sane checks could/should be added */
631
 
const char *combinepath(const char *first, const char *second){
632
 
  char *tmp;
633
 
  tmp = malloc(strlen(first) + strlen(second) + 2);
634
 
  if (tmp == NULL){
635
 
    perror("malloc");
636
 
    return NULL;
637
 
  }
638
 
  strcpy(tmp, first);
639
 
  if (first[0] != '\0' and first[strlen(first) - 1] != '/'){
640
 
    strcat(tmp, "/");
641
 
  }
642
 
  strcat(tmp, second);
643
 
  return tmp;
644
 
}
645
 
 
646
 
 
647
625
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) {
648
626
    AvahiServerConfig config;
649
627
    AvahiSServiceBrowser *sb = NULL;
657
635
    while (true){
658
636
      static struct option long_options[] = {
659
637
        {"debug", no_argument, (int *)&debug, 1},
660
 
        {"connect", required_argument, 0, 'C'},
 
638
        {"connect", required_argument, 0, 'c'},
661
639
        {"interface", required_argument, 0, 'i'},
662
 
        {"certdir", required_argument, 0, 'd'},
663
 
        {"certkey", required_argument, 0, 'c'},
664
 
        {"certfile", required_argument, 0, 'k'},
665
640
        {0, 0, 0, 0} };
666
641
      
667
642
      int option_index = 0;
678
653
      case 'i':
679
654
        interface = optarg;
680
655
        break;
681
 
      case 'C':
 
656
      case 'c':
682
657
        connect_to = optarg;
683
658
        break;
684
 
      case 'd':
685
 
        certdir = optarg;
686
 
        break;
687
 
      case 'c':
688
 
        certfile = optarg;
689
 
        break;
690
 
      case 'k':
691
 
        certkey = optarg;
692
 
        break;
693
659
      default:
694
660
        exit(EXIT_FAILURE);
695
661
      }
696
662
    }
697
 
 
698
 
    certfile = combinepath(certdir, certfile);
699
 
    if (certfile == NULL){
700
 
      goto exit;
701
 
    }
702
663
    
703
664
    if(interface != NULL){
704
665
      if_index = (AvahiIfIndex) if_nametoindex(interface);
732
693
      }
733
694
    }
734
695
    
735
 
    certkey = combinepath(certdir, certkey);
736
 
    if (certkey == NULL){
737
 
      goto exit;
738
 
    }
739
 
    
740
696
    if (not debug){
741
697
      avahi_set_log_function(empty_log);
742
698
    }
808
764
 
809
765
    if (simple_poll)
810
766
        avahi_simple_poll_free(simple_poll);
811
 
    free(certfile);
812
 
    free(certkey);
813
 
    
 
767
 
814
768
    return returncode;
815
769
}