diff -NurBP --minimal quota-tools-3.07/mntopt.h quota-tools-ctx/mntopt.h --- quota-tools-3.07/mntopt.h Wed Dec 5 14:53:25 2001 +++ quota-tools-ctx/mntopt.h Sun Oct 27 03:58:25 2002 @@ -14,9 +14,10 @@ /* mount options */ #define MNTOPT_NOQUOTA "noquota" /* don't enforce quota */ -#define MNTOPT_QUOTA "quota" /* enforce user quota */ +#define MNTOPT_QUOTA "quota" /* enforce user quota */ #define MNTOPT_USRQUOTA "usrquota" /* enforce user quota */ #define MNTOPT_GRPQUOTA "grpquota" /* enforce group quota */ +#define MNTOPT_CTXQUOTA "ctxquota" /* enforce context quota */ #define MNTOPT_RSQUASH "rsquash" /* root as ordinary user */ #define MNTOPT_BIND "bind" /* binded mount */ #define MNTOPT_LOOP "loop" /* loopback mount */ diff -NurBP --minimal quota-tools-3.07/quota.c quota-tools-ctx/quota.c --- quota-tools-3.07/quota.c Tue Jul 23 17:59:27 2002 +++ quota-tools-ctx/quota.c Sun Oct 27 03:57:19 2002 @@ -67,6 +67,7 @@ #define FL_SMARTSIZE 16 #define FL_LOCALONLY 32 #define FL_QUIETREFUSE 64 +#define FL_CONTEXT 128 int flags, fmt = -1; char *progname; @@ -84,7 +85,7 @@ gettexton(); progname = basename(argv[0]); - while ((ret = getopt(argc, argv, "guqvsVlQF:")) != -1) { + while ((ret = getopt(argc, argv, "guxqvsVlQF:")) != -1) { switch (ret) { case 'g': flags |= FL_GROUP; @@ -92,6 +93,9 @@ case 'u': flags |= FL_USER; break; + case 'x': + flags |= FL_CONTEXT; + break; case 'q': flags |= FL_QUIET; break; @@ -121,7 +125,8 @@ argc -= optind; argv += optind; - if (!(flags & FL_USER) && !(flags & FL_GROUP)) + if (!(flags & FL_USER) && !(flags & FL_GROUP) + && !(flags & FL_CONTEXT)) flags |= FL_USER; init_kernel_interface(); @@ -136,10 +141,13 @@ for (i = 0; i < ngroups; i++) ret |= showquotas(GRPQUOTA, gidset[i]); } + if (flags & FL_CONTEXT) { + ret |= showquotas(CTXQUOTA, 0); /* fixme CONTEXT */ + } exit(ret); } - if ((flags & FL_USER) && (flags & FL_GROUP)) + if ((flags & FL_USER) && (flags & FL_GROUP) && (flags & FL_CONTEXT)) usage(); if (flags & FL_USER) @@ -148,15 +156,19 @@ else if (flags & FL_GROUP) for (; argc > 0; argc--, argv++) ret |= showquotas(GRPQUOTA, group2gid(*argv)); + else if (flags & FL_CONTEXT) + for (; argc > 0; argc--, argv++) + ret |= showquotas(CTXQUOTA, atoi(*argv)); /* fixme CONTEXT */ return ret; } void usage(void) { - errstr( "%s%s%s", - _("Usage: quota [-guqvs] [-l | -Q] [-F quotaformat]\n"), + errstr( "%s%s%s%s", + _("Usage: quota [-guxqvs] [-l | -Q] [-F quotaformat]\n"), _("\tquota [-qvs] [-l | -Q] [-F quotaformat] -u username ...\n"), - _("\tquota [-qvs] [-l | -Q] [-F quotaformat] -g groupname ...\n")); + _("\tquota [-qvs] [-l | -Q] [-F quotaformat] -g groupname ...\n"), + _("\tquota [-qvs] [-l | -Q] [-F quotaformat] -x context ...\n")); fprintf(stderr, _("Bugs to: %s\n"), MY_EMAIL); exit(1); } diff -NurBP --minimal quota-tools-3.07/quota.h quota-tools-ctx/quota.h --- quota-tools-3.07/quota.h Fri May 31 01:39:26 2002 +++ quota-tools-ctx/quota.h Sun Oct 27 03:51:08 2002 @@ -6,9 +6,10 @@ typedef u_int32_t qid_t; /* Type in which we store ids in memory */ typedef u_int64_t qsize_t; /* Type in which we store size limitations */ -#define MAXQUOTAS 2 +#define MAXQUOTAS 3 #define USRQUOTA 0 /* element used for user quotas */ #define GRPQUOTA 1 /* element used for group quotas */ +#define CTXQUOTA 2 /* element used for context quotas */ /* * Definitions for the default names of the quotas files. @@ -16,6 +17,7 @@ #define INITQFNAMES { \ "user", /* USRQUOTA */ \ "group", /* GRPQUOTA */ \ + "context", /* CTXQUOTA */ \ "undefined", \ } @@ -24,7 +26,8 @@ */ #define INITQMAGICS {\ 0xd9c01f11, /* USRQUOTA */\ - 0xd9c01927 /* GRPQUOTA */\ + 0xd9c01927, /* GRPQUOTA */\ + 0xd9c01111 /* CTXQUOTA */\ } /* Size of blocks in which are counted size limits in generic utility parts */ diff -NurBP --minimal quota-tools-3.07/quotacheck.c quota-tools-ctx/quotacheck.c --- quota-tools-3.07/quotacheck.c Tue Aug 27 20:13:41 2002 +++ quota-tools-ctx/quotacheck.c Sun Oct 27 04:42:01 2002 @@ -63,7 +63,8 @@ dev_t cur_dev; /* Device we are working on */ int files_done, dirs_done; int flags, fmt = -1, cfmt; /* Options from command line; Quota format to use spec. by user; Actual format to check */ -int uwant, gwant, ucheck, gcheck; /* Does user want to check user/group quota; Do we check user/group quota? */ +int uwant, gwant, xwant, + ucheck, gcheck, xcheck; /* Does user want to check user/group quota; Do we check user/group quota? */ char *mntpoint; /* Mountpoint to check */ char *progname; struct util_dqinfo old_info[MAXQUOTAS]; /* Loaded infos */ @@ -189,8 +190,12 @@ if (type == USRQUOTA) wanted = i_uid; - else + else if (type == GRPQUOTA) wanted = i_gid; + else if (type == CTXQUOTA) + wanted = (i_uid >> 16); /* fixme CONTEXT */ + else + wanted = 0; if ((lptr = lookup_dquot(wanted, type)) == NODQUOT) lptr = add_dquot(wanted, type); @@ -281,7 +286,7 @@ static void usage(void) { - printf(_("Utility for checking and repairing quota files.\n%s [-gucfinvdmMR] [-F ] filesystem|-a\n"), progname); + printf(_("Utility for checking and repairing quota files.\n%s [-guxcfinvdmMR] [-F ] filesystem|-a\n"), progname); printf(_("Bugs to %s\n"), MY_EMAIL); exit(1); } @@ -290,7 +295,7 @@ { int ret; - while ((ret = getopt(argcnt, argstr, "VhbcvugidnfF:mMRa")) != -1) { + while ((ret = getopt(argcnt, argstr, "VhbcvugxidnfF:mMRa")) != -1) { switch (ret) { case 'b': flags |= FL_BACKUPS; @@ -301,6 +306,9 @@ case 'u': uwant = 1; break; + case 'x': + xwant = 1; + break; case 'd': flags |= FL_DEBUG; setlinebuf(stderr); @@ -343,7 +351,7 @@ usage(); } } - if (!(uwant | gwant)) + if (!(uwant | gwant | xwant)) uwant = 1; if ((argcnt == optind && !(flags & FL_ALL)) || (argcnt > optind && flags & FL_ALL)) { fputs(_("Bad number of arguments.\n"), stderr); @@ -415,6 +423,10 @@ add_to_quota(GRPQUOTA, i_num, uid, gid, inode.i_mode, inode.i_links_count, inode.i_blocks << 9); + if (xcheck) + add_to_quota(CTXQUOTA, i_num, uid, gid, + inode.i_mode, inode.i_links_count, + inode.i_blocks << 9); if (S_ISDIR(inode.i_mode)) dirs_done++; else @@ -468,6 +480,9 @@ if (gcheck) add_to_quota(GRPQUOTA, st.st_ino, st.st_uid, st.st_gid, st.st_mode, st.st_nlink, qspace); + if (xcheck) + add_to_quota(CTXQUOTA, st.st_ino, st.st_uid, st.st_gid, st.st_mode, + st.st_nlink, qspace); if (S_ISDIR(st.st_mode)) { if (st.st_dev != cur_dev) @@ -760,7 +775,14 @@ else gcheck = 0; } - if (!ucheck && !gcheck) /* Nothing to check? */ + if (xcheck) { + if (process_file(mnt, CTXQUOTA) >= 0) + add_to_quota(CTXQUOTA, st.st_ino, st.st_uid, st.st_gid, st.st_mode, + st.st_nlink, qspace); + else + xcheck = 0; + } + if (!ucheck && !gcheck && !xcheck) /* Nothing to check? */ return; if (!(flags & FL_NOREMOUNT)) { /* Now we try to remount fs read-only to prevent races when scanning filesystem */ @@ -811,6 +833,8 @@ dump_to_file(mnt, USRQUOTA); if (gcheck) dump_to_file(mnt, GRPQUOTA); + if (xcheck) + dump_to_file(mnt, CTXQUOTA); out: remove_list(); } @@ -828,10 +852,14 @@ else if ((option = hasmntopt(mnt, MNTOPT_QUOTA))) option += strlen(MNTOPT_QUOTA); } - else { + else if (type == GRPQUOTA) { if ((option = hasmntopt(mnt, MNTOPT_GRPQUOTA))) option += strlen(MNTOPT_GRPQUOTA); } + else if (type == CTXQUOTA) { + if ((option = hasmntopt(mnt, MNTOPT_CTXQUOTA))) + option += strlen(MNTOPT_CTXQUOTA); + } if (!option) die(2, _("Can't find quota option on filesystem %s with quotas!\n"), mnt->mnt_dir); if (*option == '=') /* If the file name is specified we can't detect quota format from it... */ @@ -875,9 +903,14 @@ gcheck = 1; else gcheck = 0; - if (!ucheck && !gcheck) + if (xwant && hasquota(mnt, CTXQUOTA)) + xcheck = 1; + else + xcheck = 0; + if (!ucheck && !gcheck && !xcheck) continue; if (cfmt == -1) { + /* fixme CONTEXT */ if ((cfmt = detect_filename_format(mnt, ucheck ? USRQUOTA : GRPQUOTA)) == -1) { errstr(_("Cannot guess format from filename on %s. Please specify format on commandline.\n"), mnt->mnt_fsname); diff -NurBP --minimal quota-tools-3.07/quotaops.c quota-tools-ctx/quotaops.c --- quota-tools-3.07/quotaops.c Tue Jul 23 17:59:27 2002 +++ quota-tools-ctx/quotaops.c Sun Oct 27 04:02:34 2002 @@ -148,6 +148,14 @@ return (struct dquot *)NULL; } break; + case CTXQUOTA: +/* euid = geteuid(); + if (euid != id && euid != 0) { + uid2user(id, name); + die(1, _("%s (uid %d): Permission denied\n"), name, id); + } +fixme CONTEXT */ + break; default: break; } diff -NurBP --minimal quota-tools-3.07/quotasys.c quota-tools-ctx/quotasys.c --- quota-tools-3.07/quotasys.c Mon Jul 22 21:41:56 2002 +++ quota-tools-ctx/quotasys.c Sun Oct 27 04:07:48 2002 @@ -369,6 +369,8 @@ return 1; if ((type == GRPQUOTA) && hasmntopt(mnt, MNTOPT_GRPQUOTA)) return 1; + if ((type == CTXQUOTA) && hasmntopt(mnt, MNTOPT_CTXQUOTA)) + return 1; if ((type == USRQUOTA) && hasmntopt(mnt, MNTOPT_QUOTA)) return 1; return 0; @@ -422,6 +424,10 @@ if (*(pathname = option + strlen(MNTOPT_GRPQUOTA)) == '=') has_quota_file_definition = 1; } + else if (type == CTXQUOTA && (option = hasmntopt(mnt, MNTOPT_CTXQUOTA))) { + if (*(pathname = option + strlen(MNTOPT_CTXQUOTA)) == '=') + has_quota_file_definition = 1; + } else if (type == USRQUOTA && (option = hasmntopt(mnt, MNTOPT_QUOTA))) { if (*(pathname = option + strlen(MNTOPT_QUOTA)) == '=') has_quota_file_definition = 1; @@ -602,6 +608,7 @@ { char tmp[1024]; /* Just temporary buffer */ qid_t id = (type == USRQUOTA) ? getuid() : getgid(); + /* fixem CONTEXT BAD!!! */ if (!quotactl(QCMD(Q_V1_GETQUOTA, type), dev, id, tmp)) /* OK? */ return 1; @@ -613,6 +620,7 @@ { char tmp[1024]; /* Just temporary buffer */ qid_t id = (type == USRQUOTA) ? getuid() : getgid(); + /* fixem CONTEXT BAD!!! */ if (!quotactl(QCMD(Q_V2_GETQUOTA, type), dev, id, tmp)) /* OK? */ return 1; diff -NurBP --minimal quota-tools-3.07/repquota.c quota-tools-ctx/repquota.c --- quota-tools-3.07/repquota.c Mon Jul 22 21:55:41 2002 +++ quota-tools-ctx/repquota.c Sun Oct 27 04:13:28 2002 @@ -32,6 +32,7 @@ #define FL_SHORTNUMS 32 #define FL_NONAME 64 #define FL_NOCACHE 128 /* Don't cache dquots before resolving */ +#define FL_CONTEXT 256 int flags, fmt = -1; char **mnt; @@ -42,7 +43,7 @@ static void usage(void) { - errstr(_("Utility for reporting quotas.\nUsage:\n%s [-vugs] [-c|C] [-t|n] [-F quotaformat] (-a | mntpoint)\n"), progname); + errstr(_("Utility for reporting quotas.\nUsage:\n%s [-vugxs] [-c|C] [-t|n] [-F quotaformat] (-a | mntpoint)\n"), progname); fprintf(stderr, _("Bugs to %s\n"), MY_EMAIL); exit(1); } @@ -52,7 +53,7 @@ int ret; int cache_specified = 0; - while ((ret = getopt(argcnt, argstr, "VavughtsncCF:")) != -1) { + while ((ret = getopt(argcnt, argstr, "VavugxhtsncCF:")) != -1) { switch (ret) { case '?': case 'h': @@ -66,6 +67,9 @@ case 'g': flags |= FL_GROUP; break; + case 'x': + flags |= FL_CONTEXT; + break; case 'v': flags |= FL_VERBOSE; break; @@ -108,7 +112,7 @@ fputs(_("Specified both -n and -t but only one of them can be used.\n"), stderr); exit(1); } - if (!(flags & (FL_USER | FL_GROUP))) + if (!(flags & (FL_USER | FL_GROUP | FL_CONTEXT))) flags |= FL_USER; if (!(flags & FL_ALL)) { mnt = argstr + optind; @@ -180,7 +184,7 @@ } endpwent(); } - else { + else if (type == GRPQUOTA) { struct group *grent; setgrent(); @@ -192,7 +196,21 @@ } } endgrent(); - } + } else if (type == CTXQUOTA) { +/* + struct passwd *pwent; + + setpwent(); + while ((pwent = getpwent())) { + for (i = 0; i < cached_dquots && pwent->pw_uid != dquot_cache[i].dq_id; i++); + if (i < cached_dquots) { + print(dquot_cache+i, pwent->pw_name); + dquot_cache[i].dq_flags |= DQ_PRINTED; + } + } + endpwent(); +fixme CONTEXT */ + } for (i = 0; i < cached_dquots; i++) if (!(dquot_cache[i].dq_flags & DQ_PRINTED)) { sprintf(namebuf, "#%u", dquot_cache[i].dq_id); @@ -235,7 +253,9 @@ time2str(h->qh_info.dqi_igrace, igbuf, TF_ROUND); printf(_("Block grace time: %s; Inode grace time: %s\n"), bgbuf, igbuf); printf(_(" Block limits File limits\n")); - printf(_("%-9s used soft hard grace used soft hard grace\n"), (type == USRQUOTA)?_("User"):_("Group")); + printf(_("%-9s used soft hard grace used soft hard grace\n"), + (type == USRQUOTA)?_("User"):((type == GRPQUOTA)?_("Group"): + ((type == CTXQUOTA)?_("Ctx"):_("???")))); printf("----------------------------------------------------------------------\n"); if (h->qh_ops->scan_dquots(h, output) < 0) @@ -275,6 +295,9 @@ if (flags & FL_GROUP) report(GRPQUOTA); + + if (flags & FL_CONTEXT) + report(CTXQUOTA); return 0; } diff -NurBP --minimal quota-tools-3.07/warnquota.c quota-tools-ctx/warnquota.c --- quota-tools-3.07/warnquota.c Tue Jul 23 17:59:27 2002 +++ quota-tools-ctx/warnquota.c Sun Oct 27 04:26:45 2002 @@ -65,6 +65,8 @@ "For additional assistance, please contact us at %s\nor via " \ "phone at %s.\n") +/* fixme CONTEXT */ + #define SHELL "/bin/sh" #define QUOTATAB "/etc/quotatab" #define CNF_BUFFER 2048