/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-10 01:26:02 UTC
  • mfrom: (237.1.2 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20081210012602-vhz3h75xkj24t340
First version of a somewhat complete D-Bus server interface.  Also
change user/group name to "_mandos".

* debian/mandos.postinst: Rename old "mandos" user and group to
                          "_mandos"; create "_mandos" user and group
                          if none exist.
* debian/mandos-client.postinst: - '' -

* initramfs-tools-hook: Try "_mandos" before "mandos" as user and
                        group name.

* mandos (_datetime_to_dbus_struct): New; was previously local.
  (Client.started): Renamed to "last_started".  All users changed.
  (Client.started): New; boolean.
  (Client.dbus_object_path): New.
  (Client.check_command): Renamed to "checker_command".  All users
                          changed.
  (Client.__init__): Set and use "self.dbus_object_path".  Set
                     "self.started".
  (Client.start): Update "self.started".  Emit "self.PropertyChanged"
                  signals for both "started" and "last_started".
  (Client.stop): Update "self.started".  Emit "self.PropertyChanged"
                 signal for "started".
  (Client.checker_callback): Take additional "command" argument.  All
                             callers changed. Emit
                             "self.PropertyChanged" signal.
  (Client.bump_timeout): Emit "self.PropertyChanged" signal for
                         "last_checked_ok".
  (Client.start_checker): Emit "self.PropertyChanged" signal for
                          "checker_running".
  (Client.stop_checker): Emit "self.PropertyChanged" signal for
                         "checker_running".
  (Client.still_valid): Bug fix: use "getattr(self, started, False)"
                        instead of "self.started" in case this client
                        object is so new that the "started" attribute
                        has not been created yet.
  (Client.IntervalChanged, Client.CheckerIsRunning, Client.GetChecker,
  Client.GetCreated, Client.GetFingerprint, Client.GetHost,
  Client.GetInterval, Client.GetName, Client.GetStarted,
  Client.GetTimeout, Client.StateChanged, Client.TimeoutChanged):
  Removed; all callers changed.
  (Client.CheckerCompleted): Add "condition" and "command" arguments.
                             All callers changed.
  (Client.GetAllProperties, Client.PropertyChanged): New.
  (Client.StillValid): Renamed to "IsStillValid".
  (Client.StartChecker): Changed to its own function to avoid the
                         return value from "Client.start_checker()".
  (Client.Stop): Changed to its own function to avoid the return value
                 from "Client.stop()".
  (main): Try "_mandos" before "mandos" as user and group name.
          Removed inner function "remove_from_clients".  New inner
          class "MandosServer".

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){
315
312
  
316
313
  /* Seek back to the beginning of the GPGME plaintext data buffer */
317
314
  if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
318
 
    perror("pgpme_data_seek");
 
315
    perror("gpgme_data_seek");
319
316
    plaintext_length = -1;
320
317
    goto decrypt_end;
321
318
  }
451
448
  
452
449
  gnutls_certificate_free_credentials(mc->cred);
453
450
  gnutls_global_deinit();
 
451
  gnutls_dh_params_deinit(mc->dh_params);
454
452
  return -1;
455
453
}
456
454
 
830
828
                          .dh_bits = 1024, .priority = "SECURE256"
831
829
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
832
830
    bool gnutls_initalized = false;
833
 
    bool pgpme_initalized = false;
 
831
    bool gpgme_initalized = false;
834
832
    
835
833
    {
836
834
      struct argp_option options[] = {
977
975
    }
978
976
    
979
977
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
980
 
      fprintf(stderr, "pgpme_initalized failed\n");
 
978
      fprintf(stderr, "gpgme_initalized failed\n");
981
979
      exitcode = EXIT_FAILURE;
982
980
      goto end;
983
981
    } else {
984
 
      pgpme_initalized = true;
 
982
      gpgme_initalized = true;
985
983
    }
986
984
    
987
985
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1098
1096
    if (gnutls_initalized){
1099
1097
      gnutls_certificate_free_credentials(mc.cred);
1100
1098
      gnutls_global_deinit ();
 
1099
      gnutls_dh_params_deinit(mc.dh_params);
1101
1100
    }
1102
 
 
1103
 
    if(pgpme_initalized){
 
1101
    
 
1102
    if(gpgme_initalized){
1104
1103
      gpgme_release(mc.ctx);
1105
1104
    }
1106
 
 
 
1105
    
1107
1106
    /* Removes the temp directory used by GPGME */
1108
1107
    if(tempdir[0] != '\0'){
1109
1108
      DIR *d;
1133
1132
            free(fullname);
1134
1133
          }
1135
1134
        }
 
1135
        closedir(d);
1136
1136
      }
1137
1137
      ret = rmdir(tempdir);
1138
1138
      if(ret == -1){