diff options
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | edquota.c | 10 | ||||
-rw-r--r-- | quota.c | 6 | ||||
-rw-r--r-- | quotaops.c | 6 | ||||
-rw-r--r-- | quotasys.c | 34 | ||||
-rw-r--r-- | quotasys.h | 6 | ||||
-rw-r--r-- | setquota.8 | 23 | ||||
-rw-r--r-- | setquota.c | 90 |
8 files changed, 144 insertions, 32 deletions
@@ -1,4 +1,5 @@ Changes in quota-tools from 3.11 to 3.12 +* added batch mode to the setquota(8) (Jan Kara) * added reference to setquota(8) to manpages of other tools (Jan Kara) * fixed bug in --port option of rquotad (Max Kalika) * updated quota documentation (Jan Kara) @@ -34,7 +34,7 @@ #ident "$Copyright: (c) 1980, 1990 Regents of the University of California. $" #ident "$Copyright: All rights reserved. $" -#ident "$Id: edquota.c,v 1.13 2003/07/29 20:11:36 jkar8572 Exp $" +#ident "$Id: edquota.c,v 1.14 2004/04/14 16:03:14 jkar8572 Exp $" /* * Disk quota editor. @@ -155,10 +155,10 @@ int main(int argc, char **argv) return 0; } if (pflag) { - protoid = name2id(protoname, quotatype); + protoid = name2id(protoname, quotatype, NULL); protoprivs = getprivs(protoid, handles, 0); while (argc-- > 0) { - id = name2id(*argv++, quotatype); + id = name2id(*argv++, quotatype, NULL); curprivs = getprivs(id, handles, 0); for (pprivs = protoprivs, cprivs = curprivs; pprivs && cprivs; @@ -211,7 +211,7 @@ int main(int argc, char **argv) } else if (Tflag) { for (; argc > 0; argc--, argv++) { - id = name2id(*argv, quotatype); + id = name2id(*argv, quotatype, NULL); curprivs = getprivs(id, handles, 0); if (writeindividualtimes(curprivs, tmpfd, *argv, quotatype) < 0) { errstr(_("Can't write individual grace times to file.\n")); @@ -231,7 +231,7 @@ int main(int argc, char **argv) } else { for (; argc > 0; argc--, argv++) { - id = name2id(*argv, quotatype); + id = name2id(*argv, quotatype, NULL); curprivs = getprivs(id, handles, 0); if (writeprivs(curprivs, tmpfd, *argv, quotatype) < 0) { errstr(_("Can't write quotas to file.\n")); @@ -34,7 +34,7 @@ #ident "$Copyright: (c) 1980, 1990 Regents of the University of California. $" #ident "$Copyright: All rights reserved. $" -#ident "$Id: quota.c,v 1.13 2003/02/14 18:50:17 jkar8572 Exp $" +#ident "$Id: quota.c,v 1.14 2004/04/14 16:03:14 jkar8572 Exp $" /* * Disk quota reporting program. @@ -148,10 +148,10 @@ int main(int argc, char **argv) if (flags & FL_USER) for (; argc > 0; argc--, argv++) - ret |= showquotas(USRQUOTA, user2uid(*argv)); + ret |= showquotas(USRQUOTA, user2uid(*argv, NULL)); else if (flags & FL_GROUP) for (; argc > 0; argc--, argv++) - ret |= showquotas(GRPQUOTA, group2gid(*argv)); + ret |= showquotas(GRPQUOTA, group2gid(*argv, NULL)); return ret; } @@ -34,7 +34,7 @@ #ident "$Copyright: (c) 1980, 1990 Regents of the University of California. $" #ident "$Copyright: All rights reserved. $" -#ident "$Id: quotaops.c,v 1.11 2004/01/07 15:15:31 jkar8572 Exp $" +#ident "$Id: quotaops.c,v 1.12 2004/04/14 16:03:14 jkar8572 Exp $" #include <rpc/rpc.h> #include <sys/types.h> @@ -240,7 +240,7 @@ int writeprivs(struct dquot *qlist, int outfd, char *name, int quotatype) #if defined(ALT_FORMAT) fprintf(fd, _("Disk quotas for %s %s (%cid %d):\n"), - type2name(quotatype), name, *type2name(quotatype), name2id(name, quotatype)); + type2name(quotatype), name, *type2name(quotatype), name2id(name, quotatype, NULL)); fprintf(fd, _(" Filesystem blocks soft hard inodes soft hard\n")); @@ -424,7 +424,7 @@ int writeindividualtimes(struct dquot *qlist, int outfd, char *name, int quotaty die(1, _("Can't duplicate descriptor of file to write to: %s\n"), strerror(errno)); fprintf(fd, _("Times to enforce softlimit for %s %s (%cid %d):\n"), - type2name(quotatype), name, *type2name(quotatype), name2id(name, quotatype)); + type2name(quotatype), name, *type2name(quotatype), name2id(name, quotatype, NULL)); fprintf(fd, _("Time units may be: days, hours, minutes, or seconds\n")); fprintf(fd, _(" Filesystem block grace inode grace\n")); @@ -79,18 +79,26 @@ char *type2name(int type) /* * Convert name to uid */ -uid_t user2uid(char *name) +uid_t user2uid(char *name, int *err) { struct passwd *entry; uid_t ret; char *errch; + if (err) + *err = 0; ret = strtol(name, &errch, 0); if (!*errch) /* Is name number - we got directly uid? */ return ret; if (!(entry = getpwnam(name))) { - errstr(_("User %s doesn't exist.\n"), name); - exit(1); + if (!err) { + errstr(_("User %s doesn't exist.\n"), name); + exit(1); + } + else { + *err = -1; + return 0; + } } return entry->pw_uid; } @@ -98,18 +106,26 @@ uid_t user2uid(char *name) /* * Convert group name to gid */ -gid_t group2gid(char *name) +gid_t group2gid(char *name, int *err) { struct group *entry; gid_t ret; char *errch; + if (err) + *err = 0; ret = strtol(name, &errch, 0); if (!*errch) /* Is name number - we got directly gid? */ return ret; if (!(entry = getgrnam(name))) { - errstr(_("Group %s doesn't exist.\n"), name); - exit(1); + if (!err) { + errstr(_("Group %s doesn't exist.\n"), name); + exit(1); + } + else { + *err = -1; + return 0; + } } return entry->gr_gid; } @@ -117,12 +133,12 @@ gid_t group2gid(char *name) /* * Convert name to id */ -int name2id(char *name, int qtype) +int name2id(char *name, int qtype, int *err) { if (qtype == USRQUOTA) - return user2uid(name); + return user2uid(name, err); else - return group2gid(name); + return group2gid(name, err); } /* @@ -41,13 +41,13 @@ extern int kernel_formats, kernel_iface; char *type2name(int); /* Convert username to uid */ -uid_t user2uid(char *); +uid_t user2uid(char *, int *err); /* Convert groupname to gid */ -gid_t group2gid(char *); +gid_t group2gid(char *, int *err); /* Convert user/groupname to id */ -int name2id(char *name, int qtype); +int name2id(char *name, int qtype, int *err); /* Convert uid to username */ int uid2user(uid_t, char *); @@ -47,6 +47,24 @@ setquota \- set disk quotas .I filesystem... .LP .B setquota +.B \-b +[ +.B \-r +] +[ +.B \-u +| +.B \-g +] +[ +.B \-F +.I quotaformat +] +.B \-a +| +.I filesystem... +.LP +.B setquota .B \-t [ .B \-u @@ -118,6 +136,11 @@ Use quota settings of user or group .I protoname to set the quota for the named user or group. .TP +.B -b +Read information to set from stdin (input format is +.I name block-softlimit block-hardlimit inode-softlimit inode-hardlimit +). +.TP .B -t Set grace times for users/groups. Times .B block-grace @@ -28,6 +28,7 @@ #define FL_PROTO 16 #define FL_GRACE 32 #define FL_INDIVIDUAL_GRACE 64 +#define FL_BATCH 128 int flags, fmt = -1; char **mnt; @@ -44,6 +45,7 @@ static void usage(void) " setquota [-u|-g] [-r] [-F quotaformat] <user|group>\n" "\t<block-softlimit> <block-hardlimit> <inode-softlimit> <inode-hardlimit> -a|<filesystem>...\n" " setquota [-u|-g] [-r] [-F quotaformat] <-p protouser|protogroup> <user|group> -a|<filesystem>...\n" + " setquota [-u|-g] [-r] [-F quotaformat] -b -a|<filesystem>...\n" " setquota [-u|-g] [-F quotaformat] -t <blockgrace> <inodegrace> -a|<filesystem>...\n" " setquota [-u|-g] [-F quotaformat] <user|group> -T <blockgrace> <inodegrace> -a|<filesystem>...\n")); #else @@ -51,6 +53,7 @@ static void usage(void) " setquota [-u|-g] [-F quotaformat] <user|group>\n" "\t<block-softlimit> <block-hardlimit> <inode-softlimit> <inode-hardlimit> -a|<filesystem>...\n" " setquota [-u|-g] [-F quotaformat] <-p protouser|protogroup> <user|group> -a|<filesystem>...\n" + " setquota [-u|-g] [-F quotaformat] -b -a|<filesystem>...\n" " setquota [-u|-g] [-F quotaformat] -t <blockgrace> <inodegrace> -a|<filesystem>...\n" " setquota [-u|-g] [-F quotaformat] <user|group> -T <blockgrace> <inodegrace> -a|<filesystem>...\n")); #endif @@ -88,9 +91,9 @@ static void parse_options(int argcnt, char **argstr) char *protoname = NULL; #ifdef RPC_SETQUOTA - char *opts = "igp:urVF:taT"; + char *opts = "igp:urVF:taTb"; #else - char *opts = "igp:uVF:taT"; + char *opts = "igp:uVF:taTb"; #endif while ((ret = getopt(argcnt, argstr, opts)) != -1) { @@ -117,6 +120,9 @@ static void parse_options(int argcnt, char **argstr) case 't': flags |= FL_GRACE; break; + case 'b': + flags |= FL_BATCH; + break; case 'T': flags |= FL_INDIVIDUAL_GRACE; break; @@ -130,30 +136,44 @@ static void parse_options(int argcnt, char **argstr) } } if (flags & FL_USER && flags & FL_GROUP) { - fputs(_("Group and user quotas can't be used together.\n"), stderr); + errstr(_("Group and user quotas cannot be used together.\n")); usage(); } if (flags & FL_PROTO && flags & FL_GRACE) { - fputs(_("Prototype user has no sense when editting grace times.\n"), stderr); + errstr(_("Prototype user has no sense when editting grace times.\n")); + usage(); + } + if (flags & FL_INDIVIDUAL_GRACE && flags & FL_GRACE) { + errstr(_("Cannot set both individual and global grace time.\n")); + usage(); + } + if (flags & FL_BATCH && flags & (FL_GRACE | FL_INDIVIDUAL_GRACE)) { + errstr(_("Batch mode cannot be used for setting grace times.\n")); + usage(); + } + if (flags & FL_BATCH && flags & FL_PROTO) { + errstr(_("Batch mode and prototype user cannot be used together.\n")); usage(); } if (flags & FL_GRACE) otherargs = 2; else if (flags & FL_INDIVIDUAL_GRACE) otherargs = 3; + else if (flags & FL_BATCH) + otherargs = 0; else { otherargs = 1; if (!(flags & FL_PROTO)) otherargs += 4; } if (optind + otherargs > argcnt) { - fputs(_("Bad number of arguments.\n"), stderr); + errstr(_("Bad number of arguments.\n")); usage(); } if (!(flags & (FL_USER | FL_GROUP))) flags |= FL_USER; - if (!(flags & FL_GRACE)) { - id = name2id(argstr[optind++], flag2type(flags)); + if (!(flags & (FL_GRACE | FL_BATCH))) { + id = name2id(argstr[optind++], flag2type(flags), NULL); if (!(flags & (FL_GRACE | FL_INDIVIDUAL_GRACE | FL_PROTO))) { toset.dqb_bsoftlimit = parse_num(argstr[optind++], _("block softlimit")); toset.dqb_bhardlimit = parse_num(argstr[optind++], _("block hardlimit")); @@ -161,7 +181,7 @@ static void parse_options(int argcnt, char **argstr) toset.dqb_ihardlimit = parse_num(argstr[optind++], _("inode hardlimit")); } else if (flags & FL_PROTO) - protoid = name2id(protoname, flag2type(flags)); + protoid = name2id(protoname, flag2type(flags), NULL); } if (flags & FL_GRACE) { toset.dqb_btime = parse_num(argstr[optind++], _("block grace time")); @@ -188,7 +208,7 @@ static void parse_options(int argcnt, char **argstr) mntcnt = argcnt - optind; mnt = argstr + optind; if (!mntcnt) { - fputs(_("Mountpoint not specified.\n"), stderr); + errstr(_("Mountpoint not specified.\n")); usage(); } } @@ -224,6 +244,56 @@ static void setlimits(struct quota_handle **handles) freeprivs(curprivs); } +#define MAXLINELEN (MAXNUMLEN*4+MAXNAMELEN+16) + +/* Read & parse one batch entry */ +static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize_t *bsoftlimit, qsize_t *bhardlimit) +{ + static int line = 0; + char name[MAXNAMELEN+1]; + unsigned long is, ih, bs, bh; + int ret; + + do { + line++; + ret = scanf("%s %lu %lu %lu %lu", name, &bs, &bh, &is, &ih); + if (ret == -1) + return -1; + if (ret != 5) + die(1, _("Cannot parse input line %d.\n"), line); + ret = 0; + *id = name2id(name, flag2type(flags), &ret); + if (ret) + errstr(_("Unable to get name '%s'.\n"), name); + } while (ret); + *isoftlimit = is; + *ihardlimit = ih; + *bsoftlimit = bs; + *bhardlimit = bh; + return 0; +} + +/* Set user limits in batch mode */ +static void batch_setlimits(struct quota_handle **handles) +{ + struct dquot *curprivs, *q; + qsize_t bhardlimit, bsoftlimit, ihardlimit, isoftlimit; + qid_t id; + + while (!read_entry(&id, &isoftlimit, &ihardlimit, &bsoftlimit, &bhardlimit)) { + curprivs = getprivs(id, handles, 0); + for (q = curprivs; q; q = q->dq_next) { + q->dq_dqb.dqb_bsoftlimit = bsoftlimit; + q->dq_dqb.dqb_bhardlimit = bhardlimit; + q->dq_dqb.dqb_isoftlimit = isoftlimit; + q->dq_dqb.dqb_ihardlimit = ihardlimit; + update_grace_times(q); + } + putprivs(curprivs, COMMIT_LIMITS); + freeprivs(curprivs); + } +} + /* Set grace times */ static void setgraces(struct quota_handle **handles) { @@ -270,6 +340,8 @@ int main(int argc, char **argv) setgraces(handles); else if (flags & FL_INDIVIDUAL_GRACE) setindivgraces(handles); + else if (flags & FL_BATCH) + batch_setlimits(handles); else setlimits(handles); |