/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/password-request.c

  • Committer: Teddy Hogeborn
  • Date: 2008-09-06 00:19:53 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080906001953-5nk5uti6shzuyqdr
* plugins.d/password-prompt.c (main): If successful, output an extra
                                      newline to the console before
                                      exiting, to change to a new line
                                      away from the prompt.

* plugins.d/password-request.c (main): Bug fix: Moved calls to
                                       "init_gnutls_global()",
                                       "mkdtemp()", and "init_gpgme()"
                                       to *after* changing user &
                                       group.

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 © 2008,2009 Teddy Hogeborn
13
 
 * Copyright © 2008,2009 Björn Påhlsson
 
12
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
14
13
 * 
15
14
 * This program is free software: you can redistribute it and/or
16
15
 * modify it under the terms of the GNU General Public License as
102
101
 
103
102
#define BUFFER_SIZE 256
104
103
 
 
104
/*
 
105
  #define PATHDIR "/conf/conf.d/mandos"
 
106
*/
 
107
 
105
108
#define PATHDIR "/conf/conf.d/mandos"
106
109
#define SECKEY "seckey.txt"
107
 
#define PUBKEY "pubkey.txt"
 
110
#define PUBKEY "pupkey.txt"
108
111
 
109
112
bool debug = false;
110
113
static const char mandos_protocol_version[] = "1";
111
 
const char *argp_program_version = "mandos-client " VERSION;
 
114
const char *argp_program_version = "password-request 1.0";
112
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
113
116
 
114
117
/* Used for passing in values through the Avahi callback functions */
147
150
  int ret;
148
151
  gpgme_error_t rc;
149
152
  gpgme_engine_info_t engine_info;
150
 
  
 
153
 
151
154
  
152
155
  /*
153
156
   * Helper function to insert pub and seckey to the enigne keyring.
168
171
              gpgme_strsource(rc), gpgme_strerror(rc));
169
172
      return false;
170
173
    }
171
 
    
 
174
 
172
175
    rc = gpgme_op_import(mc->ctx, pgp_data);
173
176
    if (rc != GPG_ERR_NO_ERROR){
174
177
      fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
175
178
              gpgme_strsource(rc), gpgme_strerror(rc));
176
179
      return false;
177
180
    }
178
 
    
 
181
 
179
182
    ret = TEMP_FAILURE_RETRY(close(fd));
180
183
    if(ret == -1){
181
184
      perror("close");
187
190
  if (debug){
188
191
    fprintf(stderr, "Initialize gpgme\n");
189
192
  }
190
 
  
 
193
 
191
194
  /* Init GPGME */
192
195
  gpgme_check_version(NULL);
193
196
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
196
199
            gpgme_strsource(rc), gpgme_strerror(rc));
197
200
    return false;
198
201
  }
199
 
  
 
202
 
200
203
    /* Set GPGME home directory for the OpenPGP engine only */
201
204
  rc = gpgme_get_engine_info (&engine_info);
202
205
  if (rc != GPG_ERR_NO_ERROR){
216
219
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
217
220
    return false;
218
221
  }
219
 
  
 
222
 
220
223
  /* Create new GPGME "context" */
221
224
  rc = gpgme_new(&(mc->ctx));
222
225
  if (rc != GPG_ERR_NO_ERROR){
312
315
  
313
316
  /* Seek back to the beginning of the GPGME plaintext data buffer */
314
317
  if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
315
 
    perror("gpgme_data_seek");
 
318
    perror("pgpme_data_seek");
316
319
    plaintext_length = -1;
317
320
    goto decrypt_end;
318
321
  }
448
451
  
449
452
  gnutls_certificate_free_credentials(mc->cred);
450
453
  gnutls_global_deinit();
451
 
  gnutls_dh_params_deinit(mc->dh_params);
452
454
  return -1;
453
455
}
454
456
 
828
830
                          .dh_bits = 1024, .priority = "SECURE256"
829
831
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
830
832
    bool gnutls_initalized = false;
831
 
    bool gpgme_initalized = false;
 
833
    bool pgpme_initalized = false;
832
834
    
833
835
    {
834
836
      struct argp_option options[] = {
975
977
    }
976
978
    
977
979
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
978
 
      fprintf(stderr, "gpgme_initalized failed\n");
 
980
      fprintf(stderr, "pgpme_initalized failed\n");
979
981
      exitcode = EXIT_FAILURE;
980
982
      goto end;
981
983
    } else {
982
 
      gpgme_initalized = true;
 
984
      pgpme_initalized = true;
983
985
    }
984
986
    
985
987
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1096
1098
    if (gnutls_initalized){
1097
1099
      gnutls_certificate_free_credentials(mc.cred);
1098
1100
      gnutls_global_deinit ();
1099
 
      gnutls_dh_params_deinit(mc.dh_params);
1100
1101
    }
1101
 
    
1102
 
    if(gpgme_initalized){
 
1102
 
 
1103
    if(pgpme_initalized){
1103
1104
      gpgme_release(mc.ctx);
1104
1105
    }
1105
 
    
 
1106
 
1106
1107
    /* Removes the temp directory used by GPGME */
1107
1108
    if(tempdir[0] != '\0'){
1108
1109
      DIR *d;
1132
1133
            free(fullname);
1133
1134
          }
1134
1135
        }
1135
 
        closedir(d);
1136
1136
      }
1137
1137
      ret = rmdir(tempdir);
1138
1138
      if(ret == -1){