/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: 2018-02-09 21:48:47 UTC
  • Revision ID: teddy@recompile.se-20180209214847-z9gcxqa6827z0ir5
Server bug fix: Correct bad argument list

* (mandos/AvahiServiceToSyslog.rename): Remove "self" from the
  arguments to the method when using super().

Show diffs side-by-side

added added

removed removed

Lines of Context:
310
310
                   gpgme_strsource(rc), gpgme_strerror(rc));
311
311
      return false;
312
312
    }
313
 
    {
314
 
      gpgme_import_result_t import_result
315
 
        = gpgme_op_import_result(mc->ctx);
316
 
      if((import_result->imported < 1
317
 
          or import_result->not_imported > 0)
318
 
         and import_result->unchanged == 0){
319
 
        fprintf_plus(stderr, "bad gpgme_op_import_results:\n");
320
 
        fprintf_plus(stderr,
321
 
                     "The total number of considered keys: %d\n",
322
 
                     import_result->considered);
323
 
        fprintf_plus(stderr,
324
 
                     "The number of keys without user ID: %d\n",
325
 
                     import_result->no_user_id);
326
 
        fprintf_plus(stderr,
327
 
                     "The total number of imported keys: %d\n",
328
 
                     import_result->imported);
329
 
        fprintf_plus(stderr, "The number of imported RSA keys: %d\n",
330
 
                     import_result->imported_rsa);
331
 
        fprintf_plus(stderr, "The number of unchanged keys: %d\n",
332
 
                     import_result->unchanged);
333
 
        fprintf_plus(stderr, "The number of new user IDs: %d\n",
334
 
                     import_result->new_user_ids);
335
 
        fprintf_plus(stderr, "The number of new sub keys: %d\n",
336
 
                     import_result->new_sub_keys);
337
 
        fprintf_plus(stderr, "The number of new signatures: %d\n",
338
 
                     import_result->new_signatures);
339
 
        fprintf_plus(stderr, "The number of new revocations: %d\n",
340
 
                     import_result->new_revocations);
341
 
        fprintf_plus(stderr,
342
 
                     "The total number of secret keys read: %d\n",
343
 
                     import_result->secret_read);
344
 
        fprintf_plus(stderr,
345
 
                     "The number of imported secret keys: %d\n",
346
 
                     import_result->secret_imported);
347
 
        fprintf_plus(stderr,
348
 
                     "The number of unchanged secret keys: %d\n",
349
 
                     import_result->secret_unchanged);
350
 
        fprintf_plus(stderr, "The number of keys not imported: %d\n",
351
 
                     import_result->not_imported);
352
 
        for(gpgme_import_status_t import_status
353
 
              = import_result->imports;
354
 
            import_status != NULL;
355
 
            import_status = import_status->next){
356
 
          fprintf_plus(stderr, "Import status for key: %s\n",
357
 
                       import_status->fpr);
358
 
          if(import_status->result != GPG_ERR_NO_ERROR){
359
 
            fprintf_plus(stderr, "Import result: %s: %s\n",
360
 
                         gpgme_strsource(import_status->result),
361
 
                         gpgme_strerror(import_status->result));
362
 
          }
363
 
          fprintf_plus(stderr, "Key status:\n");
364
 
          fprintf_plus(stderr,
365
 
                       import_status->status & GPGME_IMPORT_NEW
366
 
                       ? "The key was new.\n"
367
 
                       : "The key was not new.\n");
368
 
          fprintf_plus(stderr,
369
 
                       import_status->status & GPGME_IMPORT_UID
370
 
                       ? "The key contained new user IDs.\n"
371
 
                       : "The key did not contain new user IDs.\n");
372
 
          fprintf_plus(stderr,
373
 
                       import_status->status & GPGME_IMPORT_SIG
374
 
                       ? "The key contained new signatures.\n"
375
 
                       : "The key did not contain new signatures.\n");
376
 
          fprintf_plus(stderr,
377
 
                       import_status->status & GPGME_IMPORT_SUBKEY
378
 
                       ? "The key contained new sub keys.\n"
379
 
                       : "The key did not contain new sub keys.\n");
380
 
          fprintf_plus(stderr,
381
 
                       import_status->status & GPGME_IMPORT_SECRET
382
 
                       ? "The key contained a secret key.\n"
383
 
                       : "The key did not contain a secret key.\n");
384
 
        }
385
 
        return false;
386
 
      }
387
 
    }
388
313
    
389
314
    ret = close(fd);
