ed6e740bcba9d56ec382a5ef7fac634084ff872b
[ca] / bin / withdraw
1 #! /usr/bin/tclsh8.5
2 ### -*-tcl-*-
3 ###
4 ### Revoke a certificate request
5 ###
6 ### (c) 2011 Mark Wooding
7 ###
8
9 ###----- Licensing notice ---------------------------------------------------
10 ###
11 ### This program is free software; you can redistribute it and/or modify
12 ### it under the terms of the GNU General Public License as published by
13 ### the Free Software Foundation; either version 2 of the License, or
14 ### (at your option) any later version.
15 ###
16 ### This program is distributed in the hope that it will be useful,
17 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ### GNU General Public License for more details.
20 ###
21 ### You should have received a copy of the GNU General Public License
22 ### along with this program; if not, write to the Free Software Foundation,
23 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 ## Find the common utilities.
26 source [file join [file dirname $argv0] "../lib/func.tcl"]
27
28 ## Get the list of requests.
29 if {[llength $argv] != 1} {
30 puts stderr "Usage: $QUIS REQID"
31 exit 1
32 }
33 lassign $argv reqid
34
35 ## Set the request state. Don't try to revoke the certificates: they'll
36 ## expire soon enough, and there isn't really anything wrong with them
37 ## anyway. (If there were anything wrong, the request would have been
38 ## revoked.)
39 db transaction {
40 set del {}
41 foreach req [request-match $reqid "st = 'active'"] {
42 lassign [db eval { SELECT st, tag FROM request WHERE id = $req; }] \
43 reqst tag
44 if {[string equal $reqst active]} { lappend del "req/active/$tag" }
45 foreach {cert certst} [db eval {
46 SELECT seq, st FROM certificate
47 WHERE req = $req AND st = 'active';
48 }] {
49 db eval {
50 UPDATE certificate
51 SET st = 'withdrawn'
52 WHERE seq = $cert;
53 }
54 lappend del "cert/active/$tag"
55 }
56 db eval {
57 UPDATE request
58 SET st = 'withdrawn'
59 WHERE id = $req;
60 }
61 }
62 }
63 foreach f $del { file delete -force "$CERTROOT/$f" }