/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-08-16 03:29:08 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080816032908-ihw7c05r2mnyk389
Add feature to specify custom environment variables for plugins.

* plugin-runner.c (plugin): New members "environ" and "envc" to
                            contain possible custom environment.
  (getplugin): Return NULL on failure instead of doing exit(); all
               callers changed.
  (add_to_char_array): New helper function for "add_argument" and
                       "add_environment".
  (addargument): Renamed to "add_argument".  Return bool.  Call
                 "add_to_char_array" to actually do things.
  (add_environment): New; analogous to "add_argument".
  (addcustomargument): Renamed to "add_to_argv" to avoid confusion
                       with "add_argument".
  (main): New options "--global-envs" and "--envs-for" to specify
          custom environment for plugins.  Print environment for
          plugins in debug mode.  Use asprintf instead of strcpy and
          strcat.  Use execve() for plugins with custom environments.
          Free environment for plugin when freeing plugin list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
    fprintf(stderr, "bad gpgme_op_decrypt: %s: %s\n",
215
215
            gpgme_strsource(rc), gpgme_strerror(rc));
216
216
    plaintext_length = -1;
217
 
    if (debug){
218
 
      gpgme_decrypt_result_t result;
219
 
      result = gpgme_op_decrypt_result(ctx);
220
 
      if (result == NULL){
221
 
        fprintf(stderr, "gpgme_op_decrypt_result failed\n");
222
 
      } else {
223
 
        fprintf(stderr, "Unsupported algorithm: %s\n",
224
 
                result->unsupported_algorithm);
225
 
        fprintf(stderr, "Wrong key usage: %u\n",
226
 
                result->wrong_key_usage);
227
 
        if(result->file_name != NULL){
228
 
          fprintf(stderr, "File name: %s\n", result->file_name);
229
 
        }
230
 
        gpgme_recipient_t recipient;
231
 
        recipient = result->recipients;
232
 
        if(recipient){
233
 
          while(recipient != NULL){
234
 
            fprintf(stderr, "Public key algorithm: %s\n",
235
 
                    gpgme_pubkey_algo_name(recipient->pubkey_algo));
236
 
            fprintf(stderr, "Key ID: %s\n", recipient->keyid);
237
 
            fprintf(stderr, "Secret key available: %s\n",
238
 
                    recipient->status == GPG_ERR_NO_SECKEY
239
 
                    ? "No" : "Yes");
240
 
            recipient = recipient->next;
241
 
          }
242
 
        }
243
 
      }
244
 
    }
245
217
    goto decrypt_end;
246
218
  }
247
219
  
249
221
    fprintf(stderr, "Decryption of OpenPGP data succeeded\n");
250
222
  }
251
223
  
 
224
  if (debug){
 
225
    gpgme_decrypt_result_t result;
 
226
    result = gpgme_op_decrypt_result(ctx);
 
227
    if (result == NULL){
 
228
      fprintf(stderr, "gpgme_op_decrypt_result failed\n");
 
229
    } else {
 
230
      fprintf(stderr, "Unsupported algorithm: %s\n",
 
231
              result->unsupported_algorithm);
 
232
      fprintf(stderr, "Wrong key usage: %u\n",
 
233
              result->wrong_key_usage);
 
234
      if(result->file_name != NULL){
 
235
        fprintf(stderr, "File name: %s\n", result->file_name);
 
236
      }
 
237
      gpgme_recipient_t recipient;
 
238
      recipient = result->recipients;
 
239
      if(recipient){
 
240
        while(recipient != NULL){
 
241
          fprintf(stderr, "Public key algorithm: %s\n",
 
242
                  gpgme_pubkey_algo_name(recipient->pubkey_algo));
 
243
          fprintf(stderr, "Key ID: %s\n", recipient->keyid);
 
244
          fprintf(stderr, "Secret key available: %s\n",
 
245
                  recipient->status == GPG_ERR_NO_SECKEY
 
246
                  ? "No" : "Yes");
 
247
          recipient = recipient->next;
 
248
        }
 
249
      }
 
250
    }
 
251
  }
 
252
  
252
253
  /* Seek back to the beginning of the GPGME plaintext data buffer */
253
254
  if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
254
255
    perror("pgpme_data_seek");
301
302
}
302
303
 
303
304
static const char * safer_gnutls_strerror (int value) {
304
 
  const char *ret = gnutls_strerror (value); /* Spurious warning */
 
305
  const char *ret = gnutls_strerror (value);
305
306
  if (ret == NULL)
306
307
    ret = "(unknown)";
307
308
  return ret;
340
341
  /* OpenPGP credentials */
341
342
  gnutls_certificate_allocate_credentials(&mc->cred);
342
343
  if (ret != GNUTLS_E_SUCCESS){
343
 
    fprintf (stderr, "GnuTLS memory error: %s\n", /* Spurious
344
 
                                                     warning */
 
344
    fprintf (stderr, "GnuTLS memory error: %s\n",
345
345
             safer_gnutls_strerror(ret));
346
346
    gnutls_global_deinit ();
347
347
    return -1;
475
475
    fprintf(stderr, "Binding to interface %s\n", interface);
476
476
  }
477
477
  
478
 
  memset(&to, 0, sizeof(to));
 
478
  memset(&to, 0, sizeof(to));   /* Spurious warning */
479
479
  to.in6.sin6_family = AF_INET6;
480
480
  /* It would be nice to have a way to detect if we were passed an
481
481
     IPv4 address here.   Now we assume an IPv6 address. */
635
635
    } else {
636
636
      retval = -1;
637
637
    }
638
 
  } else {
639
 
    retval = -1;
640
638
  }
641
639
  
642
640
  /* Shutdown procedure */
663
661
                             flags,
664
662
                             void* userdata) {
665
663
  mandos_context *mc = userdata;
666
 
  assert(r);
 
664
  assert(r);                    /* Spurious warning */
667
665
  
668
666
  /* Called whenever a service has been resolved successfully or
669
667
     timed out */
705
703
                             flags,
706
704
                             void* userdata) {
707
705
  mandos_context *mc = userdata;
708
 
  assert(b);
 
706
  assert(b);                    /* Spurious warning */
709
707
  
710
708
  /* Called whenever a new services becomes available on the LAN or
711
709
     is removed from the LAN */
899
897
        exitcode = EXIT_FAILURE;
900
898
        goto end;
901
899
      }
902
 
      strcpy(network.ifr_name, interface);
 
900
      strcpy(network.ifr_name, interface); /* Spurious warning */
903
901
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
904
902
      if(ret == -1){
905
903
        perror("ioctl SIOCGIFFLAGS");