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