1177633Sdfr/*- 2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3330449Seadler * 4177633Sdfr * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 5177633Sdfr * Authors: Doug Rabson <dfr@rabson.org> 6177633Sdfr * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 7177633Sdfr * 8177633Sdfr * Redistribution and use in source and binary forms, with or without 9177633Sdfr * modification, are permitted provided that the following conditions 10177633Sdfr * are met: 11177633Sdfr * 1. Redistributions of source code must retain the above copyright 12177633Sdfr * notice, this list of conditions and the following disclaimer. 13177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright 14177633Sdfr * notice, this list of conditions and the following disclaimer in the 15177633Sdfr * documentation and/or other materials provided with the distribution. 16177633Sdfr * 17177633Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19177633Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20177633Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22177633Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26177633Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27177633Sdfr * SUCH DAMAGE. 28177633Sdfr */ 29177633Sdfr 30177633Sdfr#include <sys/cdefs.h> 31177633Sdfr__FBSDID("$FreeBSD: stable/11/usr.sbin/clear_locks/clear_locks.c 330449 2018-03-05 07:26:05Z eadler $"); 32177633Sdfr 33177633Sdfr#include <stdio.h> 34177633Sdfr#include <stdlib.h> 35177633Sdfr#include <unistd.h> 36177633Sdfr 37177633Sdfr#include <rpc/rpc.h> 38177633Sdfr#include <rpcsvc/nlm_prot.h> 39177633Sdfr 40177633Sdfrint 41177633Sdfrmain(int argc, char **argv) 42177633Sdfr{ 43177633Sdfr enum clnt_stat stat; 44177633Sdfr char *hostname; 45177633Sdfr nlm4_notify notify; 46177633Sdfr 47177633Sdfr if (argc != 2) { 48177633Sdfr fprintf(stderr, "Usage: clear_locks <hostname>\n"); 49177633Sdfr exit(1); 50177633Sdfr } 51177633Sdfr hostname = argv[1]; 52177633Sdfr 53177633Sdfr if (geteuid() != 0) { 54177633Sdfr fprintf(stderr, "clear_locks: must be root\n"); 55177633Sdfr exit(1); 56177633Sdfr } 57177633Sdfr 58177633Sdfr notify.name = hostname; 59177633Sdfr notify.state = 0; 60177633Sdfr stat = rpc_call("localhost", NLM_PROG, NLM_VERS4, NLM4_FREE_ALL, 61177633Sdfr (xdrproc_t) xdr_nlm4_notify, (void *) ¬ify, 62177633Sdfr (xdrproc_t) xdr_void, NULL, NULL); 63177633Sdfr 64177633Sdfr if (stat != RPC_SUCCESS) { 65177633Sdfr clnt_perrno(stat); 66177633Sdfr exit(1); 67177633Sdfr } 68177633Sdfr fprintf(stderr, "clear_locks: cleared locks for hostname %s\n", 69177633Sdfr hostname); 70177633Sdfr 71177633Sdfr return (0); 72177633Sdfr} 73