/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 mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2016-07-03 02:56:00 UTC
  • Revision ID: teddy@recompile.se-20160703025600-bn12vpzejr6zxx5v
mandos-client: Bug fix: flush stdout to detect write errors.

* plugins.d/mandos-client.c (start_mandos_communication): Do
                            fflush(stdout) to detect any write errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
import os
40
40
import collections
41
41
import doctest
 
42
import json
42
43
 
43
44
import dbus
44
45
 
64
65
    "ApprovalDelay": "Approval Delay",
65
66
    "ApprovalDuration": "Approval Duration",
66
67
    "Checker": "Checker",
67
 
    "ExtendedTimeout": "Extended Timeout"
 
68
    "ExtendedTimeout": "Extended Timeout",
 
69
    "Expires": "Expires",
 
70
    "LastCheckerStatus": "Last Checker Status",
68
71
}
69
72
defaultkeywords = ("Name", "Enabled", "Timeout", "LastCheckedOK")
70
73
domain = "se.recompile"
72
75
server_path = "/"
73
76
server_interface = domain + ".Mandos"
74
77
client_interface = domain + ".Mandos.Client"
75
 
version = "1.7.3"
 
78
version = "1.7.10"
76
79
 
77
80
 
78
81
try:
280
283
                        help="Select all clients")
281
284
    parser.add_argument("-v", "--verbose", action="store_true",
282
285
                        help="Print all fields")
 
286
    parser.add_argument("-j", "--dump-json", action="store_true",
 
287
                        help="Dump client data in JSON format")
283
288
    parser.add_argument("-e", "--enable", action="store_true",
284
289
                        help="Enable client")
285
290
    parser.add_argument("-d", "--disable", action="store_true",
328
333
    if has_actions(options) and not (options.client or options.all):
329
334
        parser.error("Options require clients names or --all.")
330
335
    if options.verbose and has_actions(options):
331
 
        parser.error("--verbose can only be used alone or with"
332
 
                     " --all.")
 
336
        parser.error("--verbose can only be used alone.")
 
337
    if options.dump_json and (options.verbose or has_actions(options)):
 
338
        parser.error("--dump-json can only be used alone.")
333
339
    if options.all and not has_actions(options):
334
340
        parser.error("--all requires an action.")
335
 
 
 
341
    
336
342
    if options.check:
337
343
        fail_count, test_count = doctest.testmod()
338
344
        sys.exit(os.EX_OK if fail_count == 0 else 1)
389
395
                sys.exit(1)
390
396
    
391
397
    if not has_actions(options) and clients:
392
 
        if options.verbose:
 
398
        if options.verbose or options.dump_json:
393
399
            keywords = ("Name", "Enabled", "Timeout", "LastCheckedOK",
394
400
                        "Created", "Interval", "Host", "Fingerprint",
395
401
                        "CheckerRunning", "LastEnabled",
396
402
                        "ApprovalPending", "ApprovedByDefault",
397
403
                        "LastApprovalRequest", "ApprovalDelay",
398
404
                        "ApprovalDuration", "Checker",
399
 
                        "ExtendedTimeout")
 
405
                        "ExtendedTimeout", "Expires",
 
406
                        "LastCheckerStatus")
400
407
        else:
401
408
            keywords = defaultkeywords
402
409
        
403
 
        print_clients(clients.values(), keywords)
 
410
        if options.dump_json:
 
411
            json.dump({client["Name"]: {key:
 
412
                                        bool(client[key])
 
413
                                        if isinstance(client[key],
 
414
                                                      dbus.Boolean)
 
415
                                        else client[key]
 
416
                                        for key in keywords }
 
417
                       for client in clients.values() },
 
418
                      fp = sys.stdout, indent = 4,
 
419
                      separators = (',', ': '))
 
420
            print()
 
421
        else:
 
422
            print_clients(clients.values(), keywords)
404
423
    else:
405
424
        # Process each client in the list by all selected options
406
425
        for client in clients: