aboutsummaryrefslogtreecommitdiff
path: root/server/wallet-admin
blob: 828cfc57fb60e42a99051a566ccc5b043f73cb76 (plain)
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
#!/usr/bin/perl -w
#
# wallet-backend -- Wallet server administrative commands.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.

##############################################################################
# Declarations and site configuration
##############################################################################

use strict;
use Wallet::Admin;

##############################################################################
# Implementation
##############################################################################

# Parse and execute a command.  We wrap this in a subroutine call for easier
# testing.
sub command {
    die "Usage: wallet-admin <command> [<args> ...]\n" unless @_;
    my $admin = Wallet::Admin->new;

    # Parse command-line options and dispatch to the appropriate calls.
    my ($command, @args) = @_;
    if ($command eq 'destroy') {
        die "too many arguments to destroy\n" if @args;
        print 'This will delete all data in the wallet database.  Are you'
            . ' sure (N/y)? ';
        my $response = <STDIN>;
        unless ($response and $response =~ /^y/i) {
            die "Aborted\n";
        }
        $admin->destroy or die $admin->error, "\n";
    } elsif ($command eq 'initialize') {
        die "too many arguments to initialize\n" if @args > 1;
        die "too few arguments to initialize\n" if @args < 1;
        die "invalid admin principal $args[0]\n"
            unless $args[0] =~ /^[^\@\s]+\@\S+$/;
        $admin->initialize (@args) or die $admin->error, "\n";
    } elsif ($command eq 'list') {
        die "too many arguments to list\n" if @args > 4;
        die "too few arguments to list\n" if @args < 1;
        my ($type, $subtype, @search) = @args;
        if ($type eq 'objects') {
            my @objects = $admin->list_objects ($subtype, @search);
            if (!@objects and $admin->error) {
                die $admin->error, "\n";
            }
            for my $object (@objects) {
                print join (' ', @$object), "\n";
            }
        } elsif ($type eq 'acls') {
            my @acls = $admin->list_acls ($subtype, @search);
            if (!@acls and $admin->error) {
                die $admin->error, "\n";
            }
            for my $acl (sort { $$a[1] cmp $$b[1] } @acls) {
                print "$$acl[1] (ACL ID: $$acl[0])\n";
            }
        } else {
            die "only objects or acls are supported for list\n";
        }
    } elsif ($command eq 'report') {
        die "too few arguments to report\n" if @args < 1;
        my $report = shift @args;
        if ($report eq 'owners') {
            die "too many arguments to report owners\n" if @args > 2;
            die "too few arguments to report owners\n" if @args < 2;
            my @lines = $admin->report_owners (@args);
            if (!@lines and $admin->error) {
                die $admin->error, "\n";
            }
            for my $line (@lines) {
                print join (' ', @$line), "\n";
            }
        } else {
            die "unknown report type $report\n";
        }
    } elsif ($command eq 'register') {
        die "too many arguments to register\n" if @args > 3;
        die "too few arguments to register\n" if @args < 3;
        my ($object, $type, $class) = @args;
        if ($object eq 'object') {
            unless ($admin->register_object ($type, $class)) {
                die $admin->error, "\n";
            }
        } elsif ($object eq 'verifier') {
            unless ($admin->register_verifier ($type, $class)) {
                die $admin->error, "\n";
            }
        } else {
            die "only object or verifier is supported for register\n";
        }
    } else {
        die "unknown command $command\n";
    }
}
command (@ARGV);
__END__

##############################################################################
# Documentation
##############################################################################

=head1 NAME

wallet-admin - Wallet server administrative commands

=for stopwords
metadata ACL hostname backend acl acls wildcard SQL Allbery

=head1 SYNOPSIS

B<wallet-admin> I<command> [I<args> ...]

=head1 DESCRIPTION

B<wallet-admin> provides a command-line interface for performing
administrative actions for the wallet system, such as setting up a new
database or running reports.  It is intended to be run on the wallet
server as a user with access to the wallet database and configuration.

