1 /*- 2 * Copyright (c) 2009 Rick Macklem, University of Guelph 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28 #include <sys/cdefs.h> 29 __FBSDID("$FreeBSD$"); 30 31 #include <sys/param.h> 32 #include <sys/linker.h> 33 #include <sys/module.h> 34 #include <sys/mount.h> 35 #include <sys/socket.h> 36 #include <sys/sysctl.h> 37 #include <sys/vnode.h> 38 39 #include <netinet/in.h> 40 41 #include <nfs/nfssvc.h> 42 43 #include <fs/nfs/rpcv2.h> 44 #include <fs/nfs/nfsproto.h> 45 #include <fs/nfs/nfskpiport.h> 46 #include <fs/nfs/nfs.h> 47 48 #include <ctype.h> 49 #include <err.h> 50 #include <errno.h> 51 #include <fcntl.h> 52 #include <limits.h> 53 #include <paths.h> 54 #include <signal.h> 55 #include <stdio.h> 56 #include <stdlib.h> 57 #include <string.h> 58 #include <unistd.h> 59 60 static void usage(void) __dead2; 61 62 int 63 main(int argc, char **argv) 64 { 65 char *cp; 66 u_char val; 67 int cnt, even; 68 struct nfsd_clid revoke_handle; 69 70 if (modfind("nfsd") < 0) 71 errx(1, "nfsd not loaded - self terminating"); 72 if (argc != 2) 73 usage(); 74 cnt = 0; 75 cp = argv[1]; 76 if (strlen(cp) % 2) 77 even = 0; 78 else 79 even = 1; 80 val = 0; 81 while (*cp) { 82 if (*cp >= '0' && *cp <= '9') 83 val += (u_char)(*cp - '0'); 84 else if (*cp >= 'A' && *cp <= 'F') 85 val += ((u_char)(*cp - 'A')) + 0xa; 86 else if (*cp >= 'a' && *cp <= 'f') 87 val += ((u_char)(*cp - 'a')) + 0xa; 88 else 89 errx(1, "Non hexadecimal digit in %s", argv[1]); 90 if (even) { 91 val <<= 4; 92 even = 0; 93 } else { 94 revoke_handle.nclid_id[cnt++] = val; 95 if (cnt > NFSV4_OPAQUELIMIT) 96 errx(1, "Clientid %s, loo long", argv[1]); 97 val = 0; 98 even = 1; 99 } 100 cp++; 101 } 102 103 /* 104 * Do the revocation system call. 105 */ 106 revoke_handle.nclid_idlen = cnt; 107 #ifdef DEBUG 108 printf("Idlen=%d\n", revoke_handle.nclid_idlen); 109 for (cnt = 0; cnt < revoke_handle.nclid_idlen; cnt++) 110 printf("%02x", revoke_handle.nclid_id[cnt]); 111 printf("\n"); 112 #else 113 if (nfssvc(NFSSVC_ADMINREVOKE, &revoke_handle) < 0) 114 err(1, "Admin revoke failed"); 115 #endif 116 } 117 118 static void 119 usage(void) 120 { 121 122 errx(1, "Usage: nfsrevoke <ClientID>"); 123 } 124