390
315
    if(ret == -1){
431
356
  /* Create new GPGME "context" */
432
357
  rc = gpgme_new(&(mc->ctx));
433
358
  if(rc != GPG_ERR_NO_ERROR){
434
 
    fprintf_plus(stderr, "bad gpgme_new: %s: %s\n",
435
 
                 gpgme_strsource(rc), gpgme_strerror(rc));
 
359
    fprintf_plus(stderr, "Mandos plugin mandos-client: "
 
360
                 "bad gpgme_new: %s: %s\n", gpgme_strsource(rc),
 
361
                 gpgme_strerror(rc));
436
362
    return false;
437
363
  }
438
364
  
474
400
  /* Create new empty GPGME data buffer for the plaintext */
475
401
  rc = gpgme_data_new(&dh_plain);
476
402
  if(rc != GPG_ERR_NO_ERROR){
477
 
    fprintf_plus(stderr, "bad gpgme_data_new: %s: %s\n",
 
403
    fprintf_plus(stderr, "Mandos plugin mandos-client: "
 
404
                 "bad gpgme_data_new: %s: %s\n",
478
405
                 gpgme_strsource(rc), gpgme_strerror(rc));
479
406
    gpgme_data_release(dh_crypto);
480
407
    return -1;
493
420
      if(result == NULL){
494
421
        fprintf_plus(stderr, "gpgme_op_decrypt_result failed\n");
495
422
      } else {
496
 
        if(result->unsupported_algorithm != NULL) {
497
 
          fprintf_plus(stderr, "Unsupported algorithm: %s\n",
498
 
                       result->unsupported_algorithm);
499
 
        }
500
 
        fprintf_plus(stderr, "Wrong key usage: %s\n",
501
 
                     result->wrong_key_usage ? "Yes" : "No");
 
423
        fprintf_plus(stderr, "Unsupported algorithm: %s\n",
 
424
                     result->unsupported_algorithm);
 
425
        fprintf_plus(stderr, "Wrong key usage: %u\n",
 
426
                     result->wrong_key_usage);
502
427
        if(result->file_name != NULL){
503
428
          fprintf_plus(stderr, "File name: %s\n", result->file_name);
504
429
        }
505
 
 
506
 
        for(gpgme_recipient_t r = result->recipients; r != NULL;
507
 
            r = r->next){
 
430
        gpgme_recipient_t recipient;
 
431
        recipient = result->recipients;
 
432
        while(recipient != NULL){
508
433
          fprintf_plus(stderr, "Public key algorithm: %s\n",
509
 
                       gpgme_pubkey_algo_name(r->pubkey_algo));
510
 
          fprintf_plus(stderr, "Key ID: %s\n", r->keyid);
 
434
                       gpgme_pubkey_algo_name
 
435
                       (recipient->pubkey_algo));
 
436
          fprintf_plus(stderr, "Key ID: %s\n", recipient->keyid);
511
437
          fprintf_plus(stderr, "Secret key available: %s\n",
512
 
                       r->status == GPG_ERR_NO_SECKEY ? "No" : "Yes");
 
438
                       recipient->status == GPG_ERR_NO_SECKEY
 
439
                       ? "No" : "Yes");
 
440
          recipient = recipient->next;
513
441
        }
514
442
      }
515
443
    }
685
613
        }
686
614
        params.size += (unsigned int)bytes_read;
687
615
      }
688
 
      ret = close(dhpfile);
689
 
      if(ret == -1){
690
 
        perror_plus("close");
691
 
      }
692
616
      if(params.data == NULL){
693
617
        dhparamsfilename = NULL;
694
618
      }
1731
1655
      perror_plus("ioctl SIOCGIFFLAGS");
1732
1656
      errno = old_errno;
1733
1657
    }
1734
 
    if((close(s) == -1) and debug){
1735
 
      old_errno = errno;
1736
 
      perror_plus("close");
1737
 
      errno = old_errno;
1738
 
    }
1739
1658
    return false;
1740
1659
  }
1741
 
  if((close(s) == -1) and debug){
1742
 
    old_errno = errno;
1743
 
    perror_plus("close");
1744
 
    errno = old_errno;
1745
 
  }
1746
1660
  return true;
1747
1661
}
1748
1662
 
2009
1923
      return;
2010
1924
    }
2011
1925
  }
2012
 
  int devnull = (int)TEMP_FAILURE_RETRY(open("/dev/null", O_RDONLY));
2013
 
  if(devnull == -1){
2014
 
    perror_plus("open(\"/dev/null\", O_RDONLY)");
2015
 
    return;
2016
 
  }
2017
1926
  int numhooks = scandirat(hookdir_fd, ".", &direntries,
2018
1927
                           runnable_hook, alphasort);
2019
1928
  if(numhooks == -1){
2020
1929
    perror_plus("scandir");
2021
 
    close(devnull);
2022
1930
    return;
2023
1931
  }
2024
1932
  struct dirent *direntry;
2025
1933
  int ret;
 
1934
  int devnull = (int)TEMP_FAILURE_RETRY(open("/dev/null", O_RDONLY));
 
1935
  if(devnull == -1){
 
1936
    perror_plus("open(\"/dev/null\", O_RDONLY)");
 
1937
    return;
 
1938
  }
2026
1939
  for(int i = 0; i < numhooks; i++){
2027
1940
    direntry = direntries[i];
2028
1941
    if(debug){
3148
3061
                                                | O_PATH));
3149
3062
    if(dir_fd == -1){
3150
3063
      perror_plus("open");
3151
 
      return;
3152
3064
    }
3153
3065
    int numentries = scandirat(dir_fd, ".", &direntries,
3154
3066
                               notdotentries, alphasort);
3171
3083
            clean_dir_at(dir_fd, direntries[i]->d_name, level+1);
3172
3084
            dret = 0;
3173
3085
          }
3174
 
          if((dret == -1) and (errno != ENOENT)){
 
3086
          if(dret == -1){
3175
3087
            fprintf_plus(stderr, "unlink(\"%s/%s\"): %s\n", dirname,
3176
3088
                         direntries[i]->d_name, strerror(errno));
3177
3089
          }
3181
3093
      
3182
3094
      /* need to clean even if 0 because man page doesn't specify */
3183
3095
      free(direntries);
 
3096
      if(numentries == -1){
 
3097
        perror_plus("scandirat");
 
3098
      }
3184
3099
      dret = unlinkat(base, dirname, AT_REMOVEDIR);
3185
3100
      if(dret == -1 and errno != ENOENT){
3186
3101
        perror_plus("rmdir");