]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/nfsrevoke/nfsrevoke.c
Remove $FreeBSD$: one-line sh pattern
[FreeBSD/FreeBSD.git] / usr.sbin / nfsrevoke / nfsrevoke.c
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 #include <sys/param.h>
30 #include <sys/linker.h>
31 #include <sys/module.h>
32 #include <sys/mount.h>
33 #include <sys/socket.h>
34 #include <sys/sysctl.h>
35 #include <sys/vnode.h>
36
37 #include <netinet/in.h>
38
39 #include <nfs/nfssvc.h>
40
41 #include <fs/nfs/rpcv2.h>
42 #include <fs/nfs/nfsproto.h>
43 #include <fs/nfs/nfskpiport.h>
44 #include <fs/nfs/nfs.h>
45
46 #include <ctype.h>
47 #include <err.h>
48 #include <errno.h>
49 #include <fcntl.h>
50 #include <limits.h>
51 #include <paths.h>
52 #include <signal.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <unistd.h>
57
58 static void usage(void) __dead2;
59
60 int
61 main(int argc, char **argv)
62 {
63         char *cp;
64         u_char val;
65         int cnt, even;
66         struct nfsd_clid revoke_handle;
67
68         if (modfind("nfsd") < 0)
69                 errx(1, "nfsd not loaded - self terminating");
70         if (argc != 2)
71                 usage();
72         cnt = 0;
73         cp = argv[1];
74         if (strlen(cp) % 2)
75                 even = 0;
76         else
77                 even = 1;
78         val = 0;
79         while (*cp) {
80                 if (*cp >= '0' && *cp <= '9')
81                         val += (u_char)(*cp - '0');
82                 else if (*cp >= 'A' && *cp <= 'F')
83                         val += ((u_char)(*cp - 'A')) + 0xa;
84                 else if (*cp >= 'a' && *cp <= 'f')
85                         val += ((u_char)(*cp - 'a')) + 0xa;
86                 else
87                         errx(1, "Non hexadecimal digit in %s", argv[1]);
88                 if (even) {
89                         val <<= 4;
90                         even = 0;
91                 } else {
92                         revoke_handle.nclid_id[cnt++] = val;
93                         if (cnt > NFSV4_OPAQUELIMIT)
94                                 errx(1, "Clientid %s, loo long", argv[1]);
95                         val = 0;
96                         even = 1;
97                 }
98                 cp++;
99         }
100
101         /*
102          * Do the revocation system call.
103          */
104         revoke_handle.nclid_idlen = cnt;
105 #ifdef DEBUG
106         printf("Idlen=%d\n", revoke_handle.nclid_idlen);
107         for (cnt = 0; cnt < revoke_handle.nclid_idlen; cnt++)
108                 printf("%02x", revoke_handle.nclid_id[cnt]);
109         printf("\n");
110 #else
111         if (nfssvc(NFSSVC_ADMINREVOKE, &revoke_handle) < 0)
112                 err(1, "Admin revoke failed");
113 #endif
114 }
115
116 static void
117 usage(void)
118 {
119
120         errx(1, "Usage: nfsrevoke <ClientID>");
121 }