This file is indexed.

/usr/bin/account-console is in account-plugin-tools 0.12+16.04.20160126-0ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#! /usr/bin/python3

import argparse
import sys

from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Accounts
from gi.repository import Signon

class GStrv(list):
    __gtype__ = GObject.type_from_name('GStrv')

class AccountConsole:
    def __init__(self):
        self.manager = Accounts.Manager()

    def list_accounts(self, args):
        accounts = self.manager.list()
        if not accounts:
            print('No accounts')
            main_loop.quit()
            return

        for account_id in accounts:
            account = self.manager.get_account(account_id)
            enabledness = 'enabled' if account.get_enabled() else 'disabled'
            print('account: id %s, %s, provider: %s' % (account_id, enabledness, account.get_provider_name()))
        main_loop.quit()


    def show_account(self, args):
        self.args = args
        account = self.manager.get_account(args.account)
        if not account:
            print >> sys.stderr, 'Account "%s" not found' % args.account
            sys.exit(1)

        enabledness = 'enabled' if account.get_enabled() else 'disabled'
        print('account: id %s, %s, provider: %s' % (account.id, enabledness, account.get_provider_name()))
        print('  Global settings:')
        i = account.get_settings_iter(None)
        self.enumerate_settings(i)

        # enumerate services and their settings
        services = account.list_services()
        for s in services:
            service = Accounts.AccountService.new(account, s)
            print('  Settings for %s' % (s.get_name(),))
            i = service.get_settings_iter(None)
            self.enumerate_settings(i)
        main_loop.quit()


    def create_account(self, args):
        self.args = args
        account = self.manager.create_account(args.provider)
        account.set_enabled(not args.disabled)
        for setting in args.s:
            (name, value) = self.parse_setting(setting)
            account.set_value(name, value)
        account.store(self.on_account_stored, None)

    def edit_account(self, args):
        self.args = args
        account = self.manager.get_account(args.account)
        if not account:
            print >> sys.stderr, 'Account "%s" not found' % args.account
            sys.exit(1)
        self.account = account

        if args.service:
            service = self.manager.get_service(args.service)
            if not service:
                print >> sys.stderr, 'Service "%s" not found' % args.service
                sys.exit(1)
            account.select_service(service)

        if args.enable:
            account.set_enabled(True)
        elif args.disable:
            account.set_enabled(False)

        for setting in args.s:
            (name, value) = self.parse_setting(setting)
            account.set_value(name, value)

        for setting in args.u:
            account.set_value(setting, None)

        if args.username is not None or args.password is not None or args.caption:
            value = GObject.Value()
            value.init(GObject.TYPE_UINT)
            signon_id = account.get_value(args.signon_id_field, value)
            if signon_id != Accounts.SettingSource.NONE and value.get_uint() != 0:
                self.identity = Signon.Identity.new_from_db(value.get_uint())
                self.identity.query_info(self.on_info_ready, None)
            else:
                self.identity = Signon.Identity.new()
                info = Signon.IdentityInfo.new()
                self.write_signon_info(info)
        else:
            account.store(self.on_account_stored, None)


    def on_info_ready(self, identity, info, error, userdata):
        if error:
            print >> sys.stderr, 'Couldn\'t get identity info'
            sys.exit(1)

        self.write_signon_info(info)


    def write_signon_info(self, info):
        if self.args.username is not None:
            info.set_username(self.args.username)
        if self.args.caption or self.args.username:
            info.set_caption(self.args.caption or self.args.username)
        if self.args.password is not None or info.get_id() == 0:
            info.set_secret(self.args.password or '', True)

        self.identity.store_credentials_with_info(info,
                self.on_credentials_stored, self.account)


    def on_credentials_stored(self, identity, id, error, account):
        account.set_variant(self.args.signon_id_field, GLib.Variant('u', id))
        account.store(self.on_account_stored, None)


    def delete_account(self, args):
        self.args = args
        account = self.manager.get_account(args.account)
        if not account:
            print >> sys.stderr, 'Account "%s" not found' % args.account
            sys.exit(1)

        account.delete()
        account.store(self.on_account_stored_deleted, None)


    def login_identity(self, args):
        session_data = {}
        for parameter in args.p:
            (key, value) = self.parse_setting(parameter)
            session_data[key] = value

        self.login(args.identity, args.method, args.mechanism,session_data)


    def login_account(self, args):
        self.args = args
        account = self.manager.get_account(args.account)
        if not account:
            print >> sys.stderr, 'Account "%s" not found' % args.account
            sys.exit(1)
        self.account = account

        service = None
        if args.service:
            service = self.manager.get_service(args.service)
            if not service:
                print >> sys.stderr, 'Service "%s" not found' % args.service
                sys.exit(1)

        account_service = Accounts.AccountService.new(account, service)
        auth_data = account_service.get_auth_data()
        identity = auth_data.get_credentials_id()
        method = auth_data.get_method()
        mechanism = auth_data.get_mechanism()
        session_data = auth_data.get_parameters()

        # last, add session data from the command line
        for parameter in args.p:
            (key, value) = self.parse_setting(parameter)
            session_data[key] = value

        self.login(identity, method, mechanism, session_data)


    def login(self, identity, method, mechanism, session_data):
        if identity:
            self.session = Signon.AuthSession.new(identity, method)
        else:
            self.session = Signon.AuthSession.new(0, method)

        print(session_data)
        self.session.process(session_data, mechanism,
                self.login_process_cb, None)


    def load_auth_parameters(self, iterator, parameters):
        allsettings = {}
        (ok, key, value) = iterator.next()
        while ok:
            allsettings[key] = value
            (ok, key, value) = iterator.next()

        for (key, value) in allsettings.iteritems():
            # if the param key itself contains a '/', assume it's a list
            if '/' in key:
                (key, item_id) = key.split('/', 1)
                if not item_id.startswith('item'):
                    continue
                if not parameters.has_key(key):
                    parameters[key] = []
                parameters[key].append(value)
            else:
                parameters[key] = value


    def login_process_cb(self, session, reply, error, userdata):
        if error:
            print >> sys.stderr, 'Got authentication error:', error.message
            sys.exit(1)

        print('Got reply: ', reply)
        main_loop.quit()


    def on_account_stored_deleted(self, account, error, userdata):
        if not error:
            print('OK')
        else:
            print >> sys.stderr, 'Error occurred: ', error.message
        main_loop.quit()

    def on_account_stored(self, account, error, userdata):
        if not error:
            if 'print_id' in self.args and self.args.print_id:
                print('%s' % (account.id))
            else:
                print('OK %s' % (account.id))
        else:
            print >> sys.stderr, 'Error occurred: ', error.message
        main_loop.quit()

    def enumerate_settings(self, iterator):
        settings = []
        (ok, key, value) = iterator.next()
        while ok:
            settings.append((key, value))
            (ok, key, value) = iterator.next()

        settings.sort()
        for (key, value) in settings:
            print('    %s: %s (%s)' % (key, value, type(value)))

    def parse_setting(self, setting):
        (name, value_str) = setting.split('=')
        if ':' in name:
            (type, name) = name.split(':')
        else:
            type = 's'

        if type == 'i':
            value = int(value_str)
        elif type == 'u':
            value = GObject.Value()
            value.init(GObject.TYPE_UINT)
            value.set_uint(int(value_str))
        elif type == 'b':
            value = bool(value_str)
        elif type == 's':
            value = value_str
        elif type == 'as':
            value = GStrv(eval(value_str))
        return (name, value)

