Module Name: src Committed By: bouyer Date: Mon Jan 31 21:14:06 UTC 2011
Modified Files: src/distrib/sets/lists/base [bouyer-quota2]: mi src/distrib/sets/lists/man [bouyer-quota2]: mi src/usr.sbin [bouyer-quota2]: Makefile Added Files: src/usr.sbin/quotactl [bouyer-quota2]: Makefile quotactl.8 quotactl.c Log Message: Add quotactl(8), a tools which reads a quota command plist from stdin or file and send it to kernel. To generate a diff of this commit: cvs rdiff -u -r1.915 -r1.915.2.1 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.1278 -r1.1278.2.1 src/distrib/sets/lists/man/mi cvs rdiff -u -r1.250 -r1.250.2.1 src/usr.sbin/Makefile cvs rdiff -u -r0 -r1.1.2.1 src/usr.sbin/quotactl/Makefile \ src/usr.sbin/quotactl/quotactl.8 src/usr.sbin/quotactl/quotactl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.915 src/distrib/sets/lists/base/mi:1.915.2.1 --- src/distrib/sets/lists/base/mi:1.915 Thu Jan 13 22:28:36 2011 +++ src/distrib/sets/lists/base/mi Mon Jan 31 21:14:05 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.915 2011/01/13 22:28:36 haad Exp $ +# $NetBSD: mi,v 1.915.2.1 2011/01/31 21:14:05 bouyer Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -1330,6 +1330,7 @@ ./usr/sbin/pwd_mkdb base-sysutil-bin ./usr/sbin/quot base-sysutil-bin ./usr/sbin/quotacheck base-sysutil-bin +./usr/sbin/quotactl base-sysutil-bin ./usr/sbin/quotaoff base-sysutil-bin ./usr/sbin/quotaon base-sysutil-bin ./usr/sbin/racoon base-netutil-bin crypto Index: src/distrib/sets/lists/man/mi diff -u src/distrib/sets/lists/man/mi:1.1278 src/distrib/sets/lists/man/mi:1.1278.2.1 --- src/distrib/sets/lists/man/mi:1.1278 Mon Jan 17 16:08:19 2011 +++ src/distrib/sets/lists/man/mi Mon Jan 31 21:14:05 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1278 2011/01/17 16:08:19 jmcneill Exp $ +# $NetBSD: mi,v 1.1278.2.1 2011/01/31 21:14:05 bouyer Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -2578,6 +2578,7 @@ ./usr/share/man/cat8/qmqpd.0 man-obsolete obsolete ./usr/share/man/cat8/quot.0 man-sysutil-catman .cat ./usr/share/man/cat8/quotacheck.0 man-sysutil-catman .cat +./usr/share/man/cat8/quotactl.0 man-sysutil-catman .cat ./usr/share/man/cat8/quotaoff.0 man-sysutil-catman .cat ./usr/share/man/cat8/quotaon.0 man-sysutil-catman .cat ./usr/share/man/cat8/racoon.0 man-netutil-catman crypto,.cat @@ -5068,6 +5069,7 @@ ./usr/share/man/html8/qmgr.html man-postfix-htmlman postfix,html ./usr/share/man/html8/quot.html man-sysutil-htmlman html ./usr/share/man/html8/quotacheck.html man-sysutil-htmlman html +./usr/share/man/html8/quotactl.html man-sysutil-htmlman html ./usr/share/man/html8/quotaoff.html man-sysutil-htmlman html ./usr/share/man/html8/quotaon.html man-sysutil-htmlman html ./usr/share/man/html8/racoon.html man-netutil-htmlman crypto,html @@ -7832,6 +7834,7 @@ ./usr/share/man/man8/qmqpd.8 man-obsolete obsolete ./usr/share/man/man8/quot.8 man-sysutil-man .man ./usr/share/man/man8/quotacheck.8 man-sysutil-man .man +./usr/share/man/man8/quotactl.8 man-sysutil-man .man ./usr/share/man/man8/quotaoff.8 man-sysutil-man .man ./usr/share/man/man8/quotaon.8 man-sysutil-man .man ./usr/share/man/man8/racoon.8 man-netutil-man crypto,.man Index: src/usr.sbin/Makefile diff -u src/usr.sbin/Makefile:1.250 src/usr.sbin/Makefile:1.250.2.1 --- src/usr.sbin/Makefile:1.250 Thu Jan 13 22:28:35 2011 +++ src/usr.sbin/Makefile Mon Jan 31 21:14:06 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.250 2011/01/13 22:28:35 haad Exp $ +# $NetBSD: Makefile,v 1.250.2.1 2011/01/31 21:14:06 bouyer Exp $ # from: @(#)Makefile 5.20 (Berkeley) 6/12/93 .include <bsd.own.mk> @@ -16,7 +16,7 @@ mrinfo mrouted mscdlabel mtrace \ mtree ndbootd ndiscvt netgroup_mkdb nfsd ofctl paxctl pcictl \ pppd psrset pstat pwd_mkdb postinstall powerd puffs quot quotacheck \ - quotaon rarpd rbootd rdate \ + quotactl quotaon rarpd rbootd rdate \ repquota rmt rpc.bootparamd rpc.lockd rpc.pcnfsd \ rpc.statd rpcbind rwhod sa screenblank sdpd services_mkdb sesd \ schedctl sliplogin \ Added files: Index: src/usr.sbin/quotactl/Makefile diff -u /dev/null src/usr.sbin/quotactl/Makefile:1.1.2.1 --- /dev/null Mon Jan 31 21:14:06 2011 +++ src/usr.sbin/quotactl/Makefile Mon Jan 31 21:14:06 2011 @@ -0,0 +1,16 @@ +# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $NetBSD: Makefile,v 1.1.2.1 2011/01/31 21:14:06 bouyer Exp $ + +.include <bsd.own.mk> +PROG= quotactl +SRCS= quotactl.c +MAN= quotactl.8 + +CPPFLAGS+=-I${NETBSDSRCDIR}/sys +DPADD= ${LIBPROP} +LDADD= -lprop + +.PATH: ${NETBSDSRCDIR}/sys/ufs/ufs +SRCS+= quota2_prop.c + +.include <bsd.prog.mk> Index: src/usr.sbin/quotactl/quotactl.8 diff -u /dev/null src/usr.sbin/quotactl/quotactl.8:1.1.2.1 --- /dev/null Mon Jan 31 21:14:06 2011 +++ src/usr.sbin/quotactl/quotactl.8 Mon Jan 31 21:14:06 2011 @@ -0,0 +1,80 @@ +.\" $NetBSD: quotactl.8,v 1.1.2.1 2011/01/31 21:14:06 bouyer Exp $ +.\" +.\" Copyright (c) 2011 Manuel Bouyer +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" +.Dd January 31, 2011 +.Dt QUOTACTL 8 +.Os +.Sh NAME +.Nm quotactl +.Nd send commands to the kernel disk quota subsystem +.Sh SYNOPSIS +.Nm +.Op Fl D +.Op Fl x +.Ar filesystem +.Op Ar plist +.Sh DESCRIPTION +.Nm +reads a property list of commands from the specified file or stdin, +and sends it to the kernel for the specified filesystem through the +.Xr quotactl 2 +system call. +.Pp +Available options: +.Bl -tag -width Ds +.It Fl x +Do not parse reply from kernel for errors and print it to stdout +.It Fl D +Debug: print plist sent to and received from kernel to stderr +.El +.Pp +If +.Fl x +is not specified, +.Nm +parses the reply from the kernel, looking at each command return value +and reporting errors. +.Sh EXIT STATUS +.Nm +exists with 0 on success. If there was problems parsing the command plist, +or the reply from the kernel, or if the +.Xr quotactl 2 +system call returned an error, the exist status will be 1. +Unless +.Fl x +is present, a message is printed to stderr for each failed command, +and the exit status will be 2 if any comand failed. +.Sh SEE ALSO +.Xr quota 1 , +.Xr quotactl 2 , +.Xr proplib 3 , +.Xr edquota 8 , +.Xr repquota 8 . +.Sh HISTORY +The +.Nm +command appeared in +.Nx 6.0 . Index: src/usr.sbin/quotactl/quotactl.c diff -u /dev/null src/usr.sbin/quotactl/quotactl.c:1.1.2.1 --- /dev/null Mon Jan 31 21:14:06 2011 +++ src/usr.sbin/quotactl/quotactl.c Mon Jan 31 21:14:06 2011 @@ -0,0 +1,182 @@ +/* $NetBSD: quotactl.c,v 1.1.2.1 2011/01/31 21:14:06 bouyer Exp $ */ +/*- + * Copyright (c) 2011 Manuel Bouyer + * All rights reserved. + * This software is distributed under the following condiions + * compliant with the NetBSD foundation policy. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: quotactl.c,v 1.1.2.1 2011/01/31 21:14:06 bouyer Exp $"); +#endif /* not lint */ + +/* + * Quota report + */ +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <prop/proplib.h> +#include <sys/quota.h> + +#include <errno.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <ufs/ufs/quota2_prop.h> + +void usage(void); + +#define READ_SIZE 4096 + +int +main(int argc, char * const argv[]) +{ + int xflag = 0; + int Dflag = 0; + FILE *f = NULL; + int ch; + char *plist, *p; + size_t plistsize; + int status = 0, error; + struct plistref pref; + prop_dictionary_t qdict, cmd; + prop_array_t cmds; + prop_object_iterator_t cmditer; + const char *mp, *xmlfile = NULL; + + while ((ch = getopt(argc, argv, "Dx")) != -1) { + switch (ch) { + case 'x': + xflag++; + break; + case 'D': + Dflag++; + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc == 0 || argc > 2) { + usage(); + } else if (argc == 1) { + xmlfile = "<stdin>"; + f = stdin; + } else { + xmlfile = argv[1]; + f = fopen(xmlfile, "r"); + if (f == NULL) + err(1, "%s", xmlfile); + } + mp = argv[0]; + + plist = malloc(READ_SIZE); + if (plist == NULL) + err(1, "alloc buffer"); + p = plist; + plistsize = READ_SIZE; + while (fread(p, sizeof(char), READ_SIZE, f) == READ_SIZE) { + plist = realloc(plist, plistsize + READ_SIZE); + if (plist == NULL) + err(1, "realloc buffer"); + p += READ_SIZE; + plistsize += READ_SIZE; + } + if (ferror(f)) + err(1, "error reading %s", xmlfile); + + qdict = prop_dictionary_internalize(plist); + if (qdict == NULL) + err(1, "can't parse %s", xmlfile); + free(plist); + if (!prop_dictionary_send_syscall(qdict, &pref)) + err(1, "can't externalize to syscall"); + if (Dflag) { + plist = prop_dictionary_externalize(qdict); + fprintf(stderr, "message to kernel:\n%s\n", plist); + free(plist); + } + prop_object_release(qdict); + if (quotactl(mp, &pref) != 0) + err(1, "quotactl failed"); + + if ((error = prop_dictionary_recv_syscall(&pref, &qdict)) != 0) { + errx(1, "error parsing reply from kernel: %s\n", + strerror(error)); + } + if (Dflag) { + plist = prop_dictionary_externalize(qdict); + fprintf(stderr, "reply from kernel:\n%s\n", plist); + free(plist); + } + if (xflag) { + plist = prop_dictionary_externalize(qdict); + if (plist == NULL) { + err(1, "can't print reply"); + } + printf("%s\n", plist); + exit(0); + } + /* parse the reply, looking for errors */ + if ((error = quota2_get_cmds(qdict, &cmds)) != 0) { + errx(1, "error parsing reply from kernel: %s\n", + strerror(error)); + } + cmditer = prop_array_iterator(cmds); + if (cmditer == NULL) + err(1, "prop_array_iterator(cmds)"); + + while ((cmd = prop_object_iterator_next(cmditer)) != NULL) { + const char *cmdstr; + int8_t error8; + if (!prop_dictionary_get_cstring_nocopy(cmd, "command", + &cmdstr)) + err(1, "error retrieving command"); + if (!prop_dictionary_get_int8(cmd, "return", &error8)) + err(1, "error retrieving return value for command %s", + cmdstr); + if (error8) { + warnx("command %s failed: %s", cmdstr, + strerror(error8)); + status = 2; + } + } + exit(status); +} + + +void +usage(void) +{ + fprintf(stderr, "usage: %s [-D] [-x] mount point [file]\n", + getprogname()); + exit(1); +}