[comp.unix.questions] How to remove old uid's from quota file under 4.2 Unix

jeff@drexel.Drexel.edu (Jeff White) (07/13/87)

  Using the quota package under 4.2 BSD, can sometime tell me how (or if
it is possible) to remove old users's uids from the master quota file for
each file system?  Since our machine in used mostly for educational and
research use, many accounts are only temporary.  However, when doing something
like a repquota /usr, I am still forced to see the quota report for uids 
whose accounts have been removed.  I'd really like to be able to remove these,
and so far the only way I can think of is to remove the quota file from each
filesystem and rebuild it from scratch.  This would help to eliminate the 
accounts which were removed a long time a go, but accounts added and then
removed after this would still appear, and I'd be back to my original problem.
Any help would be appreciated.

						Jeff White
						Drexel University - ECE Dept.
						seismo!presby!drexel!jeff

davy@ea.ecn.purdue.edu (Dave Curry) (07/16/87)

In article <480@drexel.Drexel.edu> jeff@drexel.UUCP writes:
>
>  Using the quota package under 4.2 BSD, can sometime tell me how (or if
>it is possible) to remove old users's uids from the master quota file for
>each file system?

There's no existing way to do it, but how about:

	#include <sys/types.h>
	#include <sys/quota.h>
	#include <stdio.h>
	#include <pwd.h>

	main()
	{
		FILE *fpr, *fpw;
		register int uid;
		struct dqblk dqblk;
		struct passwd *getpwuid();

		/*
		 * Use two file pointers to let stdio do buffering.
		 */
		if ((fpr = fopen("quotas", "r")) == NULL) {
			fprintf(stderr, "cannot open quotas file.\n");
			exit(1);
		}

		if ((fpw = fopen("quotas", "w")) == NULL) {
			fprintf(stderr, "cannot open quotas file.\n");
			exit(1);
		}

		i = 0;
		while (fread(&dqblk, sizeof(struct dqblk), 1, fpr) != NULL) {
			/*
			 * Not there, so zip the entry.
			 */
			if (getpwuid(i) == NULL) {
				bzero(&dqblk, sizeof(struct dqblk));
				fseek(fpw, (long) i * sizeof(struct dqblk), 0);
				fwrite(&dqblk, sizeof(struct dqblk), 1, fpw);
			}

			i++;
		}

		fclose(fpr);
		fclose(fpw);
		exit(0);
	}

Note that I haven't tried this, I just wrote it off the top of my head,
so I don't make any guarantees...

--Dave Curry
Purdue University
Engineering Computer Network

mrh@tcom.stc.co.uk (Michael Hopkins) (07/20/87)

In article <189@ea.ecn.purdue.edu> davy@ea.ecn.purdue.edu.UUCP (Dave Curry) writes:
>In article <480@drexel.Drexel.edu> jeff@drexel.UUCP writes:
>>
>>  Using the quota package under 4.2 BSD, can sometime tell me how (or if
>>it is possible) to remove old users's uids from the master quota file for
>>each file system?
>
>There's no existing way to do it, but how about:
>
> [Source included]

We too use the quota package (although we run Ultrix 1.2) and encountered
similar problems to jeff.

By a number of experiments we have observed the following. It seems that 
for quotacheck to do its job properly it needs actual entries in /etc/passwd.
Therefore to remove the numbered users shown by repquota it is necessary to 
have an entry in /etc/passwd corresponding to each numbered user shown by 
repquota.  Quotacheck then seems to clear down these users correctly 
(although we usually run it with the -v option, just to check).

Michael Hopkins
STC Telecommunications.
<mrh@tcom.stc.co.uk>

avolio@decuac.dec.com (Frederick M. Avolio) (07/21/87)

The fix to this (which I recently mailed to the original poster --
tell me if you didnt get it) was posted this past year. quotacheck
needs to clean up the quotas file when it starts up, tossing out
entries for uid's not found in the password file.

Fred