/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/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2008-12-29 02:44:54 UTC
  • Revision ID: teddy@fukt.bsnet.se-20081229024454-nbsei556dwy5azr1
* mandos (Client.timeout, Client.interval): Changed from being a
                                            property to be a normal
                                            attribute.
  (Client._timeout, Client._interval): Removed.
  (Client._timeout_milliseconds): Changed from being an attribute to
                                  be a method "timeout_milliseconds".
                                  All users changed.
  (Client._interval_milliseconds): Changed from being an attribute to
                                   be method "interval_milliseconds".
                                   All users changed.
  (Client.__init__): Take additional "use_dbus" keyword argument.
                     Only provide D-Bus interface if "use_dbus" is
                     True.
  (Client.use_dbus): New attribute.
  (Client.dbus_object_path): Changed to only be set if "self.use_dbus"
                             is True.
  (Client.enable, Client.disable, Client.checker_callback,
  Client.bump_timeout, Client.start_checker, Client.stop_checker):
  Only emit D-Bus signals if "self.use_dbus".
  (Client.SetChecker, Client.SetHost, Client.Enable): Bug fix: Emit
                                                      D-Bus signals.
  (Client.SetInterval, Client.SetTimeout): Changed to emit D-Bus
                                           signals.

  (main): Remove deprecated "default" keyword argument to "--check"
          option.  Added new "--no-dbus" option.  Added corresponding
          "use_dbus" server configuration option.  Only provide D-Bus
          interface and emit D-Bus signals if "use_dbus".  Pass
          "use_dbus" on to Client constructor.

* mandos-options.xml ([@id="dbus"]): New option.

* mandos.conf (use_dbus): New option.

* mandos.conf.xml (OPTIONS): New option "use_dbus".
  (EXAMPLE): - '' -

* mandos.xml (SYNOPSIS): New option "--no-dbus".
  (D-BUS INTERFACE): New section.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
 
12
 * Copyright © 2008 Teddy Hogeborn
 
13
 * Copyright © 2008 Björn Påhlsson
13
14
 * 
14
15
 * This program is free software: you can redistribute it and/or
15
16
 * modify it under the terms of the GNU General Public License as
101
102
 
102
103
#define BUFFER_SIZE 256
103
104
 
104
 
/*
105
 
  #define PATHDIR "/conf/conf.d/mandos"
106
 
*/
107
 
 
108
105
#define PATHDIR "/conf/conf.d/mandos"
109
106
#define SECKEY "seckey.txt"
110
 
#define PUBKEY "pupkey.txt"
 
107
#define PUBKEY "pubkey.txt"
111
108
 
112
109
bool debug = false;
113
110
static const char mandos_protocol_version[] = "1";
114
 
const char *argp_program_version = "password-request 1.0";
 
111
const char *argp_program_version = "mandos-client " VERSION;
115
112
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
116
113
 
117
114
/* Used for passing in values through the Avahi callback functions */
150
147
  int ret;
151
148
  gpgme_error_t rc;
152
149
  gpgme_engine_info_t engine_info;
153
 
 
 
150
  
154
151
  
155
152
  /*
156
153
   * Helper function to insert pub and seckey to the enigne keyring.
171
168
              gpgme_strsource(rc), gpgme_strerror(rc));
172
169
      return false;
173
170
    }
174
 
 
 
171
    
175
172
    rc = gpgme_op_import(mc->ctx, pgp_data);
176
173
    if (rc != GPG_ERR_NO_ERROR){
177
174
      fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
178
175
              gpgme_strsource(rc), gpgme_strerror(rc));
179
176
      return false;
180
177
    }
181
 
 
 
178
    
182
179
    ret = TEMP_FAILURE_RETRY(close(fd));
183
180
    if(ret == -1){
184
181
      perror("close");
190
187
  if (debug){
191
188
    fprintf(stderr, "Initialize gpgme\n");
192
189
  }
193
 
 
 
190
  
194
191
  /* Init GPGME */
195
192
  gpgme_check_version(NULL);
196
193
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
199
196
            gpgme_strsource(rc), gpgme_strerror(rc));
200
197
    return false;
201
198
  }
202
 
 
 
199
  
203
200
    /* Set GPGME home directory for the OpenPGP engine only */
204
201
  rc = gpgme_get_engine_info (&engine_info);
205
202
  if (rc != GPG_ERR_NO_ERROR){
219
216
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
220
217
    return false;
221
218
  }
222
 
 
 
219
  
223
220
  /* Create new GPGME "context" */
224
221
  rc = gpgme_new(&(mc->ctx));
225
222
  if (rc != GPG_ERR_NO_ERROR){
919
916
      }
920
917
    }
921
918
    
922
 
    ret = init_gnutls_global(&mc, pubkey, seckey);
923
 
    if (ret == -1){
924
 
      fprintf(stderr, "init_gnutls_global failed\n");
925
 
      exitcode = EXIT_FAILURE;
926
 
      goto end;
927
 
    } else {
928
 
      gnutls_initalized = true;
929
 
    }
930
 
 
931
 
    if(mkdtemp(tempdir) == NULL){
932
 
      perror("mkdtemp");
933
 
      tempdir[0] = '\0';
934
 
      goto end;
935
 
    }
936
 
    
937
 
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
938
 
      fprintf(stderr, "gpgme_initalized failed\n");
939
 
      exitcode = EXIT_FAILURE;
940
 
      goto end;
941
 
    } else {
942
 
      gpgme_initalized = true;
943
 
    }
944
 
    
945
919
    /* If the interface is down, bring it up */
946
920
    {
947
921
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
985
959
      perror("setgid");
986
960
    }
987
961
    
 
962
    ret = init_gnutls_global(&mc, pubkey, seckey);
 
963
    if (ret == -1){
 
964
      fprintf(stderr, "init_gnutls_global failed\n");
 
965
      exitcode = EXIT_FAILURE;
 
966
      goto end;
 
967
    } else {
 
968
      gnutls_initalized = true;
 
969
    }
 
970
    
 
971
    if(mkdtemp(tempdir) == NULL){
 
972
      perror("mkdtemp");
 
973
      tempdir[0] = '\0';
 
974
      goto end;
 
975
    }
 
976
    
 
977
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
 
978
      fprintf(stderr, "gpgme_initalized failed\n");
 
979
      exitcode = EXIT_FAILURE;
 
980
      goto end;
 
981
    } else {
 
982
      gpgme_initalized = true;
 
983
    }
 
984
    
988
985
    if_index = (AvahiIfIndex) if_nametoindex(interface);
989
986
    if(if_index == 0){
990
987
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1101
1098
      gnutls_global_deinit ();
1102
1099
      gnutls_dh_params_deinit(mc.dh_params);
1103
1100
    }
1104
 
 
 
1101
    
1105
1102
    if(gpgme_initalized){
1106
1103
      gpgme_release(mc.ctx);
1107
1104
    }
1108
 
 
 
1105
    
1109
1106
    /* Removes the temp directory used by GPGME */
1110
1107
    if(tempdir[0] != '\0'){
1111
1108
      DIR *d;