app = AccountConsole()

parser = argparse.ArgumentParser(description='Command-line tool for account handling')
subparsers = parser.add_subparsers(title='Valid actions')

subparser = subparsers.add_parser('list',
        help='List existing accounts')
subparser.set_defaults(func=app.list_accounts)

subparser = subparsers.add_parser('show',
        help='Show an account\'s settings')
subparser.add_argument('account', type=int,
        help='Id of the account')
subparser.set_defaults(func=app.show_account)

subparser = subparsers.add_parser('create',
        help='Create a new account')
subparser.add_argument('provider',
        help='Provider name (see /usr/share/accounts/providers)')
subparser.add_argument('--disabled', action='store_true',
        help='Create the account in disabled state')
subparser.add_argument('--print-id', action='store_true',
        help='Print the account ID on stdout')
subparser.add_argument('-s', action='append', default=[],
        help='Add a service setting, in the form [<type>:]<name>=<value>')
subparser.set_defaults(func=app.create_account)

subparser = subparsers.add_parser('edit',
        help='Edit an existing account')
subparser.add_argument('account', type=int,
        help='Id of the account')
subparser.add_argument('--disable', action='store_true',
        help='Disable the account')
subparser.add_argument('--enable', action='store_true',
        help='Enable the account')
subparser.add_argument('--service', type=str,
        help='Operates on the given service')
subparser.add_argument('-s', action='append', default=[], metavar='SETTING',
        help='Add or changes a service setting, in the form [<type>:]<name>=<value>')
subparser.add_argument('-u', action='append', default=[],
        metavar='SETTING_NAME', help='Unset a setting')
subparser.add_argument('--signon-id-field', type=str, default='CredentialsId',
        help='Name of the key holding the SignOn ID')
subparser.add_argument('--caption', type=str,
        help='SignOn caption (username description)')
subparser.add_argument('--username', type=str,
        help='SignOn username')
subparser.add_argument('--password', type=str,
        help='SignOn password')
subparser.set_defaults(func=app.edit_account)

subparser = subparsers.add_parser('delete',
        help='Deletes an existing account')
subparser.add_argument('account', type=int,
        help='Id of the account')
subparser.set_defaults(func=app.delete_account)

subparser = subparsers.add_parser('signon_login',
        help='Authenticate the given identity')
subparser.add_argument('identity', type=int,
        help='Id of the SignOn identity')
subparser.add_argument('method', type=str,
        help='Authentication method')
subparser.add_argument('mechanism', type=str,
        help='Authentication mechanism')
subparser.add_argument('-p', action='append', default=[], metavar='PARAMETER',
        help='Session parameter, in the form [<type>:]<name>=<value>')
subparser.set_defaults(func=app.login_identity)

subparser = subparsers.add_parser('login',
        help='Authenticate the given identity')
subparser.add_argument('account', type=int,
        help='Id of the SignOn identity')
subparser.add_argument('--service', type=str,
        help='Account service')
subparser.add_argument('--signon-id-field', type=str, default='CredentialsId',
        help='Name of the key holding the SignOn ID')
mm = subparser.add_argument_group()
mm.add_argument('--method', type=str,
        help='Authentication method')
mm.add_argument('--mechanism', type=str,
        help='Authentication mechanism')
subparser.add_argument('-p', action='append', default=[], metavar='PARAMETER',
        help='Session parameter, in the form [<type>:]<name>=<value>')
subparser.set_defaults(func=app.login_account)

args = parser.parse_args()
if 'func' in args:
    main_loop = GLib.MainLoop()
    GLib.idle_add(args.func, args)
    main_loop.run()
else:
    parser.print_help()