This program is a fairly thin wrapper around Wallet::Admin that translates
command strings into method calls and returns the results.

=head1 OPTIONS

B<wallet-admin> takes no traditional options.

=head1 COMMANDS

=over 4

=item destroy

Deletes all data in the wallet database and drops all of the
wallet-created tables, restoring the database to its state prior to an
C<initialize> command.  Since this command is destructive and cannot be
easily recovered from, B<wallet-admin> will prompt first to be sure the
user intends to do this.

=item initialize <principal>

Given an empty database, initializes it for use with the wallet server by
creating the necessary tables and initial metadata.  Also creates an ACL
with the name ADMIN, used for administrative privileges to the wallet
system, and adds an ACL entry to it with a scheme of C<krb5> and an
instance of <principal>.  This bootstraps the authentication system and
allows that user to make further changes to the ADMIN ACL and the rest of
the wallet database.  C<initialize> uses C<localhost> as the hostname and
<principal> as the user when logging the history of the ADMIN ACL creation
and for any subsequent actions required to initialize the database.

Before running C<initialize>, the wallet system has to be configured.  See
Wallet::Config(3) for more details.  Depending on the database backend
used, the database may also have to be created in advance.

=item list (acls | objects) [ <searchtype> [ <arg> ... ] ]

Returns a list of ACLs or objects in the database.  ACLs will be listed
in the form:

    <name> (ACL ID: <id>)

where <name> is the human-readable name and <id> is the numeric ID.  The
numeric ID is what's used internally by the wallet system.  Objects will
be listed in the form:

    <type> <name>

In both cases, there will be one line per ACL or object.

If no search type is given, all the ACLs or objects in the database will
be returned.  If a search type (and possible search arguments) are given,
then the ACLs or objects will be limited to those that match the search.

The currently supported object search types are:

=over 4

=item list objects type <type>

Returns all objects of the given type.

=item list objects flag <flag>

Returns all objects which have the given flag set.

=item list objects owner <acl name>

Returns all objects owned by the given ACL name.

=item list objects acl <acl name>

Returns all objects for which the given ACL name has any permissions.
This includes those objects owned by the ACL, but also those for which the
ACL has get permissions, for example.

=back

The currently supported ACL search types are:

=over 4

=item list acls empty

Returns all ACLs which have no entries, generally so that abandoned ACLs
can be destroyed.

=item list acls entry <schema> <identifier>

Returns all ACLs containing an entry with given schema and identifier.
The schema is used for an exact search, while the identifier given will
match any identifier containing that text, for flexibility.

=back

=item register (object | verifier) <type> <class>

Registers an implementation of a wallet object or ACL verifier in the
wallet database.  The Perl class <class> is registered as the
implementation of an object of type <type> or an ACL verifier of scheme
<type>, allowing creation of objects with that type or ACL lines with that
scheme.

All object and ACL implementations that come with wallet are registered by
default as part of database initialization, so this command is used
primarily to register local implementations of additional object types or
ACL schemes.

=item report <type> [ <arg> ... ]

Runs a wallet report.  The currently supported report types are:

=over 4

=item report owners <type-pattern> <name-pattern>

Returns a list of all ACL lines in owner ACLs for all objects matching
both <type-pattern> and <name-pattern>.  These can be the type or name of
objects or they can be patterns using C<%> as the wildcard character
following the normal rules of SQL patterns.

The output will be one line per ACL line in the form:

    <scheme> <identifier>

with duplicates suppressed.

=back

=back

=head1 SEE ALSO

Wallet::Admin(3), Wallet::Config(3), wallet-backend(8)

This program is part of the wallet system.  The current version is
available from L<http://www.eyrie.org/~eagle/software/wallet/>.

=head1 AUTHOR

Russ Allbery <rra@stanford.edu>

=cut